Bug 1539069 - Part 1: Allow BC fields to be racy, and not have ProcessID validated, r=farre
authorNika Layzell <nika@thelayzells.com>
Wed, 27 Mar 2019 13:46:01 +0000
changeset 525191 bc6af49dc687721993e8400a8c46820d83366276
parent 525190 29582b2a7db1f46fd30d47769a965d9c693a2019
child 525192 23b3ab9c9e1fee3424a45b13d52819c5677fa2f4
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfarre
bugs1539069
milestone68.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 1539069 - Part 1: Allow BC fields to be racy, and not have ProcessID validated, r=farre Differential Revision: https://phabricator.services.mozilla.com/D24975
docshell/base/BrowsingContext.h
docshell/base/BrowsingContextFieldList.h
docshell/base/CanonicalBrowsingContext.cpp
--- a/docshell/base/BrowsingContext.h
+++ b/docshell/base/BrowsingContext.h
@@ -264,16 +264,27 @@ class BrowsingContext : public nsWrapper
 
     // You probably don't want to directly call this method - instead call
     // `Commit`, which will perform the necessary synchronization.
     //
     // |aSource| is the ContentParent which is performing the mutation in the
     // parent process.
     void Apply(BrowsingContext* aOwner, ContentParent* aSource);
 
+    bool HasNonRacyField() const {
+#define MOZ_BC_FIELD(name, ...) \
+  if (m##name.isSome()) {       \
+    return true;                \
+  }
+#define MOZ_BC_FIELD_RACY(...) /* nothing */
+#include "mozilla/dom/BrowsingContextFieldList.h"
+
+      return false;
+    }
+
 #define MOZ_BC_FIELD(name, type) mozilla::Maybe<type> m##name;
 #include "mozilla/dom/BrowsingContextFieldList.h"
 
    private:
     friend struct mozilla::ipc::IPDLParamTraits<Transaction>;
   };
 
 #define MOZ_BC_FIELD(name, type)                        \
--- a/docshell/base/BrowsingContextFieldList.h
+++ b/docshell/base/BrowsingContextFieldList.h
@@ -1,20 +1,30 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-MOZ_BC_FIELD(Name, nsString)
-MOZ_BC_FIELD(Closed, bool)
+// By defualt, synced fields may only be set by the currently active process,
+// however a field can be marked as `MOZ_BC_FIELD_RACY` to relax this
+// restriction, and allow it to be set from any process.
+//
+// Process restrictions on racy fields may be added in `WillSet{name}`
+// validators.
+#ifndef MOZ_BC_FIELD_RACY
+#  define MOZ_BC_FIELD_RACY MOZ_BC_FIELD
+#endif
+
+MOZ_BC_FIELD_RACY(Name, nsString)
+MOZ_BC_FIELD_RACY(Closed, bool)
 MOZ_BC_FIELD(CrossOriginPolicy, nsILoadInfo::CrossOriginPolicy)
 
 // The current opener for this BrowsingContext. This is a weak reference, and
 // stored as the opener ID.
 MOZ_BC_FIELD(OpenerId, uint64_t)
 
 // 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)
+MOZ_BC_FIELD_RACY(IsActivatedByUserGesture, bool)
 
 #undef MOZ_BC_FIELD
-#undef MOZ_BC_FIELD_SKIP_OPENER
+#undef MOZ_BC_FIELD_RACY
--- a/docshell/base/CanonicalBrowsingContext.cpp
+++ b/docshell/base/CanonicalBrowsingContext.cpp
@@ -96,18 +96,22 @@ void CanonicalBrowsingContext::SetCurren
   MOZ_ASSERT(mWindowGlobals.Contains(aGlobal), "Global not registered!");
 
   // TODO: This should probably assert that the processes match.
   mCurrentWindowGlobal = aGlobal;
 }
 
 bool CanonicalBrowsingContext::ValidateTransaction(
     const Transaction& aTransaction, ContentParent* aProcess) {
-  if (NS_WARN_IF(aProcess && mProcessId != aProcess->ChildID())) {
-    return false;
+  // Check that the correct process is performing sets for transactions with
+  // non-racy fields.
+  if (aTransaction.HasNonRacyField()) {
+    if (NS_WARN_IF(aProcess && mProcessId != aProcess->ChildID())) {
+      return false;
+    }
   }
 
   return true;
 }
 
 JSObject* CanonicalBrowsingContext::WrapObject(
     JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
   return CanonicalBrowsingContext_Binding::Wrap(aCx, this, aGivenProto);