From 1297bbd8e9210bd9856962b5e5259b8490f8b50b Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 12 Apr 2014 10:15:56 +0200 Subject: [PATCH] Bug 968835 - Cleanup nsHTMLDocument::GetSelection; r=smaug --- content/html/document/src/nsHTMLDocument.cpp | 27 +++++++++----------- content/html/document/src/nsHTMLDocument.h | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 81f032e4e4e..32dc46811e2 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -9,6 +9,7 @@ #include "mozilla/DebugOnly.h" #include "mozilla/dom/HTMLAllCollection.h" #include "nsCOMPtr.h" +#include "nsGlobalWindow.h" #include "nsXPIDLString.h" #include "nsPrintfCString.h" #include "nsReadableUtils.h" @@ -2154,28 +2155,24 @@ NS_IMETHODIMP nsHTMLDocument::GetSelection(nsISelection** aReturn) { ErrorResult rv; - *aReturn = GetSelection(rv).take(); + NS_IF_ADDREF(*aReturn = GetSelection(rv)); return rv.ErrorCode(); } -already_AddRefed -nsHTMLDocument::GetSelection(ErrorResult& rv) +Selection* +nsHTMLDocument::GetSelection(ErrorResult& aRv) { - nsCOMPtr window = do_QueryInterface(GetScopeObject()); - nsCOMPtr pwin = do_QueryInterface(window); - if (!pwin) { - return nullptr; - } - NS_ASSERTION(pwin->IsInnerWindow(), "Should have inner window here!"); - if (!pwin->GetOuterWindow() || - pwin->GetOuterWindow()->GetCurrentInnerWindow() != pwin) { + nsCOMPtr window = do_QueryInterface(GetScopeObject()); + if (!window) { return nullptr; } - nsCOMPtr sel; - rv = window->GetSelection(getter_AddRefs(sel)); - nsRefPtr selection = static_cast(sel.get()); - return selection.forget(); + NS_ASSERTION(window->IsInnerWindow(), "Should have inner window here!"); + if (!window->IsCurrentInnerWindow()) { + return nullptr; + } + + return static_cast(window.get())->GetSelection(aRv); } NS_IMETHODIMP diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index fd9b8e05c92..774bc70dfbb 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -233,7 +233,7 @@ public: { // Deprecated } - already_AddRefed GetSelection(mozilla::ErrorResult& rv); + mozilla::Selection* GetSelection(mozilla::ErrorResult& aRv); // The XPCOM CaptureEvents works fine for us. // The XPCOM ReleaseEvents works fine for us. // We're picking up GetLocation from Document