Bug 861729 - Remove nsPIDOMWindow::mDocument r=Ms2ger

This commit is contained in:
David Zbarsky 2013-04-24 00:22:37 -04:00
parent 720289e06b
commit 13282d5cd7
2 changed files with 49 additions and 73 deletions

View File

@ -1214,7 +1214,6 @@ nsGlobalWindow::~nsGlobalWindow()
}
}
mDocument = nullptr; // Forces Release
mDoc = nullptr;
NS_ASSERTION(!mArguments, "mArguments wasn't cleaned up properly!");
@ -1466,9 +1465,7 @@ nsGlobalWindow::FreeInnerObjects()
mScreen = nullptr;
}
if (mDocument) {
NS_ASSERTION(mDoc, "Why is mDoc null?");
if (mDoc) {
// Remember the document's principal and URI.
mDocumentPrincipal = mDoc->NodePrincipal();
mDocumentURI = mDoc->GetDocumentURI();
@ -1476,7 +1473,6 @@ nsGlobalWindow::FreeInnerObjects()
}
// Remove our reference to the document and the document principal.
mDocument = nullptr;
mDoc = nullptr;
mFocusedNode = nullptr;
@ -1648,7 +1644,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
// Traverse stuff from nsPIDOMWindow
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFocusedNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioContexts)
@ -1695,7 +1690,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
// Unlink stuff from nsPIDOMWindow
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentTarget)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFrameElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFocusedNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAudioContexts)
@ -2145,7 +2139,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
NS_ASSERTION(!GetCurrentInnerWindow() ||
GetCurrentInnerWindow()->GetExtantDoc() == mDoc,
"Uh, mDocument doesn't match the current inner window "
"Uh, mDoc doesn't match the current inner window "
"document!");
bool wouldReuseInnerWindow = WouldReuseInnerWindow(aDocument);
@ -2157,7 +2151,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIDocument> oldDoc(do_QueryInterface(mDocument));
nsCOMPtr<nsIDocument> oldDoc = mDoc;
nsIScriptContext *scx = GetContextInternal();
NS_ENSURE_TRUE(scx, NS_ERROR_NOT_INITIALIZED);
@ -2172,7 +2166,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
}
#endif
if (!mDocument) {
if (!mDoc) {
// First document load.
// Get our private root. If it is equal to us, then we need to
@ -2199,10 +2193,9 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
nsresult rv = NS_OK;
// Set mDocument even if this is an outer window to avoid
// Set mDoc even if this is an outer window to avoid
// having to *always* reach into the inner window to find the
// document.
mDocument = do_QueryInterface(aDocument);
mDoc = aDocument;
#ifdef DEBUG
@ -2472,7 +2465,6 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
if (!aState) {
if (reUseInnerWindow) {
if (newInnerWindow->mDoc != aDocument) {
newInnerWindow->mDocument = do_QueryInterface(aDocument);
newInnerWindow->mDoc = aDocument;
// We're reusing the inner window for a new document. In this
@ -2560,12 +2552,12 @@ nsGlobalWindow::PreloadLocalStorage()
void
nsGlobalWindow::DispatchDOMWindowCreated()
{
if (!mDoc || !mDocument) {
if (!mDoc) {
return;
}
// Fire DOMWindowCreated at chrome event listeners
nsContentUtils::DispatchChromeEvent(mDoc, mDocument, NS_LITERAL_STRING("DOMWindowCreated"),
nsContentUtils::DispatchChromeEvent(mDoc, mDoc, NS_LITERAL_STRING("DOMWindowCreated"),
true /* bubbles */,
false /* not cancellable */);
@ -2606,7 +2598,6 @@ nsGlobalWindow::InnerSetNewDocument(nsIDocument* aDocument)
}
#endif
mDocument = do_QueryInterface(aDocument);
mDoc = aDocument;
mFocusedNode = nullptr;
mLocalStorage = nullptr;
@ -2702,14 +2693,13 @@ nsGlobalWindow::DetachFromDocShell()
if (currentInner) {
NS_ASSERTION(mDoc, "Must have doc!");
// Remember the document's principal and URI.
mDocumentPrincipal = mDoc->NodePrincipal();
mDocumentURI = mDoc->GetDocumentURI();
mDocBaseURI = mDoc->GetDocBaseURI();
// Release our document reference
mDocument = nullptr;
mDoc = nullptr;
mFocusedNode = nullptr;
}
@ -3044,8 +3034,7 @@ nsGlobalWindow::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
aVisitor.mEvent->mFlags.mIsTrusted) {
// Execute bindingdetached handlers before we tear ourselves
// down.
if (mDocument) {
NS_ASSERTION(mDoc, "Must have doc");
if (mDoc) {
mDoc->BindingManager()->ExecuteDetachedHandlers();
}
mIsDocumentLoaded = false;
@ -3230,7 +3219,7 @@ nsPIDOMWindow::MaybeCreateDoc()
{
MOZ_ASSERT(!mDoc);
if (nsIDocShell* docShell = GetDocShell()) {
// Note that |document| here is the same thing as our mDocument, but we
// Note that |document| here is the same thing as our mDoc, but we
// don't have to explicitly set the member variable because the docshell
// has already called SetNewDocument().
nsCOMPtr<nsIDocument> document = do_GetInterface(docShell);
@ -3746,9 +3735,8 @@ nsGlobalWindow::GetApplicationCache(nsIDOMOfflineResourceList **aApplicationCach
nsresult rv = webNav->GetCurrentURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
nsCOMPtr<nsIURI> manifestURI;
nsContentUtils::GetOfflineAppManifest(doc, getter_AddRefs(manifestURI));
nsContentUtils::GetOfflineAppManifest(mDoc, getter_AddRefs(manifestURI));
nsRefPtr<nsDOMOfflineResourceList> applicationCache =
new nsDOMOfflineResourceList(manifestURI, uri, this);
@ -4521,8 +4509,7 @@ nsGlobalWindow::CheckSecurityWidthAndHeight(int32_t* aWidth, int32_t* aHeight)
#ifdef MOZ_XUL
if (!nsContentUtils::IsCallerChrome()) {
// if attempting to resize the window, hide any open popups
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
nsContentUtils::HidePopupsInDocument(doc);
nsContentUtils::HidePopupsInDocument(mDoc);
}
#endif
@ -4587,8 +4574,7 @@ nsGlobalWindow::CheckSecurityLeftAndTop(int32_t* aLeft, int32_t* aTop)
if (!nsContentUtils::IsCallerChrome()) {
#ifdef MOZ_XUL
// if attempting to move the window, hide any open popups
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
nsContentUtils::HidePopupsInDocument(doc);
nsContentUtils::HidePopupsInDocument(mDoc);
#endif
nsGlobalWindow* rootWindow =
@ -4799,8 +4785,7 @@ bool
nsGlobalWindow::DispatchCustomEvent(const char *aEventName)
{
bool defaultActionEnabled = true;
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
nsContentUtils::DispatchTrustedEvent(doc,
nsContentUtils::DispatchTrustedEvent(mDoc,
GetOuterWindow(),
NS_ConvertASCIItoUTF16(aEventName),
true, true, &defaultActionEnabled);
@ -4962,8 +4947,7 @@ nsGlobalWindow::SetFullScreenInternal(bool aFullScreen, bool aRequireTrust)
// DOM full-screen mode and the user exits full-screen mode with
// the browser full-screen mode toggle keyboard-shortcut, we'll detect
// that and leave DOM API full-screen mode too.
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
nsIDocument::ExitFullscreen(doc, /* async */ false);
nsIDocument::ExitFullscreen(mDoc, /* async */ false);
}
if (!mWakeLock && mFullScreen) {
@ -5517,10 +5501,8 @@ nsGlobalWindow::Focus()
mDocShell->GetItemType(&itemType);
if (itemType == nsIDocShellTreeItem::typeChrome &&
GetPrivateRoot() == static_cast<nsIDOMWindow*>(this) &&
mDocument) {
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
NS_ASSERTION(doc, "Bogus doc?");
nsIURI* ourURI = doc->GetDocumentURI();
mDoc) {
nsIURI* ourURI = mDoc->GetDocumentURI();
if (ourURI) {
lookForPresShell = !NS_IsAboutBlank(ourURI);
}
@ -5543,8 +5525,7 @@ nsGlobalWindow::Focus()
if (!parentdoc)
return NS_OK;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
nsIContent* frame = parentdoc->FindContentForSubDocument(doc);
nsIContent* frame = parentdoc->FindContentForSubDocument(mDoc);
nsCOMPtr<nsIDOMElement> frameElement = do_QueryInterface(frame);
if (frameElement) {
uint32_t flags = nsIFocusManager::FLAG_NOSCROLL;
@ -5586,12 +5567,11 @@ nsGlobalWindow::Blur()
// if the root is focused, clear the focus
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
if (fm && mDocument) {
if (fm && mDoc) {
nsCOMPtr<nsIDOMElement> element;
fm->GetFocusedElementForWindow(this, false, nullptr, getter_AddRefs(element));
nsCOMPtr<nsIContent> content = do_QueryInterface(element);
if (content == doc->GetRootElement())
if (content == mDoc->GetRootElement())
fm->ClearFocus(this);
}
}
@ -6141,7 +6121,7 @@ nsGlobalWindow::DisableExternalCapture()
}
static
bool IsPopupBlocked(nsIDOMDocument* aDoc)
bool IsPopupBlocked(nsIDocument* aDoc)
{
nsCOMPtr<nsIPopupWindowManager> pm =
do_GetService(NS_POPUPWINDOWMANAGER_CONTRACTID);
@ -6150,15 +6130,13 @@ bool IsPopupBlocked(nsIDOMDocument* aDoc)
return false;
}
bool blocked = true;
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aDoc));
if (doc) {
uint32_t permission = nsIPopupWindowManager::ALLOW_POPUP;
pm->TestPermission(doc->NodePrincipal(), &permission);
blocked = (permission == nsIPopupWindowManager::DENY_POPUP);
if (!aDoc) {
return true;
}
return blocked;
uint32_t permission = nsIPopupWindowManager::ALLOW_POPUP;
pm->TestPermission(aDoc->NodePrincipal(), &permission);
return permission == nsIPopupWindowManager::DENY_POPUP;
}
/* static */
@ -6171,11 +6149,11 @@ nsGlobalWindow::FirePopupBlockedEvent(nsIDocument* aDoc,
if (aDoc) {
// Fire a "DOMPopupBlocked" event so that the UI can hear about
// blocked popups.
ErrorResult rv;
nsRefPtr<nsDOMEvent> event =
aDoc->CreateEvent(NS_LITERAL_STRING("PopupBlockedEvents"), rv);
nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(aDoc);
nsCOMPtr<nsIDOMEvent> event;
doc->CreateEvent(NS_LITERAL_STRING("PopupBlockedEvents"), getter_AddRefs(event));
if (event) {
nsCOMPtr<nsIDOMPopupBlockedEvent> pbev(do_QueryObject(event));
nsCOMPtr<nsIDOMPopupBlockedEvent> pbev(do_QueryInterface(event));
pbev->InitPopupBlockedEvent(NS_LITERAL_STRING("DOMPopupBlocked"),
true, true, aRequestingWindow,
aPopupURI, aPopupWindowName,
@ -6214,7 +6192,7 @@ nsGlobalWindow::CanSetProperty(const char *aPrefName)
bool
nsGlobalWindow::PopupWhitelisted()
{
if (!IsPopupBlocked(mDocument))
if (!IsPopupBlocked(mDoc))
return true;
nsCOMPtr<nsIDOMWindow> parent;
@ -6758,12 +6736,13 @@ PostMessageEvent::Run()
}
// Create the event
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(targetWindow->mDocument);
if (!domDoc)
nsIDocument* doc = targetWindow->mDoc;
if (!doc)
return NS_OK;
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc);
nsCOMPtr<nsIDOMEvent> event;
domDoc->CreateEvent(NS_LITERAL_STRING("MessageEvent"),
getter_AddRefs(event));
domDoc->CreateEvent(NS_LITERAL_STRING("MessageEvent"), getter_AddRefs(event));
if (!event)
return NS_OK;
@ -8695,11 +8674,10 @@ nsGlobalWindow::UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent)
return;
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
if (!presShell || !mDocument)
if (!presShell || !mDoc)
return;
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
Element *rootElement = doc->GetRootElement();
Element *rootElement = mDoc->GetRootElement();
if (rootElement) {
if ((mHasFocus || aFocusChanged) &&
(mFocusedNode == rootElement || aNewContent == rootElement)) {
@ -8837,8 +8815,8 @@ nsGlobalWindow::GetSessionStorage(nsIDOMStorage ** aSessionStorage)
*aSessionStorage = nullptr;
nsString documentURI;
if (mDocument) {
mDocument->GetDocumentURI(documentURI);
if (mDoc) {
mDoc->GetDocumentURI(documentURI);
}
// If the document has the sandboxed origin flag set
@ -8922,8 +8900,8 @@ nsGlobalWindow::GetLocalStorage(nsIDOMStorage ** aLocalStorage)
}
nsString documentURI;
if (mDocument) {
mDocument->GetDocumentURI(documentURI);
if (mDoc) {
mDoc->GetDocumentURI(documentURI);
}
nsIDocShell* docShell = GetDocShell();
@ -9096,9 +9074,8 @@ nsGlobalWindow::FireOfflineStatusEvent()
}
}
else {
nsCOMPtr<nsIDOMElement> documentElement;
mDocument->GetDocumentElement(getter_AddRefs(documentElement));
if(documentElement) {
Element* documentElement = mDoc->GetDocumentElement();
if(documentElement) {
eventTarget = documentElement;
}
}
@ -9996,7 +9973,7 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
// If we don't have a document (we could have been unloaded since
// the call to setTimeout was made), do nothing.
if (!mDocument) {
if (!mDoc) {
return NS_OK;
}
@ -10819,8 +10796,8 @@ nsGlobalWindow::BuildURIfromBase(const char *aURL, nsIURI **aBuiltURI,
// get JSContext
NS_ASSERTION(scx, "opening window missing its context");
NS_ASSERTION(mDocument, "opening window missing its document");
if (!scx || !mDocument)
NS_ASSERTION(mDoc, "opening window missing its document");
if (!scx || !mDoc)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMChromeWindow> chrome_win = do_QueryObject(this);

View File

@ -670,8 +670,7 @@ protected:
// value on both the outer window and the current inner window. Make
// sure you keep them in sync!
nsCOMPtr<mozilla::dom::EventTarget> mChromeEventHandler; // strong
nsCOMPtr<nsIDOMDocument> mDocument; // strong
nsCOMPtr<nsIDocument> mDoc; // strong, for fast access
nsCOMPtr<nsIDocument> mDoc; // strong
// Cache the URI when mDoc is cleared.
nsCOMPtr<nsIURI> mDocumentURI; // strong
nsCOMPtr<nsIURI> mDocBaseURI; // strong