Bug 1517014 - Part 2: Avoid the overhead of parsing our origin string into a URI in AntiTrackingCommon::IsOnContentBlockingAllowList(); r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 07 Jan 2019 18:45:28 +0000
changeset 509833 da74b409b3da3a7271521569ee0772a1e0a82aeb
parent 509832 d316c363485743e50a71e906e3a80139307bd947
child 509834 28a3d1a9925647630c4c1d3f99eccd00f5dcac2b
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1517014
milestone66.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 1517014 - Part 2: Avoid the overhead of parsing our origin string into a URI in AntiTrackingCommon::IsOnContentBlockingAllowList(); r=baku Depends on D15543 Differential Revision: https://phabricator.services.mozilla.com/D15544
toolkit/components/antitracking/AntiTrackingCommon.cpp
--- a/toolkit/components/antitracking/AntiTrackingCommon.cpp
+++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp
@@ -1378,61 +1378,55 @@ nsresult AntiTrackingCommon::IsOnContent
          "the third-party cookies UI has been disabled."));
     return NS_OK;
   }
 
   LOG_SPEC(("Deciding whether the user has overridden content blocking for %s",
             _spec),
            aTopWinURI);
 
-  nsCOMPtr<nsIIOService> ios = services::GetIOService();
-  NS_ENSURE_TRUE(ios, NS_ERROR_FAILURE);
-
   // Take the host/port portion so we can allowlist by site. Also ignore the
   // scheme, since users who put sites on the allowlist probably don't expect
   // allowlisting to depend on scheme.
   nsresult rv = NS_ERROR_FAILURE;
   nsCOMPtr<nsIURL> url = do_QueryInterface(aTopWinURI, &rv);
   if (NS_FAILED(rv)) {
     return rv;  // normal for some loads, no need to print a warning
   }
 
-  nsCString escaped(NS_LITERAL_CSTRING("https://"));
+  nsAutoCString escaped(NS_LITERAL_CSTRING("https://"));
   nsAutoCString temp;
   rv = url->GetHostPort(temp);
   NS_ENSURE_SUCCESS(rv, rv);
   escaped.Append(temp);
 
-  // Stuff the whole thing back into a URI for the permission manager.
-  nsCOMPtr<nsIURI> topWinURI;
-  rv = ios->NewURI(escaped, nullptr, nullptr, getter_AddRefs(topWinURI));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsCOMPtr<nsIPermissionManager> permMgr =
       do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Check both the normal mode and private browsing mode user override
   // permissions.
   Pair<const char*, bool> types[] = {{"trackingprotection", false},
                                      {"trackingprotection-pb", true}};
 
+  auto topWinURI = PromiseFlatCString(escaped);
   for (size_t i = 0; i < ArrayLength(types); ++i) {
     if (aIsPrivateBrowsing != types[i].second()) {
       continue;
     }
 
     uint32_t permissions = nsIPermissionManager::UNKNOWN_ACTION;
-    rv = permMgr->TestPermission(topWinURI, types[i].first(), &permissions);
+    rv = permMgr->TestPermissionOriginNoSuffix(topWinURI, types[i].first(),
+                                               &permissions);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (permissions == nsIPermissionManager::ALLOW_ACTION) {
       aIsAllowListed = true;
-      LOG_SPEC(("Found user override type %s for %s", types[i].first(), _spec),
-               topWinURI);
+      LOG(("Found user override type %s for %s", types[i].first(),
+           topWinURI.get()));
       // Stop checking the next permisson type if we decided to override.
       break;
     }
   }
 
   if (!aIsAllowListed) {
     LOG(("No user override found"));
   }