Bug 1448048. Restrict the window.Components shim to non-nightly-only to see whether sites actually use it. r=mccr8

MozReview-Commit-ID: 6W1nEyKGlER
This commit is contained in:
Boris Zbarsky 2018-03-23 12:53:48 -04:00
Родитель 0fc607c372
Коммит de9297b4bf
12 изменённых файлов: 91 добавлений и 22 удалений

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

@ -3026,7 +3026,15 @@ nsGlobalWindowInner::DoResolve(JSContext* aCx, JS::Handle<JSObject*> aObj,
// We support a cut-down Components.interfaces in case websites are
// using Components.interfaces.nsIFoo.CONSTANT_NAME for the ones
// that have constants.
if (aId == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
static bool watchingComponentsPref = false;
static bool useComponentsShim = false;
if (!watchingComponentsPref) {
watchingComponentsPref = true;
Preferences::AddBoolVarCache(&useComponentsShim, "dom.use_components_shim",
true);
}
if (useComponentsShim &&
aId == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
return ResolveComponentsShim(aCx, aObj, aDesc);
}

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

@ -60,7 +60,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
if ("id" in e.target) {
s = s + ", id=\"" + e.target.id + "\"";
}
ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
ok(e.eventPhase == Event.CAPTURING_PHASE,
"|window| should not have got a focus event, " + s);
}
@ -86,7 +86,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
if ("id" in e.target) {
s = s + ", id=\"" + e.target.id + "\"";
}
ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
ok(e.eventPhase == Event.CAPTURING_PHASE,
"|window| should not have got a blur event, " + s);
}

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

@ -16,7 +16,7 @@ var testGenerator = testSteps();
// placebo for compat. An easy way to differentiate this from the real thing
// is whether the property is read-only or not.
var c = Object.getOwnPropertyDescriptor(this, "Components");
if ((!c.value || c.writable) && typeof SpecialPowers === "object") {
if ((!c || !c.value || c.writable) && typeof SpecialPowers === "object") {
// eslint-disable-next-line no-native-reassign
Components = SpecialPowers.Components;
}

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

@ -20,7 +20,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=795275
/** Test for Warning in content scopes about Components. **/
SimpleTest.waitForExplicitFinish();
SimpleTest.executeSoon(startLoad);
SimpleTest.executeSoon(function() {
SpecialPowers.pushPrefEnv({set: [["dom.use_components_shim", true]]},
startLoad)
});
function startLoad() {
for (var i = 1; i <= document.getElementsByTagName('iframe').length; ++i) {
var frame = document.getElementById('frame' + i);

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

@ -95,6 +95,7 @@ support-files =
[test_bug1005806.html]
[test_bug1094930.html]
[test_bug1158558.html]
[test_bug1448048.html]
[test_crosscompartment_weakmap.html]
[test_frameWrapping.html]
# The JS test component we use below is only available in debug builds.

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

@ -0,0 +1,31 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1448048
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1448048</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1448048 **/
var {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
if (AppConstants.NIGHTLY_BUILD) {
is(typeof Components, "undefined", "Should be no Components shim on Nightly");
} else {
is(typeof Components, "object", "Should have a components shim on non-Nightly");
}
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1448048">Mozilla Bug 1448048</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

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

@ -9,6 +9,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=790732
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
async function doTest() {
await SpecialPowers.pushPrefEnv({set: [["dom.use_components_shim", true]]})
// Basic stuff
ok(Components, "Components shim exists!");
@ -38,6 +42,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=790732
is(Ci.nsIDOMRange, Range);
is(Ci.nsIDOMNodeFilter, NodeFilter);
is(Ci.nsIDOMXPathResult, XPathResult);
SimpleTest.finish();
}
doTest();
</script>
</head>
<body>

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

@ -14,7 +14,7 @@
// is whether the property is read-only or not.
{
let c = Object.getOwnPropertyDescriptor(this, "Components");
if ((!c.value || c.writable) && typeof SpecialPowers === "object")
if ((!c || !c.value || c.writable) && typeof SpecialPowers === "object")
Components = SpecialPowers.wrap(SpecialPowers.Components);
}

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

@ -1386,6 +1386,13 @@ pref("dom.input.skip_cursor_move_for_same_value_set", true);
pref("dom.cycle_collector.incremental", true);
// Whether to shim a Components object on untrusted windows.
#ifdef NIGHTLY_BUILD
pref("dom.use_components_shim", false);
#else // NIGHTLY_BUILD
pref("dom.use_components_shim", true);
#endif // NIGHTLY_BUILD
// Parsing perf prefs. For now just mimic what the old code did.
#ifndef XP_WIN
pref("content.sink.pending_event_mode", 0);

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

@ -268,7 +268,7 @@ class TestExecuteContent(MarionetteTestCase):
exists = send("return typeof {} != 'undefined'".format(property))
self.assertTrue(exists, "property {} is undefined".format(property))
self.assertTrue(send("return typeof Components.utils == 'undefined'"))
self.assertTrue(send("return (typeof Components == 'undefined') || (typeof Components.utils == 'undefined')"))
self.assertTrue(send("return typeof window.wrappedJSObject == 'undefined'"))
def test_no_callback(self):

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

@ -28,22 +28,24 @@
// be careful about our access to Components.interfaces. We also want to avoid
// naming collisions with anything that might be defined in the scope that imports
// this script.
//
// Even if the real |Components| doesn't exist, we might shim in a simple JS
// placebo for compat. An easy way to differentiate this from the real thing
// is whether the property is read-only or not. The real |Components| property
// is read-only.
window.__defineGetter__('_EU_Ci', function() {
// Even if the real |Components| doesn't exist, we might shim in a simple JS
// placebo for compat. An easy way to differentiate this from the real thing
// is whether the property is read-only or not.
var c = Object.getOwnPropertyDescriptor(window, 'Components');
return c.value && !c.writable ? Ci : SpecialPowers.Ci;
return c && c.value && !c.writable ? Ci : SpecialPowers.Ci;
});
window.__defineGetter__('_EU_Cc', function() {
var c = Object.getOwnPropertyDescriptor(window, 'Components');
return c.value && !c.writable ? Cc : SpecialPowers.Cc;
return c && c.value && !c.writable ? Cc : SpecialPowers.Cc;
});
window.__defineGetter__('_EU_Cu', function() {
var c = Object.getOwnPropertyDescriptor(window, 'Components');
return c.value && !c.writable ? Cu : SpecialPowers.Cu;
return c && c.value && !c.writable ? Cu : SpecialPowers.Cu;
});
window.__defineGetter__("_EU_OS", function() {
@ -119,12 +121,12 @@ function _EU_maybeWrap(o) {
return o;
}
var c = Object.getOwnPropertyDescriptor(window, 'Components');
return c.value && !c.writable ? o : SpecialPowers.wrap(o);
return c && c.value && !c.writable ? o : SpecialPowers.wrap(o);
}
function _EU_maybeUnwrap(o) {
var c = Object.getOwnPropertyDescriptor(window, 'Components');
return c.value && !c.writable ? o : SpecialPowers.unwrap(o);
return c && c.value && !c.writable ? o : SpecialPowers.unwrap(o);
}
/**
@ -2361,9 +2363,7 @@ function synthesizeDragStart(element, expectedDragData, aWindow, x, y)
var trapDrag = function(event) {
try {
// We must wrap only in plain mochitests, not chrome
var c = Object.getOwnPropertyDescriptor(window, 'Components');
var dataTransfer = c.value && !c.writable
? event.dataTransfer : SpecialPowers.wrap(event.dataTransfer);
var dataTransfer = _EU_maybeWrap(event.dataTransfer);
result = null;
if (!dataTransfer)
throw "no dataTransfer";

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

@ -865,10 +865,20 @@ SimpleTest.waitForFocus = function (callback, targetWindow, expectBlankPage) {
// If this is a request to focus a remote child window, the request must
// be forwarded to the child process.
// XXXndeakin now sure what this issue with Components.utils is about, but
// browser tests require the former and plain tests require the latter.
var Cu = Components.utils || SpecialPowers.Cu;
var Ci = Components.interfaces || SpecialPowers.Ci;
//
// Even if the real |Components| doesn't exist, we might shim in a simple JS
// placebo for compat. An easy way to differentiate this from the real thing
// is whether the property is read-only or not. The real |Components|
// property is read-only.
var c = Object.getOwnPropertyDescriptor(window, 'Components');
var Cu, Ci;
if (c && c.value && !c.writable) {
Cu = Components.utils;
Ci = Components.interfaces;
} else {
Cu = SpecialPowers.Cu;
Ci = SpecialPowers.Ci;
}
var browser = null;
if (typeof(XULElement) != "undefined" &&