Commit b40a0a3e authored by Kathleen Brade's avatar Kathleen Brade Committed by Georg Koppen
Browse files

Bug #2875: Limit device and system specific CSS Media Queries.

See also Bug #5856.
parent 6e82dc6a
Loading
Loading
Loading
Loading
+53 −33
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ GetDeviceSize(nsPresContext* aPresContext)
{
    nsSize size;

    if (aPresContext->IsDeviceSizePageSize()) {
    if (!aPresContext->IsChrome() || aPresContext->IsDeviceSizePageSize()) {
        size = GetSize(aPresContext);
    } else if (aPresContext->IsRootPaginatedDocument()) {
        // We want the page size, including unprintable areas and margins.
@@ -223,13 +223,17 @@ static nsresult
GetColor(nsPresContext* aPresContext, const nsMediaFeature*,
         nsCSSValue& aResult)
{
    uint32_t depth = 24; // Always assume 24-bit depth for non-chrome callers.

    if (aPresContext->IsChrome()) {
        // FIXME:  This implementation is bogus.  nsDeviceContext
        // doesn't provide reliable information (should be fixed in bug
        // 424386).
        // FIXME: On a monochrome device, return 0!
        nsDeviceContext *dx = GetDeviceContextFor(aPresContext);
    uint32_t depth;
        dx->GetDepth(depth);
    }

    // The spec says to use bits *per color component*, so divide by 3,
    // and round down, since the spec says to use the smallest when the
    // color components differ.
@@ -267,10 +271,15 @@ static nsresult
GetResolution(nsPresContext* aPresContext, const nsMediaFeature*,
              nsCSSValue& aResult)
{
    float dpi = 96; // Always return 96 to non-chrome callers.

    if (aPresContext->IsChrome()) {
      // Resolution measures device pixels per CSS (inch/cm/pixel).  We
      // return it in device pixels per CSS inches.
    float dpi = float(nsPresContext::AppUnitsPerCSSInch()) /
      dpi = float(nsPresContext::AppUnitsPerCSSInch()) /
            float(aPresContext->AppUnitsPerDevPixel());
    }

    aResult.SetFloatValue(dpi, eCSSUnit_Inch);
    return NS_OK;
}
@@ -299,8 +308,12 @@ static nsresult
GetDevicePixelRatio(nsPresContext* aPresContext, const nsMediaFeature*,
                    nsCSSValue& aResult)
{
    if (aPresContext->IsChrome()) {
      float ratio = aPresContext->CSSPixelsToDevPixels(1.0f);
      aResult.SetFloatValue(ratio, eCSSUnit_Number);
    } else {
      aResult.SetFloatValue(1.0, eCSSUnit_Number);
    }
    return NS_OK;
}

@@ -308,11 +321,14 @@ static nsresult
GetSystemMetric(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
                nsCSSValue& aResult)
{
    aResult.Reset();
    if (aPresContext->IsChrome()) {
      MOZ_ASSERT(aFeature->mValueType == nsMediaFeature::eBoolInteger,
                 "unexpected type");
      nsIAtom *metricAtom = *aFeature->mData.mMetric;
      bool hasMetric = nsCSSRuleProcessor::HasSystemMetric(metricAtom);
      aResult.SetIntValue(hasMetric ? 1 : 0, eCSSUnit_Integer);
    }
    return NS_OK;
}

@@ -322,6 +338,7 @@ GetWindowsTheme(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
{
    aResult.Reset();
#ifdef XP_WIN
    if (aPresContext->IsChrome()) {
        uint8_t windowsThemeId =
            nsCSSRuleProcessor::GetWindowsThemeIdentifier();

@@ -337,6 +354,7 @@ GetWindowsTheme(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
                break;
            }
        }
    }
#endif
    return NS_OK;
}
@@ -346,6 +364,8 @@ GetOperatinSystemVersion(nsPresContext* aPresContext, const nsMediaFeature* aFea
                         nsCSSValue& aResult)
{
    aResult.Reset();
    if (!aPresContext->IsChrome()) return NS_OK;

#ifdef XP_WIN
    int32_t metricResult;
    if (NS_SUCCEEDED(