From 691abfe5eb75c899a6ea5aeeea7c37f1376a0ea0 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Fri, 19 Apr 2013 18:18:33 -0400 Subject: [PATCH] Bug 861729 - Remove nsPIDOMWindow::GetExtantDocument r=Ms2ger --- content/base/public/nsContentUtils.h | 4 +- content/base/src/nsContentUtils.cpp | 8 ++-- content/base/src/nsDOMFile.cpp | 5 +-- content/base/src/nsDOMMutationObserver.h | 2 +- content/base/src/nsDocument.cpp | 2 +- content/base/src/nsFrameLoader.cpp | 6 +-- content/base/src/nsXMLHttpRequest.cpp | 6 +-- content/events/src/nsDOMEvent.cpp | 6 +-- content/events/src/nsDOMEventTargetHelper.cpp | 4 +- content/events/src/nsEventDispatcher.cpp | 2 +- content/events/src/nsEventListenerManager.cpp | 6 +-- content/events/src/nsEventStateManager.cpp | 10 +---- content/html/content/src/HTMLImageElement.cpp | 3 +- content/html/content/src/HTMLInputElement.cpp | 3 +- .../html/content/src/HTMLOptionElement.cpp | 3 +- content/html/document/src/nsHTMLDocument.cpp | 3 +- content/xml/document/src/XMLDocument.cpp | 3 +- .../templates/src/nsXULTemplateBuilder.cpp | 3 +- docshell/base/nsDocShell.cpp | 8 +--- dom/base/Navigator.cpp | 24 +++++------- dom/base/nsDOMClassInfo.cpp | 4 +- dom/base/nsDOMException.cpp | 3 +- dom/base/nsDOMWindowUtils.cpp | 32 +++++++-------- dom/base/nsGlobalWindow.cpp | 37 ++++++++---------- dom/base/nsGlobalWindow.h | 2 +- dom/base/nsGlobalWindowCommands.cpp | 2 +- dom/base/nsHistory.cpp | 6 +-- dom/base/nsJSEnvironment.cpp | 2 +- dom/base/nsJSTimeoutHandler.cpp | 2 +- dom/base/nsLocation.cpp | 2 +- dom/base/nsPIDOMWindow.h | 5 --- dom/base/nsWindowMemoryReporter.cpp | 2 +- dom/indexedDB/IDBDatabase.h | 3 +- dom/media/MediaManager.cpp | 3 +- dom/power/WakeLock.cpp | 39 +++++++++---------- dom/src/jsurl/nsJSProtocolHandler.cpp | 5 +-- dom/workers/WorkerPrivate.cpp | 4 +- .../src/nsAutoWindowStateHelper.cpp | 20 +++++++--- .../windowwatcher/src/nsWindowWatcher.cpp | 10 ++--- js/xpconnect/src/XPCComponents.cpp | 3 +- layout/base/nsDocumentViewer.cpp | 5 +-- layout/base/nsPresShell.cpp | 2 +- 42 files changed, 132 insertions(+), 172 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 9da9cc53d9c..bae2e293cff 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -426,7 +426,7 @@ public: * * @return The document or null if no JS Context. */ - static nsIDOMDocument *GetDocumentFromCaller(); + static nsIDocument* GetDocumentFromCaller(); /** * Get the document through the JS context that's currently on the stack. @@ -435,7 +435,7 @@ public: * * @return The document or null if no JS context */ - static nsIDOMDocument *GetDocumentFromContext(); + static nsIDocument* GetDocumentFromContext(); // Check if a node is in the document prolog, i.e. before the document // element. diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 6e22edf6e79..cde5e19bee9 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -1710,7 +1710,7 @@ nsContentUtils::GetWindowFromCaller() return nullptr; } -nsIDOMDocument * +nsIDocument* nsContentUtils::GetDocumentFromCaller() { JSContext *cx = nullptr; @@ -1726,10 +1726,10 @@ nsContentUtils::GetDocumentFromCaller() return nullptr; } - return win->GetExtantDocument(); + return win->GetExtantDoc(); } -nsIDOMDocument * +nsIDocument* nsContentUtils::GetDocumentFromContext() { JSContext *cx = nullptr; @@ -1741,7 +1741,7 @@ nsContentUtils::GetDocumentFromContext() if (sgo) { nsCOMPtr pwin = do_QueryInterface(sgo); if (pwin) { - return pwin->GetExtantDocument(); + return pwin->GetExtantDoc(); } } } diff --git a/content/base/src/nsDOMFile.cpp b/content/base/src/nsDOMFile.cpp index 10490dc1b94..ac82f1868ed 100644 --- a/content/base/src/nsDOMFile.cpp +++ b/content/base/src/nsDOMFile.cpp @@ -260,8 +260,7 @@ nsDOMFileBase::MozSlice(int64_t aStart, int64_t aEnd, if (sgo) { nsCOMPtr window = do_QueryInterface(sgo); if (window) { - nsCOMPtr document = - do_QueryInterface(window->GetExtantDocument()); + nsCOMPtr document = window->GetExtantDoc(); if (document) { document->WarnOnceAbout(nsIDocument::eMozSlice); } @@ -276,7 +275,7 @@ nsDOMFileBase::GetInternalStream(nsIInputStream **aStream) { // Must be overridden NS_NOTREACHED("Must override GetInternalStream"); - + return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/content/base/src/nsDOMMutationObserver.h b/content/base/src/nsDOMMutationObserver.h index a9694ad8234..f778942ecc6 100644 --- a/content/base/src/nsDOMMutationObserver.h +++ b/content/base/src/nsDOMMutationObserver.h @@ -408,7 +408,7 @@ protected: bool Suppressed() { if (mOwner) { - nsCOMPtr d = do_QueryInterface(mOwner->GetExtantDocument()); + nsCOMPtr d = mOwner->GetExtantDoc(); return d && d->IsInSyncOperation(); } return false; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index c3cec880713..964ac4b0022 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -11295,7 +11295,7 @@ nsAutoSyncOperation::nsAutoSyncOperation(nsIDocument* aDoc) win->GetTop(getter_AddRefs(topWindow)); nsCOMPtr top = do_QueryInterface(topWindow); if (top) { - nsCOMPtr doc = do_QueryInterface(top->GetExtantDocument()); + nsCOMPtr doc = top->GetExtantDoc(); MarkDocumentTreeToBeInSyncOperation(doc, &mDocuments); } } diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index 0dbdc172c92..6c24715495a 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -1095,10 +1095,8 @@ nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther, SameCOMIdentity(otherChromeEventHandler, otherContent), "How did that happen, exactly?"); - nsCOMPtr ourChildDocument = - do_QueryInterface(ourWindow->GetExtantDocument()); - nsCOMPtr otherChildDocument = - do_QueryInterface(otherWindow->GetExtantDocument()); + nsCOMPtr ourChildDocument = ourWindow->GetExtantDoc(); + nsCOMPtr otherChildDocument = otherWindow ->GetExtantDoc(); if (!ourChildDocument || !otherChildDocument) { // This shouldn't be happening return NS_ERROR_NOT_IMPLEMENTED; diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index aa552f135c0..e36112e9018 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -390,7 +390,7 @@ nsXMLHttpRequest::InitParameters(bool aAnon, bool aSystem) // Chrome is always allowed access, so do the permission check only // for non-chrome pages. if (!nsContentUtils::IsCallerChrome()) { - nsCOMPtr doc = do_QueryInterface(window->GetExtantDocument()); + nsCOMPtr doc = window->GetExtantDoc(); if (!doc) { return; } @@ -560,7 +560,7 @@ static void LogMessage(const char* aWarning, nsPIDOMWindow* aWindow) { nsCOMPtr doc; if (aWindow) { - doc = do_QueryInterface(aWindow->GetExtantDocument()); + doc = aWindow->GetExtantDoc(); } nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "DOM", doc, @@ -2861,7 +2861,7 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable& aBody) nsCOMPtr suspendedWindow(do_QueryInterface(topWindow)); if (suspendedWindow && (suspendedWindow = suspendedWindow->GetCurrentInnerWindow())) { - suspendedDoc = do_QueryInterface(suspendedWindow->GetExtantDocument()); + suspendedDoc = suspendedWindow->GetExtantDoc(); if (suspendedDoc) { suspendedDoc->SuppressEventHandling(); } diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 18058e53fa0..0c0f40722f5 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -321,7 +321,7 @@ nsDOMEvent::Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj, bool trusted = false; nsCOMPtr w = do_QueryInterface(aOwner); if (w) { - nsCOMPtr d = do_QueryInterface(w->GetExtantDocument()); + nsCOMPtr d = w->GetExtantDoc(); if (d) { trusted = nsContentUtils::IsChromeDoc(d); nsIPresShell* s = d->GetShell(); @@ -369,7 +369,7 @@ nsDOMEvent::Init(mozilla::dom::EventTarget* aGlobal) bool trusted = false; nsCOMPtr w = do_QueryInterface(aGlobal); if (w) { - nsCOMPtr d = do_QueryInterface(w->GetExtantDocument()); + nsCOMPtr d = w->GetExtantDoc(); if (d) { trusted = nsContentUtils::IsChromeDoc(d); nsIPresShell* s = d->GetShell(); @@ -521,7 +521,7 @@ nsDOMEvent::PreventDefault() if (!node) { nsCOMPtr win = do_QueryInterface(mEvent->currentTarget); if (win) { - node = do_QueryInterface(win->GetExtantDocument()); + node = win->GetExtantDoc(); } } if (node && !nsContentUtils::IsChromeDoc(node->OwnerDoc())) { diff --git a/content/events/src/nsDOMEventTargetHelper.cpp b/content/events/src/nsDOMEventTargetHelper.cpp index cd6c34e6cc0..066183f57b7 100644 --- a/content/events/src/nsDOMEventTargetHelper.cpp +++ b/content/events/src/nsDOMEventTargetHelper.cpp @@ -26,8 +26,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDOMEventTargetHelper) if (MOZ_UNLIKELY(cb.WantDebugInfo())) { char name[512]; nsAutoString uri; - if (tmp->mOwnerWindow && tmp->mOwnerWindow->GetExtantDocument()) { - tmp->mOwnerWindow->GetExtantDocument()->GetDocumentURI(uri); + if (tmp->mOwnerWindow && tmp->mOwnerWindow->GetExtantDoc()) { + tmp->mOwnerWindow->GetExtantDoc()->GetDocumentURI(uri); } PR_snprintf(name, sizeof(name), "nsDOMEventTargetHelper %s", NS_ConvertUTF16toUTF8(uri).get()); diff --git a/content/events/src/nsEventDispatcher.cpp b/content/events/src/nsEventDispatcher.cpp index 2be0fa4eb25..f937037f59e 100644 --- a/content/events/src/nsEventDispatcher.cpp +++ b/content/events/src/nsEventDispatcher.cpp @@ -463,7 +463,7 @@ nsEventDispatcher::Dispatch(nsISupports* aTarget, if (!node) { nsCOMPtr win = do_QueryInterface(aTarget); if (win) { - node = do_QueryInterface(win->GetExtantDocument()); + node = win->GetExtantDoc(); } } diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 0e9518a8313..6c87a7797c0 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -282,7 +282,7 @@ nsEventListenerManager::AddEventListenerInternal( // Go from our target to the nearest enclosing DOM window. nsPIDOMWindow* window = GetInnerWindowForTarget(); if (window) { - nsCOMPtr doc = do_QueryInterface(window->GetExtantDocument()); + nsCOMPtr doc = window->GetExtantDoc(); if (doc) { doc->WarnOnceAbout(nsIDocument::eMutationEvent); } @@ -336,7 +336,7 @@ nsEventListenerManager::AddEventListenerInternal( nsPIDOMWindow* window = GetInnerWindowForTarget(); if (window) { #ifdef DEBUG - nsCOMPtr d = do_QueryInterface(window->GetExtantDocument()); + nsCOMPtr d = window->GetExtantDoc(); NS_WARN_IF_FALSE(!nsContentUtils::IsChromeDoc(d), "Please do not use mouseenter/leave events in chrome. " "They are slower than mouseover/out!"); @@ -828,7 +828,7 @@ nsEventListenerManager::CompileEventHandlerInternal(nsListenerStruct *aListenerS } else { win = do_QueryInterface(mTarget); if (win) { - doc = do_QueryInterface(win->GetExtantDocument()); + doc = win->GetExtantDoc(); } } diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 9646ef5c99f..3a217e51ec0 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -265,13 +265,7 @@ static nsIDocument * GetDocumentFromWindow(nsIDOMWindow *aWindow) { nsCOMPtr win = do_QueryInterface(aWindow); - nsCOMPtr doc; - - if (win) { - doc = do_QueryInterface(win->GetExtantDocument()); - } - - return doc; + return win ? win->GetExtantDoc() : nullptr; } static int32_t @@ -3257,7 +3251,7 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext, currentWindow->GetTop(getter_AddRefs(currentTop)); mDocument->GetWindow()->GetTop(getter_AddRefs(newTop)); nsCOMPtr win = do_QueryInterface(currentWindow); - nsCOMPtr currentDoc = do_QueryInterface(win->GetExtantDocument()); + nsCOMPtr currentDoc = win->GetExtantDoc(); if (nsContentUtils::IsChromeDoc(currentDoc) || (currentTop && newTop && currentTop != newTop)) { fm->SetFocusedWindow(mDocument->GetWindow()); diff --git a/content/html/content/src/HTMLImageElement.cpp b/content/html/content/src/HTMLImageElement.cpp index c77fe0ef219..2c2e4a1ff69 100644 --- a/content/html/content/src/HTMLImageElement.cpp +++ b/content/html/content/src/HTMLImageElement.cpp @@ -53,8 +53,7 @@ NS_NewHTMLImageElement(already_AddRefed aNodeInfo, */ nsCOMPtr nodeInfo(aNodeInfo); if (!nodeInfo) { - nsCOMPtr doc = - do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); + nsCOMPtr doc = nsContentUtils::GetDocumentFromCaller(); NS_ENSURE_TRUE(doc, nullptr); nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::img, nullptr, diff --git a/content/html/content/src/HTMLInputElement.cpp b/content/html/content/src/HTMLInputElement.cpp index 642507d1955..c144ed91bf1 100644 --- a/content/html/content/src/HTMLInputElement.cpp +++ b/content/html/content/src/HTMLInputElement.cpp @@ -397,8 +397,7 @@ HTMLInputElement::AsyncClickHandler::Run() uint32_t permission; pm->TestPermission(doc->NodePrincipal(), &permission); if (permission == nsIPopupWindowManager::DENY_POPUP) { - nsCOMPtr domDoc = do_QueryInterface(doc); - nsGlobalWindow::FirePopupBlockedEvent(domDoc, win, nullptr, EmptyString(), EmptyString()); + nsGlobalWindow::FirePopupBlockedEvent(doc, win, nullptr, EmptyString(), EmptyString()); return NS_OK; } } diff --git a/content/html/content/src/HTMLOptionElement.cpp b/content/html/content/src/HTMLOptionElement.cpp index 6c54815a881..5bfadb6430c 100644 --- a/content/html/content/src/HTMLOptionElement.cpp +++ b/content/html/content/src/HTMLOptionElement.cpp @@ -44,8 +44,7 @@ NS_NewHTMLOptionElement(already_AddRefed aNodeInfo, */ nsCOMPtr nodeInfo(aNodeInfo); if (!nodeInfo) { - nsCOMPtr doc = - do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); + nsCOMPtr doc = nsContentUtils::GetDocumentFromCaller(); NS_ENSURE_TRUE(doc, nullptr); nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::option, nullptr, diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 4b13be92692..7c2d510520f 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -1504,8 +1504,7 @@ nsHTMLDocument::Open(JSContext* cx, // Note: We want to use GetDocumentFromContext here because this document // should inherit the security information of the document that's opening us, // (since if it's secure, then it's presumably trusted). - nsCOMPtr callerDoc = - do_QueryInterface(nsContentUtils::GetDocumentFromContext()); + nsCOMPtr callerDoc = nsContentUtils::GetDocumentFromContext(); if (!callerDoc) { // If we're called from C++ or in some other way without an originating // document we can't do a document.open w/o changing the principal of the diff --git a/content/xml/document/src/XMLDocument.cpp b/content/xml/document/src/XMLDocument.cpp index 443e899b6fb..ed3deae6fab 100644 --- a/content/xml/document/src/XMLDocument.cpp +++ b/content/xml/document/src/XMLDocument.cpp @@ -320,8 +320,7 @@ XMLDocument::Load(const nsAString& aUrl, ErrorResult& aRv) ReportUseOfDeprecatedMethod(this, "UseOfDOM3LoadMethodWarning"); - nsCOMPtr callingDoc = - do_QueryInterface(nsContentUtils::GetDocumentFromContext()); + nsCOMPtr callingDoc = nsContentUtils::GetDocumentFromContext(); nsIURI *baseURI = mDocumentURI; nsAutoCString charset; diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index 5401dd38604..a397e73e60e 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -1074,8 +1074,7 @@ nsXULTemplateBuilder::Observe(nsISupports* aSubject, if (!strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC)) { nsCOMPtr window = do_QueryInterface(aSubject); if (window) { - nsCOMPtr doc = - do_QueryInterface(window->GetExtantDocument()); + nsCOMPtr doc = window->GetExtantDoc(); if (doc && doc == mObservedDocument) NodeWillBeDestroyed(doc); } diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 461d4c2c153..a9fb158e1ab 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -7048,10 +7048,7 @@ nsDocShell::CanSavePresentation(uint32_t aLoadType, // If the document does not want its presentation cached, then don't. nsCOMPtr doc = mScriptGlobal->GetExtantDoc(); - if (!doc || !doc->CanSavePresentation(aNewRequest)) - return false; - - return true; + return doc && doc->CanSavePresentation(aNewRequest); } void @@ -8677,8 +8674,7 @@ nsDocShell::InternalLoad(nsIURI * aURI, // document in |newWin|, if any. nsCOMPtr piNewWin = do_QueryInterface(newWin); if (piNewWin) { - nsCOMPtr newDoc = - do_QueryInterface(piNewWin->GetExtantDocument()); + nsCOMPtr newDoc = piNewWin->GetExtantDoc(); if (!newDoc || newDoc->IsInitialDocument()) { isNewWindow = true; aFlags |= INTERNAL_LOAD_FLAGS_FIRST_LOAD; diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index ecf11f09c01..4d4eaa61bab 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -481,7 +481,7 @@ Navigator::GetCookieEnabled(bool* aCookieEnabled) return NS_OK; } - nsCOMPtr doc = do_QueryInterface(win->GetExtantDocument()); + nsCOMPtr doc = win->GetExtantDoc(); if (!doc) { return NS_OK; } @@ -626,17 +626,16 @@ namespace { class VibrateWindowListener : public nsIDOMEventListener { public: - VibrateWindowListener(nsIDOMWindow *aWindow, nsIDOMDocument *aDocument) + VibrateWindowListener(nsIDOMWindow* aWindow, nsIDocument* aDocument) { mWindow = do_GetWeakReference(aWindow); mDocument = do_GetWeakReference(aDocument); - nsCOMPtr target = do_QueryInterface(aDocument); NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange"); - target->AddSystemEventListener(visibilitychange, - this, /* listener */ - true, /* use capture */ - false /* wants untrusted */); + aDocument->AddSystemEventListener(visibilitychange, + this, /* listener */ + true, /* use capture */ + false /* wants untrusted */); } virtual ~VibrateWindowListener() @@ -754,12 +753,9 @@ Navigator::Vibrate(const JS::Value& aPattern, JSContext* cx) nsCOMPtr win = do_QueryReferent(mWindow); NS_ENSURE_TRUE(win, NS_OK); - nsCOMPtr domDoc = win->GetExtantDocument(); - NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE); - - bool hidden = true; - domDoc->GetHidden(&hidden); - if (hidden) { + nsCOMPtr doc = win->GetExtantDoc(); + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); + if (doc->Hidden()) { // Hidden documents cannot start or stop a vibration. return NS_OK; } @@ -819,7 +815,7 @@ Navigator::Vibrate(const JS::Value& aPattern, JSContext* cx) else { gVibrateWindowListener->RemoveListener(); } - gVibrateWindowListener = new VibrateWindowListener(win, domDoc); + gVibrateWindowListener = new VibrateWindowListener(win, doc); nsCOMPtr domWindow = do_QueryInterface(static_cast(win)); diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index c89ac2210e5..5e2e5cea8aa 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -3284,7 +3284,7 @@ nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSHandleObject obj, // The rest of this function is for HTML documents only. // nsCOMPtr htmlDoc = - do_QueryInterface(win->GetExtantDocument()); + do_QueryInterface(win->GetExtantDoc()); if (!htmlDoc) return true; nsHTMLDocument *document = static_cast(htmlDoc.get()); @@ -6216,7 +6216,7 @@ nsDocumentSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, return NS_OK; } - nsIDOMDocument* currentDoc = win->GetExtantDocument(); + nsIDocument* currentDoc = win->GetExtantDoc(); if (SameCOMIdentity(doc, currentDoc)) { jsval winVal; diff --git a/dom/base/nsDOMException.cpp b/dom/base/nsDOMException.cpp index c203bac61ac..3f9f710cb5a 100644 --- a/dom/base/nsDOMException.cpp +++ b/dom/base/nsDOMException.cpp @@ -183,8 +183,7 @@ nsDOMException::GetCode(uint16_t* aCode) // Warn only when the code was changed (other than DOM Core) // or the code is useless (zero) if (NS_ERROR_GET_MODULE(mResult) != NS_ERROR_MODULE_DOM || !mCode) { - nsCOMPtr doc = - do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); + nsCOMPtr doc = nsContentUtils::GetDocumentFromCaller(); if (doc) { doc->WarnOnceAbout(nsIDocument::eDOMExceptionCode); } diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index b7556076478..a5e7c4c2530 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -188,14 +188,14 @@ nsDOMWindowUtils::GetDocumentMetadata(const nsAString& aName, nsCOMPtr window = do_QueryReferent(mWindow); if (window) { - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); if (doc) { nsCOMPtr name = do_GetAtom(aName); doc->GetHeaderData(name, aValue); return NS_OK; } } - + aValue.Truncate(); return NS_OK; } @@ -266,7 +266,7 @@ nsDOMWindowUtils::GetViewportInfo(uint32_t aDisplayWidth, nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_STATE(window); - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); NS_ENSURE_STATE(doc); nsViewportInfo info = nsContentUtils::GetViewportInfo(doc, aDisplayWidth, aDisplayHeight); @@ -1247,7 +1247,7 @@ nsDOMWindowUtils::ElementFromPoint(float aX, float aY, nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_STATE(window); - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); NS_ENSURE_STATE(doc); Element* el = @@ -1272,7 +1272,7 @@ nsDOMWindowUtils::NodesFromRect(float aX, float aY, nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_STATE(window); - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); NS_ENSURE_STATE(doc); return doc->NodesFromRectHelper(aX, aY, aTopSize, aRightSize, aBottomSize, aLeftSize, @@ -1424,7 +1424,7 @@ nsDOMWindowUtils::SuppressEventHandling(bool aSuppress) nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_STATE(window); - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); if (aSuppress) { @@ -1446,7 +1446,7 @@ nsDOMWindowUtils::GetScrollXY(bool aFlushLayout, int32_t* aScrollX, int32_t* aSc nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_STATE(window); - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); NS_ENSURE_STATE(doc); if (aFlushLayout) { @@ -2460,15 +2460,15 @@ nsDOMWindowUtils::GetCursorType(int16_t *aCursor) NS_ENSURE_ARG_POINTER(aCursor); nsCOMPtr window = do_QueryReferent(mWindow); - NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); bool isSameDoc = false; - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); do { - if (nsEventStateManager::sMouseOverDocument == doc.get()) { + if (nsEventStateManager::sMouseOverDocument == doc) { isSameDoc = true; break; } @@ -2937,17 +2937,13 @@ nsDOMWindowUtils::GetPlugins(JSContext* cx, JS::Value* aPlugins) nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_STATE(window); - nsIDOMDocument* ddoc = window->GetExtantDocument(); - - nsresult rv; - nsCOMPtr doc = do_QueryInterface(ddoc, &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr doc = window->GetExtantDoc(); nsTArray plugins; doc->GetPlugins(plugins); JSObject* jsPlugins = nullptr; - rv = nsTArrayToJSArray(cx, plugins, &jsPlugins); + nsresult rv = nsTArrayToJSArray(cx, plugins, &jsPlugins); NS_ENSURE_SUCCESS(rv, rv); *aPlugins = OBJECT_TO_JSVAL(jsPlugins); @@ -3014,7 +3010,7 @@ nsDOMWindowUtils::RemoteFrameFullscreenChanged(nsIDOMElement* aFrameElement, nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_STATE(window); - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); NS_ENSURE_STATE(doc); doc->RemoteFrameFullscreenChanged(aFrameElement, aNewOrigin); @@ -3031,7 +3027,7 @@ nsDOMWindowUtils::RemoteFrameFullscreenReverted() nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_STATE(window); - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); NS_ENSURE_STATE(doc); doc->RemoteFrameFullscreenReverted(); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 4df6d680357..caa068e4f3f 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2143,7 +2143,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, } NS_ASSERTION(!GetCurrentInnerWindow() || - GetCurrentInnerWindow()->GetExtantDocument() == mDocument, + GetCurrentInnerWindow()->GetExtantDoc() == mDoc, "Uh, mDocument doesn't match the current inner window " "document!"); @@ -6137,7 +6137,7 @@ nsGlobalWindow::SetResizable(bool aResizable) static void ReportUseOfDeprecatedMethod(nsGlobalWindow* aWindow, const char* aWarning) { - nsCOMPtr doc = do_QueryInterface(aWindow->GetExtantDocument()); + nsCOMPtr doc = aWindow->GetExtantDoc(); nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "DOM Events", doc, nsContentUtils::eDOM_PROPERTIES, @@ -6200,7 +6200,7 @@ bool IsPopupBlocked(nsIDOMDocument* aDoc) /* static */ void -nsGlobalWindow::FirePopupBlockedEvent(nsIDOMDocument* aDoc, +nsGlobalWindow::FirePopupBlockedEvent(nsIDocument* aDoc, nsIDOMWindow *aRequestingWindow, nsIURI *aPopupURI, const nsAString &aPopupWindowName, const nsAString &aPopupWindowFeatures) @@ -6208,9 +6208,9 @@ nsGlobalWindow::FirePopupBlockedEvent(nsIDOMDocument* aDoc, if (aDoc) { // Fire a "DOMPopupBlocked" event so that the UI can hear about // blocked popups. - nsCOMPtr event; - aDoc->CreateEvent(NS_LITERAL_STRING("PopupBlockedEvents"), - getter_AddRefs(event)); + ErrorResult rv; + nsCOMPtr event = + aDoc->CreateEvent(NS_LITERAL_STRING("PopupBlockedEvents"), rv); if (event) { nsCOMPtr pbev(do_QueryInterface(event)); pbev->InitPopupBlockedEvent(NS_LITERAL_STRING("DOMPopupBlocked"), @@ -6219,9 +6219,8 @@ nsGlobalWindow::FirePopupBlockedEvent(nsIDOMDocument* aDoc, aPopupWindowFeatures); event->SetTrusted(true); - nsCOMPtr targ(do_QueryInterface(aDoc)); bool defaultActionEnabled; - targ->DispatchEvent(event, &defaultActionEnabled); + aDoc->DispatchEvent(event, &defaultActionEnabled); } } } @@ -6362,9 +6361,11 @@ nsGlobalWindow::FireAbuseEvents(bool aBlocked, bool aWindow, getter_AddRefs(popupURI)); // fire an event chock full of informative URIs - if (aBlocked) - FirePopupBlockedEvent(topDoc, this, popupURI, aPopupWindowName, + if (aBlocked) { + nsCOMPtr topDocument = do_QueryInterface(topDoc); + FirePopupBlockedEvent(topDocument, this, popupURI, aPopupWindowName, aPopupWindowFeatures); + } if (aWindow) FirePopupWindowEvent(topDoc); } @@ -6891,7 +6892,7 @@ nsGlobalWindow::PostMessageMoz(const JS::Value& aMessage, } else if (callerInnerWin) { // otherwise use the URI of the document to generate origin - nsCOMPtr doc = do_QueryInterface(callerInnerWin->GetExtantDocument()); + nsCOMPtr doc = callerInnerWin->GetExtantDoc(); if (!doc) return NS_OK; callerOuterURI = doc->GetDocumentURI(); @@ -7211,7 +7212,7 @@ nsGlobalWindow::EnterModalState() if (topWin->mModalStateDepth == 0) { NS_ASSERTION(!mSuspendedDoc, "Shouldn't have mSuspendedDoc here!"); - mSuspendedDoc = do_QueryInterface(topWin->GetExtantDocument()); + mSuspendedDoc = topWin->GetExtantDoc(); if (mSuspendedDoc && mSuspendedDoc->EventHandlingSuppressed()) { mSuspendedDoc->SuppressEventHandling(); } else { @@ -7324,8 +7325,7 @@ nsGlobalWindow::LeaveModalState(nsIDOMWindow *aCallerWin) NS_WARNING("failed to dispatch pending timeout runnable"); if (mSuspendedDoc) { - nsCOMPtr currentDoc = - do_QueryInterface(topWin->GetExtantDocument()); + nsCOMPtr currentDoc = topWin->GetExtantDoc(); mSuspendedDoc->UnsuppressEventHandlingAndFireEvents(currentDoc == mSuspendedDoc); mSuspendedDoc = nullptr; } @@ -7815,7 +7815,7 @@ nsGlobalWindow::UpdateCommands(const nsAString& anAction) return NS_OK; nsCOMPtr xulDoc = - do_QueryInterface(rootWindow->GetExtantDocument()); + do_QueryInterface(rootWindow->GetExtantDoc()); // See if we contain a XUL document. if (xulDoc) { // Retrieve the command dispatcher and call updateCommands on it. @@ -9960,10 +9960,7 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName, #ifdef DEBUG_jst { nsCOMPtr pidomwin(do_QueryInterface(*aReturn)); - - nsIDOMDocument *temp = pidomwin->GetExtantDocument(); - - NS_ASSERTION(temp, "No document in new window!!!"); + NS_ASSERTION(pidomwin->GetExtantDoc(), "No document in new window!!!"); } #endif @@ -9971,7 +9968,7 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName, (*aReturn)->GetDocument(getter_AddRefs(doc)); } } - + if (checkForPopup) { if (abuseLevel >= openControlled) { nsGlobalWindow *opened = static_cast(*aReturn); diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 336896427fe..5769b9bfb81 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -584,7 +584,7 @@ public: mCleanedUp); } - static void FirePopupBlockedEvent(nsIDOMDocument* aDoc, + static void FirePopupBlockedEvent(nsIDocument* aDoc, nsIDOMWindow *aRequestingWindow, nsIURI *aPopupURI, const nsAString &aPopupWindowName, const nsAString &aPopupWindowFeatures); diff --git a/dom/base/nsGlobalWindowCommands.cpp b/dom/base/nsGlobalWindowCommands.cpp index e9917bd6826..a4571b4e4a5 100644 --- a/dom/base/nsGlobalWindowCommands.cpp +++ b/dom/base/nsGlobalWindowCommands.cpp @@ -345,7 +345,7 @@ nsClipboardCommand::IsCommandEnabled(const char* aCommandName, nsISupports *aCon nsCOMPtr window = do_QueryInterface(aContext); NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); - nsCOMPtr doc = do_QueryInterface(window->GetExtantDocument()); + nsCOMPtr doc = window->GetExtantDoc(); *outCmdEnabled = nsCopySupport::CanCopy(doc); return NS_OK; } diff --git a/dom/base/nsHistory.cpp b/dom/base/nsHistory.cpp index 65c8c5f4312..d2f08a0a99b 100644 --- a/dom/base/nsHistory.cpp +++ b/dom/base/nsHistory.cpp @@ -231,8 +231,7 @@ nsHistory::Go(int32_t aDelta) // trick to work around gecko reflow bugs, and this should have // the same effect. - nsCOMPtr doc = - do_QueryInterface(window->GetExtantDocument()); + nsCOMPtr doc = window->GetExtantDoc(); nsIPresShell *shell; nsPresContext *pcx; @@ -338,8 +337,7 @@ nsHistory::GetState(nsIVariant **aState) if (!nsContentUtils::CanCallerAccess(win->GetOuterWindow())) return NS_ERROR_DOM_SECURITY_ERR; - nsCOMPtr doc = - do_QueryInterface(win->GetExtantDocument()); + nsCOMPtr doc = win->GetExtantDoc(); if (!doc) return NS_ERROR_NOT_AVAILABLE; diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index ff1fa55119a..f68ccb89126 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -620,7 +620,7 @@ PrintWinURI(nsGlobalWindow *win) return; } - nsCOMPtr doc = do_QueryInterface(win->GetExtantDocument()); + nsCOMPtr doc = win->GetExtantDoc(); if (!doc) { printf("No document in the window.\n"); return; diff --git a/dom/base/nsJSTimeoutHandler.cpp b/dom/base/nsJSTimeoutHandler.cpp index 740eb46c537..d5d4147639f 100644 --- a/dom/base/nsJSTimeoutHandler.cpp +++ b/dom/base/nsJSTimeoutHandler.cpp @@ -241,7 +241,7 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval, if (expr) { // if CSP is enabled, and setTimeout/setInterval was called with a string // or object, disable the registration and log an error - nsCOMPtr doc = do_QueryInterface(aWindow->GetExtantDocument()); + nsCOMPtr doc = aWindow->GetExtantDoc(); if (doc) { nsCOMPtr csp; diff --git a/dom/base/nsLocation.cpp b/dom/base/nsLocation.cpp index e2d7b7820de..6d26b31f103 100644 --- a/dom/base/nsLocation.cpp +++ b/dom/base/nsLocation.cpp @@ -787,7 +787,7 @@ nsLocation::Reload(bool aForceget) // page since some sites may use this trick to work around gecko // reflow bugs, and this should have the same effect. - nsCOMPtr doc(do_QueryInterface(window->GetExtantDocument())); + nsCOMPtr doc = window->GetExtantDoc(); nsIPresShell *shell; nsPresContext *pcx; diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 92ec99f3b78..9e1b42d7b57 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -172,11 +172,6 @@ public: virtual void MaybeUpdateTouchState() {} virtual void UpdateTouchState() {} - // GetExtantDocument provides a backdoor to the DOM GetDocument accessor - nsIDOMDocument* GetExtantDocument() const - { - return mDocument; - } nsIDocument* GetExtantDoc() const { return mDoc; diff --git a/dom/base/nsWindowMemoryReporter.cpp b/dom/base/nsWindowMemoryReporter.cpp index 6fe4cc7accb..eb70158f70a 100644 --- a/dom/base/nsWindowMemoryReporter.cpp +++ b/dom/base/nsWindowMemoryReporter.cpp @@ -58,7 +58,7 @@ GetWindowURI(nsIDOMWindow *aWindow) nsCOMPtr pWindow = do_QueryInterface(aWindow); NS_ENSURE_TRUE(pWindow, NULL); - nsCOMPtr doc = do_QueryInterface(pWindow->GetExtantDocument()); + nsCOMPtr doc = pWindow->GetExtantDoc(); nsCOMPtr uri; if (doc) { diff --git a/dom/indexedDB/IDBDatabase.h b/dom/indexedDB/IDBDatabase.h index 016508fb738..af6a5e8ba0c 100644 --- a/dom/indexedDB/IDBDatabase.h +++ b/dom/indexedDB/IDBDatabase.h @@ -102,8 +102,7 @@ public: return nullptr; } - nsCOMPtr doc = - do_QueryInterface(GetOwner()->GetExtantDocument()); + nsCOMPtr doc = GetOwner()->GetExtantDoc(); return doc.forget(); } diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 4d077f1224d..4f18537ab5f 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -975,9 +975,8 @@ MediaManager::GetUserMedia(bool aPrivileged, nsPIDOMWindow* aWindow, nsCOMPtr doc = aWindow->GetExtantDoc(); pm->TestPermission(doc->NodePrincipal(), &permission); if (permission == nsIPopupWindowManager::DENY_POPUP) { - nsCOMPtr domDoc = aWindow->GetExtantDocument(); nsGlobalWindow::FirePopupBlockedEvent( - domDoc, aWindow, nullptr, EmptyString(), EmptyString() + doc, aWindow, nullptr, EmptyString(), EmptyString() ); return NS_OK; } diff --git a/dom/power/WakeLock.cpp b/dom/power/WakeLock.cpp index ff12c8eac93..7bbd81c8082 100644 --- a/dom/power/WakeLock.cpp +++ b/dom/power/WakeLock.cpp @@ -11,7 +11,6 @@ #include "nsError.h" #include "nsIDOMWindow.h" #include "nsIDOMEvent.h" -#include "nsIDOMDocument.h" #include "nsIDOMEventTarget.h" #include "nsPIDOMWindow.h" #include "PowerManager.h" @@ -69,9 +68,9 @@ WakeLock::Init(const nsAString &aTopic, nsIDOMWindow *aWindow) * is always considered invisible. */ if (window) { - nsCOMPtr domDoc = window->GetExtantDocument(); - NS_ENSURE_STATE(domDoc); - domDoc->GetHidden(&mHidden); + nsCOMPtr doc = window->GetExtantDoc(); + NS_ENSURE_STATE(doc); + mHidden = doc->Hidden(); } AttachEventListener(); @@ -168,17 +167,16 @@ void WakeLock::AttachEventListener() { nsCOMPtr window = do_QueryReferent(mWindow); - - if (window) { - nsCOMPtr domDoc = window->GetExtantDocument(); - if (domDoc) { - nsCOMPtr target = do_QueryInterface(domDoc); - target->AddSystemEventListener(NS_LITERAL_STRING("visibilitychange"), - this, - /* useCapture = */ true, - /* wantsUntrusted = */ false); - target = do_QueryInterface(window); + if (window) { + nsCOMPtr doc = window->GetExtantDoc(); + if (doc) { + doc->AddSystemEventListener(NS_LITERAL_STRING("visibilitychange"), + this, + /* useCapture = */ true, + /* wantsUntrusted = */ false); + + nsCOMPtr target = do_QueryInterface(window); target->AddSystemEventListener(NS_LITERAL_STRING("pagehide"), this, /* useCapture = */ true, @@ -197,13 +195,12 @@ WakeLock::DetachEventListener() nsCOMPtr window = do_QueryReferent(mWindow); if (window) { - nsCOMPtr domDoc = window->GetExtantDocument(); - if (domDoc) { - nsCOMPtr target = do_QueryInterface(domDoc); - target->RemoveSystemEventListener(NS_LITERAL_STRING("visibilitychange"), - this, - /* useCapture = */ true); - target = do_QueryInterface(window); + nsCOMPtr doc = window->GetExtantDoc(); + if (doc) { + doc->RemoveSystemEventListener(NS_LITERAL_STRING("visibilitychange"), + this, + /* useCapture = */ true); + nsCOMPtr target = do_QueryInterface(window); target->RemoveSystemEventListener(NS_LITERAL_STRING("pagehide"), this, /* useCapture = */ true); diff --git a/dom/src/jsurl/nsJSProtocolHandler.cpp b/dom/src/jsurl/nsJSProtocolHandler.cpp index e1116b615cd..74e10b2777f 100644 --- a/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -641,8 +641,7 @@ nsJSChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext) } } - mDocumentOnloadBlockedOn = - do_QueryInterface(mOriginalInnerWindow->GetExtantDocument()); + mDocumentOnloadBlockedOn = mOriginalInnerWindow->GetExtantDoc(); if (mDocumentOnloadBlockedOn) { // If we're a document channel, we need to actually block onload on our // _parent_ document. This is because we don't actually set our @@ -667,7 +666,7 @@ nsJSChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext) if (mIsAsync) { // post an event to do the rest method = &nsJSChannel::EvaluateScript; - } else { + } else { EvaluateScript(); if (mOpenedStreamChannel) { // That will handle notifying things diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index a2f1bb26dfc..c67e7fe7d53 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -2505,7 +2505,7 @@ WorkerPrivate::Create(JSContext* aCx, JSObject* aObj, WorkerPrivate* aParent, // If we're called from a window then we can dig out the principal and URI // from the document. - document = do_QueryInterface(window->GetExtantDocument()); + document = window->GetExtantDoc(); if (!document) { JS_ReportError(aCx, "No document in this window!"); return nullptr; @@ -3114,7 +3114,7 @@ WorkerPrivate::CheckXHRParamsAllowed(nsPIDOMWindow* aWindow) return false; } - nsCOMPtr doc = do_QueryInterface(aWindow->GetExtantDocument()); + nsCOMPtr doc = aWindow->GetExtantDoc(); if (!doc) { return false; } diff --git a/embedding/components/windowwatcher/src/nsAutoWindowStateHelper.cpp b/embedding/components/windowwatcher/src/nsAutoWindowStateHelper.cpp index 56a068d0abf..567a1a6dfa8 100644 --- a/embedding/components/windowwatcher/src/nsAutoWindowStateHelper.cpp +++ b/embedding/components/windowwatcher/src/nsAutoWindowStateHelper.cpp @@ -5,13 +5,18 @@ #include "nsAutoWindowStateHelper.h" +#include "nsDOMEvent.h" +#include "nsGUIEvent.h" +#include "nsIDocument.h" +#include "nsIDOMEvent.h" #include "nsIDOMWindow.h" #include "nsPIDOMWindow.h" -#include "nsIDOMEventTarget.h" -#include "nsIDOMEvent.h" #include "nsString.h" #include "nsGUIEvent.h" +using namespace mozilla; +using namespace mozilla::dom; + /**************************************************************** ****************** nsAutoWindowStateHelper ********************* ****************************************************************/ @@ -50,18 +55,21 @@ nsAutoWindowStateHelper::DispatchEventToChrome(const char *aEventName) // The functions of nsContentUtils do not provide the required behavior, // so the following is inlined. - nsIDOMDocument* doc = window->GetExtantDocument(); + nsIDocument* doc = window->GetExtantDoc(); if (!doc) { return true; } - nsCOMPtr event; - doc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); + ErrorResult rv; + nsRefPtr event = doc->CreateEvent(NS_LITERAL_STRING("Events"), rv); + if (rv.Failed()) { + return false; + } NS_ENSURE_TRUE(NS_SUCCEEDED(event->InitEvent(NS_ConvertASCIItoUTF16(aEventName), true, true)), false); event->SetTrusted(true); event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; - nsCOMPtr target(do_QueryInterface(window)); + nsCOMPtr target = do_QueryInterface(window); bool defaultActionEnabled; target->DispatchEvent(event, &defaultActionEnabled); return defaultActionEnabled; diff --git a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp index bd9b9ac7932..f8c9bad6977 100644 --- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp +++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp @@ -772,8 +772,7 @@ nsWindowWatcher::OpenWindowInternal(nsIDOMWindow *aParent, nsCOMPtr callerItem = GetCallerTreeItem(parentItem); nsCOMPtr callerWin = do_GetInterface(callerItem); if (callerWin) { - nsCOMPtr doc = - do_QueryInterface(callerWin->GetExtantDocument()); + nsCOMPtr doc = callerWin->GetExtantDoc(); if (doc) { newMuCV->SetDefaultCharacterSet(doc->GetDocumentCharacterSet()); } @@ -911,8 +910,8 @@ nsWindowWatcher::OpenWindowInternal(nsIDOMWindow *aParent, Also using GetDocument to force document creation seems to screw up focus in the hidden window; see bug 36016. */ - nsCOMPtr doc(do_QueryInterface(w->GetExtantDocument())); - if (doc) { + nsCOMPtr doc = w->GetExtantDoc(); + if (doc) { // Set the referrer loadInfo->SetReferrer(doc->GetDocumentURI()); } @@ -1799,8 +1798,7 @@ nsWindowWatcher::ReadyOpenedDocShellItem(nsIDocShellTreeItem *aOpenedItem, NS_ASSERTION(!chan, "Why is there a document channel?"); #endif - nsCOMPtr doc = - do_QueryInterface(piOpenedWindow->GetExtantDocument()); + nsCOMPtr doc = piOpenedWindow->GetExtantDoc(); if (doc) { doc->SetIsInitialDocument(true); } diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 703a466a4a7..6040b716eac 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -4934,8 +4934,7 @@ ContentComponentsGetterOp(JSContext *cx, JSHandleObject obj, JSHandleId id, nsCOMPtr win = do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(obj)); if (win) { - nsCOMPtr doc = - do_QueryInterface(win->GetExtantDocument()); + nsCOMPtr doc = win->GetExtantDoc(); if (doc) doc->WarnOnceAbout(nsIDocument::eComponents, /* asError = */ true); } diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index c819de61af3..23a57bea1ff 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -933,8 +933,7 @@ nsDocumentViewer::InitInternal(nsIWidget* aParentWidget, getter_AddRefs(window)); if (window) { - nsCOMPtr curDoc = - do_QueryInterface(window->GetExtantDocument()); + nsCOMPtr curDoc = window->GetExtantDoc(); if (aForceSetNewDocument || curDoc != mDocument) { window->SetNewDocument(mDocument, aState, false); nsJSContext::LoadStart(); @@ -3343,7 +3342,7 @@ nsDocumentViewer::GetPopupNode(nsIDOMNode** aNode) if (!node) { nsPIDOMWindow* rootWindow = root->GetWindow(); if (rootWindow) { - nsCOMPtr rootDoc = do_QueryInterface(rootWindow->GetExtantDocument()); + nsCOMPtr rootDoc = rootWindow->GetExtantDoc(); if (rootDoc) { nsXULPopupManager* pm = nsXULPopupManager::GetInstance(); if (pm) { diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 9aaeb374c2e..2f47d6e3ce8 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -5980,7 +5980,7 @@ PresShell::HandleEvent(nsIFrame *aFrame, return NS_OK; } - retargetEventDoc = do_QueryInterface(window->GetExtantDocument()); + retargetEventDoc = window->GetExtantDoc(); if (!retargetEventDoc) return NS_OK; } else if (capturingContent) {