Back out 8e59146e161e:29acf1494fed (bug 790732) for failing in exactly the same way it failed on the tryserver

CLOSED TREE
This commit is contained in:
Phil Ringnalda 2013-03-26 23:40:45 -07:00
parent 0ecf218a04
commit 6463b16c25
14 changed files with 29 additions and 264 deletions

View File

@ -5162,98 +5162,6 @@ LocationSetterUnwrapper(JSContext *cx, JSHandleObject obj_, JSHandleId id, JSBoo
return LocationSetter<nsIDOMWindow>(cx, obj, id, strict, vp);
}
struct InterfaceShimEntry {
const char *geckoName;
const char *domName;
};
// We add shims from Components.interfaces.nsIDOMFoo to window.Foo for each
// interface that has interface constants that sites might be getting off
// of Ci.
const InterfaceShimEntry kInterfaceShimMap[] =
{ { "nsIDOMFileReader", "FileReader" },
{ "nsIXMLHttpRequest", "XMLHttpRequest" },
{ "nsIDOMDOMException", "DOMException" },
{ "nsIDOMNode", "Node" },
{ "nsIDOMUserDataHandler", "UserDataHandler" },
{ "nsIDOMCSSPrimitiveValue", "CSSPrimitiveValue" },
{ "nsIDOMCSSRule", "CSSRule" },
{ "nsIDOMCSSValue", "CSSValue" },
{ "nsIDOMEvent", "Event" },
{ "nsIDOMNSEvent", "Event" },
{ "nsIDOMKeyEvent", "KeyEvent" },
{ "nsIDOMMouseEvent", "MouseEvent" },
{ "nsIDOMMouseScrollEvent", "MouseScrollEvent" },
{ "nsIDOMMutationEvent", "MutationEvent" },
{ "nsIDOMSimpleGestureEvent", "SimpleGestureEvent" },
{ "nsIDOMUIEvent", "UIEvent" },
{ "nsIDOMGeoPositionError", "GeoPositionError" },
{ "nsIDOMHTMLMediaElement", "HTMLMediaElement" },
{ "nsIDOMMediaError", "MediaError" },
{ "nsIDOMLoadStatus", "LoadStatus" },
{ "nsIDOMOfflineResourceList", "OfflineResourceList" },
{ "nsIDOMRange", "Range" },
{ "nsIDOMSVGFETurbulenceElement", "SVGFETurbulenceElement" },
{ "nsIDOMSVGFEMorphologyElement", "SVGFEMorphologyElement" },
{ "nsIDOMSVGFEConvolveMatrixElement", "SVGFEConvolveMatrixElement" },
{ "nsIDOMSVGFEDisplacementMapElement", "SVGFEDisplacementMapElement" },
{ "nsIDOMSVGLength", "SVGLength" },
{ "nsIDOMSVGUnitTypes", "SVGUnitTypes" },
{ "nsIDOMNodeFilter", "NodeFilter" },
{ "nsIDOMXPathNamespace", "XPathNamespace" },
{ "nsIDOMXPathResult", "XPathResult" },
{ "nsIDOMXULButtonElement", "XULButtonElement" },
{ "nsIDOMXULCheckboxElement", "XULCheckboxElement" },
{ "nsIDOMXULPopupElement", "XULPopupElement" } };
static nsresult
DefineComponentsShim(JSContext *cx, JS::HandleObject global)
{
// Keep track of how often this happens.
Telemetry::Accumulate(Telemetry::COMPONENTS_SHIM_ACCESSED_BY_CONTENT, true);
// Create a fake Components object.
JSObject *components = JS_NewObject(cx, nullptr, nullptr, global);
NS_ENSURE_TRUE(components, NS_ERROR_OUT_OF_MEMORY);
bool ok = JS_DefineProperty(cx, global, "Components", JS::ObjectValue(*components),
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE);
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
// Create a fake interfaces object.
JSObject *interfaces = JS_NewObject(cx, nullptr, nullptr, global);
NS_ENSURE_TRUE(interfaces, NS_ERROR_OUT_OF_MEMORY);
ok = JS_DefineProperty(cx, components, "interfaces", JS::ObjectValue(*interfaces),
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY);
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
// Define a bunch of shims from the Ci.nsIDOMFoo to window.Foo for DOM
// interfaces with constants.
for (uint32_t i = 0; i < ArrayLength(kInterfaceShimMap); ++i) {
// Grab the names from the table.
const char *geckoName = kInterfaceShimMap[i].geckoName;
const char *domName = kInterfaceShimMap[i].domName;
// Look up the appopriate interface object on the global.
JS::Value v = JS::UndefinedValue();
ok = JS_GetProperty(cx, global, domName, &v);
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
if (!v.isObject()) {
NS_WARNING("Unable to find interface object on global");
continue;
}
// Define the shim on the interfaces object.
ok = JS_DefineProperty(cx, interfaces, geckoName, v,
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY);
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
}
return NS_OK;
}
NS_IMETHODIMP
nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj_, jsid id_, uint32_t flags,
@ -5266,12 +5174,6 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_OK;
}
MOZ_ASSERT(*_retval == true); // guaranteed by XPC_WN_Helper_NewResolve
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS)) {
*objp = obj;
return DefineComponentsShim(cx, obj);
}
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
MOZ_ASSERT(win->IsInnerWindow());

View File

@ -1971,17 +1971,6 @@ nsGlobalWindow::SetOuterObject(JSContext* aCx, JSObject* aOuterObject)
return NS_OK;
}
// We need certain special behavior for remote XUL whitelisted domains, but we
// don't want that behavior to take effect in automation, because we whitelist
// all the mochitest domains. So we need to check a pref here.
static bool
TreatAsRemoteXUL(nsIPrincipal* aPrincipal)
{
MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(aPrincipal));
return nsContentUtils::AllowXULXBLForPrincipal(aPrincipal) &&
!Preferences::GetBool("dom.use_xbl_scopes_for_remote_xul", false);
}
/**
* Create a new global object that will be used for an inner window.
* Return the native global and an nsISupports 'holder' that can be used
@ -2015,19 +2004,10 @@ CreateNativeGlobalForInner(JSContext* aCx,
nsIXPConnect* xpc = nsContentUtils::XPConnect();
// Determine if we need the Components object.
bool componentsInContent =
!Preferences::GetBool("dom.omit_components_in_content", true) ||
!Preferences::GetBool("dom.xbl_scopes", true);
bool needComponents = componentsInContent ||
nsContentUtils::IsSystemPrincipal(aPrincipal) ||
TreatAsRemoteXUL(aPrincipal);
uint32_t flags = needComponents ? 0 : nsIXPConnect::OMIT_COMPONENTS_OBJECT;
nsRefPtr<nsIXPConnectJSObjectHolder> jsholder;
nsresult rv = xpc->InitClassesWithNewWrappedGlobal(
aCx, ToSupports(aNewInner),
aPrincipal, flags, zoneSpec, getter_AddRefs(jsholder));
aPrincipal, 0, zoneSpec, getter_AddRefs(jsholder));
NS_ENSURE_SUCCESS(rv, rv);
MOZ_ASSERT(jsholder);

View File

@ -4880,7 +4880,8 @@ ContentComponentsGetterOp(JSContext *cx, JSHandleObject obj, JSHandleId id,
// static
JSBool
nsXPCComponents::AttachComponentsObject(XPCCallContext& ccx,
XPCWrappedNativeScope* aScope)
XPCWrappedNativeScope* aScope,
JSObject* aTarget)
{
JSObject *components = aScope->GetComponentsJSObject(ccx);
if (!components)
@ -4888,11 +4889,13 @@ nsXPCComponents::AttachComponentsObject(XPCCallContext& ccx,
JSObject *global = aScope->GetGlobalJSObject();
MOZ_ASSERT(js::IsObjectInContextCompartment(global, ccx));
if (!aTarget)
aTarget = global;
jsid id = ccx.GetRuntime()->GetStringID(XPCJSRuntime::IDX_COMPONENTS);
JSPropertyOp getter = AccessCheck::isChrome(global) ? nullptr
: &ContentComponentsGetterOp;
return JS_DefinePropertyById(ccx, global, id, js::ObjectValue(*components),
return JS_DefinePropertyById(ccx, aTarget, id, js::ObjectValue(*components),
getter, nullptr, JSPROP_PERMANENT | JSPROP_READONLY);
}

View File

@ -282,18 +282,8 @@ EnableUniversalXPConnect(JSContext *cx)
// Recompute all the cross-compartment wrappers leaving the newly-privileged
// compartment.
bool ok = js::RecomputeWrappers(cx, js::SingleCompartment(compartment),
js::AllCompartments());
NS_ENSURE_TRUE(ok, false);
// The Components object normally isn't defined for unprivileged web content,
// but we define it when UniversalXPConnect is enabled to support legacy
// tests.
XPCWrappedNativeScope *scope = priv->scope;
if (!scope)
return true;
XPCCallContext ccx(NATIVE_CALLER, cx);
return nsXPCComponents::AttachComponentsObject(ccx, scope);
return js::RecomputeWrappers(cx, js::SingleCompartment(compartment),
js::AllCompartments());
}
}

View File

@ -946,6 +946,9 @@ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj)
scope->RemoveWrappedNativeProtos();
if (!nsXPCComponents::AttachComponentsObject(ccx, scope))
return UnexpectedFailure(NS_ERROR_FAILURE);
if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, aGlobalJSObj))
return UnexpectedFailure(NS_ERROR_FAILURE);

View File

@ -3722,9 +3722,13 @@ public:
NS_DECL_NSISECURITYCHECKEDCOMPONENT
public:
// The target is the object upon which |Components| will be defined. If
// aTarget is left null, a default object will be computed. This is usually
// the right thing to do.
static JSBool
AttachComponentsObject(XPCCallContext& ccx,
XPCWrappedNativeScope* aScope);
XPCWrappedNativeScope* aScope,
JSObject* aTarget = NULL);
void SystemIsBeingShutDown() {ClearMembers();}

View File

@ -20,14 +20,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=795275
/** Test for Warning in content scopes about Components. **/
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({set: [['dom.omit_components_in_content', false]]}, startLoad);
function startLoad() {
for (var i = 1; i <= document.getElementsByTagName('iframe').length; ++i) {
var frame = document.getElementById('frame' + i);
frame.contentWindow.location = 'http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug795275.html';
frame.onload = frameLoaded;
}
}
// Set up our console listener.
var gWarnings = 0;
@ -81,10 +73,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=795275
]]>
</script>
<iframe id="frame1"/>
<iframe id="frame2"/>
<iframe id="frame3"/>
<iframe id="frame4"/>
<iframe id="frame5"/>
<iframe id="frame1" onload="frameLoaded();" type="content" src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug795275.html" />
<iframe id="frame2" onload="frameLoaded();" type="content" src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug795275.html" />
<iframe id="frame3" onload="frameLoaded();" type="content" src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug795275.html" />
<iframe id="frame4" onload="frameLoaded();" type="content" src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug795275.html" />
<iframe id="frame5" onload="frameLoaded();" type="content" src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug795275.html" />
</window>

View File

@ -80,8 +80,6 @@ MOCHITEST_FILES = chrome_wrappers_helper.html \
file_bug781476.html \
test_bug785096.html \
test_bug789713.html \
test_bug790732.html \
file_bug790732.html \
test_bug793969.html \
file_bug795275.html \
file_bug795275.xml \

View File

@ -1,56 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<script>
function testShim() {
// Basic stuff
ok(Components, "Components shim exists!");
var Ci = Components.interfaces;
ok(Ci, "interfaces shim exists!");
is(typeof Components.classes, 'undefined', "Shouldn't have a Cc");
// Check each interface that we shim. We start by checking specific
// constants for a couple of interfaces, and then once it's pretty clear that
// it's working as intended we just check that the objects themselves are the
// same.
is(Ci.nsIDOMFileReader.DONE, FileReader.DONE);
is(Ci.nsIXMLHttpRequest.HEADERS_RECEIVED, XMLHttpRequest.HEADERS_RECEIVED);
is(Ci.nsIDOMDOMException.DATA_CLONE_ERR, DOMException.DATA_CLONE_ERR);
is(Ci.nsIDOMNode.DOCUMENT_NODE, Node.DOCUMENT_NODE);
is(Ci.nsIDOMUserDataHandler.NODE_CLONED, UserDataHandler.NODE_CLONED);
is(Ci.nsIDOMCSSPrimitiveValue.CSS_PX, CSSPrimitiveValue.CSS_PX);
is(Ci.nsIDOMCSSRule.NAMESPACE_RULE, CSSRule.NAMESPACE_RULE);
is(Ci.nsIDOMCSSValue.CSS_PRIMITIVE_VALUE, CSSValue.CSS_PRIMITIVE_VALUE);
is(Ci.nsIDOMEvent.FOCUS, Event.FOCUS);
is(Ci.nsIDOMNSEvent.CLICK, Event.CLICK);
is(Ci.nsIDOMKeyEvent, KeyEvent);
is(Ci.nsIDOMMouseEvent, MouseEvent);
is(Ci.nsIDOMMouseScrollEvent, MouseScrollEvent);
is(Ci.nsIDOMMutationEvent, MutationEvent);
is(Ci.nsIDOMSimpleGestureEvent, SimpleGestureEvent);
is(Ci.nsIDOMUIEvent, UIEvent);
is(Ci.nsIDOMGeoPositionError, GeoPositionError);
is(Ci.nsIDOMHTMLMediaElement, HTMLMediaElement);
is(Ci.nsIDOMMediaError, MediaError);
is(Ci.nsIDOMLoadStatus, LoadStatus);
is(Ci.nsIDOMOfflineResourceList, OfflineResourceList);
is(Ci.nsIDOMRange, Range);
is(Ci.nsIDOMSVGFETurbulenceElement, SVGFETurbulenceElement);
is(Ci.nsIDOMSVGFEMorphologyElement, SVGFEMorphologyElement);
is(Ci.nsIDOMSVGFEConvolveMatrixElement, SVGFEConvolveMatrixElement);
is(Ci.nsIDOMSVGFEDisplacementMapElement, SVGFEDisplacementMapElement);
is(Ci.nsIDOMSVGLength, SVGLength);
is(Ci.nsIDOMSVGUnitTypes, SVGUnitTypes);
is(Ci.nsIDOMNodeFilter, NodeFilter);
is(Ci.nsIDOMXPathNamespace, XPathNamespace);
is(Ci.nsIDOMXPathResult, XPathResult);
is(Ci.nsIDOMXULButtonElement, XULButtonElement);
is(Ci.nsIDOMXULCheckboxElement, XULCheckboxElement);
is(Ci.nsIDOMXULPopupElement, XULPopupElement);
}
</script>
</head>
<body>
</body>
</html>

View File

@ -1,46 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=790732
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 790732</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 the Components shim. We split into two files because this stuff
is currently pref-controlled. **/
SimpleTest.waitForExplicitFinish();
function prepare() {
SpecialPowers.pushPrefEnv({set: [['dom.omit_components_in_content', true]]},
function () { $('ifr').onload = go;
$('ifr').contentWindow.location =
'file_bug790732.html'; }
);
}
function go() {
ok(true, "Started test");
var iwin = $('ifr').contentWindow;
iwin.ok = ok;
iwin.is = is;
iwin.testShim();
SimpleTest.finish();
}
</script>
</head>
<body onload="prepare()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=790732">Mozilla Bug 790732</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<iframe id="ifr"></iframe>
</body>
</html>

View File

@ -715,9 +715,6 @@ pref("dom.min_background_timeout_value", 1000);
// Run content XBL in a separate scope.
pref("dom.xbl_scopes", true);
// Stop defining the Components object in content.
pref("dom.omit_components_in_content", false);
// Don't use new input types
pref("dom.experimental_forms", false);

View File

@ -138,7 +138,7 @@ var resolveCallback = {
const interfaces = [Ci.nsIProtocolProxyCallback, Ci.nsISupports];
if (!interfaces.some( function(v) { return iid.equals(v) } ))
throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
@ -160,10 +160,12 @@ var resolveCallback = {
function startup() {
//need to allow for arbitrary network servers defined in PAC instead of a hardcoded moz-proxy.
var ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"].
getService(SpecialPowers.Ci.nsIIOService);
var ios = SpecialPowers.wrap(Components).
classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var pps = SpecialPowers.Cc["@mozilla.org/network/protocol-proxy-service;1"].getService();
var pps = SpecialPowers.wrap(Components).
classes["@mozilla.org/network/protocol-proxy-service;1"].getService();
var uri = ios.newURI("http://example.com", null, null);
pps.asyncResolve(uri, 0, resolveCallback);
@ -181,7 +183,7 @@ var storageObserver = {
Ci.nsISupports, Ci.nsISupportsWeakReference];
if (!interfaces.some( function(v) { return iid.equals(v) } ))
throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE;
return this;
},

View File

@ -122,7 +122,7 @@ const shiftModifier = Event.SHIFT_MASK;
// Get the form history service
var fh = SpecialPowers.Cc["@mozilla.org/satchel/form-history;1"].
getService(SpecialPowers.Ci.nsIFormHistory2);
getService(Components.interfaces.nsIFormHistory2);
ok(fh != null, "got form history service");
fh.removeAllEntries();

View File

@ -2895,10 +2895,6 @@
"kind": "flag",
"description": "Whether content ever accesed Components.interfaces in this session"
},
"COMPONENTS_SHIM_ACCESSED_BY_CONTENT": {
"kind": "flag",
"description": "Whether content ever accesed the Components shim in this session"
},
"CHECK_ADDONS_MODIFIED_MS": {
"kind": "exponential",
"high": "5000",