Bug 1532661 - Part 3: Add WillSetX and DidSetX callbacks for BrowsingContext synced fields, r=farre
authorNika Layzell <nika@thelayzells.com>
Thu, 14 Mar 2019 18:51:07 +0000
changeset 524932 58f77fa35eeab8de03c52f316d9f0553685a5f8d
parent 524931 a39da23d450b7e3cda053097d77ca47de40f1bb2
child 524933 9ce1a2365afff092f9107a5f1ae1eca6a34dfce3
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfarre
bugs1532661
milestone67.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 1532661 - Part 3: Add WillSetX and DidSetX callbacks for BrowsingContext synced fields, r=farre Depends on D22191 Differential Revision: https://phabricator.services.mozilla.com/D22192
docshell/base/BrowsingContext.cpp
docshell/base/BrowsingContext.h
--- a/docshell/base/BrowsingContext.cpp
+++ b/docshell/base/BrowsingContext.cpp
@@ -683,17 +683,19 @@ void BrowsingContext::Transaction::Commi
 
   Apply(aBrowsingContext, nullptr);
 }
 
 void BrowsingContext::Transaction::Apply(BrowsingContext* aBrowsingContext,
                                          ContentParent* aSource) {
 #define MOZ_BC_FIELD(name, ...)                         \
   if (m##name) {                                        \
+    aBrowsingContext->WillSet##name(*m##name, aSource); \
     aBrowsingContext->m##name = std::move(*m##name);    \
+    aBrowsingContext->DidSet##name(aSource);            \
     m##name.reset();                                    \
   }
 #include "mozilla/dom/BrowsingContextFieldList.h"
 }
 
 void BrowsingContext::LocationProxy::SetHref(const nsAString& aHref,
                                              nsIPrincipal& aSubjectPrincipal,
                                              ErrorResult& aError) {
--- a/docshell/base/BrowsingContext.h
+++ b/docshell/base/BrowsingContext.h
@@ -57,18 +57,23 @@ class BrowsingContextBase {
  protected:
   BrowsingContextBase() {
     // default-construct each field.
 #define MOZ_BC_FIELD(name, type) m##name = type();
 #include "mozilla/dom/BrowsingContextFieldList.h"
   }
   ~BrowsingContextBase() = default;
 
-#define BC_FIELD(name, type) type m##name;
-#include "mozilla/dom/BCFieldList.h"
+#define MOZ_BC_FIELD(name, type)                                    \
+  type m##name;                                                     \
+                                                                    \
+  /* shadow to validate fields. aSource is setter process or null*/ \
+  void WillSet##name(type const& aValue, ContentParent* aSource) {} \
+  void DidSet##name(ContentParent* aSource) {}
+#include "mozilla/dom/BrowsingContextFieldList.h"
 };
 
 // BrowsingContext, in this context, is the cross process replicated
 // environment in which information about documents is stored. In
 // particular the tree structure of nested browsing contexts is
 // represented by the tree of BrowsingContexts.
 //
 // The tree of BrowsingContexts is created in step with its
@@ -336,16 +341,24 @@ class BrowsingContext : public nsWrapper
    private:
     friend class RemoteLocationProxy;
     BrowsingContext* GetBrowsingContext() {
       return reinterpret_cast<BrowsingContext*>(
           uintptr_t(this) - offsetof(BrowsingContext, mLocation));
     }
   };
 
+  // Ensure that opener is in the same BrowsingContextGroup.
+  void WillSetOpener(const RefPtr<BrowsingContext>& aValue,
+                     ContentParent* aSource) {
+    if (aValue) {
+      MOZ_RELEASE_ASSERT(aValue->Group() == Group());
+    }
+  }
+
   // Type of BrowsingContent
   const Type mType;
 
   // Unique id identifying BrowsingContext
   const uint64_t mBrowsingContextId;
 
   RefPtr<BrowsingContextGroup> mGroup;
   RefPtr<BrowsingContext> mParent;