Bug 1522412 - P3. Adopt nsIChannel.LOAD_BYPASS_URL_CLASSIFIER in the algorithm determining if we should classify a channel's URI. r=Ehsan,mayhemer
authordlee <dlee@mozilla.com>
Mon, 25 Mar 2019 12:48:25 +0000
changeset 465926 64664ada91eeeca17041a8498caf7966705eb6a8
parent 465925 393b5a62f63010255f958b98d62b15188183f30b
child 465927 9f3f62ed5b24d73000310597ef736d707a3f5a6c
push id35755
push usercbrindusan@mozilla.com
push dateTue, 26 Mar 2019 00:24:34 +0000
treeherdermozilla-central@4146cbd2103c [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
@@ -10357,18 +10357,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();