Bug 1517014 - Part 4: Remove a useless QueryInterface from AntiTrackingCommon::IsOnContentBlockingAllowList(); r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 07 Jan 2019 18:45:32 +0000
changeset 509835 14d8f03b496c919c3049db1a094570a7122a4513
parent 509834 28a3d1a9925647630c4c1d3f99eccd00f5dcac2b
child 509846 aac6849c6ff0eb4981b569988a094f04e42f14dd
child 509847 b776171d854c35104b3ba19f2beb55f484ddf0c1
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 4: Remove a useless QueryInterface from AntiTrackingCommon::IsOnContentBlockingAllowList(); r=baku The only implementation of nsIURI which has a GetHostPort() method which can succeed is nsStandardURL, which implements nsIURL. Other implementations either do not implement nsIURL (so in the old version, they would bail out early) or they do, but their GetHostPort() method returns an error code unconditionally (so in the old version, they would bail out later). Hence, this patch doesn't change the semantics of the code. Depends on D15545 Differential Revision: https://phabricator.services.mozilla.com/D15546
toolkit/components/antitracking/AntiTrackingCommon.cpp
--- a/toolkit/components/antitracking/AntiTrackingCommon.cpp
+++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp
@@ -1381,26 +1381,24 @@ nsresult AntiTrackingCommon::IsOnContent
 
   LOG_SPEC(("Deciding whether the user has overridden content blocking for %s",
             _spec),
            aTopWinURI);
 
   // 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)) {
+  nsAutoCString escaped(NS_LITERAL_CSTRING("https://"));
+  nsAutoCString temp;
+  nsresult rv = aTopWinURI ? aTopWinURI->GetHostPort(temp) : NS_ERROR_FAILURE;
+  // GetHostPort returns an empty string (with a success error code) for file://
+  // URIs.
+  if (NS_FAILED(rv) || temp.IsEmpty()) {
     return rv;  // normal for some loads, no need to print a warning
   }
-
-  nsAutoCString escaped(NS_LITERAL_CSTRING("https://"));
-  nsAutoCString temp;
-  rv = url->GetHostPort(temp);
-  NS_ENSURE_SUCCESS(rv, rv);
   escaped.Append(temp);
 
   nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, NS_ERROR_FAILURE);
 
   // Check both the normal mode and private browsing mode user override
   // permissions.
   Pair<const char*, bool> types[] = {{"trackingprotection", false},