Bug 923656 - Global search box dropdown options: Having "Search Bing for: foo" web search between local searches is "surprising" r=mkmelin, ui-r=josiahone
authorJim Porter <jporter@mozilla.com>
Mon, 23 Feb 2015 00:13:29 -0600
changeset 17554 f5c8e7536911c6440a56cb82e6ff4dfca1ab240a
parent 17553 d3380f10946c24b60ebdcf0c9a7ab3c92500bc4d
child 17555 710080f9a4af5175ed353b1a4b75a06ef5186fc6
push id10803
push usersquibblyflabbetydoo@gmail.com
push dateMon, 23 Feb 2015 06:13:39 +0000
treeherdercomm-central@710080f9a4af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, josiahone
bugs923656
Bug 923656 - Global search box dropdown options: Having "Search Bing for: foo" web search between local searches is "surprising" r=mkmelin, ui-r=josiahone
mail/base/content/mailWindow.js
mail/base/content/messenger.css
mail/base/content/nsContextMenu.js
mail/base/content/webSearch.xml
mail/base/jar.mn
mail/base/modules/glodaWebSearch.js
mail/base/modules/moz.build
mail/locales/en-US/chrome/messenger/glodaComplete.properties
mail/locales/en-US/chrome/messenger/messenger.properties
--- a/mail/base/content/mailWindow.js
+++ b/mail/base/content/mailWindow.js
@@ -5,17 +5,16 @@
 
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource:///modules/appIdleManager.js");
 Components.utils.import("resource:///modules/MailUtils.js");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource:///modules/gloda/log4moz.js");
 Components.utils.import("resource:///modules/gloda/public.js");
-Components.utils.import("resource:///modules/glodaWebSearch.js");
 
 //This file stores variables common to mail windows
 var messenger;
 var statusFeedback;
 var msgWindow;
 
 var accountManager;
 
@@ -104,18 +103,16 @@ function InitMsgWindow()
   MailServices.mailSession.AddMsgWindow(msgWindow);
   let messagepane = document.getElementById("messagepane");
   messagepane.docShell.allowAuth = false;
   messagepane.docShell.allowDNSPrefetch = false;
   msgWindow.rootDocShell.allowAuth = true;
   msgWindow.rootDocShell.appType = Components.interfaces.nsIDocShell.APP_TYPE_MAIL;
   // Ensure we don't load xul error pages into the main window
   msgWindow.rootDocShell.useErrorPages = false;
-
-  GlodaWebSearch.onLoad();
 }
 
 // We're going to implement our status feedback for the mail window in JS now.
 // the following contains the implementation of our status feedback object
 
 function nsMsgStatusFeedback()
 {
   this._statusText = document.getElementById("statusText");
--- a/mail/base/content/messenger.css
+++ b/mail/base/content/messenger.css
@@ -3,22 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* ===== messenger.css ==================================================
   == Content specific styles for Messenger.
   ======================================================================= */
 
 @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
 
-/* ::::: mail xbl bindings ::::: */
-
-.autocomplete-richlistitem[type="websearch"] {
-  -moz-binding: url("chrome://messenger/content/webSearch.xml#websearch");
-}
-
 /* attachment list styles */
 
 attachmentlist {
   -moz-appearance: listbox;
   -moz-user-focus: normal;
 }
 
 attachmentlist[orient="horizontal"] {
--- a/mail/base/content/nsContextMenu.js
+++ b/mail/base/content/nsContextMenu.js
@@ -10,17 +10,16 @@ Components.utils.import("resource:///mod
 
 XPCOMUtils.defineLazyGetter(this, "PageMenuParent", function() {
   let tmp = {};
   Cu.import("resource://gre/modules/PageMenu.jsm", tmp);
   return new tmp.PageMenuParent();
 });
 
 var gSpellChecker = new InlineSpellChecker();
-var gGlodaBundle = null;
 
 function nsContextMenu(aXulMenu, aIsShift) {
   this.target         = null;
   this.menu           = null;
   this.onTextInput    = false;
   this.onEditableArea = false;
   this.onImage        = false;
   this.onLoadedImage  = false;
@@ -176,32 +175,33 @@ nsContextMenu.prototype = {
     this.showItem("mailContext-addemail", this.onMailtoLink && !this.inThreadPane);
 
 
     let searchTheWeb = document.getElementById("mailContext-searchTheWeb");
     this.showItem(searchTheWeb, !this.inThreadPane && !this.onPlayableMedia &&
                   this.isContentSelected);
 
     if (!searchTheWeb.hidden) {
-      let selection = document.commandDispatcher.focusedWindow.getSelection();
-      if (gGlodaBundle === null)
-        gGlodaBundle = Services.strings.createBundle(
-          "chrome://messenger/locale/glodaComplete.properties");
+      let selection = document.commandDispatcher.focusedWindow.getSelection()
+                              .toString();
 
-      let key = "glodaComplete.webSearch1.label";
-      let selString = selection.toString();
-      if (selString.length > 15) {
+      let bundle = document.getElementById("bundle_messenger");
+      let key = "openSearch.label";
+      let abbrSelection;
+      if (selection.length > 15) {
         key += ".truncated";
-        selString = selString.slice(0, 15);
+        abbrSelection = selection.slice(0, 15);
+      } else {
+        abbrSelection = selection;
       }
 
-      searchTheWeb.label = gGlodaBundle.GetStringFromName(key)
-                                      .replace("#1", Services.search.currentEngine.name)
-                                      .replace("#2", selString);
-      searchTheWeb.value = selection.toString();
+      searchTheWeb.label = bundle.getFormattedString(key, [
+        Services.search.currentEngine.name, abbrSelection
+      ]);
+      searchTheWeb.value = selection;
     }
   },
   initMediaPlayerItems: function CM_initMediaPlayerItems() {
     let onMedia = this.onVideo || this.onAudio;
     // Several mutually exclusive items.... play/pause, mute/unmute, show/hide
     this.showItem("mailContext-media-play", onMedia && this.target.paused);
     this.showItem("mailContext-media-pause", onMedia && !this.target.paused);
     this.showItem("mailContext-media-mute", onMedia && !this.target.muted);
deleted file mode 100644
--- a/mail/base/content/webSearch.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<!-- 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/. -->
-
-<bindings id="autocompleteBindings"
-          xmlns="http://www.mozilla.org/xbl"
-          xmlns:html="http://www.w3.org/1999/xhtml"
-          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-          xmlns:xbl="http://www.mozilla.org/xbl">
-  <binding id="websearch" extends="chrome://gloda/content/glodacomplete.xml#glodacomplete-base-richlistitem">
-    <content orient="horizontal">
-      <xul:image anonid="icon"/>
-      <xul:description anonid="explanation" class="explanation websearch"/>
-    </content>
-    <implementation implements="nsIDOMXULSelectControlItemElement">
-      <constructor>
-        <![CDATA[
-          this._explanation = document.getAnonymousElementByAttribute(
-            this, "anonid", "explanation");
-          this.bundle = Services.strings.createBundle(
-            "chrome://messenger/locale/glodaComplete.properties");
-          this._adjustAcItem();
-          ]]>
-      </constructor>
-
-      <property name="label" readonly="true">
-        <getter>
-          <![CDATA[
-            return this.bundle
-                       .GetStringFromName("glodaComplete.webSearch1.label")
-                       .replace("#1", Services.search.currentEngine.name)
-                       .replace("#2", this.row.item.tag);
-          ]]>
-        </getter>
-      </property>
-
-      <method name="_adjustAcItem">
-        <body>
-          <![CDATA[
-            this._explanation.value =
-              this.bundle.GetStringFromName("glodaComplete.webSearch1.label")
-                         .replace("#1", Services.search.currentEngine.name)
-                         .replace("#2", this.row.term);
-          ]]>
-        </body>
-      </method>
-    </implementation>
-  </binding>
-</bindings>
--- a/mail/base/jar.mn
+++ b/mail/base/jar.mn
@@ -43,17 +43,16 @@ messenger.jar:
     content/messenger/SearchDialog.js               (content/SearchDialog.js)
     content/messenger/ABSearchDialog.xul            (content/ABSearchDialog.xul)
     content/messenger/ABSearchDialog.js             (content/ABSearchDialog.js)
     content/messenger/FilterListDialog.xul          (content/FilterListDialog.xul)
     content/messenger/FilterListDialog.js           (content/FilterListDialog.js)
 *   content/messenger/plugins.js                    (content/plugins.js)
     content/messenger/specialTabs.js                (content/specialTabs.js)
     content/messenger/specialTabs.xul               (content/specialTabs.xul)
-    content/messenger/webSearch.xml                 (content/webSearch.xml)
     content/messenger/webSearchTab.xul              (content/webSearchTab.xul)
     content/messenger/webSearchTab.js               (content/webSearchTab.js)
     content/messenger/subscribe.xul                 (content/subscribe.xul)
     content/messenger/subscribe.js                  (content/subscribe.js)
 *   content/messenger/aboutDialog.xul               (content/aboutDialog.xul)
 *   content/messenger/aboutDialog.js                (content/aboutDialog.js)
 *   content/messenger/aboutRights.xhtml             (content/aboutRights.xhtml)
 *   content/messenger/systemIntegrationDialog.xul   (content/systemIntegrationDialog.xul)
deleted file mode 100644
--- a/mail/base/modules/glodaWebSearch.js
+++ /dev/null
@@ -1,76 +0,0 @@
-/* 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/. */
-
-const EXPORTED_SYMBOLS = ["GlodaWebSearch"];
-
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-const Cu = Components.utils;
-
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-
-function ResultRowSingle(term) {
-  this.term = term;
-  this.typeForStyle = "websearch";
-  this.nounDef = null;
-}
-
-ResultRowSingle.prototype = {
-  multi: false,
-  fullText: false,
-};
-
-function GlodaWebSearchCompleter() { }
-
-GlodaWebSearchCompleter.prototype = {
-  complete: function GlodaWebSearchCompleter_complete(aResult, aString) {
-    aResult.addRows([new ResultRowSingle(aString)]);
-    // We have nothing pending.
-    return false;
-  },
-  onItemsAdded: function(aItems, aCollection) {
-  },
-  onItemsModified: function(aItems, aCollection) {
-  },
-  onItemsRemoved: function(aItems, aCollection) {
-  },
-  onQueryCompleted: function(aCollection) {
-  }
-};
-
-var GlodaWebSearch = {
-  bundle: Services.strings.createBundle(
-    "chrome://messenger/locale/glodaComplete.properties"),
-
-  _initialized: false,
-
-  onLoad: function() {
-    if (this._initialized)
-      return;
-    this._initialized = true;
-
-    Services.obs.addObserver(this, "autocomplete-did-enter-text", false);
-    this.glodaCompleter = Cc["@mozilla.org/autocomplete/search;1?name=gloda"]
-                            .getService().wrappedJSObject;
-
-    // Add us as the second completer.
-    this.glodaCompleter.completers.splice(1, 0, new GlodaWebSearchCompleter());
-  },
-
-  observe: function(aSubject, aTopic, aData) {
-    if (aTopic == "autocomplete-did-enter-text") {
-      let curResult = this.glodaCompleter.curResult;
-      if (!curResult)
-        return; // autocomplete didn't even finish.
-
-      let row = curResult.getObjectAt(aSubject.popup.selectedIndex);
-      if (!row || (row.typeForStyle != "websearch"))
-        return; // It's not our row.
-
-      let ownerWindow = aSubject.ownerDocument.defaultView;
-      ownerWindow.openSearchTab(aSubject.state.string);
-    }
-  },
-};
--- a/mail/base/modules/moz.build
+++ b/mail/base/modules/moz.build
@@ -3,17 +3,16 @@
 # 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/.
 
 EXTRA_JS_MODULES += [
     'attachmentChecker.js',
     'dbViewWrapper.js',
     'displayNameUtils.js',
     'distribution.js',
-    'glodaWebSearch.js',
     'MailConsts.js',
     'mailInstrumentation.js',
     'mailMigrator.js',
     'MailUtils.js',
     'mailViewManager.js',
     'MsgHdrSyntheticView.js',
     'oauth.jsm',
     'quickFilterManager.js',
--- a/mail/locales/en-US/chrome/messenger/glodaComplete.properties
+++ b/mail/locales/en-US/chrome/messenger/glodaComplete.properties
@@ -12,20 +12,8 @@ glodaComplete.messagesTagged.label=Messa
 #  a particular word (replacing #1).
 glodaComplete.messagesMentioning.label=Messages mentioning: #1
 
 # LOCALIZATION NOTE (glodaComplete.messagesWithMany.label): The label used
 #  in the autocomplete widget to refer to a search for all messages mentioning
 #  a set of words, or a phrase containing multiple words (e.g. "red pepper")
 #  We use the same words in en-US, but maybe that's not always true.
 glodaComplete.messagesMentioningMany.label=Messages mentioning: #1
-
-# LOCALIZATION NOTE (glodaComplete.webSearch1.label): The label used in the
-#  autocomplete widget to refer to a search on the web for a short string
-#  containing at most 15 characters. #1 is the search provider to use. #2 is
-#  the string to search for, truncated to 15 characters.
-glodaComplete.webSearch1.label=Search #1 for: #2
-
-# LOCALIZATION NOTE (glodaComplete.webSearch1.label.truncated): The label used in
-#  the autocomplete widget to refer to a search on the web for a short string
-#  containing more than 15 characters. #1 is the search provider to use. #2 is
-#  the string to search for, truncated to 15 characters.
-glodaComplete.webSearch1.label.truncated=Search #1 for: #2…
--- a/mail/locales/en-US/chrome/messenger/messenger.properties
+++ b/mail/locales/en-US/chrome/messenger/messenger.properties
@@ -789,8 +789,20 @@ ignoredSubthreadFeedback=Replies to the 
 # LOCALIZATION NOTE (ignoredThreadsFeedback): Semi-colon list of plural forms.
 # #1 is the number of threads
 ignoredThreadsFeedback=Replies to the thread that was selected will not be shown.;Replies to the #1 threads that were selected will not be shown.
 # LOCALIZATION NOTE (ignoredSubthreadsFeedback): Semi-colon list of plural forms.
 # #1 is number of subthreads
 ignoredSubthreadsFeedback=Replies to the subthread that was selected will not be shown.;Replies to the #1 subthreads that were selected will not be shown.
 # LOCALIZATION NOTE (saveAsType): replace %S with the extension of the file to be saved.
 saveAsType=%S file
+
+# LOCALIZATION NOTE (openSearch.label): The label used in the autocomplete
+# widget to refer to a search on the web for a short string containing at most
+# 15 characters. %1$S is the search provider to use. %2$S is the string to
+# search for.
+openSearch.label=Search %1$S for "%2$S"
+
+# LOCALIZATION NOTE (openSearch.label.truncated): The label used in the
+# autocomplete widget to refer to a search on the web for a short string
+# containing more than 15 characters. %1$S is the search provider to use. %2$S
+# is the string to search for, truncated to 15 characters.
+openSearch.label.truncated=Search %1$S for "%2$S…"