From ad384dbcf6a863e4e2d8af89f163d6cb074726bd Mon Sep 17 00:00:00 2001 From: Masatoshi Kimura Date: Tue, 20 Aug 2013 02:44:31 +0900 Subject: [PATCH] Bug 856424 - Unpref Components for content. r=bholley --- dom/base/nsDOMClassInfo.cpp | 17 ++++-- dom/base/nsGlobalWindow.cpp | 4 +- js/xpconnect/src/XPCComponents.cpp | 45 +------------- js/xpconnect/tests/chrome/test_bug795275.xul | 6 +- js/xpconnect/tests/mochitest/Makefile.in | 1 - .../tests/mochitest/file_bug790732.html | 54 ----------------- .../tests/mochitest/file_bug795275.html | 2 +- .../tests/mochitest/test_bug790732.html | 58 +++++++++++++------ modules/libpref/src/init/all.js | 3 - toolkit/components/telemetry/Histograms.json | 12 ---- .../tests/chrome/sandbox_content_perms.html | 12 ++-- 11 files changed, 63 insertions(+), 151 deletions(-) delete mode 100644 js/xpconnect/tests/mochitest/file_bug790732.html diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index d2b7ec0dab5f..afe13845ce60 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -3577,11 +3577,17 @@ const InterfaceShimEntry kInterfaceShimMap[] = { "nsIDOMXPathResult", "XPathResult" } }; static nsresult -DefineComponentsShim(JSContext *cx, JS::HandleObject global) +DefineComponentsShim(JSContext *cx, JS::HandleObject global, nsPIDOMWindow *win) { // Keep track of how often this happens. Telemetry::Accumulate(Telemetry::COMPONENTS_SHIM_ACCESSED_BY_CONTENT, true); + // Warn once. + nsCOMPtr doc = win->GetExtantDoc(); + if (doc) { + doc->WarnOnceAbout(nsIDocument::eComponents, /* asError = */ true); + } + // Create a fake Components object. JS::Rooted components(cx, JS_NewObject(cx, nullptr, nullptr, global)); NS_ENSURE_TRUE(components, NS_ERROR_OUT_OF_MEMORY); @@ -3637,14 +3643,15 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, } 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()); + if (id == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS)) { + *objp = obj; + return DefineComponentsShim(cx, obj, win); + } + nsIScriptContext *my_context = win->GetContextInternal(); // Don't resolve standard classes on XrayWrappers, only resolve them if we're diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index c9e35ad24f73..6fda33b80ab5 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2111,9 +2111,7 @@ CreateNativeGlobalForInner(JSContext* aCx, nsIXPConnect* xpc = nsContentUtils::XPConnect(); // Determine if we need the Components object. - bool componentsInContent = !Preferences::GetBool("dom.omit_components_in_content", true); - bool needComponents = componentsInContent || - nsContentUtils::IsSystemPrincipal(aPrincipal) || + bool needComponents = nsContentUtils::IsSystemPrincipal(aPrincipal) || TreatAsRemoteXUL(aPrincipal); uint32_t flags = needComponents ? 0 : nsIXPConnect::OMIT_COMPONENTS_OBJECT; diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index d8faca5875d1..a8996ce7bb75 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -5231,35 +5231,6 @@ nsXPCComponents::SetProperty(nsIXPConnectWrappedNative *wrapper, return NS_ERROR_XPC_CANT_MODIFY_PROP_ON_WN; } -static bool -ContentComponentsGetterOp(JSContext *cx, HandleObject obj, HandleId id, - MutableHandleValue vp) -{ - // If chrome is accessing the Components object of content, allow. - MOZ_ASSERT(nsContentUtils::GetCurrentJSContext() == cx); - if (nsContentUtils::IsCallerChrome()) - return true; - - // If the caller is XBL, this is ok. - if (nsContentUtils::IsCallerXBL()) - return true; - - // Do Telemetry on how often this happens. - Telemetry::Accumulate(Telemetry::COMPONENTS_OBJECT_ACCESSED_BY_CONTENT, true); - - // Warn once. - JSAutoCompartment ac(cx, obj); - nsCOMPtr win = - do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(obj)); - if (win) { - nsCOMPtr doc = win->GetExtantDoc(); - if (doc) - doc->WarnOnceAbout(nsIDocument::eComponents, /* asError = */ true); - } - - return true; -} - // static bool nsXPCComponents::AttachComponentsObject(JSContext* aCx, @@ -5273,10 +5244,8 @@ nsXPCComponents::AttachComponentsObject(JSContext* aCx, MOZ_ASSERT(js::IsObjectInContextCompartment(global, aCx)); RootedId id(aCx, XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS)); - JSPropertyOp getter = AccessCheck::isChrome(global) ? nullptr - : &ContentComponentsGetterOp; return JS_DefinePropertyById(aCx, global, id, js::ObjectValue(*components), - getter, nullptr, JSPROP_PERMANENT | JSPROP_READONLY); + nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY); } /* void lookupMethod (); */ @@ -5324,12 +5293,6 @@ nsXPCComponents::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, c { static const char* const allowed[] = { "isSuccessCode", "lookupMethod", nullptr }; *_retval = xpc_CheckAccessList(methodName, allowed); - if (*_retval && - methodName[0] == 'l' && - !nsContentUtils::IsCallerXBL()) - { - Telemetry::Accumulate(Telemetry::COMPONENTS_LOOKUPMETHOD_ACCESSED_BY_CONTENT, true); - } return NS_OK; } @@ -5339,12 +5302,6 @@ nsXPCComponents::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName { static const char* const allowed[] = { "interfaces", "interfacesByID", "results", nullptr}; *_retval = xpc_CheckAccessList(propertyName, allowed); - if (*_retval && - propertyName[0] == 'i' && - !nsContentUtils::IsCallerXBL()) - { - Telemetry::Accumulate(Telemetry::COMPONENTS_INTERFACES_ACCESSED_BY_CONTENT, true); - } return NS_OK; } diff --git a/js/xpconnect/tests/chrome/test_bug795275.xul b/js/xpconnect/tests/chrome/test_bug795275.xul index 816013f491a0..3ef773eae9f8 100644 --- a/js/xpconnect/tests/chrome/test_bug795275.xul +++ b/js/xpconnect/tests/chrome/test_bug795275.xul @@ -20,7 +20,7 @@ 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); + SimpleTest.executeSoon(startLoad); function startLoad() { for (var i = 1; i <= document.getElementsByTagName('iframe').length; ++i) { var frame = document.getElementById('frame' + i); @@ -60,10 +60,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=795275 function go() { getWin('frame1').touchComponents(); getWin('frame2').touchInterfaces(); - getWin('frame3').touchLookupMethod(); + ok(getWin('frame3').touchLookupMethod(), "Components.lookupMethod should be undefined"); getWin('frame4').touchComponents(); getWin('frame4').touchInterfaces(); - getWin('frame4').touchLookupMethod(); + ok(getWin('frame4').touchLookupMethod(), "Components.lookupMethod should be undefined"); // This shouldn't warn. getWin('frame5').touchViaXBL(); diff --git a/js/xpconnect/tests/mochitest/Makefile.in b/js/xpconnect/tests/mochitest/Makefile.in index 4c947e94803a..aca7ae38620e 100644 --- a/js/xpconnect/tests/mochitest/Makefile.in +++ b/js/xpconnect/tests/mochitest/Makefile.in @@ -81,7 +81,6 @@ MOCHITEST_FILES = chrome_wrappers_helper.html \ test_bug785096.html \ test_bug789713.html \ test_bug790732.html \ - file_bug790732.html \ test_bug793969.html \ file_bug795275.html \ file_bug795275.xml \ diff --git a/js/xpconnect/tests/mochitest/file_bug790732.html b/js/xpconnect/tests/mochitest/file_bug790732.html deleted file mode 100644 index d69af55c16a6..000000000000 --- a/js/xpconnect/tests/mochitest/file_bug790732.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - diff --git a/js/xpconnect/tests/mochitest/file_bug795275.html b/js/xpconnect/tests/mochitest/file_bug795275.html index a6b1d04aed04..d23a47650850 100644 --- a/js/xpconnect/tests/mochitest/file_bug795275.html +++ b/js/xpconnect/tests/mochitest/file_bug795275.html @@ -13,7 +13,7 @@ Components.interfaces; } function touchLookupMethod() { - Components.lookupMethod(document, 'getElementById'); + return !Components.lookupMethod; } function touchViaXBL() { diff --git a/js/xpconnect/tests/mochitest/test_bug790732.html b/js/xpconnect/tests/mochitest/test_bug790732.html index 771950e4b8a5..a830165baf30 100644 --- a/js/xpconnect/tests/mochitest/test_bug790732.html +++ b/js/xpconnect/tests/mochitest/test_bug790732.html @@ -10,30 +10,52 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=790732 - + Mozilla Bug 790732