Fixing bug 318461. Move SetNewDocument() and SetOpenerWindow() from nsIScriptGlobalObject to nsPIDOMWindow to clean out non-script related methods form the nsIScriptGlobalObject interface. r=mrbkap@gmail.com, sr=bzbarsky@mit.edu

This commit is contained in:
jst%mozilla.jstenback.com 2005-12-01 19:35:27 +00:00
Родитель 48dc046434
Коммит 175fe145fe
11 изменённых файлов: 97 добавлений и 110 удалений

Просмотреть файл

@ -1932,16 +1932,18 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace)
return rv;
}
// Before we reset the doc notify the globalwindow of the change.
// Before we reset the doc notify the globalwindow of the change,
// but only if we still have a window (i.e. our window object the
// current inner window in our outer window).
if (mScriptGlobalObject) {
nsPIDOMWindow *window = GetInnerWindow();
if (window) {
// Hold onto ourselves on the offchance that we're down to one ref
nsCOMPtr<nsIDOMDocument> kungFuDeathGrip =
do_QueryInterface((nsIHTMLDocument*)this);
rv = mScriptGlobalObject->SetNewDocument((nsDocument *)this, nsnull,
PR_FALSE);
rv = window->SetNewDocument(this, nsnull, PR_FALSE);
if (NS_FAILED(rv)) {
return rv;

Просмотреть файл

@ -69,10 +69,6 @@ public:
// nsIScriptGlobalObject methods
virtual void SetContext(nsIScriptContext *aContext);
virtual nsIScriptContext *GetContext();
virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
nsISupports *aState,
PRBool aClearScope);
virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener);
virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
virtual JSObject *GetGlobalJSObject();
@ -275,23 +271,6 @@ nsXBLDocGlobalObject::GetContext()
}
nsresult
nsXBLDocGlobalObject::SetNewDocument(nsIDOMDocument *aDocument,
nsISupports *aState,
PRBool aClearScope)
{
NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;
}
void
nsXBLDocGlobalObject::SetOpenerWindow(nsIDOMWindowInternal *aOpener)
{
NS_NOTREACHED("waaah!");
}
void
nsXBLDocGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner)
{

Просмотреть файл

@ -88,10 +88,6 @@ public:
// nsIScriptGlobalObject methods
virtual void SetContext(nsIScriptContext *aContext);
virtual nsIScriptContext *GetContext();
virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
nsISupports *aState,
PRBool aClearScope);
virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener);
virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
virtual JSObject *GetGlobalJSObject();
@ -837,23 +833,6 @@ nsXULPDGlobalObject::GetContext()
}
nsresult
nsXULPDGlobalObject::SetNewDocument(nsIDOMDocument *aDocument,
nsISupports *aState,
PRBool aClearScope)
{
NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;
}
void
nsXULPDGlobalObject::SetOpenerWindow(nsIDOMWindowInternal *aOpener)
{
NS_NOTREACHED("waaah!");
}
void
nsXULPDGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner)
{

Просмотреть файл

@ -1079,7 +1079,7 @@ nsresult nsDocShell::FindTarget(const PRUnichar *aWindowTarget,
PRBool *aIsNewWindow,
nsIDocShell **aResult)
{
nsresult rv;
nsresult rv = NS_OK;
*aResult = nsnull;
*aIsNewWindow = PR_FALSE;
@ -1149,10 +1149,10 @@ nsresult nsDocShell::FindTarget(const PRUnichar *aWindowTarget,
nsIBrowserDOMWindow::OPEN_NEW,
getter_AddRefs(newWindow));
nsCOMPtr<nsIScriptGlobalObject> newObj =
nsCOMPtr<nsPIDOMWindow> newPIWindow =
do_GetInterface(newWindow);
if (newObj)
newObj->SetOpenerWindow(parentWindow);
if (newPIWindow)
newPIWindow->SetOpenerWindow(parentWindow);
}
}
// else fall through to the normal Open method, from which
@ -5088,7 +5088,10 @@ HandleRestorePresentationEvent(PLEvent *aEvent)
RestorePresentationEvent *event =
NS_STATIC_CAST(RestorePresentationEvent*, aEvent);
nsresult rv = event->mDocShell->RestoreFromHistory();
#ifdef NS_DEBUG
nsresult rv =
#endif
event->mDocShell->RestoreFromHistory();
NS_ASSERTION(NS_SUCCEEDED(rv), "RestoreFromHistory failed");
return nsnull;
}
@ -7983,7 +7986,10 @@ nsDocShell::SetHistoryEntry(nsCOMPtr<nsISHEntry> *aPtr, nsISHEntry *aEntry)
nsDocShell *rootDocShell = NS_STATIC_CAST(nsDocShell*,
rootIDocShell);
nsresult rv = SetChildHistoryEntry(oldRootEntry, rootDocShell,
#ifdef NS_DEBUG
nsresult rv =
#endif
SetChildHistoryEntry(oldRootEntry, rootDocShell,
0, &data);
NS_ASSERTION(NS_SUCCEEDED(rv), "SetChildHistoryEntry failed");
}

Просмотреть файл

@ -77,8 +77,8 @@ class nsIDocument;
struct nsTimeout;
#define NS_PIDOMWINDOW_IID \
{ 0x96138335, 0x51be, 0x4b2e, \
{ 0x81, 0xd4, 0x35, 0x8a, 0xaf, 0x5b, 0x17, 0xfa } }
{ 0x207fe64a, 0x7123, 0x43d0, \
{ 0x91, 0x1d, 0x51, 0x19, 0x35, 0x9a, 0xb5, 0x77 } }
class nsPIDOMWindow : public nsIDOMWindowInternal
{
@ -296,6 +296,9 @@ public:
nsIDOMEvent **aDOMEvent, PRUint32 aFlags,
nsEventStatus *aEventStatus) = 0;
/**
* Get the docshell in this window.
*/
nsIDocShell *GetDocShell()
{
if (mOuterWindow) {
@ -305,8 +308,30 @@ public:
return mDocShell;
}
/**
* Set or unset the docshell in the window.
*/
virtual void SetDocShell(nsIDocShell *aDocShell) = 0;
/**
* Set a new document in the window. Calling this method will in
* most cases create a new inner window. If this method is called on
* an inner window the call will be forewarded to the outer window,
* if the inner window is not the current inner window an
* NS_ERROR_NOT_AVAILABLE error code will be returned. This may be
* called with a pointer to the current document, in that case the
* document remains unchanged, but a new inner window will be
* created.
*/
virtual nsresult SetNewDocument(nsIDocument *aDocument,
nsISupports *aState,
PRBool aClearScope) = 0;
/**
* Set the opener window.
*/
virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener) = 0;
protected:
// The nsPIDOMWindow constructor. The aOuterWindow argument should

Просмотреть файл

@ -52,8 +52,8 @@ class nsIScriptGlobalObjectOwner;
struct JSObject;
#define NS_ISCRIPTGLOBALOBJECT_IID \
{ 0x3a09462f, 0xe0f7, 0x4c54, \
{ 0xaa, 0x08, 0x69, 0x25, 0x51, 0xe0, 0xcc, 0x8d } }
{ 0xd3db0400, 0xcf29, 0x45ac, \
{ 0x80, 0x72, 0x94, 0x6d, 0x99, 0x3d, 0x9d, 0xa8 } }
/**
* The JavaScript specific global object. This often used to store
@ -67,10 +67,6 @@ public:
virtual void SetContext(nsIScriptContext *aContext) = 0;
virtual nsIScriptContext *GetContext() = 0;
virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
nsISupports *aState,
PRBool aClearScope) = 0;
virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener)=0;
/**
* Let the script global object know who its owner is.

Просмотреть файл

@ -802,7 +802,7 @@ WindowStateHolder::~WindowStateHolder()
NS_IMPL_ISUPPORTS1(WindowStateHolder, WindowStateHolder)
nsresult
nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
nsISupports* aState,
PRBool aClearScopeHint)
{
@ -810,7 +810,7 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
}
nsresult
nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
nsISupports* aState,
PRBool aClearScopeHint,
PRBool aIsInternalCall)
@ -823,6 +823,12 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
return NS_ERROR_NOT_INITIALIZED;
}
// Refuse to set a new document if the call came from an inner
// window that's not the current inner window.
if (mOuterWindow->GetCurrentInnerWindow() != this) {
return NS_ERROR_NOT_AVAILABLE;
}
return GetOuterWindowInternal()->SetNewDocument(aDocument,
aState,
aClearScopeHint, PR_TRUE);
@ -839,9 +845,6 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
"Uh, mDocument doesn't match the current inner window "
"document!");
nsCOMPtr<nsIDocument> newDoc(do_QueryInterface(aDocument));
NS_ENSURE_TRUE(newDoc, NS_ERROR_FAILURE);
nsresult rv = NS_OK;
nsCOMPtr<nsIDocument> oldDoc(do_QueryInterface(mDocument));
@ -904,7 +907,7 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
// check xpc here.
nsIXPConnect *xpc = nsContentUtils::XPConnect();
PRBool reUseInnerWindow = WouldReuseInnerWindow(newDoc, PR_FALSE);
PRBool reUseInnerWindow = WouldReuseInnerWindow(aDocument, PR_FALSE);
// Remember the old document's principal.
nsIPrincipal *oldPrincipal = nsnull;
@ -917,7 +920,7 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
// the existing inner window or the new document is from the same
// origin as the old document.
if (!reUseInnerWindow && mNavigator && oldPrincipal) {
nsIPrincipal *newPrincipal = newDoc->GetPrincipal();
nsIPrincipal *newPrincipal = aDocument->GetPrincipal();
rv = NS_ERROR_FAILURE;
if (newPrincipal) {
@ -934,7 +937,7 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
}
}
if (mNavigator && newDoc != oldDoc) {
if (mNavigator && aDocument != oldDoc) {
// We didn't drop our reference to our old navigator object and
// we're loading a new document. Notify the navigator object about
// the new document load so that it can make sure it is ready for
@ -947,8 +950,8 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
// having to *always* reach into the inner window to find the
// document.
mDocument = aDocument;
mDoc = newDoc;
mDocument = do_QueryInterface(aDocument);
mDoc = aDocument;
if (IsOuterWindow()) {
scx->WillInitializeContext();
@ -967,7 +970,7 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
currentInner->mListenerManager = nsnull;
}
if (!reUseInnerWindow || newDoc != oldDoc) {
if (!reUseInnerWindow || aDocument != oldDoc) {
nsWindowSH::InvalidateGlobalScopePolluter(cx, currentInner->mJSObject);
}
}
@ -1074,7 +1077,7 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
PRBool termFuncSet = PR_FALSE;
if (oldDoc == newDoc) {
if (oldDoc == aDocument) {
nsCOMPtr<nsIJSContextStack> stack =
do_GetService(sJSStackContractID);
@ -1177,7 +1180,7 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
// which could hold event handlers alive, which hold the context
// alive etc.
if ((!reUseInnerWindow || newDoc != oldDoc) && !aState) {
if ((!reUseInnerWindow || aDocument != oldDoc) && !aState) {
nsCOMPtr<nsIHTMLDocument> html_doc(do_QueryInterface(mDocument));
nsWindowSH::InstallGlobalScopePolluter(cx, newInnerWindow->mJSObject,
html_doc);
@ -1214,14 +1217,14 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument,
NS_ENSURE_SUCCESS(rv, rv);
}
if (newDoc) {
newDoc->SetScriptGlobalObject(newInnerWindow);
if (aDocument) {
aDocument->SetScriptGlobalObject(newInnerWindow);
}
if (!aState) {
if (reUseInnerWindow) {
newInnerWindow->mDocument = aDocument;
newInnerWindow->mDoc = newDoc;
newInnerWindow->mDocument = do_QueryInterface(aDocument);
newInnerWindow->mDoc = aDocument;
// We're reusing the inner window for a new document. In this
// case we don't clear the inner window's scope, but we must
@ -5704,9 +5707,9 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName,
containerPref, nsIBrowserDOMWindow::OPEN_NEW,
getter_AddRefs(domReturn));
nsCOMPtr<nsIScriptGlobalObject> domObj(do_GetInterface(domReturn));
if (domObj) {
domObj->SetOpenerWindow(this);
nsCOMPtr<nsPIDOMWindow> domWin(do_GetInterface(domReturn));
if (domWin) {
domWin->SetOpenerWindow(this);
}
}
} else {

Просмотреть файл

@ -153,17 +153,8 @@ public:
// nsIScriptGlobalObject
virtual void SetContext(nsIScriptContext *aContext);
virtual nsIScriptContext *GetContext();
virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
nsISupports *aState,
PRBool aClearScopeHint);
virtual void SetDocShell(nsIDocShell* aDocShell);
virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener);
virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
virtual nsresult HandleDOMEvent(nsPresContext* aPresContext,
nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus* aEventStatus);
virtual JSObject *GetGlobalJSObject();
virtual void OnFinalize(JSObject *aJSObject);
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
@ -219,8 +210,18 @@ public:
virtual NS_HIDDEN_(nsresult) SaveWindowState(nsISupports **aState);
virtual NS_HIDDEN_(nsresult) RestoreWindowState(nsISupports *aState);
virtual NS_HIDDEN_(nsresult) ResumeTimeouts();
virtual NS_HIDDEN_(PRBool) WouldReuseInnerWindow(nsIDocument *aNewDocument);
virtual NS_HIDDEN_(nsresult) HandleDOMEvent(nsPresContext* aPresContext,
nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus* aEventStatus);
virtual NS_HIDDEN_(void) SetDocShell(nsIDocShell* aDocShell);
virtual NS_HIDDEN_(nsresult) SetNewDocument(nsIDocument *aDocument,
nsISupports *aState,
PRBool aClearScopeHint);
virtual NS_HIDDEN_(void) SetOpenerWindow(nsIDOMWindowInternal *aOpener);
// nsIDOMViewCSS
NS_DECL_NSIDOMVIEWCSS
@ -277,7 +278,7 @@ protected:
void FreeInnerObjects(JSContext *cx);
nsresult SetNewDocument(nsIDOMDocument *aDocument,
nsresult SetNewDocument(nsIDocument *aDocument,
nsISupports *aState,
PRBool aClearScopeHint,
PRBool aIsInternalCall);
@ -383,7 +384,6 @@ protected:
already_AddRefed<nsIWidget> GetMainWidget();
void SuspendTimeouts();
virtual nsresult ResumeTimeouts();
void Freeze()
{

Просмотреть файл

@ -1526,13 +1526,13 @@ nsWindowWatcher::ReadyOpenedDocShellItem(nsIDocShellTreeItem *aOpenedItem,
nsresult rv = NS_ERROR_FAILURE;
*aOpenedWindow = 0;
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(aOpenedItem));
if (globalObject) {
nsCOMPtr<nsPIDOMWindow> piOpenedWindow(do_GetInterface(aOpenedItem));
if (piOpenedWindow) {
if (aParent) {
nsCOMPtr<nsIDOMWindowInternal> internalParent(do_QueryInterface(aParent));
globalObject->SetOpenerWindow(internalParent); // damnit
piOpenedWindow->SetOpenerWindow(internalParent); // damnit
}
rv = CallQueryInterface(globalObject, aOpenedWindow);
rv = CallQueryInterface(piOpenedWindow, aOpenedWindow);
}
return rv;
}

Просмотреть файл

@ -47,7 +47,6 @@
#include "nsIContent.h"
#include "nsIContentViewerContainer.h"
#include "nsIDocumentViewer.h"
#include "nsIDOMWindowInternal.h"
#include "nsIDocumentViewerPrint.h"
#include "nsIDocument.h"
@ -59,7 +58,6 @@
#include "nsICSSStyleSheet.h"
#include "nsIFrame.h"
#include "nsIScriptGlobalObject.h"
#include "nsILinkHandler.h"
#include "nsIDOMDocument.h"
#include "nsISelectionListener.h"
@ -848,16 +846,12 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
if (!aInPrintPreview) {
// Set script-context-owner in the document
nsCOMPtr<nsIScriptGlobalObject> global;
requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObject),
getter_AddRefs(global));
nsCOMPtr<nsPIDOMWindow> window;
requestor->GetInterface(NS_GET_IID(nsPIDOMWindow),
getter_AddRefs(window));
if (global) {
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument));
if (domdoc) {
global->SetNewDocument(domdoc, aState, PR_TRUE);
}
if (window) {
window->SetNewDocument(mDocument, aState, PR_TRUE);
}
}
}
@ -1627,9 +1621,9 @@ DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
mDocument = newDoc;
// Set the script global object on the new document
nsCOMPtr<nsIScriptGlobalObject> global = do_GetInterface(container);
if (global) {
global->SetNewDocument(aDocument, nsnull, PR_TRUE);
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(container);
if (window) {
window->SetNewDocument(newDoc, nsnull, PR_TRUE);
}
}

Просмотреть файл

@ -347,7 +347,10 @@ public:
static const nsIHashable* KeyToPointer(nsIHashable* aKey) { return aKey; }
static PLDHashNumber HashKey(const nsIHashable* aKey) {
PRUint32 code = 8888; // magic number if GetHashCode fails :-(
nsresult rv = NS_CONST_CAST(nsIHashable*,aKey)->GetHashCode(&code);
#ifdef NS_DEBUG
nsresult rv =
#endif
NS_CONST_CAST(nsIHashable*,aKey)->GetHashCode(&code);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetHashCode should not throw!");
return code;
}