Bug 1618536 - Introduce nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD representing preload of font, mapping to TYPE_FONT externally, r=baku
authorHonza Bambas <honzab.moz@firemni.cz>
Mon, 11 May 2020 14:13:16 +0000
changeset 529103 2af03857e0879f3006e72000eafababcda10d8a9
parent 529102 d7a40b7e663fc49c0cea2c6f3d3c5afe64bae298
child 529104 e7c7716689d645ff5e83b08b182b9902f7ee1515
push id37404
push usercsabou@mozilla.com
push dateMon, 11 May 2020 21:47:06 +0000
treeherdermozilla-central@61a83cc0b74b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1618536
milestone78.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 1618536 - Introduce nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD representing preload of font, mapping to TYPE_FONT externally, r=baku Depends on D69628 Differential Revision: https://phabricator.services.mozilla.com/D72118
dom/base/nsContentPolicyUtils.h
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/base/nsIContentPolicy.idl
dom/cache/DBSchema.cpp
dom/fetch/InternalRequest.cpp
dom/fetch/InternalRequest.h
dom/security/SecFetch.cpp
dom/security/nsCSPUtils.cpp
--- a/dom/base/nsContentPolicyUtils.h
+++ b/dom/base/nsContentPolicyUtils.h
@@ -136,16 +136,17 @@ inline const char* NS_CP_ContentTypeName
     CASE_RETURN(TYPE_SAVEAS_DOWNLOAD);
     CASE_RETURN(TYPE_SPECULATIVE);
     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);
     default:
       return "<Unknown Type>";
   }
 }
 
 #undef CASE_RETURN
 
 /* Passes on parameters from its "caller"'s context. */
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7985,17 +7985,18 @@ already_AddRefed<nsPIWindowRoot> nsConte
   return nullptr;
 }
 
 /* static */
 bool nsContentUtils::IsPreloadType(nsContentPolicyType aType) {
   return (aType == nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD ||
           aType == nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD ||
           aType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD ||
-          aType == nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD);
+          aType == nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD ||
+          aType == nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD);
 }
 
 /* static */
 bool nsContentUtils::IsUpgradableDisplayType(nsContentPolicyType aType) {
   MOZ_ASSERT(NS_IsMainThread());
   return (aType == nsIContentPolicy::TYPE_IMAGE ||
           aType == nsIContentPolicy::TYPE_MEDIA);
 }
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -3406,16 +3406,19 @@ nsContentUtils::InternalContentPolicyTyp
     case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET:
     case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD:
       return nsIContentPolicy::TYPE_STYLESHEET;
 
     case nsIContentPolicy::TYPE_INTERNAL_DTD:
     case nsIContentPolicy::TYPE_INTERNAL_FORCE_ALLOWED_DTD:
       return nsIContentPolicy::TYPE_DTD;
 
+    case nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD:
+      return nsIContentPolicy::TYPE_FONT;
+
     default:
       return aType;
   }
 }
 
 /* static */ inline nsContentPolicyType
 nsContentUtils::InternalContentPolicyTypeToExternalOrWorker(
     nsContentPolicyType aType) {
--- a/dom/base/nsIContentPolicy.idl
+++ b/dom/base/nsIContentPolicy.idl
@@ -389,16 +389,22 @@ interface nsIContentPolicy : nsISupports
    * Indicates an internal constant for scripts loaded through an
    * paintWorklet.
    *
    * This will be mapped to TYPE_SCRIPT before being passed to content policy
    * implementations.
    */
   const nsContentPolicyType TYPE_INTERNAL_PAINTWORKLET = 50;
 
+  /**
+   * Same as TYPE_FONT but indicates this is a <link rel=preload as=font>
+   * preload initiated load.
+   */
+  const nsContentPolicyType TYPE_INTERNAL_FONT_PRELOAD = 51;
+
   /* 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
@@ -331,17 +331,18 @@ static_assert(nsIContentPolicy::TYPE_INV
                   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_PAINTWORKLET == 50 &&
+                  nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD == 51,
               "nsContentPolicyType values are as expected");
 
 namespace {
 
 typedef int32_t EntryId;
 
 struct IdCount {
   explicit IdCount(int32_t aId) : mId(aId), mCount(1) {}
--- a/dom/fetch/InternalRequest.cpp
+++ b/dom/fetch/InternalRequest.cpp
@@ -288,16 +288,17 @@ RequestDestination InternalRequest::MapC
       destination = RequestDestination::_empty;
       break;
     case nsIContentPolicy::TYPE_DTD:
     case nsIContentPolicy::TYPE_INTERNAL_DTD:
     case nsIContentPolicy::TYPE_INTERNAL_FORCE_ALLOWED_DTD:
       destination = RequestDestination::_empty;
       break;
     case nsIContentPolicy::TYPE_FONT:
+    case nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD:
       destination = RequestDestination::Font;
       break;
     case nsIContentPolicy::TYPE_MEDIA:
       destination = RequestDestination::_empty;
       break;
     case nsIContentPolicy::TYPE_INTERNAL_AUDIO:
       destination = RequestDestination::Audio;
       break;
--- a/dom/fetch/InternalRequest.h
+++ b/dom/fetch/InternalRequest.h
@@ -37,17 +37,17 @@ namespace dom {
  * below for examples).
  *
  * RequestDestination| nsContentPolicyType
  * ------------------+--------------------
  * audio             | TYPE_INTERNAL_AUDIO
  * audioworklet      | TYPE_INTERNAL_AUDIOWORKLET
  * document          | TYPE_DOCUMENT, TYPE_INTERNAL_IFRAME, TYPE_SUBDOCUMENT
  * embed             | TYPE_INTERNAL_EMBED
- * font              | TYPE_FONT
+ * font              | TYPE_FONT, TYPE_INTERNAL_FONT_PRELOAD
  * image             | TYPE_INTERNAL_IMAGE, TYPE_INTERNAL_IMAGE_PRELOAD,
  *                   | TYPE_IMAGE, TYPE_INTERNAL_IMAGE_FAVICON, TYPE_IMAGESET
  * manifest          | TYPE_WEB_MANIFEST
  * object            | TYPE_INTERNAL_OBJECT, TYPE_OBJECT
  * "paintworklet"    | TYPE_INTERNAL_PAINTWORKLET
  * report"           | TODO
  * script            | TYPE_INTERNAL_SCRIPT, TYPE_INTERNAL_SCRIPT_PRELOAD,
  *                   | TYPE_INTERNAL_MODULE, TYPE_INTERNAL_MODULE_PRELOAD,
--- a/dom/security/SecFetch.cpp
+++ b/dom/security/SecFetch.cpp
@@ -70,16 +70,17 @@ nsCString MapInternalContentPolicyTypeTo
       return NS_LITERAL_CSTRING("empty");
     case nsIContentPolicy::TYPE_OBJECT_SUBREQUEST:
       return NS_LITERAL_CSTRING("empty");
     case nsIContentPolicy::TYPE_DTD:
     case nsIContentPolicy::TYPE_INTERNAL_DTD:
     case nsIContentPolicy::TYPE_INTERNAL_FORCE_ALLOWED_DTD:
       return NS_LITERAL_CSTRING("empty");
     case nsIContentPolicy::TYPE_FONT:
+    case nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD:
       return NS_LITERAL_CSTRING("font");
     case nsIContentPolicy::TYPE_MEDIA:
       return NS_LITERAL_CSTRING("empty");
     case nsIContentPolicy::TYPE_INTERNAL_AUDIO:
       return NS_LITERAL_CSTRING("audio");
     case nsIContentPolicy::TYPE_INTERNAL_VIDEO:
       return NS_LITERAL_CSTRING("video");
     case nsIContentPolicy::TYPE_INTERNAL_TRACK:
--- a/dom/security/nsCSPUtils.cpp
+++ b/dom/security/nsCSPUtils.cpp
@@ -266,16 +266,17 @@ CSPDirective CSP_ContentTypeToDirective(
     case nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET:
     case nsIContentPolicy::TYPE_INTERNAL_PAINTWORKLET:
       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;
 
     case nsIContentPolicy::TYPE_MEDIA:
       return nsIContentSecurityPolicy::MEDIA_SRC_DIRECTIVE;
 
     case nsIContentPolicy::TYPE_WEB_MANIFEST:
       return nsIContentSecurityPolicy::WEB_MANIFEST_SRC_DIRECTIVE;