From 443d3620c8256c0878433dfd44f80512a5012ca2 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 27 Feb 2013 22:05:18 +0100 Subject: [PATCH] Bug 842495 - Cleanup contentDocument/contentWindow getters; r=mounir --- content/html/content/src/HTMLFrameElement.cpp | 27 --------- content/html/content/src/HTMLFrameElement.h | 5 +- .../content/src/nsGenericHTMLFrameElement.cpp | 59 ++++++++++--------- .../content/src/nsGenericHTMLFrameElement.h | 4 +- dom/webidl/HTMLFrameElement.webidl | 2 - 5 files changed, 35 insertions(+), 62 deletions(-) diff --git a/content/html/content/src/HTMLFrameElement.cpp b/content/html/content/src/HTMLFrameElement.cpp index 6a7262fb696..ba8e463bd40 100644 --- a/content/html/content/src/HTMLFrameElement.cpp +++ b/content/html/content/src/HTMLFrameElement.cpp @@ -116,33 +116,6 @@ HTMLFrameElement::GetAttributeMappingFunction() const return &MapAttributesIntoRule; } -already_AddRefed -HTMLFrameElement::GetContentDocument(ErrorResult& aRv) -{ - nsCOMPtr doc; - nsresult rv = nsGenericHTMLFrameElement::GetContentDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - return nullptr; - } - - nsCOMPtr ret = do_QueryInterface(doc); - return ret.forget(); -} - -already_AddRefed -HTMLFrameElement::GetContentWindow(ErrorResult& aRv) -{ - nsCOMPtr win; - nsresult rv = nsGenericHTMLFrameElement::GetContentWindow(getter_AddRefs(win)); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - return nullptr; - } - - return win.forget(); -} - JSObject* HTMLFrameElement::WrapNode(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap) diff --git a/content/html/content/src/HTMLFrameElement.h b/content/html/content/src/HTMLFrameElement.h index 0391a410d3c..c6ff2f8002c 100644 --- a/content/html/content/src/HTMLFrameElement.h +++ b/content/html/content/src/HTMLFrameElement.h @@ -102,9 +102,8 @@ public: SetAttrHelper(nsGkAtoms::src, aSrc); } - already_AddRefed GetContentDocument(ErrorResult& aRv); - - already_AddRefed GetContentWindow(ErrorResult& aRv); + using nsGenericHTMLFrameElement::GetContentDocument; + using nsGenericHTMLFrameElement::GetContentWindow; protected: virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope, diff --git a/content/html/content/src/nsGenericHTMLFrameElement.cpp b/content/html/content/src/nsGenericHTMLFrameElement.cpp index c3f29a62820..ad5f8eb121e 100644 --- a/content/html/content/src/nsGenericHTMLFrameElement.cpp +++ b/content/html/content/src/nsGenericHTMLFrameElement.cpp @@ -51,69 +51,71 @@ nsresult nsGenericHTMLFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument) { NS_PRECONDITION(aContentDocument, "Null out param"); - *aContentDocument = nullptr; + nsIDocument* document = GetContentDocument(); + nsIDOMDocument* domDocument = + static_cast(document->AsDOMNode()); + NS_ADDREF(*aContentDocument = domDocument); + return NS_OK; +} - nsCOMPtr win; - GetContentWindow(getter_AddRefs(win)); - - if (!win) { - return NS_OK; - } - - return win->GetDocument(aContentDocument); +nsIDocument* +nsGenericHTMLFrameElement::GetContentDocument() +{ + nsCOMPtr win = GetContentWindow(); + return win ? win->GetDoc() : nullptr; } nsresult nsGenericHTMLFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow) { NS_PRECONDITION(aContentWindow, "Null out param"); - *aContentWindow = nullptr; + nsCOMPtr window = GetContentWindow(); + window.forget(aContentWindow); + return NS_OK; +} - nsresult rv = EnsureFrameLoader(); - NS_ENSURE_SUCCESS(rv, rv); +already_AddRefed +nsGenericHTMLFrameElement::GetContentWindow() +{ + EnsureFrameLoader(); if (!mFrameLoader) { - return NS_OK; + return nullptr; } bool depthTooGreat = false; mFrameLoader->GetDepthTooGreat(&depthTooGreat); if (depthTooGreat) { // Claim to have no contentWindow - return NS_OK; + return nullptr; } nsCOMPtr doc_shell; mFrameLoader->GetDocShell(getter_AddRefs(doc_shell)); - nsCOMPtr win(do_GetInterface(doc_shell)); + nsCOMPtr win = do_GetInterface(doc_shell); if (!win) { - return NS_OK; + return nullptr; } NS_ASSERTION(win->IsOuterWindow(), "Uh, this window should always be an outer window!"); - return CallQueryInterface(win, aContentWindow); + return win.forget(); } -nsresult +void nsGenericHTMLFrameElement::EnsureFrameLoader() { if (!GetParent() || !IsInDoc() || mFrameLoader || mFrameLoaderCreationDisallowed) { // If frame loader is there, we just keep it around, cached - return NS_OK; + return; } + // Strangely enough, this method doesn't actually ensure that the + // frameloader exists. It's more of a best-effort kind of thing. mFrameLoader = nsFrameLoader::Create(this, mNetworkCreated); - if (!mFrameLoader) { - // Strangely enough, this method doesn't actually ensure that the - // frameloader exists. It's more of a best-effort kind of thing. - return NS_OK; - } - - return NS_OK; } nsresult @@ -150,14 +152,13 @@ nsGenericHTMLFrameElement::SwapFrameLoaders(nsIFrameLoaderOwner* aOtherOwner) nsresult nsGenericHTMLFrameElement::LoadSrc() { - nsresult rv = EnsureFrameLoader(); - NS_ENSURE_SUCCESS(rv, rv); + EnsureFrameLoader(); if (!mFrameLoader) { return NS_OK; } - rv = mFrameLoader->LoadFrame(); + nsresult rv = mFrameLoader->LoadFrame(); #ifdef DEBUG if (NS_FAILED(rv)) { NS_WARNING("failed to load URL"); diff --git a/content/html/content/src/nsGenericHTMLFrameElement.h b/content/html/content/src/nsGenericHTMLFrameElement.h index 78b6f19ab2f..cef2f8254ee 100644 --- a/content/html/content/src/nsGenericHTMLFrameElement.h +++ b/content/html/content/src/nsGenericHTMLFrameElement.h @@ -90,9 +90,11 @@ protected: // This doesn't really ensure a frame loade in all cases, only when // it makes sense. - nsresult EnsureFrameLoader(); + void EnsureFrameLoader(); nsresult LoadSrc(); + nsIDocument* GetContentDocument(); nsresult GetContentDocument(nsIDOMDocument** aContentDocument); + already_AddRefed GetContentWindow(); nsresult GetContentWindow(nsIDOMWindow** aContentWindow); nsRefPtr mFrameLoader; diff --git a/dom/webidl/HTMLFrameElement.webidl b/dom/webidl/HTMLFrameElement.webidl index a2b369c152e..727baf8662d 100644 --- a/dom/webidl/HTMLFrameElement.webidl +++ b/dom/webidl/HTMLFrameElement.webidl @@ -24,9 +24,7 @@ interface HTMLFrameElement : HTMLElement { attribute DOMString longDesc; [SetterThrows] attribute boolean noResize; - [GetterThrows] readonly attribute Document? contentDocument; - [GetterThrows] readonly attribute WindowProxy? contentWindow; [TreatNullAs=EmptyString, SetterThrows] attribute DOMString marginHeight;