Bug 1272239 - P1. Support completion for test database. r=francois draft
authorDimiL <dlee@mozilla.com>
Mon, 30 May 2016 17:09:06 +0800
changeset 372729 6a5a3b48ef2a49616f06dd1ba8f9d1a4640c710a
parent 372484 2c7440e46d8786b2c82a1d2004e2b6d9d13f4046
child 372730 e3237ee539468e88a2eae67a5d9afa5ffde64432
push id19587
push userdlee@mozilla.com
push dateMon, 30 May 2016 09:09:43 +0000
reviewersfrancois
bugs1272239
milestone49.0a1
Bug 1272239 - P1. Support completion for test database. r=francois MozReview-Commit-ID: CGJo5asUhSE
toolkit/components/url-classifier/SafeBrowsing.jsm
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
--- a/toolkit/components/url-classifier/SafeBrowsing.jsm
+++ b/toolkit/components/url-classifier/SafeBrowsing.jsm
@@ -22,32 +22,29 @@ function log(...stuff) {
     return;
   }
 
   var d = new Date();
   let msg = "SafeBrowsing: " + d.toTimeString() + ": " + stuff.join(" ");
   dump(Services.urlFormatter.trimSensitiveURLs(msg) + "\n");
 }
 
-// Skip all the ones containining "test", because we never need to ask for
-// updates for them.
 function getLists(prefName) {
   log("getLists: " + prefName);
   let pref = null;
   try {
     pref = Services.prefs.getCharPref(prefName);
   } catch(e) {
     return null;
   }
   // Splitting an empty string returns [''], we really want an empty array.
   if (!pref) {
     return [];
   }
   return pref.split(",")
-    .filter(function(value) { return value.indexOf("test-") == -1; })
     .map(function(value) { return value.trim(); });
 }
 
 // These may be a comma-separated lists of tables.
 const phishingLists = getLists("urlclassifier.phishTable");
 const malwareLists = getLists("urlclassifier.malwareTable");
 const downloadBlockLists = getLists("urlclassifier.downloadBlockTable");
 const downloadAllowLists = getLists("urlclassifier.downloadAllowTable");
@@ -77,16 +74,22 @@ this.SafeBrowsing = {
 
   registerTableWithURLs: function(listname) {
     let listManager = Cc["@mozilla.org/url-classifier/listmanager;1"].
       getService(Ci.nsIUrlListManager);
 
     let providerName = this.listToProvider[listname];
     let provider = this.providers[providerName];
 
+    // Some tables do not have an corresponding provider, for example, "test-" tables.
+    // Those tables can't register update or gethash url.
+    if (!provider) {
+      return;
+    }
+
     listManager.registerTable(listname, providerName, provider.updateURL, provider.gethashURL);
   },
 
   registerTables: function() {
     for (let i = 0; i < phishingLists.length; ++i) {
       this.registerTableWithURLs(phishingLists[i]);
     }
     for (let i = 0; i < malwareLists.length; ++i) {
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -857,18 +857,17 @@ nsUrlClassifierLookupCallback::LookupCom
       rv = listManager->GetGethashUrl(result.mTableName, gethashUrl);
       NS_ENSURE_SUCCESS(rv, rv);
       LOG(("The match from %s needs to be completed at %s",
            result.mTableName.get(), gethashUrl.get()));
       // gethashUrls may be empty in 2 cases: test tables, and on startup where
       // we may have found a prefix in an existing table before the listmanager
       // has registered the table. In the second case we should not call
       // complete.
-      if ((!gethashUrl.IsEmpty() ||
-           StringBeginsWith(result.mTableName, NS_LITERAL_CSTRING("test-"))) &&
+      if (!gethashUrl.IsEmpty() &&
           mDBService->GetCompleter(result.mTableName,
                                    getter_AddRefs(completer))) {
         nsAutoCString partialHash;
         partialHash.Assign(reinterpret_cast<char*>(&result.hash.prefix),
                            PREFIX_SIZE);
 
         nsresult rv = completer->Complete(partialHash, gethashUrl, this);
         if (NS_SUCCEEDED(rv)) {
@@ -1622,19 +1621,16 @@ nsUrlClassifierDBService::GetCompleter(c
 
   // If we don't know about this table at all, or are disallowing completions
   // for it, skip completion checks.
   if (!mGethashTables.Contains(tableName) ||
       mDisallowCompletionsTables.Contains(tableName)) {
     return false;
   }
 
-  MOZ_ASSERT(!StringBeginsWith(tableName, NS_LITERAL_CSTRING("test-")),
-             "We should never fetch hash completions for test tables");
-
   // Otherwise, call gethash to find the hash completions.
   return NS_SUCCEEDED(CallGetService(NS_URLCLASSIFIERHASHCOMPLETER_CONTRACTID,
                                      completer));
 }
 
 NS_IMETHODIMP
 nsUrlClassifierDBService::Observe(nsISupports *aSubject, const char *aTopic,
                                   const char16_t *aData)