Bug 1389315 - Isolate cached completion by provider draft
authorThomas Nguyen <tnguyen@mozilla.com>
Thu, 14 Sep 2017 17:05:52 +0800
changeset 664712 e2035f43d57d32028aea58c4d759a988ef247069
parent 664711 8873db0003853c8d27ec02fee67fd83f4b0b171d
child 731514 7f092c3d6dca44c7610427a2629826804d5553d5
push id79774
push userbmo:tnguyen@mozilla.com
push dateThu, 14 Sep 2017 09:06:07 +0000
bugs1389315
milestone57.0a1
Bug 1389315 - Isolate cached completion by provider MozReview-Commit-ID: INiuM5ydv2f
toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
--- a/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
+++ b/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
@@ -315,16 +315,17 @@ function HashCompleterRequest(aCompleter
   // nsIChannel that the hash completion query is transmitted over.
   this._channel = null;
   // Response body of hash completion. Created in onDataAvailable.
   this._response = "";
   // Whether we have been informed of a shutdown by the quit-application event.
   this._shuttingDown = false;
   this.gethashUrl = aGethashUrl;
 
+  this.provider = "";
   // Multiple partial hashes can be associated with the same tables
   // so we use a map here.
   this.tableNames = new Map();
 
   this.telemetryProvider = "";
   this.telemetryClockStart = 0;
 }
 HashCompleterRequest.prototype = {
@@ -350,16 +351,20 @@ HashCompleterRequest.prototype = {
         this.isV4 = isTableNameV4;
       } else if (this.isV4 !== isTableNameV4) {
         log('ERROR: Cannot mix "proto" tables with other types within ' +
             "the same gethash URL.");
       }
       this.tableNames.set(aTableName);
 
       // Assuming all tables with the same gethash URL have the same provider
+      if (this.provider == "") {
+        this.provider = gUrlUtil.getProvider(aTableName);
+      }
+
       if (this.telemetryProvider == "") {
         this.telemetryProvider = gUrlUtil.getTelemetryProvider(aTableName);
       }
     }
   },
 
   fillTableStatesBase64: function HCR_fillTableStatesBase64(aCallback) {
     gDbService.getTables(aTableData => {
@@ -662,16 +667,23 @@ HashCompleterRequest.prototype = {
     }
 
     return aStart + newlineIndex + 1 + dataLength;
   },
 
   // This adds a complete hash to any entry in |this._requests| that matches
   // the hash.
   handleItem: function HCR_handleItem(aData) {
+    let provider = gUrlUtil.getProvider(aData.tableName);
+    if (provider != this.provider) {
+      log("Response contains table : " + aData.tableName +
+          " of a different provider " + provider);
+      return;
+    }
+
     for (let i = 0; i < this._requests.length; i++) {
       let request = this._requests[i];
       if (aData.completeHash.startsWith(request.partialHash)) {
         request.response.matches.push(aData);
       }
     }
   },