Bug 1410074: Restrict system metric stuff in content pages. r=xidorn

MozReview-Commit-ID: 6rmMQfr8fzf
This commit is contained in:
Emilio Cobos Álvarez 2017-10-19 16:23:45 +02:00
Родитель e1d5b96032
Коммит 93d40bb9bb
3 изменённых файлов: 81 добавлений и 74 удалений

Просмотреть файл

@ -394,6 +394,9 @@ GetSystemMetric(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
const bool isAccessibleFromContentPages =
!(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
MOZ_ASSERT(!isAccessibleFromContentPages ||
*aFeature->mName == nsGkAtoms::_moz_touch_enabled);
if (isAccessibleFromContentPages &&
ShouldResistFingerprinting(aPresContext)) {
// If "privacy.resistFingerprinting" is enabled, then we simply don't
@ -404,6 +407,7 @@ GetSystemMetric(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
MOZ_ASSERT(aFeature->mValueType == nsMediaFeature::eBoolInteger,
"unexpected type");
nsAtom* metricAtom = *aFeature->mData.mMetric;
bool hasMetric = nsCSSRuleProcessor::HasSystemMetric(metricAtom);
aResult.SetIntValue(hasMetric ? 1 : 0, eCSSUnit_Integer);
@ -414,6 +418,8 @@ GetWindowsTheme(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
nsCSSValue& aResult)
{
aResult.Reset();
MOZ_ASSERT(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
if (ShouldResistFingerprinting(aPresContext)) {
return;
}
@ -442,6 +448,8 @@ GetOperatingSystemVersion(nsPresContext* aPresContext, const nsMediaFeature* aFe
nsCSSValue& aResult)
{
aResult.Reset();
MOZ_ASSERT(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
if (ShouldResistFingerprinting(aPresContext)) {
return;
}
@ -466,6 +474,7 @@ static void
GetIsGlyph(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
nsCSSValue& aResult)
{
MOZ_ASSERT(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
aResult.SetIntValue(aPresContext->IsGlyph() ? 1 : 0, eCSSUnit_Integer);
}
@ -683,7 +692,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_overlay_scrollbars,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::overlay_scrollbars },
GetSystemMetric
},
@ -691,7 +700,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_windows_default_theme,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::windows_default_theme },
GetSystemMetric
},
@ -699,7 +708,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_mac_graphite_theme,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::mac_graphite_theme },
GetSystemMetric
},
@ -707,7 +716,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_mac_yosemite_theme,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::mac_yosemite_theme },
GetSystemMetric
},
@ -715,7 +724,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_windows_accent_color_in_titlebar,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::windows_accent_color_in_titlebar },
GetSystemMetric
},
@ -723,7 +732,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_windows_compositor,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::windows_compositor },
GetSystemMetric
},
@ -731,7 +740,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_windows_classic,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::windows_classic },
GetSystemMetric
},
@ -739,7 +748,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_windows_glass,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::windows_glass },
GetSystemMetric
},
@ -747,6 +756,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_touch_enabled,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
// FIXME(emilio): Restrict (or remove?) when bug 1035774 lands.
nsMediaFeature::eNoRequirements,
{ &nsGkAtoms::touch_enabled },
GetSystemMetric
@ -755,7 +765,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_menubar_drag,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::menubar_drag },
GetSystemMetric
},
@ -763,7 +773,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_windows_theme,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eIdent,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ nullptr },
GetWindowsTheme
},
@ -771,7 +781,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_os_version,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eIdent,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ nullptr },
GetOperatingSystemVersion
},
@ -780,7 +790,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_swipe_animation_enabled,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ &nsGkAtoms::swipe_animation_enabled },
GetSystemMetric
},
@ -792,7 +802,7 @@ nsMediaFeatures::features[] = {
&nsGkAtoms::_moz_is_glyph,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eBoolInteger,
nsMediaFeature::eNoRequirements,
nsMediaFeature::eUserAgentAndChromeOnly,
{ nullptr },
GetIsGlyph
},

Просмотреть файл

@ -4,6 +4,8 @@
/* jshint loopfunc:true */
/* global window, screen, ok, SpecialPowers, matchMedia */
const is_chrome_window = window.location.protocol === "chrome:";
// Expected values. Format: [name, pref_off_value, pref_on_value]
// If pref_*_value is an array with two values, then we will match
// any value in between those two values. If a value is null, then
@ -52,11 +54,7 @@ var suppressed_toggles = [
];
var toggles_enabled_in_content = [
"-moz-mac-graphite-theme",
"-moz-touch-enabled",
"-moz-windows-compositor",
"-moz-windows-default-theme",
"-moz-windows-glass",
];
// Possible values for '-moz-os-version'
@ -113,7 +111,7 @@ var testToggles = function (resisting) {
suppressed_toggles.forEach(
function (key) {
var exists = keyValMatches(key, 0) || keyValMatches(key, 1);
if (resisting || toggles_enabled_in_content.indexOf(key) === -1) {
if (resisting || (toggles_enabled_in_content.indexOf(key) === -1 && !is_chrome_window)) {
ok(!exists, key + " should not exist.");
} else {
ok(exists, key + " should exist.");
@ -202,7 +200,6 @@ var suppressedMediaQueryCSSLine = function (key, color, suppressed) {
// expected value, then the element will be colored green.
var generateCSSLines = function (resisting) {
let lines = ".spoof { background-color: red;}\n";
let is_chrome_window = window.location.protocol === "chrome:";
expected_values.forEach(
function ([key, offVal, onVal]) {
lines += mediaQueryCSSLine(key, resisting ? onVal : offVal, "green");

Просмотреть файл

@ -638,48 +638,48 @@ function run() {
expression_should_not_be_parseable("-moz-scrollbar-end-backward");
expression_should_not_be_parseable("-moz-scrollbar-end-forward");
expression_should_not_be_parseable("-moz-scrollbar-thumb-proportional");
expression_should_be_parseable("-moz-overlay-scrollbars");
expression_should_be_parseable("-moz-windows-default-theme");
expression_should_be_parseable("-moz-mac-graphite-theme");
expression_should_be_parseable("-moz-mac-yosemite-theme");
expression_should_be_parseable("-moz-windows-accent-color-in-titlebar");
expression_should_be_parseable("-moz-windows-compositor");
expression_should_be_parseable("-moz-windows-classic");
expression_should_be_parseable("-moz-windows-glass");
expression_should_not_be_parseable("-moz-overlay-scrollbars");
expression_should_not_be_parseable("-moz-windows-default-theme");
expression_should_not_be_parseable("-moz-mac-graphite-theme");
expression_should_not_be_parseable("-moz-mac-yosemite-theme");
expression_should_not_be_parseable("-moz-windows-accent-color-in-titlebar");
expression_should_not_be_parseable("-moz-windows-compositor");
expression_should_not_be_parseable("-moz-windows-classic");
expression_should_not_be_parseable("-moz-windows-glass");
expression_should_not_be_parseable("-moz-swipe-animation-enabled");
expression_should_be_parseable("-moz-touch-enabled");
expression_should_be_parseable("-moz-swipe-animation-enabled");
expression_should_not_be_parseable("-moz-scrollbar-start-backward: 0");
expression_should_not_be_parseable("-moz-scrollbar-start-forward: 0");
expression_should_not_be_parseable("-moz-scrollbar-end-backward: 0");
expression_should_not_be_parseable("-moz-scrollbar-end-forward: 0");
expression_should_not_be_parseable("-moz-scrollbar-thumb-proportional: 0");
expression_should_be_parseable("-moz-overlay-scrollbars: 0");
expression_should_be_parseable("-moz-windows-default-theme: 0");
expression_should_be_parseable("-moz-mac-graphite-theme: 0");
expression_should_be_parseable("-moz-mac-yosemite-theme: 0");
expression_should_be_parseable("-moz-windows-accent-color-in-titlebar: 0");
expression_should_be_parseable("-moz-windows-compositor: 0");
expression_should_be_parseable("-moz-windows-classic: 0");
expression_should_be_parseable("-moz-windows-glass: 0");
expression_should_not_be_parseable("-moz-overlay-scrollbars: 0");
expression_should_not_be_parseable("-moz-windows-default-theme: 0");
expression_should_not_be_parseable("-moz-mac-graphite-theme: 0");
expression_should_not_be_parseable("-moz-mac-yosemite-theme: 0");
expression_should_not_be_parseable("-moz-windows-accent-color-in-titlebar: 0");
expression_should_not_be_parseable("-moz-windows-compositor: 0");
expression_should_not_be_parseable("-moz-windows-classic: 0");
expression_should_not_be_parseable("-moz-windows-glass: 0");
expression_should_not_be_parseable("-moz-swipe-animation-enabled: 0");
expression_should_be_parseable("-moz-touch-enabled: 0");
expression_should_be_parseable("-moz-swipe-animation-enabled: 0");
expression_should_not_be_parseable("-moz-scrollbar-start-backward: 1");
expression_should_not_be_parseable("-moz-scrollbar-start-forward: 1");
expression_should_not_be_parseable("-moz-scrollbar-end-backward: 1");
expression_should_not_be_parseable("-moz-scrollbar-end-forward: 1");
expression_should_not_be_parseable("-moz-scrollbar-thumb-proportional: 1");
expression_should_be_parseable("-moz-overlay-scrollbars: 1");
expression_should_be_parseable("-moz-windows-default-theme: 1");
expression_should_be_parseable("-moz-mac-graphite-theme: 1");
expression_should_be_parseable("-moz-mac-yosemite-theme: 1");
expression_should_be_parseable("-moz-windows-accent-color-in-titlebar: 1");
expression_should_be_parseable("-moz-windows-compositor: 1");
expression_should_be_parseable("-moz-windows-classic: 1");
expression_should_be_parseable("-moz-windows-glass: 1");
expression_should_not_be_parseable("-moz-overlay-scrollbars: 1");
expression_should_not_be_parseable("-moz-windows-default-theme: 1");
expression_should_not_be_parseable("-moz-mac-graphite-theme: 1");
expression_should_not_be_parseable("-moz-mac-yosemite-theme: 1");
expression_should_not_be_parseable("-moz-windows-accent-color-in-titlebar: 1");
expression_should_not_be_parseable("-moz-windows-compositor: 1");
expression_should_not_be_parseable("-moz-windows-classic: 1");
expression_should_not_be_parseable("-moz-windows-glass: 1");
expression_should_not_be_parseable("-moz-swipe-animation-enabled: 1");
expression_should_be_parseable("-moz-touch-enabled: 1");
expression_should_be_parseable("-moz-swipe-animation-enabled: 1");
expression_should_not_be_parseable("-moz-scrollbar-start-backward: -1");
expression_should_not_be_parseable("-moz-scrollbar-start-forward: -1");
@ -714,55 +714,55 @@ function run() {
expression_should_not_be_parseable("-moz-swipe-animation-enabled: true");
// windows theme media queries
expression_should_be_parseable("-moz-windows-theme: aero");
expression_should_be_parseable("-moz-windows-theme: aero-lite");
expression_should_be_parseable("-moz-windows-theme: luna-blue");
expression_should_be_parseable("-moz-windows-theme: luna-olive");
expression_should_be_parseable("-moz-windows-theme: luna-silver");
expression_should_be_parseable("-moz-windows-theme: royale");
expression_should_be_parseable("-moz-windows-theme: generic");
expression_should_be_parseable("-moz-windows-theme: zune");
expression_should_be_parseable("-moz-windows-theme: garbage");
expression_should_not_be_parseable("-moz-windows-theme: aero");
expression_should_not_be_parseable("-moz-windows-theme: aero-lite");
expression_should_not_be_parseable("-moz-windows-theme: luna-blue");
expression_should_not_be_parseable("-moz-windows-theme: luna-olive");
expression_should_not_be_parseable("-moz-windows-theme: luna-silver");
expression_should_not_be_parseable("-moz-windows-theme: royale");
expression_should_not_be_parseable("-moz-windows-theme: generic");
expression_should_not_be_parseable("-moz-windows-theme: zune");
expression_should_not_be_parseable("-moz-windows-theme: garbage");
expression_should_not_be_parseable("-moz-windows-theme: ''");
expression_should_not_be_parseable("-moz-windows-theme: ");
// os version media queries (currently windows only)
expression_should_be_parseable("-moz-os-version: windows-win7");
expression_should_be_parseable("-moz-os-version: windows-win8");
expression_should_be_parseable("-moz-os-version: windows-win10");
expression_should_not_be_parseable("-moz-os-version: windows-win7");
expression_should_not_be_parseable("-moz-os-version: windows-win8");
expression_should_not_be_parseable("-moz-os-version: windows-win10");
expression_should_not_be_parseable("-moz-os-version: ");
// OpenType SVG media features
query_should_be_parseable("(-moz-is-glyph)");
query_should_not_be_parseable("(-moz-is-glyph)");
query_should_not_be_parseable("not (-moz-is-glyph)");
query_should_not_be_parseable("only (-moz-is-glyph)");
query_should_be_parseable("all and (-moz-is-glyph)");
query_should_be_parseable("not all and (-moz-is-glyph)");
query_should_be_parseable("only all and (-moz-is-glyph)");
query_should_not_be_parseable("all and (-moz-is-glyph)");
query_should_not_be_parseable("not all and (-moz-is-glyph)");
query_should_not_be_parseable("only all and (-moz-is-glyph)");
query_should_be_parseable("(-moz-is-glyph:0)");
query_should_not_be_parseable("(-moz-is-glyph:0)");
query_should_not_be_parseable("not (-moz-is-glyph:0)");
query_should_not_be_parseable("only (-moz-is-glyph:0)");
query_should_be_parseable("all and (-moz-is-glyph:0)");
query_should_be_parseable("not all and (-moz-is-glyph:0)");
query_should_be_parseable("only all and (-moz-is-glyph:0)");
query_should_not_be_parseable("all and (-moz-is-glyph:0)");
query_should_not_be_parseable("not all and (-moz-is-glyph:0)");
query_should_not_be_parseable("only all and (-moz-is-glyph:0)");
query_should_be_parseable("(-moz-is-glyph:1)");
query_should_not_be_parseable("(-moz-is-glyph:1)");
query_should_not_be_parseable("not (-moz-is-glyph:1)");
query_should_not_be_parseable("only (-moz-is-glyph:1)");
query_should_be_parseable("all and (-moz-is-glyph:1)");
query_should_be_parseable("not all and (-moz-is-glyph:1)");
query_should_be_parseable("only all and (-moz-is-glyph:1)");
query_should_not_be_parseable("all and (-moz-is-glyph:1)");
query_should_not_be_parseable("not all and (-moz-is-glyph:1)");
query_should_not_be_parseable("only all and (-moz-is-glyph:1)");
query_should_not_be_parseable("(min--moz-is-glyph:0)");
query_should_not_be_parseable("(max--moz-is-glyph:0)");
query_should_not_be_parseable("(min--moz-is-glyph:1)");
query_should_not_be_parseable("(max--moz-is-glyph:1)");
should_apply("not all and (-moz-is-glyph)");
should_apply("(-moz-is-glyph:0)");
should_apply("not all and (-moz-is-glyph:1)");
should_apply("only all and (-moz-is-glyph:0)");
should_not_apply("not all and (-moz-is-glyph)");
should_not_apply("(-moz-is-glyph:0)");
should_not_apply("not all and (-moz-is-glyph:1)");
should_not_apply("only all and (-moz-is-glyph:0)");
should_not_apply("(-moz-is-glyph)");
should_not_apply("(-moz-is-glyph:1)");
should_not_apply("not all and (-moz-is-glyph:0)");