Bug 795403 - Cleanup nsXULWindow::GetWindowDOMElement; r=bz

This commit is contained in:
Ms2ger 2012-10-02 10:24:10 +02:00
parent 4f2bf30d93
commit 1dd5e5bd0b
4 changed files with 33 additions and 52 deletions

View File

@ -258,8 +258,7 @@ nsChromeTreeOwner::SetPersistence(bool aPersistPosition,
bool aPersistSizeMode)
{
NS_ENSURE_STATE(mXULWindow);
nsCOMPtr<nsIDOMElement> docShellElement;
mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement));
nsCOMPtr<nsIDOMElement> docShellElement = mXULWindow->GetWindowDOMElement();
if (!docShellElement)
return NS_ERROR_FAILURE;
@ -296,8 +295,7 @@ nsChromeTreeOwner::GetPersistence(bool* aPersistPosition,
bool* aPersistSizeMode)
{
NS_ENSURE_STATE(mXULWindow);
nsCOMPtr<nsIDOMElement> docShellElement;
mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement));
nsCOMPtr<nsIDOMElement> docShellElement = mXULWindow->GetWindowDOMElement();
if (!docShellElement)
return NS_ERROR_FAILURE;

View File

@ -312,9 +312,8 @@ nsContentTreeOwner::SetPersistence(bool aPersistPosition,
bool aPersistSizeMode)
{
NS_ENSURE_STATE(mXULWindow);
nsCOMPtr<nsIDOMElement> docShellElement;
mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement));
if(!docShellElement)
nsCOMPtr<nsIDOMElement> docShellElement = mXULWindow->GetWindowDOMElement();
if (!docShellElement)
return NS_ERROR_FAILURE;
nsAutoString persistString;
@ -381,9 +380,8 @@ nsContentTreeOwner::GetPersistence(bool* aPersistPosition,
bool* aPersistSizeMode)
{
NS_ENSURE_STATE(mXULWindow);
nsCOMPtr<nsIDOMElement> docShellElement;
mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement));
if(!docShellElement)
nsCOMPtr<nsIDOMElement> docShellElement = mXULWindow->GetWindowDOMElement();
if (!docShellElement)
return NS_ERROR_FAILURE;
nsAutoString persistString;
@ -725,8 +723,7 @@ NS_IMETHODIMP nsContentTreeOwner::SetTitle(const PRUnichar* aTitle)
// if there is no location bar we modify the title to display at least
// the scheme and host (if any) as an anti-spoofing measure.
//
nsCOMPtr<nsIDOMElement> docShellElement;
mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement));
nsCOMPtr<nsIDOMElement> docShellElement = mXULWindow->GetWindowDOMElement();
if (docShellElement) {
nsAutoString chromeString;
@ -956,11 +953,9 @@ private:
void nsContentTreeOwner::XULWindow(nsXULWindow* aXULWindow)
{
mXULWindow = aXULWindow;
if(mXULWindow && mPrimary)
{
if (mXULWindow && mPrimary) {
// Get the window title modifiers
nsCOMPtr<nsIDOMElement> docShellElement;
mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement));
nsCOMPtr<nsIDOMElement> docShellElement = mXULWindow->GetWindowDOMElement();
nsAutoString contentTitleSetting;

View File

@ -54,6 +54,7 @@
#include "prenv.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/Element.h"
using namespace mozilla;
@ -1003,11 +1004,8 @@ bool nsXULWindow::LoadPositionFromXUL()
if (mIsHiddenWindow)
return false;
nsCOMPtr<nsIDOMElement> windowElement;
GetWindowDOMElement(getter_AddRefs(windowElement));
NS_ASSERTION(windowElement, "no xul:window");
if (!windowElement)
return false;
nsCOMPtr<nsIDOMElement> windowElement = GetWindowDOMElement();
NS_ENSURE_TRUE(windowElement, false);
int32_t currX = 0;
int32_t currY = 0;
@ -1072,11 +1070,8 @@ bool nsXULWindow::LoadSizeFromXUL()
if (mIsHiddenWindow)
return false;
nsCOMPtr<nsIDOMElement> windowElement;
GetWindowDOMElement(getter_AddRefs(windowElement));
NS_ASSERTION(windowElement, "no xul:window");
if (!windowElement)
return false;
nsCOMPtr<nsIDOMElement> windowElement = GetWindowDOMElement();
NS_ENSURE_TRUE(windowElement, false);
int32_t currWidth = 0;
int32_t currHeight = 0;
@ -1153,11 +1148,8 @@ bool nsXULWindow::LoadMiscPersistentAttributesFromXUL()
if (mIsHiddenWindow)
return false;
nsCOMPtr<nsIDOMElement> windowElement;
GetWindowDOMElement(getter_AddRefs(windowElement));
NS_ASSERTION(windowElement, "no xul:window");
if (!windowElement)
return false;
nsCOMPtr<nsIDOMElement> windowElement = GetWindowDOMElement();
NS_ENSURE_TRUE(windowElement, false);
nsAutoString stateString;
@ -1243,8 +1235,10 @@ void nsXULWindow::StaggerPosition(int32_t &aRequestedX, int32_t &aRequestedY,
if (!wm)
return;
nsCOMPtr<nsIDOMElement> windowElement;
GetWindowDOMElement(getter_AddRefs(windowElement));
nsCOMPtr<nsIDOMElement> windowElement = GetWindowDOMElement();
if (!windowElement)
return;
nsCOMPtr<nsIXULWindow> ourXULWindow(this);
nsAutoString windowType;
@ -1344,8 +1338,7 @@ void nsXULWindow::StaggerPosition(int32_t &aRequestedX, int32_t &aRequestedY,
void nsXULWindow::SyncAttributesToWidget()
{
nsCOMPtr<nsIDOMElement> windowElement;
GetWindowDOMElement(getter_AddRefs(windowElement));
nsCOMPtr<nsIDOMElement> windowElement = GetWindowDOMElement();
if (!windowElement)
return;
@ -1410,8 +1403,7 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
if (!mDocShell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMElement> docShellElement;
GetWindowDOMElement(getter_AddRefs(docShellElement));
nsCOMPtr<nsIDOMElement> docShellElement = GetWindowDOMElement();
if (!docShellElement)
return NS_ERROR_FAILURE;
@ -1537,25 +1529,22 @@ NS_IMETHODIMP nsXULWindow::GetWindowDOMWindow(nsIDOMWindow** aDOMWindow)
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::GetWindowDOMElement(nsIDOMElement** aDOMElement)
nsIDOMElement*
nsXULWindow::GetWindowDOMElement() const
{
NS_ENSURE_STATE(mDocShell);
NS_ENSURE_ARG_POINTER(aDOMElement);
*aDOMElement = nullptr;
NS_ENSURE_TRUE(mDocShell, nullptr);
nsCOMPtr<nsIContentViewer> cv;
mDocShell->GetContentViewer(getter_AddRefs(cv));
NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(cv, nullptr);
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(cv->GetDocument()));
NS_ENSURE_TRUE(domdoc, NS_ERROR_FAILURE);
const nsIDocument* document = cv->GetDocument();
NS_ENSURE_TRUE(document, nullptr);
domdoc->GetDocumentElement(aDOMElement);
NS_ENSURE_TRUE(*aDOMElement, NS_ERROR_FAILURE);
dom::Element* element = document->GetRootElement();
NS_ENSURE_TRUE(element, nullptr);
return NS_OK;
return static_cast<nsIDOMElement*>(element->AsDOMNode());
}
nsresult nsXULWindow::ContentShellAdded(nsIDocShellTreeItem* aContentShell,
@ -1988,8 +1977,7 @@ void nsXULWindow::PersistentAttributesDirty(uint32_t aDirtyFlags)
NS_IMETHODIMP nsXULWindow::ApplyChromeFlags()
{
nsCOMPtr<nsIDOMElement> window;
GetWindowDOMElement(getter_AddRefs(window));
nsCOMPtr<nsIDOMElement> window = GetWindowDOMElement();
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
if (mChromeLoaded) {

View File

@ -91,7 +91,7 @@ protected:
NS_IMETHOD SavePersistentAttributes();
NS_IMETHOD GetWindowDOMWindow(nsIDOMWindow** aDOMWindow);
NS_IMETHOD GetWindowDOMElement(nsIDOMElement** aDOMElement);
nsIDOMElement* GetWindowDOMElement() const;
// See nsIDocShellTreeOwner for docs on next two methods
NS_HIDDEN_(nsresult) ContentShellAdded(nsIDocShellTreeItem* aContentShell,