Bug 1182308 - Windows 10 search rewrite should handle more Bing domains. r=jaws, a=lmandel
authorJustin Dolske <dolske@mozilla.com>
Thu, 16 Jul 2015 17:29:32 -0700
changeset 268906 bf517c651131d2c963413212df207646d63f8b1c
parent 268905 15833b3289cb51941a9ef960f8cdd41b9836f571
child 268907 85cd0bf009c62f0ebbbd559182ecc810c4be079a
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, lmandel
bugs1182308
milestone41.0a2
Bug 1182308 - Windows 10 search rewrite should handle more Bing domains. r=jaws, a=lmandel
browser/components/nsBrowserContentHandler.js
--- a/browser/components/nsBrowserContentHandler.js
+++ b/browser/components/nsBrowserContentHandler.js
@@ -732,17 +732,30 @@ nsDefaultCommandLineHandler.prototype = 
     try {
       var ar;
       while ((ar = cmdLine.handleFlagWithParam("url", false))) {
         var uri = resolveURIInternal(cmdLine, ar);
 
         // Searches in the Windows 10 task bar searchbox simply open the default browser
         // with a URL for a search on Bing. Here we extract the search term and use the
         // user's default search engine instead.
-        if (redirectWinSearch && uri.spec.startsWith("https://www.bing.com/search")) {
+        var uriScheme = "", uriHost = "", uriPath = "";
+        try {
+          uriScheme = uri.scheme;
+          uriHost = uri.host;
+          uriPath = uri.path;
+        } catch(e) {
+        }
+
+        // Most Windows searches are "https://www.bing.com/search...", but bug
+        // 1182308 reports a Chinese edition of Windows 10 using
+        // "http://cn.bing.com/search...", so be a bit flexible in what we match.
+        if (redirectWinSearch &&
+            (uriScheme == "http" || uriScheme == "https") &&
+            uriHost.endsWith(".bing.com") && uriPath.startsWith("/search")) {
           try {
             var url = uri.QueryInterface(Components.interfaces.nsIURL);
             var params = new URLSearchParams(url.query);
             // We don't want to rewrite all Bing URLs coming from external apps. Look
             // for the magic URL parm that's present in searches from the task bar.
             // (Typed searches use "form=WNSGPH", Cortana voice searches use "FORM=WNSBOX")
             var formParam = params.get("form");
             if (!formParam) {