Bug 1444525: Extract the logic to see if we're a top-level chrome window. r?bz
MozReview-Commit-ID: C9x7AwYR99n
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -2626,16 +2626,37 @@ XULDocument::ResumeWalk()
mStillWalking = false;
if (mPendingSheets == 0) {
rv = DoneWalking();
}
return rv;
}
+already_AddRefed<nsIXULWindow>
+XULDocument::GetXULWindowIfToplevelChrome() const
+{
+ nsCOMPtr<nsIDocShellTreeItem> item = GetDocShell();
+ if (!item) {
+ return nullptr;
+ }
+ nsCOMPtr<nsIDocShellTreeOwner> owner;
+ item->GetTreeOwner(getter_AddRefs(owner));
+ nsCOMPtr<nsIXULWindow> xulWin = do_GetInterface(owner);
+ if (!xulWin) {
+ return nullptr;
+ }
+ nsCOMPtr<nsIDocShell> xulWinShell;
+ xulWin->GetDocShell(getter_AddRefs(xulWinShell));
+ if (!SameCOMIdentity(xulWinShell, item)) {
+ return nullptr;
+ }
+ return xulWin.forget();
+}
+
nsresult
XULDocument::DoneWalking()
{
NS_PRECONDITION(mPendingSheets == 0, "there are sheets to be loaded");
NS_PRECONDITION(!mStillWalking, "walk not done");
// XXXldb This is where we should really be setting the chromehidden
// attribute.
@@ -2667,27 +2688,19 @@ XULDocument::DoneWalking()
static_cast<nsIDocument*>(this),
NS_LITERAL_STRING("MozBeforeInitialXULLayout"),
true,
false);
// Before starting layout, check whether we're a toplevel chrome
// window. If we are, setup some state so that we don't have to restyle
// the whole tree after StartLayout.
- if (nsCOMPtr<nsIDocShellTreeItem> item = GetDocShell()) {
- nsCOMPtr<nsIDocShellTreeOwner> owner;
- item->GetTreeOwner(getter_AddRefs(owner));
- if (nsCOMPtr<nsIXULWindow> xulWin = do_GetInterface(owner)) {
- nsCOMPtr<nsIDocShell> xulWinShell;
- xulWin->GetDocShell(getter_AddRefs(xulWinShell));
- if (SameCOMIdentity(xulWinShell, item)) {
- // We're the chrome document!
- xulWin->BeforeStartLayout();
- }
- }
+ if (nsCOMPtr<nsIXULWindow> win = GetXULWindowIfToplevelChrome()) {
+ // We're the chrome document!
+ win->BeforeStartLayout();
}
StartLayout();
if (mIsWritingFastLoad && IsChromeURI(mDocumentURI))
nsXULPrototypeCache::GetInstance()->WritePrototype(mMasterPrototype);
NS_ASSERTION(mDelayFrameLoaderInitialization,
--- a/dom/xul/XULDocument.h
+++ b/dom/xul/XULDocument.h
@@ -194,16 +194,20 @@ public:
ErrorResult& aRv);
using nsDocument::GetBoxObjectFor;
void LoadOverlay(const nsAString& aURL, nsIObserver* aObserver,
ErrorResult& aRv);
protected:
virtual ~XULDocument();
+ // Returns the associated XUL window if this is a top-level chrome document,
+ // null otherwise.
+ already_AddRefed<nsIXULWindow> GetXULWindowIfToplevelChrome() const;
+
// Implementation methods
friend nsresult
(::NS_NewXULDocument(nsIDocument** aResult));
nsresult Init(void) override;
nsresult StartLayout(void);
nsresult GetViewportSize(int32_t* aWidth, int32_t* aHeight);