зеркало из https://github.com/mozilla/gecko-dev.git
Bug 856424 - Unpref Components for content. r=bholley
This commit is contained in:
Родитель
493d170af8
Коммит
ad384dbcf6
|
@ -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<nsIDocument> doc = win->GetExtantDoc();
|
||||
if (doc) {
|
||||
doc->WarnOnceAbout(nsIDocument::eComponents, /* asError = */ true);
|
||||
}
|
||||
|
||||
// Create a fake Components object.
|
||||
JS::Rooted<JSObject*> 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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<nsPIDOMWindow> win =
|
||||
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(obj));
|
||||
if (win) {
|
||||
nsCOMPtr<nsIDocument> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -1,54 +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.nsIDOMSVGLength, SVGLength);
|
||||
is(Ci.nsIDOMNodeFilter, NodeFilter);
|
||||
is(Ci.nsIDOMXPathNamespace, XPathNamespace);
|
||||
is(Ci.nsIDOMXPathResult, XPathResult);
|
||||
|
||||
// Test for Bug 895231
|
||||
for (var k of Object.keys(Components.interfaces)) {
|
||||
ok(SpecialPowers.Ci.hasOwnProperty(k),
|
||||
k + " should be removed from the Components shim");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
|
@ -13,7 +13,7 @@
|
|||
Components.interfaces;
|
||||
}
|
||||
function touchLookupMethod() {
|
||||
Components.lookupMethod(document, 'getElementById');
|
||||
return !Components.lookupMethod;
|
||||
}
|
||||
|
||||
function touchViaXBL() {
|
||||
|
|
|
@ -10,30 +10,52 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=790732
|
|||
<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();
|
||||
// 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");
|
||||
|
||||
function prepare() {
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.omit_components_in_content', true]]},
|
||||
function () { $('ifr').onload = go;
|
||||
$('ifr').contentWindow.location =
|
||||
'/tests/js/xpconnect/tests/mochitest/file_bug790732.html'; }
|
||||
);
|
||||
}
|
||||
// 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.nsIDOMSVGLength, SVGLength);
|
||||
is(Ci.nsIDOMNodeFilter, NodeFilter);
|
||||
is(Ci.nsIDOMXPathNamespace, XPathNamespace);
|
||||
is(Ci.nsIDOMXPathResult, XPathResult);
|
||||
|
||||
function go() {
|
||||
ok(true, "Started test");
|
||||
var iwin = $('ifr').contentWindow;
|
||||
iwin.ok = ok;
|
||||
iwin.is = is;
|
||||
iwin.testShim();
|
||||
SimpleTest.finish();
|
||||
// Test for Bug 895231
|
||||
for (var k of Object.keys(Components.interfaces)) {
|
||||
ok(SpecialPowers.Ci.hasOwnProperty(k),
|
||||
k + " should be removed from the Components shim");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="prepare()">
|
||||
<body>
|
||||
<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">
|
||||
|
|
|
@ -779,9 +779,6 @@ pref("dom.min_timeout_value", 4);
|
|||
// And for background windows
|
||||
pref("dom.min_background_timeout_value", 1000);
|
||||
|
||||
// Stop defining the Components object in content.
|
||||
pref("dom.omit_components_in_content", true);
|
||||
|
||||
// Don't use new input types
|
||||
pref("dom.experimental_forms", false);
|
||||
|
||||
|
|
|
@ -3007,18 +3007,6 @@
|
|||
"description": "The device supports touch input",
|
||||
"cpp_guard": "XP_WIN"
|
||||
},
|
||||
"COMPONENTS_OBJECT_ACCESSED_BY_CONTENT": {
|
||||
"kind": "flag",
|
||||
"description": "Whether content ever accesed the Components object in this session"
|
||||
},
|
||||
"COMPONENTS_LOOKUPMETHOD_ACCESSED_BY_CONTENT": {
|
||||
"kind": "flag",
|
||||
"description": "Whether content ever accesed Components.lookupMethod in this session"
|
||||
},
|
||||
"COMPONENTS_INTERFACES_ACCESSED_BY_CONTENT": {
|
||||
"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"
|
||||
|
|
|
@ -18,16 +18,14 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
function CcDenied() {
|
||||
// Once Components goes away in content, the question of whether or not
|
||||
// Components.classes throws is not well-formed.
|
||||
function CcNotPresent() {
|
||||
if (typeof Components === 'undefined')
|
||||
return true;
|
||||
// Components shim doesn't define Components.classes.
|
||||
try {
|
||||
Components.classes;
|
||||
return false;
|
||||
return typeof Components.classes === 'undefined';
|
||||
} catch (e) {
|
||||
return !!/denied/.exec(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +39,7 @@
|
|||
.docCharsetIsForced;
|
||||
}),
|
||||
|
||||
ccAccess: !!CcDenied(),
|
||||
ccAccess: !!CcNotPresent(),
|
||||
};
|
||||
|
||||
let resultsJSON = JSON.stringify(results);
|
||||
|
|
Загрузка…
Ссылка в новой задаче