Bug 1522412 - P3. Adopt nsIChannel.LOAD_BYPASS_URL_CLASSIFIER in the algorithm determining if we should classify a channel's URI. r=Ehsan,mayhemer
☠☠ backed out by 747a5da93708 ☠ ☠
authorDimi Lee <dlee@mozilla.com>
Thu, 21 Mar 2019 07:32:46 +0000
changeset 465374 5399bca472b1a519f595480e786aa970f51cbb66
parent 465373 91e5b339fe11c8211bced586f5eb31be46a47693
child 465375 fe288a48cecb6e867fb85dec61cd51017b2ee8db
push id35738
push userccoroiu@mozilla.com
push dateThu, 21 Mar 2019 21:59:09 +0000
treeherdermozilla-central@7eb8e627961c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan, mayhemer
bugs1522412, 1442496
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 1522412 - P3. Adopt nsIChannel.LOAD_BYPASS_URL_CLASSIFIER in the algorithm determining if we should classify a channel's URI. r=Ehsan,mayhemer This patch uses the flag to exempt channels from classification, but it doesn't include the use cases of this flag. See Bug 1442496 for the list of the call sites should use this flag. Differential Revision: https://phabricator.services.mozilla.com/D22112
accessible/base/Logging.cpp
docshell/base/nsDocShell.cpp
netwerk/base/nsIChannel.idl
netwerk/base/nsNetUtil.cpp
--- a/accessible/base/Logging.cpp
+++ b/accessible/base/Logging.cpp
@@ -306,16 +306,19 @@ static void LogRequest(nsIRequest* aRequ
     if (loadFlags & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI)
       printf("retargeted document uri; ");
     if (loadFlags & nsIChannel::LOAD_REPLACE) printf("replace; ");
     if (loadFlags & nsIChannel::LOAD_INITIAL_DOCUMENT_URI)
       printf("initial document uri; ");
     if (loadFlags & nsIChannel::LOAD_TARGETED) printf("targeted; ");
     if (loadFlags & nsIChannel::LOAD_CALL_CONTENT_SNIFFERS)
       printf("call content sniffers; ");
+    if (loadFlags & nsIChannel::LOAD_BYPASS_URL_CLASSIFIER) {
+      printf("bypass classify uri; ");
+    }
   } else {
     printf("    no request");
   }
 }
 
 static void LogDocAccState(DocAccessible* aDocument) {
   printf("document acc state: ");
   if (aDocument->HasLoadState(DocAccessible::eCompletelyLoaded))
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -10358,18 +10358,18 @@ nsresult nsDocShell::DoChannelLoad(nsICh
           break;
         case 2:
           loadFlags |= nsIRequest::VALIDATE_NEVER;
           break;
       }
       break;
   }
 
-  if (!aBypassClassifier) {
-    // Keep this for later use
+  if (aBypassClassifier) {
+    loadFlags |= nsIChannel::LOAD_BYPASS_URL_CLASSIFIER;
   }
 
   // If the user pressed shift-reload, then do not allow ServiceWorker
   // interception to occur. See step 12.1 of the SW HandleFetch algorithm.
   if (IsForceReloading()) {
     loadFlags |= nsIChannel::LOAD_BYPASS_SERVICE_WORKER;
   }
 
--- a/netwerk/base/nsIChannel.idl
+++ b/netwerk/base/nsIChannel.idl
@@ -243,17 +243,21 @@ interface nsIChannel : nsIRequest
      * If this flag is set, the channel should call the content sniffers as
      * described in nsNetCID.h about NS_CONTENT_SNIFFER_CATEGORY.
      *
      * Note: Channels may ignore this flag; however, new channel implementations
      * should only do so with good reason.
      */
     const unsigned long LOAD_CALL_CONTENT_SNIFFERS = 1 << 21;
 
-    // LOAD_BYPASS_URL_CLASSIFIER will be added
+    /**
+     * This flag tells the channel to bypass URL classifier service check
+     * when opening the channel.
+     */
+    const unsigned long LOAD_BYPASS_URL_CLASSIFIER = 1 << 22;
 
     /**
      * If this flag is set, the media-type content sniffer will be allowed
      * to override any server-set content-type. Otherwise it will only
      * be allowed to override "no content type" and application/octet-stream.
      */
     const unsigned long LOAD_MEDIA_SNIFFER_OVERRIDES_CONTENT_TYPE = 1 << 23;
 
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -3033,25 +3033,33 @@ bool NS_IsOffline() {
  * automatically classified either because there is a bug in the algorithm
  * or the data in loadinfo is wrong.
  * 1. beConservative, this is set by ServiceRequest and we treat
  *    channel created for ServiceRequest as critical channels.
  * 2. nsIChannel::LOAD_BYPASS_URL_CLASSIFIER, channel's opener can use this
  *    flag to enforce bypassing the URL classifier check.
  */
 bool NS_ShouldClassifyChannel(nsIChannel *aChannel) {
+  nsLoadFlags loadFlags;
+  Unused << aChannel->GetLoadFlags(&loadFlags);
+  //  If our load flags dictate that we must let this channel through without
+  //  URL classification, obey that here without performing more checks.
+  if (loadFlags & nsIChannel::LOAD_BYPASS_URL_CLASSIFIER) {
+    return false;
+  }
+
   nsCOMPtr<nsIHttpChannelInternal> httpChannel(do_QueryInterface(aChannel));
   if (httpChannel) {
     bool beConservative;
     nsresult rv = httpChannel->GetBeConservative(&beConservative);
 
-    // beConservative flag, set by ServiceRequest to ensure channels that fetch
-    // update use conservative TLS setting, are used here to identify channels
-    // are critical to bypass classification. for channels don't support
-    // beConservative, continue to apply the exemption rules.
+    // beConservative flag, set by ServiceRequest to ensure channels that
+    // fetch update use conservative TLS setting, are used here to identify
+    // channels are critical to bypass classification. for channels don't
+    // support beConservative, continue to apply the exemption rules.
     if (NS_SUCCEEDED(rv) && beConservative) {
       return false;
     }
   }
 
   nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   if (loadInfo) {
     nsContentPolicyType type = loadInfo->GetExternalContentPolicyType();