Backout 33addcc556b8 to c8bb41305006 (at the request of mrbkap)

This commit is contained in:
Luke Wagner 2010-08-16 21:37:37 -07:00
parent 6b0104f903
commit 59422fe649
10 changed files with 141 additions and 182 deletions

View File

@ -1512,8 +1512,7 @@ public:
WindowStateHolder(nsGlobalWindow *aWindow,
nsIXPConnectJSObjectHolder *aHolder,
nsNavigator *aNavigator,
nsIXPConnectJSObjectHolder *aOuterProto,
nsIXPConnectJSObjectHolder *aOuterRealProto);
nsIXPConnectJSObjectHolder *aOuterProto);
nsGlobalWindow* GetInnerWindow() { return mInnerWindow; }
nsIXPConnectJSObjectHolder *GetInnerWindowHolder()
@ -1521,7 +1520,6 @@ public:
nsNavigator* GetNavigator() { return mNavigator; }
nsIXPConnectJSObjectHolder* GetOuterProto() { return mOuterProto; }
nsIXPConnectJSObjectHolder* GetOuterRealProto() { return mOuterRealProto; }
void DidRestoreWindow()
{
@ -1530,7 +1528,6 @@ public:
mInnerWindowHolder = nsnull;
mNavigator = nsnull;
mOuterProto = nsnull;
mOuterRealProto = nsnull;
}
protected:
@ -1542,7 +1539,6 @@ protected:
nsCOMPtr<nsIXPConnectJSObjectHolder> mInnerWindowHolder;
nsRefPtr<nsNavigator> mNavigator;
nsCOMPtr<nsIXPConnectJSObjectHolder> mOuterProto;
nsCOMPtr<nsIXPConnectJSObjectHolder> mOuterRealProto;
};
NS_DEFINE_STATIC_IID_ACCESSOR(WindowStateHolder, WINDOWSTATEHOLDER_IID)
@ -1550,12 +1546,10 @@ NS_DEFINE_STATIC_IID_ACCESSOR(WindowStateHolder, WINDOWSTATEHOLDER_IID)
WindowStateHolder::WindowStateHolder(nsGlobalWindow *aWindow,
nsIXPConnectJSObjectHolder *aHolder,
nsNavigator *aNavigator,
nsIXPConnectJSObjectHolder *aOuterProto,
nsIXPConnectJSObjectHolder *aOuterRealProto)
nsIXPConnectJSObjectHolder *aOuterProto)
: mInnerWindow(aWindow),
mNavigator(aNavigator),
mOuterProto(aOuterProto),
mOuterRealProto(aOuterRealProto)
mOuterProto(aOuterProto)
{
NS_PRECONDITION(aWindow, "null window");
NS_PRECONDITION(aWindow->IsInnerWindow(), "Saving an outer window");
@ -1728,20 +1722,12 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
JSAutoRequest ar(cx);
nsCOMPtr<WindowStateHolder> wsh = do_QueryInterface(aState);
NS_ASSERTION(!aState || wsh, "What kind of weird state are you giving me here?");
// Make sure to clear scope on the outer window *before* we
// initialize the new inner window. If we don't, things
// (Object.prototype etc) could leak from the old outer to the new
// inner scope.
mContext->ClearScope(mJSObject, PR_FALSE);
// This code should not be called during shutdown any more (now that
// we don't ever call SetNewDocument(nsnull), so no need to null
// check xpc here.
nsIXPConnect *xpc = nsContentUtils::XPConnect();
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
if (reUseInnerWindow) {
// We're reusing the current inner window.
NS_ASSERTION(!currentInner->IsFrozen(),
@ -1753,6 +1739,9 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
}
} else {
if (aState) {
nsCOMPtr<WindowStateHolder> wsh = do_QueryInterface(aState);
NS_ASSERTION(wsh, "What kind of weird state are you giving me here?");
newInnerWindow = wsh->GetInnerWindow();
mInnerWindowHolder = wsh->GetInnerWindowHolder();
@ -1886,37 +1875,12 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
mJSObject = (JSObject *)mContext->GetNativeGlobal();
} else {
// XXX New global object and brain transplant!
rv = xpc->GetWrappedNativeOfJSObject(cx, mJSObject,
getter_AddRefs(wrapper));
NS_ENSURE_SUCCESS(rv, rv);
// Restore our object's prototype to its original value so we're sure to
// update it under ReparentWrappedNativeIfFound.
JSObject *proto;
wrapper->GetJSObjectPrototype(&proto);
if (!JS_SetPrototype(cx, mJSObject, proto)) {
NS_ERROR("Can't set prototype");
return NS_ERROR_UNEXPECTED;
}
nsIXPConnect *xpc = nsContentUtils::XPConnect();
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
xpc->ReparentWrappedNativeIfFound(cx, currentInner->mJSObject,
newInnerWindow->mJSObject,
ToSupports(this),
getter_AddRefs(holder));
if (aState) {
if (nsIXPConnectJSObjectHolder *holder = wsh->GetOuterRealProto()) {
holder->GetJSObject(&proto);
} else {
proto = nsnull;
}
if (!JS_SetPrototype(cx, mJSObject, proto)) {
NS_ERROR("can't set prototype");
return NS_ERROR_FAILURE;
}
}
}
}
@ -1970,6 +1934,11 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
html_doc);
}
// This code should not be called during shutdown any more (now that
// we don't ever call SetNewDocument(nsnull), so no need to null
// check xpc here.
nsIXPConnect *xpc = nsContentUtils::XPConnect();
if (aDocument) {
aDocument->SetScriptGlobalObject(newInnerWindow);
}
@ -2035,11 +2004,10 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
mContext->GC();
mContext->DidInitializeContext();
if (!wrapper) {
rv = xpc->GetWrappedNativeOfJSObject(cx, mJSObject,
getter_AddRefs(wrapper));
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
rv = xpc->GetWrappedNativeOfJSObject(cx, mJSObject,
getter_AddRefs(wrapper));
NS_ENSURE_SUCCESS(rv, rv);
rv = xpc->UpdateXOWs((JSContext *)GetContextInternal()->GetNativeContext(),
wrapper, nsIXPConnect::XPC_XOW_NAVIGATED);
@ -9083,39 +9051,21 @@ nsGlobalWindow::SaveWindowState(nsISupports **aState)
// to the page.
inner->Freeze();
// Remember the outer window's prototype.
JSContext *cx = (JSContext *)mContext->GetNativeContext();
JSAutoRequest req(cx);
nsIXPConnect *xpc = nsContentUtils::XPConnect();
// Remember the outer window's XPConnect prototype.
nsCOMPtr<nsIClassInfo> ci =
do_QueryInterface((nsIScriptGlobalObject *)this);
nsCOMPtr<nsIXPConnectJSObjectHolder> proto;
nsresult rv = xpc->GetWrappedNativePrototype(cx, mJSObject, ci,
getter_AddRefs(proto));
nsresult rv = nsContentUtils::XPConnect()->
GetWrappedNativePrototype((JSContext *)mContext->GetNativeContext(),
mJSObject, ci, getter_AddRefs(proto));
NS_ENSURE_SUCCESS(rv, rv);
JSObject *realProto = JS_GetPrototype(cx, mJSObject);
nsCOMPtr<nsIXPConnectJSObjectHolder> realProtoHolder;
if (realProto) {
rv = xpc->HoldObject(cx, realProto, getter_AddRefs(realProtoHolder));
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsISupports> state = new WindowStateHolder(inner,
mInnerWindowHolder,
mNavigator,
proto,
realProtoHolder);
proto);
NS_ENSURE_TRUE(state, NS_ERROR_OUT_OF_MEMORY);
JSObject *wnProto;
proto->GetJSObject(&wnProto);
if (!JS_SetPrototype(cx, mJSObject, wnProto)) {
return NS_ERROR_FAILURE;
}
#ifdef DEBUG_PAGE_CACHE
printf("saving window state, state = %p\n", (void*)state);
#endif

View File

@ -59,8 +59,6 @@ _TEST_FILES = \
test_clipboard_events.html \
test_focusrings.xul \
test_nodesFromRect.html \
test_frameElementWrapping.html \
file_frameElementWrapping.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -1,26 +0,0 @@
<html>
<script>
function check(elt, expectXOW, message) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var result = ((utils.getClassName(elt) === 'XPCCrossOriginWrapper') === expectXOW)
? "PASS"
: "FAIL";
top.postMessage(result + ',' + message, '*');
}
try {
// true if same origin, throws otherwise
var sameOrigin = top.location.href !== '';
} catch (e) {
sameOrigin = false;
}
check(frameElement, !sameOrigin,
sameOrigin
? 'no wrapper needed if same origin'
: 'wrapper needed if not same origin');
</script>
</html>

View File

@ -1,38 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for location object behaviors</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<iframe id="ifr" src="file_frameElementWrapping.html"></iframe>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var count = 0;
function runTest(result, message) {
ok(result === 'PASS', message);
if (++count === 2)
SimpleTest.finish();
else
$('ifr').contentWindow.location = 'http://example.org/tests/dom/tests/mochitest/general/file_frameElementWrapping.html';
}
window.addEventListener("message",
function(event) { runTest.apply(null, event.data.split(',')) },
false);
</script>
</pre>
</body>
</html>

View File

@ -1024,13 +1024,10 @@ obj_eval(JSContext *cx, uintN argc, Value *vp)
return JS_FALSE;
obj = obj->wrappedObject(cx);
OBJ_TO_INNER_OBJECT(cx, obj);
if (!obj)
return JS_FALSE;
/*
* Ban indirect uses of eval (nonglobal.eval = eval; nonglobal.eval(....))
* that attempt to use a non-global object as the scope object.
* Ban all indirect uses of eval (global.foo = eval; global.foo(...)) and
* calls that attempt to use a non-global object as the "with" object in
* the former indirect case.
*/
{
JSObject *parent = obj->getParent();
@ -1089,6 +1086,10 @@ obj_eval(JSContext *cx, uintN argc, Value *vp)
/* Pretend that we're top level. */
staticLevel = 0;
OBJ_TO_INNER_OBJECT(cx, obj);
if (!obj)
return JS_FALSE;
if (!js_CheckPrincipalsAccess(cx, obj,
JS_StackFramePrincipals(cx, caller),
cx->runtime->atomState.evalAtom)) {

View File

@ -399,7 +399,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
%}
[uuid(7a3c8687-6f52-47d5-9b8e-2ed8bf86c415)]
[uuid(4abf8614-2b0c-495f-8c67-97115470b53c)]
interface nsIXPConnect : nsISupports
{
%{ C++
@ -413,6 +413,16 @@ interface nsIXPConnect : nsISupports
initClasses(in JSContextPtr aJSContext,
in JSObjectPtr aGlobalJSObj);
/**
* Like initClasses, but only does some of the initialization on the
* existing global. In particular this function assumes that the outer
* window has already been connected to an inner window, so
* re-initializing things like XPCNativeWrapper is useless.
*/
void
initClassesForOuterObject(in JSContextPtr aJSContext,
in JSObjectPtr aGlobalJSObj);
/**
* Creates a new global object using the given aCOMObj as the global
* object. The object will be set up according to the flags (defined
@ -885,11 +895,4 @@ interface nsIXPConnect : nsISupports
[notxpcom] void getNativeWrapperGetPropertyOp(out JSPropertyOp getProperty);
[notxpcom] void getXrayWrapperPropertyHolderGetPropertyOp(out JSPropertyOp getProperty);
/**
* Creates a JS object holder around aObject that will hold the object
* alive for as long as the holder stays alive.
*/
nsIXPConnectJSObjectHolder holdObject(in JSContextPtr aJSContext,
in JSObjectPtr aObject);
};

View File

@ -746,6 +746,32 @@ XPC_NW_HasInstance(JSContext *cx, JSObject *obj, const jsval *valp, JSBool *bp)
return JS_TRUE;
}
static JSBool
MirrorWrappedNativeParent(JSContext *cx, XPCWrappedNative *wrapper,
JSObject **result NS_OUTPARAM)
{
JSObject *wn_parent = wrapper->GetFlatJSObject()->getParent();
if (!wn_parent) {
*result = nsnull;
} else {
XPCWrappedNative *parent_wrapper =
XPCWrappedNative::GetAndMorphWrappedNativeOfJSObject(cx, wn_parent);
// parent_wrapper can be null if we're in a Components.utils.evalInSandbox
// scope. In that case, the best we can do is just use the
// non-native-wrapped sandbox global object for our parent.
if (parent_wrapper) {
*result = XPCNativeWrapper::GetNewOrUsed(cx, parent_wrapper, nsnull,
nsnull);
if (!*result)
return JS_FALSE;
} else {
*result = nsnull;
}
}
return JS_TRUE;
}
static JSBool
XPCNativeWrapperCtor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
@ -1083,15 +1109,38 @@ XPCNativeWrapper::GetNewOrUsed(JSContext *cx, XPCWrappedNative *wrapper,
return obj;
}
JSObject *nw_parent = wrapper->GetScope()->GetGlobalJSObject();
JSObject *nw_parent;
if (!MirrorWrappedNativeParent(cx, wrapper, &nw_parent)) {
return nsnull;
}
PRBool lock;
if (!nw_parent) {
nw_parent = wrapper->GetScope()->GetGlobalJSObject();
lock = PR_FALSE;
} else {
lock = PR_TRUE;
}
if (lock) {
// Make sure nw_parent doesn't get collected while we're creating
// the new wrapper.
::JS_LockGCThing(cx, nw_parent);
}
bool call = NATIVE_HAS_FLAG(wrapper, WantCall) ||
NATIVE_HAS_FLAG(wrapper, WantConstruct);
obj = JS_NewObjectWithGivenProto(cx, GetJSClass(call), nsnull, nw_parent);
obj = ::JS_NewObjectWithGivenProto(cx, GetJSClass(call), nsnull, nw_parent);
if (lock) {
::JS_UnlockGCThing(cx, nw_parent);
}
if (!obj ||
!JS_SetPrivate(cx, obj, wrapper) ||
!JS_SetReservedSlot(cx, obj, 0, JSVAL_ZERO)) {
!::JS_SetPrivate(cx, obj, wrapper) ||
!::JS_SetReservedSlot(cx, obj, 0, JSVAL_ZERO)) {
return nsnull;
}
@ -1136,10 +1185,30 @@ XPCNativeWrapper::CreateExplicitWrapper(JSContext *cx,
return JS_FALSE;
}
if (!JS_SetReservedSlot(cx, wrapperObj, 0, INT_TO_JSVAL(FLAG_EXPLICIT))) {
if (!::JS_SetReservedSlot(cx, wrapperObj, 0, INT_TO_JSVAL(FLAG_EXPLICIT))) {
return JS_FALSE;
}
JSObject *parent = nsnull;
// Make sure wrapperObj doesn't get collected while we're wrapping
// parents for it.
JS_LockGCThing(cx, wrapperObj);
// A deep XPCNativeWrapper has a parent chain that mirrors its
// XPCWrappedNative's chain.
if (!MirrorWrappedNativeParent(cx, wrappedNative, &parent))
return JS_FALSE;
JS_UnlockGCThing(cx, wrapperObj);
if (!parent) {
parent = wrappedNative->GetScope()->GetGlobalJSObject();
}
if (!JS_SetParent(cx, wrapperObj, parent))
return JS_FALSE;
// Set the XPCWrappedNative as private data in the native wrapper.
if (!JS_SetPrivate(cx, wrapperObj, wrappedNative)) {
return JS_FALSE;

View File

@ -109,6 +109,13 @@ ClassNeedsXOW(const char *name)
return strcmp(++name, "indow") == 0;
case 'L':
return strcmp(++name, "ocation") == 0;
case 'H':
if (strncmp(++name, "TML", 3))
break;
name += 3;
if (*name == 'I')
++name;
return strcmp(name, "FrameElement") == 0;
default:
break;
}

View File

@ -1042,6 +1042,25 @@ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj)
return NS_OK;
}
/* void initClassesForOuterObject (in JSContextPtr aJSContext, in JSObjectPtr aGlobalJSObj); */
NS_IMETHODIMP nsXPConnect::InitClassesForOuterObject(JSContext * aJSContext, JSObject * aGlobalJSObj)
{
// Nest frame chain save/restore in request created by XPCCallContext.
XPCCallContext ccx(NATIVE_CALLER, aJSContext);
if(!ccx.IsValid())
return UnexpectedFailure(NS_ERROR_FAILURE);
SaveFrame sf(aJSContext);
XPCWrappedNativeScope* scope =
XPCWrappedNativeScope::GetNewOrUsed(ccx, aGlobalJSObj);
if(!scope)
return UnexpectedFailure(NS_ERROR_FAILURE);
scope->RemoveWrappedNativeProtos();
return NS_OK;
}
static JSBool
TempGlobalResolve(JSContext *aJSContext, JSObject *obj, jsid id)
{
@ -2767,19 +2786,6 @@ nsXPConnect::GetNativeWrapperGetPropertyOp(JSPropertyOp *getPropertyPtr)
*getPropertyPtr = XPCNativeWrapper::GetJSClass(true)->getProperty;
}
NS_IMETHODIMP
nsXPConnect::HoldObject(JSContext *aJSContext, JSObject *aObject,
nsIXPConnectJSObjectHolder **aHolder)
{
XPCCallContext ccx(NATIVE_CALLER, aJSContext);
XPCJSObjectHolder* objHolder = XPCJSObjectHolder::newHolder(ccx, aObject);
if(!objHolder)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aHolder = objHolder);
return NS_OK;
}
/* These are here to be callable from a debugger */
JS_BEGIN_EXTERN_C
JS_EXPORT_API(void) DumpJSStack()

View File

@ -1650,19 +1650,8 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
// Now we can just fix up the parent and return the wrapper
if(aNewParent)
{
if(!JS_SetParent(ccx, flat, aNewParent))
return NS_ERROR_FAILURE;
JSObject *nw;
if(wrapper &&
(nw = wrapper->GetWrapper()) &&
!JS_SetParent(ccx, nw, JS_GetGlobalForObject(ccx, aNewParent)))
{
return NS_ERROR_FAILURE;
}
}
if(aNewParent && !JS_SetParent(ccx, flat, aNewParent))
return NS_ERROR_FAILURE;
*aWrapper = nsnull;
wrapper.swap(*aWrapper);