Bug 1655714 - Add TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT and use in TryCacheLoadAndCompileScript(), r=kmag
authorFrederik Braun <fbraun@mozilla.com>
Mon, 10 Aug 2020 09:04:37 +0000
changeset 544061 12683a4cbe493347ff3355963301ae1f549981d6
parent 544059 375f4410ee3addb91206514f1d19693087cdf4bb
child 544062 2b47950ed3a1b06ed5378d50a054cee6e4105ae5
push id37687
push userapavel@mozilla.com
push dateMon, 10 Aug 2020 21:36:34 +0000
treeherdermozilla-central@ee09cb88af17 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1655714
milestone81.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 1655714 - Add TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT and use in TryCacheLoadAndCompileScript(), r=kmag The main point of this change is to not use TYPE_OTHER in `TryCacheLoadAndCompileScript()`, for extra clarity, we're not using a catch-all TYPE_INTERNAL_SCRIPT. This is why the changeset introduces a new type TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT which in itself adds lots of changes to various files. Differential Revision: https://phabricator.services.mozilla.com/D85977
dom/base/nsContentPolicyUtils.h
dom/base/nsContentUtils.h
dom/base/nsFrameMessageManager.cpp
dom/base/nsIContentPolicy.idl
dom/cache/DBSchema.cpp
dom/fetch/InternalRequest.cpp
dom/fetch/InternalRequest.h
dom/security/SecFetch.cpp
dom/security/nsCSPUtils.cpp
netwerk/protocol/http/nsHttpChannel.cpp
--- a/dom/base/nsContentPolicyUtils.h
+++ b/dom/base/nsContentPolicyUtils.h
@@ -137,16 +137,17 @@ inline const char* NS_CP_ContentTypeName
     CASE_RETURN(TYPE_INTERNAL_MODULE);
     CASE_RETURN(TYPE_INTERNAL_MODULE_PRELOAD);
     CASE_RETURN(TYPE_INTERNAL_DTD);
     CASE_RETURN(TYPE_INTERNAL_FORCE_ALLOWED_DTD);
     CASE_RETURN(TYPE_INTERNAL_AUDIOWORKLET);
     CASE_RETURN(TYPE_INTERNAL_PAINTWORKLET);
     CASE_RETURN(TYPE_INTERNAL_FONT_PRELOAD);
     CASE_RETURN(TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT);
+    CASE_RETURN(TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT);
     default:
       return "<Unknown Type>";
   }
 }
 
 #undef CASE_RETURN
 
 /* Passes on parameters from its "caller"'s context. */
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -3399,16 +3399,17 @@ nsContentUtils::InternalContentPolicyTyp
     case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
     case nsIContentPolicy::TYPE_INTERNAL_WORKER:
     case nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER:
     case nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER:
     case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS:
     case nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET:
     case nsIContentPolicy::TYPE_INTERNAL_PAINTWORKLET:
     case nsIContentPolicy::TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT:
+    case nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT:
       return nsIContentPolicy::TYPE_SCRIPT;
 
     case nsIContentPolicy::TYPE_INTERNAL_EMBED:
     case nsIContentPolicy::TYPE_INTERNAL_OBJECT:
       return nsIContentPolicy::TYPE_OBJECT;
 
     case nsIContentPolicy::TYPE_INTERNAL_FRAME:
     case nsIContentPolicy::TYPE_INTERNAL_IFRAME:
--- a/dom/base/nsFrameMessageManager.cpp
+++ b/dom/base/nsFrameMessageManager.cpp
@@ -1201,17 +1201,17 @@ void nsMessageManagerScriptExecutor::Try
 
   script = ScriptPreloader::GetChildSingleton().GetCachedScript(cx, url);
 
   if (!script) {
     nsCOMPtr<nsIChannel> channel;
     NS_NewChannel(getter_AddRefs(channel), uri,
                   nsContentUtils::GetSystemPrincipal(),
                   nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
-                  nsIContentPolicy::TYPE_OTHER);
+                  nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT);
 
     if (!channel) {
       return;
     }
 
     nsCOMPtr<nsIInputStream> input;
     rv = channel->Open(getter_AddRefs(input));
     NS_ENSURE_SUCCESS_VOID(rv);
--- a/dom/base/nsIContentPolicy.idl
+++ b/dom/base/nsIContentPolicy.idl
@@ -401,16 +401,24 @@ interface nsIContentPolicy : nsISupports
   /**
    * Indicates the load of a (Firefox-internal) script through ChromeUtils
    *
    * This will be mapped to TYPE_SCRIPT before being passed to content policy
    * implementations.
   */
   const nsContentPolicyType TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT = 52;
 
+/**
+ * Indicates the load of a script through FrameMessageManager
+   *
+   * This will be mapped to TYPE_SCRIPT before being passed to content policy
+   * implementations.
+  */
+  const nsContentPolicyType TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT = 53;
+
   /* When adding new content types, please update
    * NS_CP_ContentTypeName, nsCSPContext, CSP_ContentTypeToDirective,
    * DoContentSecurityChecks, all nsIContentPolicy implementations, the
    * static_assert in dom/cache/DBSchema.cpp, ChannelWrapper.webidl,
    * ChannelWrapper.cpp, PermissionManager.cpp, and other things that are not
    * listed here that are related to nsIContentPolicy. */
 
   //////////////////////////////////////////////////////////////////////
--- a/dom/cache/DBSchema.cpp
+++ b/dom/cache/DBSchema.cpp
@@ -283,71 +283,70 @@ static_assert(int(ResponseType::Basic) =
 static_assert(DEFAULT_NAMESPACE == 0 && CHROME_ONLY_NAMESPACE == 1 &&
                   NUMBER_OF_NAMESPACES == 2,
               "Namespace values are as expected");
 
 // If the static_asserts below fails, it means that you have changed the
 // nsContentPolicy enum in a way that may be incompatible with the existing data
 // stored in the DOM Cache.  You would need to update the Cache database schema
 // accordingly and adjust the failing static_assert.
-static_assert(nsIContentPolicy::TYPE_INVALID == 0 &&
-                  nsIContentPolicy::TYPE_OTHER == 1 &&
-                  nsIContentPolicy::TYPE_SCRIPT == 2 &&
-                  nsIContentPolicy::TYPE_IMAGE == 3 &&
-                  nsIContentPolicy::TYPE_STYLESHEET == 4 &&
-                  nsIContentPolicy::TYPE_OBJECT == 5 &&
-                  nsIContentPolicy::TYPE_DOCUMENT == 6 &&
-                  nsIContentPolicy::TYPE_SUBDOCUMENT == 7 &&
-                  nsIContentPolicy::TYPE_REFRESH == 8 &&
-                  nsIContentPolicy::TYPE_PING == 10 &&
-                  nsIContentPolicy::TYPE_XMLHTTPREQUEST == 11 &&
-                  nsIContentPolicy::TYPE_DATAREQUEST == 11 &&
-                  nsIContentPolicy::TYPE_OBJECT_SUBREQUEST == 12 &&
-                  nsIContentPolicy::TYPE_DTD == 13 &&
-                  nsIContentPolicy::TYPE_FONT == 14 &&
-                  nsIContentPolicy::TYPE_MEDIA == 15 &&
-                  nsIContentPolicy::TYPE_WEBSOCKET == 16 &&
-                  nsIContentPolicy::TYPE_CSP_REPORT == 17 &&
-                  nsIContentPolicy::TYPE_XSLT == 18 &&
-                  nsIContentPolicy::TYPE_BEACON == 19 &&
-                  nsIContentPolicy::TYPE_FETCH == 20 &&
-                  nsIContentPolicy::TYPE_IMAGESET == 21 &&
-                  nsIContentPolicy::TYPE_WEB_MANIFEST == 22 &&
-                  nsIContentPolicy::TYPE_INTERNAL_SCRIPT == 23 &&
-                  nsIContentPolicy::TYPE_INTERNAL_WORKER == 24 &&
-                  nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER == 25 &&
-                  nsIContentPolicy::TYPE_INTERNAL_EMBED == 26 &&
-                  nsIContentPolicy::TYPE_INTERNAL_OBJECT == 27 &&
-                  nsIContentPolicy::TYPE_INTERNAL_FRAME == 28 &&
-                  nsIContentPolicy::TYPE_INTERNAL_IFRAME == 29 &&
-                  nsIContentPolicy::TYPE_INTERNAL_AUDIO == 30 &&
-                  nsIContentPolicy::TYPE_INTERNAL_VIDEO == 31 &&
-                  nsIContentPolicy::TYPE_INTERNAL_TRACK == 32 &&
-                  nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST == 33 &&
-                  nsIContentPolicy::TYPE_INTERNAL_EVENTSOURCE == 34 &&
-                  nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER == 35 &&
-                  nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD == 36 &&
-                  nsIContentPolicy::TYPE_INTERNAL_IMAGE == 37 &&
-                  nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD == 38 &&
-                  nsIContentPolicy::TYPE_INTERNAL_STYLESHEET == 39 &&
-                  nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD == 40 &&
-                  nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON == 41 &&
-                  nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS == 42 &&
-                  nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD == 43 &&
-                  nsIContentPolicy::TYPE_SPECULATIVE == 44 &&
-                  nsIContentPolicy::TYPE_INTERNAL_MODULE == 45 &&
-                  nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD == 46 &&
-                  nsIContentPolicy::TYPE_INTERNAL_DTD == 47 &&
-                  nsIContentPolicy::TYPE_INTERNAL_FORCE_ALLOWED_DTD == 48 &&
-                  nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET == 49 &&
-                  nsIContentPolicy::TYPE_INTERNAL_PAINTWORKLET == 50 &&
-                  nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD == 51 &&
-                  nsIContentPolicy::TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT ==
-                      52,
-              "nsContentPolicyType values are as expected");
+static_assert(
+    nsIContentPolicy::TYPE_INVALID == 0 && nsIContentPolicy::TYPE_OTHER == 1 &&
+        nsIContentPolicy::TYPE_SCRIPT == 2 &&
+        nsIContentPolicy::TYPE_IMAGE == 3 &&
+        nsIContentPolicy::TYPE_STYLESHEET == 4 &&
+        nsIContentPolicy::TYPE_OBJECT == 5 &&
+        nsIContentPolicy::TYPE_DOCUMENT == 6 &&
+        nsIContentPolicy::TYPE_SUBDOCUMENT == 7 &&
+        nsIContentPolicy::TYPE_REFRESH == 8 &&
+        nsIContentPolicy::TYPE_PING == 10 &&
+        nsIContentPolicy::TYPE_XMLHTTPREQUEST == 11 &&
+        nsIContentPolicy::TYPE_DATAREQUEST == 11 &&
+        nsIContentPolicy::TYPE_OBJECT_SUBREQUEST == 12 &&
+        nsIContentPolicy::TYPE_DTD == 13 && nsIContentPolicy::TYPE_FONT == 14 &&
+        nsIContentPolicy::TYPE_MEDIA == 15 &&
+        nsIContentPolicy::TYPE_WEBSOCKET == 16 &&
+        nsIContentPolicy::TYPE_CSP_REPORT == 17 &&
+        nsIContentPolicy::TYPE_XSLT == 18 &&
+        nsIContentPolicy::TYPE_BEACON == 19 &&
+        nsIContentPolicy::TYPE_FETCH == 20 &&
+        nsIContentPolicy::TYPE_IMAGESET == 21 &&
+        nsIContentPolicy::TYPE_WEB_MANIFEST == 22 &&
+        nsIContentPolicy::TYPE_INTERNAL_SCRIPT == 23 &&
+        nsIContentPolicy::TYPE_INTERNAL_WORKER == 24 &&
+        nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER == 25 &&
+        nsIContentPolicy::TYPE_INTERNAL_EMBED == 26 &&
+        nsIContentPolicy::TYPE_INTERNAL_OBJECT == 27 &&
+        nsIContentPolicy::TYPE_INTERNAL_FRAME == 28 &&
+        nsIContentPolicy::TYPE_INTERNAL_IFRAME == 29 &&
+        nsIContentPolicy::TYPE_INTERNAL_AUDIO == 30 &&
+        nsIContentPolicy::TYPE_INTERNAL_VIDEO == 31 &&
+        nsIContentPolicy::TYPE_INTERNAL_TRACK == 32 &&
+        nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST == 33 &&
+        nsIContentPolicy::TYPE_INTERNAL_EVENTSOURCE == 34 &&
+        nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER == 35 &&
+        nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD == 36 &&
+        nsIContentPolicy::TYPE_INTERNAL_IMAGE == 37 &&
+        nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD == 38 &&
+        nsIContentPolicy::TYPE_INTERNAL_STYLESHEET == 39 &&
+        nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD == 40 &&
+        nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON == 41 &&
+        nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS == 42 &&
+        nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD == 43 &&
+        nsIContentPolicy::TYPE_SPECULATIVE == 44 &&
+        nsIContentPolicy::TYPE_INTERNAL_MODULE == 45 &&
+        nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD == 46 &&
+        nsIContentPolicy::TYPE_INTERNAL_DTD == 47 &&
+        nsIContentPolicy::TYPE_INTERNAL_FORCE_ALLOWED_DTD == 48 &&
+        nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET == 49 &&
+        nsIContentPolicy::TYPE_INTERNAL_PAINTWORKLET == 50 &&
+        nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD == 51 &&
+        nsIContentPolicy::TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT == 52 &&
+        nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT == 53,
+    "nsContentPolicyType values are as expected");
 
 namespace {
 
 typedef int32_t EntryId;
 
 struct IdCount {
   explicit IdCount(int32_t aId) : mId(aId), mCount(1) {}
   int32_t mId;
--- a/dom/fetch/InternalRequest.cpp
+++ b/dom/fetch/InternalRequest.cpp
@@ -198,16 +198,17 @@ RequestDestination InternalRequest::MapC
       break;
     case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
     case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
     case nsIContentPolicy::TYPE_INTERNAL_MODULE:
     case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
     case nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER:
     case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS:
     case nsIContentPolicy::TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT:
+    case nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT:
     case nsIContentPolicy::TYPE_SCRIPT:
       destination = RequestDestination::Script;
       break;
     case nsIContentPolicy::TYPE_INTERNAL_WORKER:
       destination = RequestDestination::Worker;
       break;
     case nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER:
       destination = RequestDestination::Sharedworker;
--- a/dom/fetch/InternalRequest.h
+++ b/dom/fetch/InternalRequest.h
@@ -49,16 +49,17 @@ namespace dom {
  * "paintworklet"    | TYPE_INTERNAL_PAINTWORKLET
  * report"           | TODO
  * script            | TYPE_INTERNAL_SCRIPT, TYPE_INTERNAL_SCRIPT_PRELOAD,
  *                   | TYPE_INTERNAL_MODULE, TYPE_INTERNAL_MODULE_PRELOAD,
  *                   | TYPE_SCRIPT,
  *                   | TYPE_INTERNAL_SERVICE_WORKER,
  *                   | TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS,
  *                   | TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT
+ *                   | TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT
  * sharedworker      | TYPE_INTERNAL_SHARED_WORKER
  * serviceworker     | The spec lists this as a valid value for the enum,
  *                   | however it is impossible to observe a request with this
  *                   | destination value.
  * style             | TYPE_INTERNAL_STYLESHEET,
  *                   | TYPE_INTERNAL_STYLESHEET_PRELOAD,
  *                   | TYPE_STYLESHEET
  * track             | TYPE_INTERNAL_TRACK
--- a/dom/security/SecFetch.cpp
+++ b/dom/security/SecFetch.cpp
@@ -19,16 +19,17 @@ nsCString MapInternalContentPolicyTypeTo
     case nsIContentPolicy::TYPE_OTHER:
       return "empty"_ns;
     case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
     case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
     case nsIContentPolicy::TYPE_INTERNAL_MODULE:
     case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
     case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS:
     case nsIContentPolicy::TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT:
+    case nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT:
     case nsIContentPolicy::TYPE_SCRIPT:
       return "script"_ns;
     case nsIContentPolicy::TYPE_INTERNAL_WORKER:
       return "worker"_ns;
     case nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER:
       return "sharedworker"_ns;
     case nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER:
       return "serviceworker"_ns;
--- a/dom/security/nsCSPUtils.cpp
+++ b/dom/security/nsCSPUtils.cpp
@@ -261,16 +261,17 @@ CSPDirective CSP_ContentTypeToDirective(
     case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
     case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
     case nsIContentPolicy::TYPE_INTERNAL_MODULE:
     case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
     case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS:
     case nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET:
     case nsIContentPolicy::TYPE_INTERNAL_PAINTWORKLET:
     case nsIContentPolicy::TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT:
+    case nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT:
       return nsIContentSecurityPolicy::SCRIPT_SRC_DIRECTIVE;
 
     case nsIContentPolicy::TYPE_STYLESHEET:
       return nsIContentSecurityPolicy::STYLE_SRC_DIRECTIVE;
 
     case nsIContentPolicy::TYPE_FONT:
     case nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD:
       return nsIContentSecurityPolicy::FONT_SRC_DIRECTIVE;
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -1607,16 +1607,17 @@ nsresult EnsureMIMEOfScript(nsHttpChanne
 
   switch (aLoadInfo->InternalContentPolicyType()) {
     case nsIContentPolicy::TYPE_SCRIPT:
     case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
     case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
     case nsIContentPolicy::TYPE_INTERNAL_MODULE:
     case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
     case nsIContentPolicy::TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT:
+    case nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT:
       AccumulateCategorical(
           Telemetry::LABELS_SCRIPT_BLOCK_INCORRECT_MIME_3::script_load);
       break;
     case nsIContentPolicy::TYPE_INTERNAL_WORKER:
     case nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER:
       AccumulateCategorical(
           Telemetry::LABELS_SCRIPT_BLOCK_INCORRECT_MIME_3::worker_load);
       break;