Bug 1597456 - Fix uses of nsIDocShellTreeItem in mozilla::TextEditor::IsSafeToInsertData. r=masayuki
authorTetsuharu OHZEKI <tetsuharu.ohzeki@gmail.com>
Fri, 10 Jan 2020 22:16:53 +0000
changeset 509865 13133dc6b4d60c6949c8806032dde7a87514a184
parent 509864 84052ee4136c7d73ed83e2d3134294666b0ad9b2
child 509866 408f6c0f98146da1f540d5b6759e4d9a787db8ab
push id37005
push usernerli@mozilla.com
push dateSat, 11 Jan 2020 21:51:30 +0000
treeherdermozilla-central@408f6c0f9814 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1597456
milestone74.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1597456 - Fix uses of nsIDocShellTreeItem in mozilla::TextEditor::IsSafeToInsertData. r=masayuki Differential Revision: https://phabricator.services.mozilla.com/D59445
editor/libeditor/TextEditorDataTransfer.cpp
--- a/editor/libeditor/TextEditorDataTransfer.cpp
+++ b/editor/libeditor/TextEditorDataTransfer.cpp
@@ -16,16 +16,17 @@
 #include "nsCOMPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsFocusManager.h"
 #include "nsIClipboard.h"
 #include "nsIContent.h"
+#include "mozilla/dom/BrowsingContext.h"
 #include "mozilla/dom/Document.h"
 #include "nsIDragService.h"
 #include "nsIDragSession.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIPrincipal.h"
 #include "nsIFormControl.h"
 #include "nsISupportsPrimitives.h"
@@ -639,22 +640,24 @@ bool TextEditor::CanPasteTransferable(ns
 }
 
 bool TextEditor::IsSafeToInsertData(Document* aSourceDoc) {
   // Try to determine whether we should use a sanitizing fragment sink
   bool isSafe = false;
 
   RefPtr<Document> destdoc = GetDocument();
   NS_ASSERTION(destdoc, "Where is our destination doc?");
-  nsCOMPtr<nsIDocShellTreeItem> dsti = destdoc->GetDocShell();
-  nsCOMPtr<nsIDocShellTreeItem> root;
-  if (dsti) {
-    dsti->GetInProcessRootTreeItem(getter_AddRefs(root));
+
+  nsCOMPtr<nsIDocShell> docShell;
+  if (RefPtr<BrowsingContext> bc = destdoc->GetBrowsingContext()) {
+    RefPtr<BrowsingContext> root = bc->Top();
+    MOZ_ASSERT(root, "root should not be null");
+
+    docShell = root->GetDocShell();
   }
-  nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(root);
 
   isSafe = docShell && docShell->GetAppType() == nsIDocShell::APP_TYPE_EDITOR;
 
   if (!isSafe && aSourceDoc) {
     nsIPrincipal* srcPrincipal = aSourceDoc->NodePrincipal();
     nsIPrincipal* destPrincipal = destdoc->NodePrincipal();
     NS_ASSERTION(srcPrincipal && destPrincipal,
                  "How come we don't have a principal?");