Fix bug 306642 -- caller's shouldn't have to guess at how to force inner window
creation. r+sr=jst
This commit is contained in:
Родитель
6014a35033
Коммит
99ff6019ee
|
@ -77,8 +77,8 @@ class nsIDocument;
|
|||
struct nsTimeout;
|
||||
|
||||
#define NS_PIDOMWINDOW_IID \
|
||||
{ 0x207fe64a, 0x7123, 0x43d0, \
|
||||
{ 0x91, 0x1d, 0x51, 0x19, 0x35, 0x9a, 0xb5, 0x77 } }
|
||||
{ 0xabb217ba, 0x2528, 0x467e, \
|
||||
{ 0xaa, 0x29, 0xdd, 0x84, 0x2d, 0x97, 0x3c, 0x78 } }
|
||||
|
||||
class nsPIDOMWindow : public nsIDOMWindowInternal
|
||||
{
|
||||
|
@ -280,6 +280,15 @@ public:
|
|||
return mInnerWindow;
|
||||
}
|
||||
|
||||
nsPIDOMWindow *EnsureInnerWindow()
|
||||
{
|
||||
NS_ASSERTION(IsOuterWindow(), "EnsureInnerWindow called on inner window");
|
||||
// GetDocument forces inner window creation if there isn't one already
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
GetDocument(getter_AddRefs(doc));
|
||||
return GetCurrentInnerWindow();
|
||||
}
|
||||
|
||||
PRBool IsInnerWindow() const
|
||||
{
|
||||
return mIsInnerWindow;
|
||||
|
|
|
@ -5627,22 +5627,18 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
// We're resolving a property on an outer window for which there
|
||||
// is no inner window yet, and the window is not frozen
|
||||
// (i.e. we're not in the middle of initializing XPConnect
|
||||
// classes on it). If the context is already initalized, trigger
|
||||
// creation of a new inner window by calling GetDocument() on
|
||||
// the outer window. This will create a synthetic about:blank
|
||||
// document, and an inner window which may be reused by the
|
||||
// actual document being loaded into this outer window. This way
|
||||
// properties defined on the window before the document load
|
||||
// started will be visible to the document once it's loaded,
|
||||
// assuming same origin etc.
|
||||
// classes on it). If the context is already initalized, force
|
||||
// creation of a new inner window. This will create a synthetic
|
||||
// about:blank document, and an inner window which may be reused
|
||||
// by the actual document being loaded into this outer
|
||||
// window. This way properties defined on the window before the
|
||||
// document load started will be visible to the document once
|
||||
// it's loaded, assuming same origin etc.
|
||||
nsIScriptContext *scx = win->GetContextInternal();
|
||||
|
||||
if (scx && scx->IsContextInitialized()) {
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
win->GetDocument(getter_AddRefs(doc));
|
||||
|
||||
// Grab the new inner window.
|
||||
innerWin = win->GetCurrentInnerWindowInternal();
|
||||
innerWin = win->EnsureInnerWindowInternal();
|
||||
|
||||
if (!innerWin) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
|
|
@ -266,6 +266,11 @@ public:
|
|||
return NS_STATIC_CAST(nsGlobalWindow *, mInnerWindow);
|
||||
}
|
||||
|
||||
nsGlobalWindow *EnsureInnerWindowInternal()
|
||||
{
|
||||
return NS_STATIC_CAST(nsGlobalWindow *, EnsureInnerWindow());
|
||||
}
|
||||
|
||||
PRBool IsFrozen() const
|
||||
{
|
||||
return mIsFrozen;
|
||||
|
|
|
@ -150,12 +150,9 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel)
|
|||
|
||||
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(global));
|
||||
|
||||
// Get the document out of the window to make sure we create a new
|
||||
// inner window if one doesn't already exist (see bug 306630).
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
win->GetDocument(getter_AddRefs(doc));
|
||||
|
||||
nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow();
|
||||
// Make sure we create a new inner window if one doesn't already exist (see
|
||||
// bug 306630).
|
||||
nsPIDOMWindow *innerWin = win->EnsureInnerWindow();
|
||||
|
||||
if (!innerWin) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
@ -178,15 +175,6 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel)
|
|||
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
||||
}
|
||||
|
||||
// Now get the DOM Document. Accessing the document will create one
|
||||
// if necessary. So, basically, this call ensures that a document gets
|
||||
// created -- if necessary.
|
||||
rv = domWindow->GetDocument(getter_AddRefs(doc));
|
||||
NS_ASSERTION(doc, "No DOMDocument!");
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scriptContext = global->GetContext();
|
||||
if (!scriptContext)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче