зеркало из https://github.com/mozilla/gecko-dev.git
Bug 818716 - Move XBL detection into nsContentUtils and remove filename hack. r=mrbkap
This commit is contained in:
Родитель
be465ba470
Коммит
65be2969d3
|
@ -196,6 +196,7 @@ public:
|
|||
static JSContext* GetContextFromDocument(nsIDocument *aDocument);
|
||||
|
||||
static bool IsCallerChrome();
|
||||
static bool IsCallerXBL();
|
||||
|
||||
static bool IsImageSrcSetDisabled();
|
||||
|
||||
|
|
|
@ -1752,6 +1752,17 @@ nsContentUtils::IsCallerChrome()
|
|||
return xpc::IsUniversalXPConnectEnabled(GetCurrentJSContext());
|
||||
}
|
||||
|
||||
bool
|
||||
nsContentUtils::IsCallerXBL()
|
||||
{
|
||||
JSScript *script;
|
||||
JSContext *cx = GetCurrentJSContext();
|
||||
if (!cx || !JS_DescribeScriptedCaller(cx, &script, nullptr) || !script)
|
||||
return false;
|
||||
return JS_GetScriptUserBit(script);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
nsContentUtils::IsImageSrcSetDisabled()
|
||||
{
|
||||
|
@ -5972,35 +5983,10 @@ nsContentTypeParser::GetParameter(const char* aParameterName, nsAString& aResult
|
|||
|
||||
/* static */
|
||||
|
||||
// If you change this code, change also AllowedToAct() in
|
||||
// XPCSystemOnlyWrapper.cpp!
|
||||
bool
|
||||
nsContentUtils::CanAccessNativeAnon()
|
||||
{
|
||||
JSContext* cx = GetCurrentJSContext();
|
||||
if (!cx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsCallerChrome()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow any code loaded from chrome://global/ to touch us, even if it was
|
||||
// cloned into a less privileged context.
|
||||
JSScript *script;
|
||||
if (!JS_DescribeScriptedCaller(cx, &script, nullptr) || !script) {
|
||||
return false;
|
||||
}
|
||||
static const char prefix[] = "chrome://global/";
|
||||
const char *filename;
|
||||
if ((filename = JS_GetScriptFilename(cx, script)) &&
|
||||
!strncmp(filename, prefix, ArrayLength(prefix) - 1))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return IsCallerChrome() || IsCallerXBL();
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
|
|
|
@ -9537,8 +9537,16 @@ nsHTMLPluginObjElementSH::GetPluginInstanceIfSafe(nsIXPConnectWrappedNative *wra
|
|||
nsCOMPtr<nsIObjectLoadingContent> objlc(do_QueryInterface(content));
|
||||
NS_ASSERTION(objlc, "Object nodes must implement nsIObjectLoadingContent");
|
||||
|
||||
bool callerIsContentJS = (!xpc::AccessCheck::callerIsChrome() &&
|
||||
!xpc::AccessCheck::callerIsXBL(cx) &&
|
||||
// The below methods pull the cx off the stack, so make sure they match.
|
||||
//
|
||||
// NB: Sometimes there's a null cx on the stack, in which case |cx| is the
|
||||
// safe JS context. But in that case, IsCallerChrome() will return true,
|
||||
// so the ensuing expression is short-circuited.
|
||||
MOZ_ASSERT_IF(nsContentUtils::GetCurrentJSContext(),
|
||||
cx == nsContentUtils::GetCurrentJSContext());
|
||||
|
||||
bool callerIsContentJS = (!nsContentUtils::IsCallerChrome() &&
|
||||
!nsContentUtils::IsCallerXBL() &&
|
||||
js::IsContextRunningJS(cx));
|
||||
return objlc->ScriptRequestPluginInstance(callerIsContentJS,
|
||||
_result);
|
||||
|
|
|
@ -4792,7 +4792,7 @@ ContentComponentsGetterOp(JSContext *cx, JSHandleObject obj, JSHandleId id,
|
|||
return true;
|
||||
|
||||
// If the caller is XBL, this is ok.
|
||||
if (AccessCheck::callerIsXBL(cx))
|
||||
if (nsContentUtils::IsCallerXBL())
|
||||
return true;
|
||||
|
||||
// Do Telemetry on how often this happens.
|
||||
|
@ -4881,7 +4881,7 @@ nsXPCComponents::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, c
|
|||
*_retval = xpc_CheckAccessList(methodName, allowed);
|
||||
if (*_retval &&
|
||||
methodName[0] == 'l' &&
|
||||
!AccessCheck::callerIsXBL(nsContentUtils::GetCurrentJSContext()))
|
||||
!nsContentUtils::IsCallerXBL())
|
||||
{
|
||||
Telemetry::Accumulate(Telemetry::COMPONENTS_LOOKUPMETHOD_ACCESSED_BY_CONTENT, true);
|
||||
}
|
||||
|
@ -4896,7 +4896,7 @@ nsXPCComponents::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName
|
|||
*_retval = xpc_CheckAccessList(propertyName, allowed);
|
||||
if (*_retval &&
|
||||
propertyName[0] == 'i' &&
|
||||
!AccessCheck::callerIsXBL(nsContentUtils::GetCurrentJSContext()))
|
||||
!nsContentUtils::IsCallerXBL())
|
||||
{
|
||||
Telemetry::Accumulate(Telemetry::COMPONENTS_INTERFACES_ACCESSED_BY_CONTENT, true);
|
||||
}
|
||||
|
|
|
@ -227,15 +227,6 @@ AccessCheck::isCrossOriginAccessPermitted(JSContext *cx, JSObject *wrapper, jsid
|
|||
return IsWindow(name) && IsFrameId(cx, obj, id);
|
||||
}
|
||||
|
||||
bool
|
||||
AccessCheck::callerIsXBL(JSContext *cx)
|
||||
{
|
||||
JSScript *script;
|
||||
if (!JS_DescribeScriptedCaller(cx, &script, nullptr) || !script)
|
||||
return false;
|
||||
return JS_GetScriptUserBit(script);
|
||||
}
|
||||
|
||||
bool
|
||||
AccessCheck::isSystemOnlyAccessPermitted(JSContext *cx)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,6 @@ class AccessCheck {
|
|||
static nsIPrincipal *getPrincipal(JSCompartment *compartment);
|
||||
static bool isCrossOriginAccessPermitted(JSContext *cx, JSObject *obj, jsid id,
|
||||
js::Wrapper::Action act);
|
||||
static bool callerIsXBL(JSContext *cx);
|
||||
static bool isSystemOnlyAccessPermitted(JSContext *cx);
|
||||
|
||||
static bool needsSystemOnlyWrapper(JSObject *obj);
|
||||
|
|
Загрузка…
Ссылка в новой задаче