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 275381 a7706082d5aa661ffdefa95ca4d5799f0dd8dfa7
parent 275380 c8ade2012d88b6d9544c0e57572188f77625dd29
child 275382 e28e902ee47b508a9e2e6d3e33e6815f7edfeb65
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, lmandel
bugs1182308
milestone40.0
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
@@ -717,17 +717,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) {