Bug 1373718 - Update follow-on search add-on to 0.9.1 - fix double reporting and fix case sensitivity. r?past draft
authorMark Banner <standard8@mozilla.com>
Fri, 16 Jun 2017 17:25:53 +0100
changeset 595671 949732c6a36561958abb35d2b491a9b5907dd3d5
parent 595489 fe809f57bf2287bb937c3422ed03a63740b3448b
child 633763 b54092420df47c106fddbdf9348f624e67f0fa32
push id64400
push userbmo:standard8@mozilla.com
push dateFri, 16 Jun 2017 16:26:28 +0000
reviewerspast
bugs1373718
milestone56.0a1
Bug 1373718 - Update follow-on search add-on to 0.9.1 - fix double reporting and fix case sensitivity. r?past
browser/extensions/followonsearch/content/followonsearch-fs.js
browser/extensions/followonsearch/install.rdf
--- a/browser/extensions/followonsearch/content/followonsearch-fs.js
+++ b/browser/extensions/followonsearch/content/followonsearch-fs.js
@@ -138,24 +138,31 @@ function log(message) {
   // console.log(message);
 }
 
 // Hack to handle the most common reload case.
 // If gLastSearch is the same as the current URL, ignore the search.
 // This also prevents us from handling reloads with hashes twice
 let gLastSearch = null;
 
+// Keep track of the original window we were loaded in
+// so we don't handle requests for other windows.
+let gOriginalWindow = null;
+
 /**
  * Since most codes are in the URL, we can handle them via
  * a progress listener.
  */
 var webProgressListener = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]),
   onLocationChange(aWebProgress, aRequest, aLocation, aFlags)
   {
+    if (aWebProgress.DOMWindow && (aWebProgress.DOMWindow != gOriginalWindow)) {
+      return;
+    }
     try {
       if (!aWebProgress.isTopLevel ||
           // Not a URL
           (!aLocation.schemeIs("http") && !aLocation.schemeIs("https")) ||
           // Doesn't have a query string or a ref
           (!aLocation.query && !aLocation.ref) ||
           // Is the same as our last search (avoids reloads)
           aLocation.spec == gLastSearch) {
@@ -226,19 +233,19 @@ function onPageLoad(event) {
   var uri = doc.documentURIObject;
   if (!(uri instanceof Ci.nsIStandardURL) ||
       (!uri.schemeIs("http") && !uri.schemeIs("https")) ||
        uri.host != "www.bing.com" ||
       !doc.location.search ||
       uri.spec == gLastSearch) {
     return;
   }
-  var queries = new URLSearchParams(doc.location.search);
+  var queries = new URLSearchParams(doc.location.search.toLowerCase());
   // For Bing, QBRE form code is used for all follow-on search
-  if (queries.get("form") != "QBRE") {
+  if (queries.get("form") != "qbre") {
     return;
   }
   if (parseCookies(doc.cookie).SRCHS == "PC=MOZI") {
     log(`${uri.host} search with code MOZI - Follow on`);
     sendSaveTelemetryMsg("MOZI", "bing", "follow-on");
     gLastSearch = uri.spec;
   }
 }
@@ -258,16 +265,18 @@ function sendSaveTelemetryMsg(code, sap,
     type,
   });
 }
 
 addEventListener("DOMContentLoaded", onPageLoad, false);
 docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress)
         .addProgressListener(webProgressListener, Ci.nsIWebProgress.NOTIFY_LOCATION);
 
+gOriginalWindow = content;
+
 let gDisabled = false;
 
 addMessageListener(kShutdownMsg, () => {
   if (!gDisabled) {
     removeEventListener("DOMContentLoaded", onPageLoad, false);
     docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress)
             .removeProgressListener(webProgressListener);
     gDisabled = true;
--- a/browser/extensions/followonsearch/install.rdf
+++ b/browser/extensions/followonsearch/install.rdf
@@ -2,17 +2,17 @@
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:em="http://www.mozilla.org/2004/em-rdf#">
   <Description about="urn:mozilla:install-manifest">
     <em:id>followonsearch@mozilla.com</em:id>
     <em:name>Follow-on Search Telemetry</em:name>
-    <em:version>0.9.0</em:version>
+    <em:version>0.9.1</em:version>
     <em:type>2</em:type>
     <em:bootstrap>true</em:bootstrap>
     <em:multiprocessCompatible>true</em:multiprocessCompatible>
     <em:targetApplication>
       <Description>
         <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
         <em:minVersion>52.0</em:minVersion>
         <em:maxVersion>59.*</em:maxVersion>