Backout 0b170d1f5d10 (bug 735280) due to red.

This commit is contained in:
Ryan VanderMeulen 2012-04-24 22:09:23 -04:00
parent 767f3c603c
commit 41b2438cb3
14 changed files with 33 additions and 187 deletions

View File

@ -21,14 +21,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=246699
** Test for Bug 246699 ** Test for Bug 246699
** (should produce stack information for caps errors) ** (should produce stack information for caps errors)
**/ **/
function isError(e)
{
return e.constructor.name === "Error" || e.constructor.name === "TypeError";
}
function hasStack(e) function hasStack(e)
{ {
return isError(e) && /inciteCaps/.test(e.stack); return e.constructor.name === "Error" && /inciteCaps/.test(e.stack);
} }
function inciteCaps(f) function inciteCaps(f)

View File

@ -52,7 +52,7 @@ if (typeof window == 'undefined')
} }
else else
{ {
expect = /(Script error.|Permission denied to access property 'classes')/; expect = /(Script error.|Permission denied for <file:\/\/> to get property XPCComponents.classes)/;
window._onerror = window.onerror; window._onerror = window.onerror;
window.onerror = (function (msg, page, line) { window.onerror = (function (msg, page, line) {
@ -64,8 +64,7 @@ else
gDelayTestDriverEnd = true; gDelayTestDriverEnd = true;
// Trying to set Components.classes will trigger a Permission denied exception window.location="javascript:Components.classes";
window.location="javascript:Components.classes = 42";
actual = 'No Error'; actual = 'No Error';
} }

View File

@ -60,7 +60,6 @@
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "jsgc.h" #include "jsgc.h"
#include "jsfriendapi.h" #include "jsfriendapi.h"
#include "AccessCheck.h"
#include "mozilla/dom/bindings/Utils.h" #include "mozilla/dom/bindings/Utils.h"
using namespace mozilla; using namespace mozilla;
@ -4194,8 +4193,7 @@ NS_IMETHODIMP
nsXPCComponents::GetHelperForLanguage(PRUint32 language, nsXPCComponents::GetHelperForLanguage(PRUint32 language,
nsISupports **retval) nsISupports **retval)
{ {
*retval = static_cast<nsIXPCComponents*>(this); *retval = nsnull;
NS_ADDREF(this);
return NS_OK; return NS_OK;
} }
@ -4247,9 +4245,8 @@ nsXPCComponents::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
nsXPCComponents::nsXPCComponents(XPCWrappedNativeScope* aScope) nsXPCComponents::nsXPCComponents()
: mScope(aScope), : mInterfaces(nsnull),
mInterfaces(nsnull),
mInterfacesByID(nsnull), mInterfacesByID(nsnull),
mClasses(nsnull), mClasses(nsnull),
mClassesByID(nsnull), mClassesByID(nsnull),
@ -4259,7 +4256,6 @@ nsXPCComponents::nsXPCComponents(XPCWrappedNativeScope* aScope)
mConstructor(nsnull), mConstructor(nsnull),
mUtils(nsnull) mUtils(nsnull)
{ {
MOZ_ASSERT(aScope, "aScope must not be null");
} }
nsXPCComponents::~nsXPCComponents() nsXPCComponents::~nsXPCComponents()
@ -4343,7 +4339,6 @@ nsXPCComponents::GetManager(nsIComponentManager * *aManager)
#define XPC_MAP_WANT_NEWRESOLVE #define XPC_MAP_WANT_NEWRESOLVE
#define XPC_MAP_WANT_GETPROPERTY #define XPC_MAP_WANT_GETPROPERTY
#define XPC_MAP_WANT_SETPROPERTY #define XPC_MAP_WANT_SETPROPERTY
#define XPC_MAP_WANT_PRECREATE
#define XPC_MAP_FLAGS nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE #define XPC_MAP_FLAGS nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
#include "xpc_map_end.h" /* This will #undef the above */ #include "xpc_map_end.h" /* This will #undef the above */
@ -4432,20 +4427,16 @@ nsXPCComponents::SetProperty(nsIXPConnectWrappedNative *wrapper,
// static // static
JSBool JSBool
nsXPCComponents::AttachComponentsObject(XPCCallContext& ccx, nsXPCComponents::AttachNewComponentsObject(XPCCallContext& ccx,
XPCWrappedNativeScope* aScope, XPCWrappedNativeScope* aScope,
JSObject* aGlobal) JSObject* aGlobal)
{ {
if (!aGlobal) if (!aGlobal)
return false; return false;
nsXPCComponents* components = aScope->GetComponents(); nsXPCComponents* components = new nsXPCComponents();
if (!components) { if (!components)
components = new nsXPCComponents(aScope); return false;
if (!components)
return false;
aScope->SetComponents(components);
}
nsCOMPtr<nsIXPCComponents> cholder(components); nsCOMPtr<nsIXPCComponents> cholder(components);
@ -4461,14 +4452,15 @@ nsXPCComponents::AttachComponentsObject(XPCCallContext& ccx,
if (!wrapper) if (!wrapper)
return false; return false;
jsid id = ccx.GetRuntime()->GetStringID(XPCJSRuntime::IDX_COMPONENTS); aScope->SetComponents(components);
JSObject* obj = wrapper->GetSameCompartmentSecurityWrapper(ccx);
if (!wrapper)
return false;
return JS_DefinePropertyById(ccx, aGlobal, id, OBJECT_TO_JSVAL(obj), jsid id = ccx.GetRuntime()->GetStringID(XPCJSRuntime::IDX_COMPONENTS);
nsnull, nsnull, JSObject* obj;
JSPROP_PERMANENT | JSPROP_READONLY);
return NS_SUCCEEDED(wrapper->GetJSObject(&obj)) &&
obj && JS_DefinePropertyById(ccx, aGlobal, id, OBJECT_TO_JSVAL(obj),
nsnull, nsnull,
JSPROP_PERMANENT | JSPROP_READONLY);
} }
/* void lookupMethod (); */ /* void lookupMethod (); */
@ -4536,15 +4528,3 @@ nsXPCComponents::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName
*_retval = nsnull; *_retval = nsnull;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsXPCComponents::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, JSObject **parentObj)
{
// this should never happen
if (!mScope) {
NS_WARNING("mScope must not be null when nsXPCComponents::PreCreate is called");
return NS_ERROR_FAILURE;
}
*parentObj = mScope->GetGlobalJSObject();
return NS_OK;
}

View File

@ -1683,8 +1683,6 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
JSObject *ww = wrapper->GetWrapper(); JSObject *ww = wrapper->GetWrapper();
if (ww) { if (ww) {
JSObject *newwrapper; JSObject *newwrapper;
MOZ_ASSERT(!xpc::WrapperFactory::IsComponentsObject(flat),
"Components object should never get here");
if (xpc::WrapperFactory::IsLocationObject(flat)) { if (xpc::WrapperFactory::IsLocationObject(flat)) {
newwrapper = xpc::WrapperFactory::WrapLocationObject(ccx, newobj); newwrapper = xpc::WrapperFactory::WrapLocationObject(ccx, newobj);
if (!newwrapper) if (!newwrapper)
@ -2242,10 +2240,6 @@ XPCWrappedNative::GetSameCompartmentSecurityWrapper(JSContext *cx)
wrapper = xpc::WrapperFactory::WrapSOWObject(cx, flat); wrapper = xpc::WrapperFactory::WrapSOWObject(cx, flat);
if (!wrapper) if (!wrapper)
return NULL; return NULL;
} else if (xpc::WrapperFactory::IsComponentsObject(flat)) {
wrapper = xpc::WrapperFactory::WrapComponentsObject(cx, flat);
if (!wrapper)
return NULL;
} }
// If we made a wrapper, cache it and return it. // If we made a wrapper, cache it and return it.

View File

@ -190,15 +190,11 @@ XPCWrappedNativeScope::IsDyingScope(XPCWrappedNativeScope *scope)
void void
XPCWrappedNativeScope::SetComponents(nsXPCComponents* aComponents) XPCWrappedNativeScope::SetComponents(nsXPCComponents* aComponents)
{ {
NS_IF_ADDREF(aComponents);
NS_IF_RELEASE(mComponents);
mComponents = aComponents; mComponents = aComponents;
} }
nsXPCComponents*
XPCWrappedNativeScope::GetComponents()
{
return mComponents;
}
// Dummy JS class to let wrappers w/o an xpc prototype share // Dummy JS class to let wrappers w/o an xpc prototype share
// scopes. By doing this we avoid allocating a new scope for every // scopes. By doing this we avoid allocating a new scope for every
// wrapper on creation of the wrapper, and most wrappers won't need // wrapper on creation of the wrapper, and most wrappers won't need
@ -312,14 +308,9 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope()
if (mContext) if (mContext)
mContext->RemoveScope(this); mContext->RemoveScope(this);
// This should not be necessary, since the Components object should die
// with the scope but just in case.
if (mComponents)
mComponents->mScope = nsnull;
// XXX we should assert that we are dead or that xpconnect has shutdown // XXX we should assert that we are dead or that xpconnect has shutdown
// XXX might not want to do this at xpconnect shutdown time??? // XXX might not want to do this at xpconnect shutdown time???
mComponents = nsnull; NS_IF_RELEASE(mComponents);
JSRuntime *rt = mRuntime->GetJSRuntime(); JSRuntime *rt = mRuntime->GetJSRuntime();
mGlobalJSObject.finalize(rt); mGlobalJSObject.finalize(rt);

View File

@ -1131,7 +1131,7 @@ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj)
scope->RemoveWrappedNativeProtos(); scope->RemoveWrappedNativeProtos();
if (!nsXPCComponents::AttachComponentsObject(ccx, scope, aGlobalJSObj)) if (!nsXPCComponents::AttachNewComponentsObject(ccx, scope, aGlobalJSObj))
return UnexpectedFailure(NS_ERROR_FAILURE); return UnexpectedFailure(NS_ERROR_FAILURE);
if (XPCPerThreadData::IsMainThread(ccx)) { if (XPCPerThreadData::IsMainThread(ccx)) {
@ -1333,7 +1333,7 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
if (!(aFlags & nsIXPConnect::OMIT_COMPONENTS_OBJECT)) { if (!(aFlags & nsIXPConnect::OMIT_COMPONENTS_OBJECT)) {
// XPCCallContext gives us an active request needed to save/restore. // XPCCallContext gives us an active request needed to save/restore.
if (!nsXPCComponents::AttachComponentsObject(ccx, wrappedGlobal->GetScope(), global)) if (!nsXPCComponents::AttachNewComponentsObject(ccx, wrappedGlobal->GetScope(), global))
return UnexpectedFailure(NS_ERROR_FAILURE); return UnexpectedFailure(NS_ERROR_FAILURE);
if (XPCPerThreadData::IsMainThread(ccx)) { if (XPCPerThreadData::IsMainThread(ccx)) {

View File

@ -1610,7 +1610,6 @@ public:
IsDyingScope(XPCWrappedNativeScope *scope); IsDyingScope(XPCWrappedNativeScope *scope);
void SetComponents(nsXPCComponents* aComponents); void SetComponents(nsXPCComponents* aComponents);
nsXPCComponents *GetComponents();
void SetGlobal(XPCCallContext& ccx, JSObject* aGlobal, nsISupports* aNative); void SetGlobal(XPCCallContext& ccx, JSObject* aGlobal, nsISupports* aNative);
static void InitStatics() { gScopes = nsnull; gDyingScopes = nsnull; } static void InitStatics() { gScopes = nsnull; gDyingScopes = nsnull; }
@ -1660,7 +1659,7 @@ private:
Native2WrappedNativeMap* mWrappedNativeMap; Native2WrappedNativeMap* mWrappedNativeMap;
ClassInfo2WrappedNativeProtoMap* mWrappedNativeProtoMap; ClassInfo2WrappedNativeProtoMap* mWrappedNativeProtoMap;
ClassInfo2WrappedNativeProtoMap* mMainThreadWrappedNativeProtoMap; ClassInfo2WrappedNativeProtoMap* mMainThreadWrappedNativeProtoMap;
nsRefPtr<nsXPCComponents> mComponents; nsXPCComponents* mComponents;
XPCWrappedNativeScope* mNext; XPCWrappedNativeScope* mNext;
// The JS global object for this scope. If non-null, this will be the // The JS global object for this scope. If non-null, this will be the
// default parent for the XPCWrappedNatives that have us as the scope, // default parent for the XPCWrappedNatives that have us as the scope,
@ -3903,21 +3902,19 @@ public:
public: public:
static JSBool static JSBool
AttachComponentsObject(XPCCallContext& ccx, AttachNewComponentsObject(XPCCallContext& ccx,
XPCWrappedNativeScope* aScope, XPCWrappedNativeScope* aScope,
JSObject* aGlobal); JSObject* aGlobal);
void SystemIsBeingShutDown() {ClearMembers();} void SystemIsBeingShutDown() {ClearMembers();}
virtual ~nsXPCComponents(); virtual ~nsXPCComponents();
private: private:
nsXPCComponents(XPCWrappedNativeScope* aScope); nsXPCComponents();
void ClearMembers(); void ClearMembers();
private: private:
friend class XPCWrappedNativeScope;
XPCWrappedNativeScope* mScope;
nsXPCComponents_Interfaces* mInterfaces; nsXPCComponents_Interfaces* mInterfaces;
nsXPCComponents_InterfacesByID* mInterfacesByID; nsXPCComponents_InterfacesByID* mInterfacesByID;
nsXPCComponents_Classes* mClasses; nsXPCComponents_Classes* mClasses;

View File

@ -1,43 +0,0 @@
function run_test() {
var Cu = Components.utils;
var sb1 = Cu.Sandbox("http://www.blah.com");
var sb2 = Cu.Sandbox("http://www.blah.com");
var sb3 = Cu.Sandbox(this);
var sb4 = Cu.Sandbox("http://www.other.com");
var rv;
// non-chrome accessing chrome Components
sb1.C = Components;
rv = Cu.evalInSandbox("C.utils", sb1);
do_check_eq(rv, undefined);
rv = Cu.evalInSandbox("C.interfaces", sb1);
do_check_neq(rv, undefined);
// non-chrome accessing own Components
rv = Cu.evalInSandbox("Components.utils", sb1);
do_check_eq(rv, undefined);
rv = Cu.evalInSandbox("Components.interfaces", sb1);
do_check_neq(rv, undefined);
// non-chrome same origin
var C2 = Cu.evalInSandbox("Components", sb2);
do_check_neq(rv, C2.utils);
sb1.C2 = C2;
rv = Cu.evalInSandbox("C2.utils", sb1);
do_check_eq(rv, undefined);
rv = Cu.evalInSandbox("C2.interfaces", sb1);
do_check_neq(rv, undefined);
// chrome accessing chrome
sb3.C = Components;
rv = Cu.evalInSandbox("C.utils", sb3);
do_check_eq(rv, Cu);
// non-chrome cross origin
sb4.C2 = C2;
rv = Cu.evalInSandbox("C2.interfaces", sb1);
do_check_neq(rv, undefined);
rv = Cu.evalInSandbox("C2.utils", sb1);
do_check_eq(rv, undefined);
}

View File

@ -25,4 +25,3 @@ fail-if = os == "android"
[test_unload.js] [test_unload.js]
[test_attributes.js] [test_attributes.js]
[test_params.js] [test_params.js]
[test_components.js]

View File

@ -607,29 +607,4 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper:
return true; // Allow return true; // Allow
} }
bool
ComponentsObjectPolicy::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper::Action act,
Permission &perm)
{
perm = DenyAccess;
JSAutoEnterCompartment ac;
if (!ac.enter(cx, wrapper))
return false;
if (JSID_IS_STRING(id) && act == Wrapper::GET) {
JSFlatString *flatId = JSID_TO_FLAT_STRING(id);
if (JS_FlatStringEqualsAscii(flatId, "isSuccessCode") ||
JS_FlatStringEqualsAscii(flatId, "lookupMethod") ||
JS_FlatStringEqualsAscii(flatId, "interfaces") ||
JS_FlatStringEqualsAscii(flatId, "interfacesByID") ||
JS_FlatStringEqualsAscii(flatId, "results"))
{
perm = PermitPropertyAccess;
return true;
}
}
return PermitIfUniversalXPConnect(cx, id, act, perm); // Deny
}
} }

View File

@ -175,10 +175,4 @@ struct ExposedPropertiesOnly : public Policy {
Permission &perm); Permission &perm);
}; };
// Components specific policy
struct ComponentsObjectPolicy : public Policy {
static bool check(JSContext *cx, JSObject *wrapper, jsid id, js::Wrapper::Action act,
Permission &perm);
};
} }

View File

@ -151,10 +151,7 @@ FilteringWrapper<Base, Policy>::enter(JSContext *cx, JSObject *wrapper, jsid id,
LocationPolicy> LocationPolicy>
#define XLW FilteringWrapper<XrayWrapper<CrossCompartmentSecurityWrapper>, \ #define XLW FilteringWrapper<XrayWrapper<CrossCompartmentSecurityWrapper>, \
LocationPolicy> LocationPolicy>
#define CW FilteringWrapper<SameCompartmentSecurityWrapper, \
ComponentsObjectPolicy>
#define XCW FilteringWrapper<CrossCompartmentSecurityWrapper, \
ComponentsObjectPolicy>
template<> SOW SOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG | template<> SOW SOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::SOW_FLAG); WrapperFactory::SOW_FLAG);
template<> SCSOW SCSOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG | template<> SCSOW SCSOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
@ -171,9 +168,6 @@ template<> NNXOW NNXOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
template<> LW LW::singleton(WrapperFactory::SHADOWING_FORBIDDEN); template<> LW LW::singleton(WrapperFactory::SHADOWING_FORBIDDEN);
template<> XLW XLW::singleton(WrapperFactory::SHADOWING_FORBIDDEN); template<> XLW XLW::singleton(WrapperFactory::SHADOWING_FORBIDDEN);
template<> CW CW::singleton(0);
template<> XCW XCW::singleton(0);
template class SOW; template class SOW;
template class COW; template class COW;
template class XOW; template class XOW;

View File

@ -366,9 +366,6 @@ WrapperFactory::Rewrap(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSO
wrapper = &FilteringWrapper<XrayProxy, CrossOriginAccessiblePropertiesOnly>::singleton; wrapper = &FilteringWrapper<XrayProxy, CrossOriginAccessiblePropertiesOnly>::singleton;
} else if (mozilla::dom::bindings::IsDOMClass(JS_GetClass(obj))) { } else if (mozilla::dom::bindings::IsDOMClass(JS_GetClass(obj))) {
wrapper = &FilteringWrapper<XrayDOM, CrossOriginAccessiblePropertiesOnly>::singleton; wrapper = &FilteringWrapper<XrayDOM, CrossOriginAccessiblePropertiesOnly>::singleton;
} else if (IsComponentsObject(obj)) {
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
ComponentsObjectPolicy>::singleton;
} else { } else {
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper, wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
ExposedPropertiesOnly>::singleton; ExposedPropertiesOnly>::singleton;
@ -403,9 +400,6 @@ WrapperFactory::Rewrap(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSO
if (AccessCheck::needsSystemOnlyWrapper(obj)) { if (AccessCheck::needsSystemOnlyWrapper(obj)) {
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper, wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
OnlyIfSubjectIsSystem>::singleton; OnlyIfSubjectIsSystem>::singleton;
} else if (IsComponentsObject(obj)) {
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
ComponentsObjectPolicy>::singleton;
} else if (!targetdata || !targetdata->wantXrays || } else if (!targetdata || !targetdata->wantXrays ||
(type = GetXrayType(obj)) == NotXray) { (type = GetXrayType(obj)) == NotXray) {
// Do the double-wrapping if need be. // Do the double-wrapping if need be.
@ -530,21 +524,4 @@ WrapperFactory::WrapSOWObject(JSContext *cx, JSObject *obj)
return wrapperObj; return wrapperObj;
} }
bool
WrapperFactory::IsComponentsObject(JSObject *obj)
{
const char *name = js::GetObjectClass(obj)->name;
return name[0] == 'n' && !strcmp(name, "nsXPCComponents");
}
JSObject *
WrapperFactory::WrapComponentsObject(JSContext *cx, JSObject *obj)
{
JSObject *wrapperObj =
Wrapper::New(cx, obj, JS_GetPrototype(obj), JS_GetGlobalForObject(cx, obj),
&FilteringWrapper<SameCompartmentSecurityWrapper, ComponentsObjectPolicy>::singleton);
return wrapperObj;
}
} }

View File

@ -110,12 +110,6 @@ class WrapperFactory {
// Wrap a (same compartment) object in a SOW. // Wrap a (same compartment) object in a SOW.
static JSObject *WrapSOWObject(JSContext *cx, JSObject *obj); static JSObject *WrapSOWObject(JSContext *cx, JSObject *obj);
// Return true if this is a Components object.
static bool IsComponentsObject(JSObject *obj);
// Wrap a (same compartment) Components object.
static JSObject *WrapComponentsObject(JSContext *cx, JSObject *obj);
}; };
extern js::Wrapper WaiveXrayWrapperWrapper; extern js::Wrapper WaiveXrayWrapperWrapper;