Bug 1603649 - Follow-up: replace docShell iteration. r=farre,benc
authorJorg K <jorgk@jorgk.com>
Fri, 20 Dec 2019 23:50:38 +0100
changeset 37795 a4ce4142023188329b2b894918053c05a4a91ff2
parent 37794 c328fb103d47cd62bca9bfff421addd09e602624
child 37796 d8d88f20aa207a30b777ec63b191d15579c8561c
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
reviewersfarre, benc
bugs1603649
Bug 1603649 - Follow-up: replace docShell iteration. r=farre,benc
mailnews/base/src/nsMessenger.cpp
mailnews/base/src/nsMsgPrintEngine.cpp
mailnews/base/src/nsMsgWindow.cpp
mailnews/compose/src/moz.build
mailnews/compose/src/nsMsgComposeService.cpp
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -42,16 +42,19 @@
 
 /* for access to docshell */
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIWebNavigation.h"
 #include "nsContentUtils.h"
 #include "nsDocShellLoadState.h"
+#include "mozilla/dom/Element.h"
+#include "mozilla/dom/XULFrameElement.h"
+#include "nsFrameLoader.h"
 
 // mail
 #include "nsIMsgMailNewsUrl.h"
 #include "nsMsgBaseCID.h"
 #include "nsIMsgAccountManager.h"
 #include "nsIMsgMailSession.h"
 #include "nsIMailboxUrl.h"
 #include "nsIMsgFolder.h"
@@ -225,27 +228,24 @@ NS_IMETHODIMP nsMessenger::SetWindow(moz
     mWindow = aWin;
 
     rv = mailSession->AddFolderListener(this, nsIFolderListener::removed);
     NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ENSURE_TRUE(aWin, NS_ERROR_FAILURE);
     nsCOMPtr<nsPIDOMWindowOuter> win = nsPIDOMWindowOuter::From(aWin);
     nsIDocShell *rootShell = win->GetDocShell();
-    nsTArray<RefPtr<nsIDocShell>> docShells;
-    rootShell->GetAllDocShellsInSubtree(
-        nsIDocShell::typeContent, nsIDocShell::ENUMERATE_FORWARDS, docShells);
-    for (auto &child : docShells) {
-      bool childNameEquals = false;
-      child->NameEquals(NS_LITERAL_STRING("messagepane"), &childNameEquals);
-      if (childNameEquals) {
-        mDocShell = child;
-        break;
-      }
-    }
+    RefPtr<mozilla::dom::Element> el = rootShell->GetDocument()->GetElementById(
+        NS_LITERAL_STRING("messagepane"));
+    RefPtr<mozilla::dom::XULFrameElement> frame =
+        mozilla::dom::XULFrameElement::FromNodeOrNull(el);
+    mDocShell = nullptr;
+    RefPtr<mozilla::dom::Document> doc;
+    if (frame) doc = frame->GetContentDocument();
+    if (doc) mDocShell = doc->GetDocShell();
     if (mDocShell) {
       // Important! Clear out mCurrentDisplayCharset so we reset a default
       // charset on mDocshell the next time we try to load something into it.
       mCurrentDisplayCharset = "";
 
       if (aMsgWindow)
         aMsgWindow->GetTransactionManager(getter_AddRefs(mTxnMgr));
     }
--- a/mailnews/base/src/nsMsgPrintEngine.cpp
+++ b/mailnews/base/src/nsMsgPrintEngine.cpp
@@ -34,16 +34,19 @@
 // Interfaces Needed
 #include "nsIBaseWindow.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIWebNavigation.h"
 #include "nsContentUtils.h"
 #include "nsIChannel.h"
 #include "nsServiceManagerUtils.h"
+#include "mozilla/dom/Element.h"
+#include "mozilla/dom/XULFrameElement.h"
+#include "nsFrameLoader.h"
 
 static const char *kPrintingPromptService =
     "@mozilla.org/embedcomp/printingprompt-service;1";
 
 /////////////////////////////////////////////////////////////////////////
 // nsMsgPrintEngine implementation
 /////////////////////////////////////////////////////////////////////////
 
@@ -212,27 +215,24 @@ nsMsgPrintEngine::SetWindow(mozIDOMWindo
   mWindow = aWin;
 
   NS_ENSURE_TRUE(mWindow, NS_ERROR_FAILURE);
   nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(mWindow);
 
   window->GetDocShell()->SetAppType(nsIDocShell::APP_TYPE_MAIL);
 
   nsIDocShell *rootShell = window->GetDocShell();
-  nsTArray<RefPtr<nsIDocShell>> docShells;
-  rootShell->GetAllDocShellsInSubtree(
-      nsIDocShell::typeContent, nsIDocShell::ENUMERATE_FORWARDS, docShells);
-  for (auto &child : docShells) {
-    bool childNameEquals = false;
-    child->NameEquals(NS_LITERAL_STRING("content"), &childNameEquals);
-    if (childNameEquals) {
-      mDocShell = child;
-      break;
-    }
-  }
+  RefPtr<mozilla::dom::Element> el =
+      rootShell->GetDocument()->GetElementById(NS_LITERAL_STRING("content"));
+  RefPtr<mozilla::dom::XULFrameElement> frame =
+      mozilla::dom::XULFrameElement::FromNodeOrNull(el);
+  NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
+  RefPtr<mozilla::dom::Document> doc = frame->GetContentDocument();
+  NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
+  mDocShell = doc->GetDocShell();
   NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
   SetupObserver();
   return NS_OK;
 }
 
 /* void setParentWindow (in mozIDOMWindowProxy ptr); */
 NS_IMETHODIMP nsMsgPrintEngine::SetParentWindow(mozIDOMWindowProxy *ptr) {
   mParentWindow = ptr;
--- a/mailnews/base/src/nsMsgWindow.cpp
+++ b/mailnews/base/src/nsMsgWindow.cpp
@@ -30,17 +30,20 @@
 #include "nsContentUtils.h"
 #include "nsMsgContentPolicy.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIAuthPrompt.h"
 #include "nsMsgUtils.h"
 #include "mozilla/TransactionManager.h"
 #include "mozilla/dom/LoadURIOptionsBinding.h"
+#include "mozilla/dom/Element.h"
+#include "mozilla/dom/XULFrameElement.h"
 #include "mozilla/Components.h"
+#include "nsFrameLoader.h"
 
 NS_IMPL_ISUPPORTS(nsMsgWindow, nsIMsgWindow, nsIURIContentListener,
                   nsISupportsWeakReference, nsIMsgWindowTest)
 
 nsMsgWindow::nsMsgWindow() {
   mCharsetOverride = false;
   m_stopped = false;
 }
@@ -64,32 +67,28 @@ nsresult nsMsgWindow::Init() {
 NS_IMETHODIMP nsMsgWindow::GetMessageWindowDocShell(nsIDocShell **aDocShell) {
   *aDocShell = nullptr;
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mMessageWindowDocShellWeak));
   if (!docShell) {
     // if we don't have a docshell, then we need to look up the message pane
     // docshell
     nsCOMPtr<nsIDocShell> rootShell(do_QueryReferent(mRootDocShellWeak));
     if (rootShell) {
-      nsCOMPtr<nsIDocShellTreeItem> msgDocShellItem;
       if (rootShell) {
-        nsTArray<RefPtr<nsIDocShell>> docShells;
-        rootShell->GetAllDocShellsInSubtree(nsIDocShell::typeContent,
-                                            nsIDocShell::ENUMERATE_FORWARDS,
-                                            docShells);
-        for (auto &child : docShells) {
-          bool childNameEquals = false;
-          child->NameEquals(NS_LITERAL_STRING("messagepane"), &childNameEquals);
-          if (childNameEquals) {
-            docShell = child;
-            break;
-          }
-        }
+        RefPtr<mozilla::dom::Element> el =
+            rootShell->GetDocument()->GetElementById(
+                NS_LITERAL_STRING("messagepane"));
+        RefPtr<mozilla::dom::XULFrameElement> frame =
+            mozilla::dom::XULFrameElement::FromNodeOrNull(el);
+        NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
+        RefPtr<mozilla::dom::Document> doc = frame->GetContentDocument();
+        NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
+        docShell = doc->GetDocShell();
+        NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
       }
-      NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
       // we don't own mMessageWindowDocShell so don't try to keep a reference to
       // it!
       mMessageWindowDocShellWeak = do_GetWeakReference(docShell);
     }
   }
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
   docShell.forget(aDocShell);
--- a/mailnews/compose/src/moz.build
+++ b/mailnews/compose/src/moz.build
@@ -45,16 +45,18 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'coco
         'nsMsgAppleCodes.h',
         'nsMsgAppleDouble.h',
     ]
 
 LOCAL_INCLUDES += [
   '/%s/dom/base' % CONFIG['mozreltopsrcdir'],
 ]
 
+include('/ipc/chromium/chromium-config.mozbuild')
+
 FINAL_LIBRARY = 'mail'
 
 # clang-cl rightly complains about switch on nsresult.
 if CONFIG['CC_TYPE'] == 'clang-cl':
     CXXFLAGS += ['-Wno-switch']
 
 EXTRA_JS_MODULES += [
     'SMTPProtocolHandler.jsm',
--- a/mailnews/compose/src/nsMsgComposeService.cpp
+++ b/mailnews/compose/src/nsMsgComposeService.cpp
@@ -44,16 +44,19 @@
 #include "mozilla/dom/Selection.h"
 #include "nsUTF8Utils.h"
 #include "mozilla/intl/LineBreaker.h"
 #include "mozilla/Services.h"
 #include "mimemoz2.h"
 #include "nsIArray.h"
 #include "nsArrayUtils.h"
 #include "nsIURIMutator.h"
+#include "mozilla/dom/Element.h"
+#include "mozilla/dom/XULFrameElement.h"
+#include "nsFrameLoader.h"
 
 #ifdef MSGCOMP_TRACE_PERFORMANCE
 #  include "mozilla/Logging.h"
 #  include "nsIMsgHdr.h"
 #  include "nsIMsgMessageService.h"
 #  include "nsMsgUtils.h"
 #endif
 
@@ -243,27 +246,24 @@ nsMsgComposeService::GetOrigWindowSelect
 
   // Now delve down in to the message to get the HTML representation of the
   // selection
   nsCOMPtr<nsIDocShell> rootShell;
   rv = aMsgWindow->GetRootDocShell(getter_AddRefs(rootShell));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDocShell> messagePaneDocShell;
-  nsTArray<RefPtr<nsIDocShell>> docShells;
-  rootShell->GetAllDocShellsInSubtree(
-      nsIDocShell::typeContent, nsIDocShell::ENUMERATE_FORWARDS, docShells);
-  for (auto &child : docShells) {
-    bool childNameEquals = false;
-    child->NameEquals(NS_LITERAL_STRING("messagepane"), &childNameEquals);
-    if (childNameEquals) {
-      messagePaneDocShell = child;
-      break;
-    }
-  }
+  RefPtr<mozilla::dom::Element> el = rootShell->GetDocument()->GetElementById(
+      NS_LITERAL_STRING("messagepane"));
+  RefPtr<mozilla::dom::XULFrameElement> frame =
+      mozilla::dom::XULFrameElement::FromNodeOrNull(el);
+  NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
+  RefPtr<mozilla::dom::Document> doc = frame->GetContentDocument();
+  NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
+  messagePaneDocShell = doc->GetDocShell();
   NS_ENSURE_TRUE(messagePaneDocShell, NS_ERROR_FAILURE);
 
   nsCOMPtr<mozIDOMWindowProxy> domWindow(do_GetInterface(messagePaneDocShell));
   NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
   nsCOMPtr<nsPIDOMWindowOuter> privateWindow =
       nsPIDOMWindowOuter::From(domWindow);
   RefPtr<mozilla::dom::Selection> sel = privateWindow->GetSelection();
   NS_ENSURE_TRUE(sel, NS_ERROR_FAILURE);