Bug 1563996 - Make dom.ipc.cpows.forbid-unsafe-from-browser a static pref. r=sfink
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 09 Jul 2019 07:58:02 +0000
changeset 481858 25c1534cc16eae5509972706e6e802933da273c7
parent 481857 9933d2e3bf28a75544285b1aac1b7ebbf4b1fd0c
child 481859 71e66aca29eb5cdc74b1b05dd74ed2e35e940bc9
push id36265
push userrgurzau@mozilla.com
push dateTue, 09 Jul 2019 15:37:42 +0000
treeherdermozilla-central@404680ad41e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1563996
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 1563996 - Make dom.ipc.cpows.forbid-unsafe-from-browser a static pref. r=sfink Differential Revision: https://phabricator.services.mozilla.com/D37198
js/ipc/JavaScriptParent.cpp
modules/libpref/init/StaticPrefList.h
--- a/js/ipc/JavaScriptParent.cpp
+++ b/js/ipc/JavaScriptParent.cpp
@@ -11,16 +11,17 @@
 #include "nsJSUtils.h"
 #include "nsIScriptError.h"
 #include "jsfriendapi.h"
 #include "js/Proxy.h"
 #include "js/HeapAPI.h"
 #include "js/Wrapper.h"
 #include "xpcprivate.h"
 #include "mozilla/Casting.h"
+#include "mozilla/StaticPrefs.h"
 #include "mozilla/Telemetry.h"
 #include "nsAutoPtr.h"
 
 using namespace js;
 using namespace JS;
 using namespace mozilla;
 using namespace mozilla::jsipc;
 using namespace mozilla::dom;
@@ -33,24 +34,17 @@ JavaScriptParent::JavaScriptParent() : s
   JS_AddExtraGCRootsTracer(danger::GetJSContext(), TraceParent, this);
 }
 
 JavaScriptParent::~JavaScriptParent() {
   JS_RemoveExtraGCRootsTracer(danger::GetJSContext(), TraceParent, this);
 }
 
 static bool ForbidUnsafeBrowserCPOWs() {
-  static bool result;
-  static bool cached = false;
-  if (!cached) {
-    cached = true;
-    Preferences::AddBoolVarCache(
-        &result, "dom.ipc.cpows.forbid-unsafe-from-browser", false);
-  }
-  return result;
+  return StaticPrefs::dom_ipc_cpows_forbid_unsafe_from_browser();
 }
 
 bool JavaScriptParent::allowMessage(JSContext* cx) {
   MOZ_ASSERT(cx);
 
   // If we're running browser code while running tests (in automation),
   // then we allow all safe CPOWs and forbid unsafe CPOWs
   // based on a pref (which defaults to forbidden).
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -1575,16 +1575,23 @@ VARCACHE_PREF(
 VARCACHE_PREF(
   Live,
   "dom.ipc.tabs.shutdownTimeoutSecs",
   dom_ipc_tabs_shutdownTimeoutSecs,
   RelaxedAtomicUint32, PREF_VALUE
 )
 #undef PREF_VALUE
 
+VARCACHE_PREF(
+  Live,
+  "dom.ipc.cpows.forbid-unsafe-from-browser",
+   dom_ipc_cpows_forbid_unsafe_from_browser,
+  bool, false
+)
+
 // If this is true, "keypress" event's keyCode value and charCode value always
 // become same if the event is not created/initialized by JS.
 VARCACHE_PREF(
   Live,
   "dom.keyboardevent.keypress.set_keycode_and_charcode_to_same_value",
   dom_keyboardevent_keypress_set_keycode_and_charcode_to_same_value,
   bool, true
 )