Bug 1186909 - Use eTLD+1 rather than host for the history query lookup for nsIPermissionManager migrations
authorMichael Layzell <michael@thelayzells.com>
Tue, 21 Jul 2015 19:27:13 -0400
changeset 254395 2c86f53d8b660bc5639ef37ccb790bcf2d15bfd1
parent 254394 3e5260eb5db7bdef71462df6140fc0a5755a3018
child 254396 783c6c78c458faa61337d0dbbfd413edee53512f
push id62739
push usereakhgari@mozilla.com
push dateThu, 23 Jul 2015 21:58:32 +0000
treeherdermozilla-inbound@3f100c37ad23 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1186909
milestone42.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 1186909 - Use eTLD+1 rather than host for the history query lookup for nsIPermissionManager migrations
extensions/cookie/nsPermissionManager.cpp
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -332,18 +332,32 @@ UpgradeHostToOriginAndInsert(const nsACS
 
   nsCOMPtr<nsINavHistoryService> histSrv = do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
 
   if (histSrv) {
     nsCOMPtr<nsINavHistoryQuery> histQuery;
     rv = histSrv->GetNewQuery(getter_AddRefs(histQuery));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    // We want to only find history items for this particular host, and subdomains
-    rv = histQuery->SetDomain(aHost);
+    // Get the eTLD+1 of the domain
+    nsAutoCString eTLD1;
+    nsCOMPtr<nsIEffectiveTLDService> tldService =
+      do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
+    MOZ_ASSERT(tldService); // We should always have a tldService
+    if (tldService) {
+      rv = tldService->GetBaseDomainFromHost(aHost, 0, eTLD1);
+      NS_ENSURE_SUCCESS(rv, rv);
+    } else {
+      // We should never hit this branch, but we produce a fake eTLD1
+      // to avoid crashing in a release build in case we hit this branch
+      eTLD1 = aHost;
+    }
+
+    // We want to only find history items for this particular eTLD+1, and subdomains
+    rv = histQuery->SetDomain(eTLD1);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = histQuery->SetDomainIsHost(false);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsINavHistoryQueryOptions> histQueryOpts;
     rv = histSrv->GetNewQueryOptions(getter_AddRefs(histQueryOpts));
     NS_ENSURE_SUCCESS(rv, rv);