Bug 1576407: Part 1 - Add HadOriginalOpener flag to BrowsingContext. r=farre
☠☠ backed out by be74f006fdfd ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Wed, 28 Aug 2019 18:07:31 +0000
changeset 550979 be7cbc61f825fdfc36b20d476bef710ef275ad73
parent 550978 3e2987e01215fb9ce600074886866766da1444dd
child 550980 08d4c25fc67068280c150f260fd8e2381eab87c9
push id11858
push userrmaries@mozilla.com
push dateThu, 29 Aug 2019 15:29:30 +0000
treeherdermozilla-beta@e9268d2f3233 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfarre
bugs1576407
milestone70.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 1576407: Part 1 - Add HadOriginalOpener flag to BrowsingContext. r=farre This is currently only available on the outer window, but needs to move to BrowsingContext in order from us to remove redundant opener tracking from the former. Differential Revision: https://phabricator.services.mozilla.com/D43690
docshell/base/BrowsingContext.cpp
docshell/base/BrowsingContext.h
docshell/base/BrowsingContextFieldList.h
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsGlobalWindowOuter.h
--- a/docshell/base/BrowsingContext.cpp
+++ b/docshell/base/BrowsingContext.cpp
@@ -127,17 +127,20 @@ already_AddRefed<BrowsingContext> Browsi
                                            /* aProcessId */ 0, aType);
   } else {
     context = new BrowsingContext(aParent, group, id, aType);
   }
 
   // The name and opener fields need to be explicitly initialized. Don't bother
   // using transactions to set them, as we haven't been attached yet.
   context->mName = aName;
-  context->mOpenerId = aOpener ? aOpener->Id() : 0;
+  if (aOpener) {
+    context->mOpenerId = aOpener->Id();
+    context->mHadOriginalOpener = true;
+  }
   context->mEmbedderPolicy = nsILoadInfo::EMBEDDER_POLICY_NULL;
 
   BrowsingContext* inherit = aParent ? aParent : aOpener;
   if (inherit) {
     context->mOpenerPolicy = inherit->mOpenerPolicy;
     // CORPP 3.1.3 https://mikewest.github.io/corpp/#integration-html
     context->mEmbedderPolicy = inherit->mEmbedderPolicy;
   }
--- a/docshell/base/BrowsingContext.h
+++ b/docshell/base/BrowsingContext.h
@@ -211,16 +211,18 @@ class BrowsingContext : public nsWrapper
 
   already_AddRefed<BrowsingContext> GetOpener() const { return Get(mOpenerId); }
   void SetOpener(BrowsingContext* aOpener) {
     SetOpenerId(aOpener ? aOpener->Id() : 0);
   }
 
   bool HasOpener() const;
 
+  bool HadOriginalOpener() const { return mHadOriginalOpener; }
+
   /**
    * When a new browsing context is opened by a sandboxed document, it needs to
    * keep track of the browsing context that opened it, so that it can be
    * navigated by it.  This is the "one permitted sandboxed navigator".
    */
   already_AddRefed<BrowsingContext> GetOnePermittedSandboxedNavigator() const {
     return Get(mOnePermittedSandboxedNavigatorId);
   }
@@ -476,19 +478,17 @@ class BrowsingContext : public nsWrapper
 
    protected:
     friend class RemoteLocationProxy;
     BrowsingContext* GetBrowsingContext() override {
       return reinterpret_cast<BrowsingContext*>(
           uintptr_t(this) - offsetof(BrowsingContext, mLocation));
     }
 
-    already_AddRefed<nsIDocShell> GetDocShell() override {
-      return nullptr;
-    }
+    already_AddRefed<nsIDocShell> GetDocShell() override { return nullptr; }
   };
 
   // Ensure that opener is in the same BrowsingContextGroup.
   bool MaySetOpener(const uint64_t& aValue, ContentParent* aSource) {
     if (aValue != 0) {
       RefPtr<BrowsingContext> opener = Get(aValue);
       return opener && opener->Group() == Group();
     }
--- a/docshell/base/BrowsingContextFieldList.h
+++ b/docshell/base/BrowsingContextFieldList.h
@@ -16,16 +16,18 @@ MOZ_BC_FIELD(EmbedderPolicy, nsILoadInfo
 MOZ_BC_FIELD(OpenerPolicy, nsILoadInfo::CrossOriginOpenerPolicy)
 
 // The current opener for this BrowsingContext. This is a weak reference, and
 // stored as the opener ID.
 MOZ_BC_FIELD(OpenerId, uint64_t)
 
 MOZ_BC_FIELD(OnePermittedSandboxedNavigatorId, uint64_t)
 
+MOZ_BC_FIELD(HadOriginalOpener, bool)
+
 // Toplevel browsing contexts only. This field controls whether the browsing
 // context is currently considered to be activated by a gesture.
 MOZ_BC_FIELD(IsActivatedByUserGesture, bool)
 
 // Hold the audio muted state and should be used
 // on top level browsing contexts only.
 MOZ_BC_FIELD(Muted, bool)
 
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -4725,17 +4725,17 @@ void nsGlobalWindowOuter::MakeScriptDial
   }
 }
 
 bool nsGlobalWindowOuter::CanMoveResizeWindows(CallerType aCallerType) {
   // When called from chrome, we can avoid the following checks.
   if (aCallerType != CallerType::System) {
     // Don't allow scripts to move or resize windows that were not opened by a
     // script.
-    if (!mHadOriginalOpener) {
+    if (!HadOriginalOpener()) {
       return false;
     }
 
     if (!CanSetProperty("dom.disable_window_move_resize")) {
       return false;
     }
 
     // Ignore the request if we have more than one tab in the window.
@@ -6268,17 +6268,17 @@ void nsGlobalWindowOuter::CloseOuter(boo
   // Don't allow scripts from content to close non-neterror windows that
   // were not opened by script.
   if (mDoc) {
     nsAutoString url;
     nsresult rv = mDoc->GetURL(url);
     NS_ENSURE_SUCCESS_VOID(rv);
 
     if (!StringBeginsWith(url, NS_LITERAL_STRING("about:neterror")) &&
-        !mHadOriginalOpener && !aTrustedCaller) {
+        !HadOriginalOpener() && !aTrustedCaller) {
       bool allowClose =
           mAllowScriptsToClose ||
           Preferences::GetBool("dom.allow_scripts_to_close_windows", true);
       if (!allowClose) {
         // We're blocking the close operation
         // report localized error msg in JS console
         nsContentUtils::ReportToConsole(
             nsIScriptError::warningFlag, NS_LITERAL_CSTRING("DOM Window"),
--- a/dom/base/nsGlobalWindowOuter.h
+++ b/dom/base/nsGlobalWindowOuter.h
@@ -451,17 +451,19 @@ class nsGlobalWindowOuter final : public
 
   void MaybeForgiveSpamCount();
   bool IsClosedOrClosing() {
     return (mIsClosed || mInClose || mHavePendingClose || mCleanedUp);
   }
 
   bool IsCleanedUp() const { return mCleanedUp; }
 
-  bool HadOriginalOpener() const { return mHadOriginalOpener; }
+  bool HadOriginalOpener() const {
+    return GetBrowsingContext()->HadOriginalOpener();
+  }
 
   bool IsTopLevelWindow();
 
   virtual void FirePopupBlockedEvent(
       Document* aDoc, nsIURI* aPopupURI, const nsAString& aPopupWindowName,
       const nsAString& aPopupWindowFeatures) override;
 
   virtual void NotifyContentBlockingEvent(