Bug 1449338 - Show currently selected engine in newtabs search input. r=mikedeboer
authorDale Harvey <dale@arandomurl.com>
Tue, 17 Apr 2018 13:30:54 +0100
changeset 467991 34a41ccd3a2e1590cbe2d2c7adc9d19e1e2f969a
parent 467990 22561999866358c9d283cfbb6b283551ed94d585
child 467992 8aa0c90b5a3a8f6703a1fd2c5dc48c110a2b7599
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1449338
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1449338 - Show currently selected engine in newtabs search input. r=mikedeboer MozReview-Commit-ID: GTsx9dReoxS
browser/base/content/contentSearchUI.js
browser/modules/ContentSearch.jsm
browser/modules/test/browser/browser_ContentSearch.js
--- a/browser/base/content/contentSearchUI.js
+++ b/browser/base/content/contentSearchUI.js
@@ -4,16 +4,17 @@
 
 "use strict";
 
 this.ContentSearchUIController = (function() {
 
 const MAX_DISPLAYED_SUGGESTIONS = 6;
 const SUGGESTION_ID_PREFIX = "searchSuggestion";
 const ONE_OFF_ID_PREFIX = "oneOff";
+const DEFAULT_INPUT_ICON = "chrome://browser/skin/search-glass.svg";
 
 const HTML_NS = "http://www.w3.org/1999/xhtml";
 
 /**
  * Creates a new object that manages search suggestions and their UI for a text
  * box.
  *
  * The UI consists of an html:table that's inserted into the DOM after the given
@@ -86,16 +87,17 @@ ContentSearchUIController.prototype = {
     } else {
       icon = "chrome://mozapps/skin/places/defaultFavicon.svg";
     }
     this._defaultEngine = {
       name: engine.name,
       icon,
     };
     this._updateDefaultEngineHeader();
+    this._updateDefaultEngineIcon();
 
     if (engine && document.activeElement == this.input) {
       this._speculativeConnect();
     }
   },
 
   get engines() {
     return this._engines;
@@ -604,16 +606,24 @@ ContentSearchUIController.prototype = {
   _onMsgStrings(strings) {
     this._strings = strings;
     this._updateDefaultEngineHeader();
     this._updateSearchWithHeader();
     document.getElementById("contentSearchSettingsButton").textContent =
       this._strings.searchSettings;
   },
 
+  _updateDefaultEngineIcon() {
+    let eng = this._engines.find(engine => engine.name === this.defaultEngine.name);
+    // We only show the engines icon for default engines, otherwise show
+    // a default; default engines have an identifier
+    let icon = eng.identifier ? this.defaultEngine.icon : DEFAULT_INPUT_ICON;
+    document.body.style.setProperty("--newtab-search-icon", "url(" + icon + ")");
+  },
+
   _updateDefaultEngineHeader() {
     let header = document.getElementById("contentSearchDefaultEngineHeader");
     header.firstChild.setAttribute("src", this.defaultEngine.icon);
     if (!this._strings) {
       return;
     }
     while (header.firstChild.nextSibling) {
       header.firstChild.nextSibling.remove();
--- a/browser/modules/ContentSearch.jsm
+++ b/browser/modules/ContentSearch.jsm
@@ -334,16 +334,17 @@ var ContentSearch = {
       let iconBuffer = uri;
       if (!uriFlag) {
         iconBuffer = await this._arrayBufferFromDataURI(uri);
       }
       state.engines.push({
         name: engine.name,
         iconBuffer,
         hidden: hiddenList.includes(engine.name),
+        identifier: engine.identifier
       });
     }
     return state;
   },
 
   _processEventQueue() {
     if (this._currentEventPromise || !this._eventQueue.length) {
       return;
--- a/browser/modules/test/browser/browser_ContentSearch.js
+++ b/browser/modules/test/browser/browser_ContentSearch.js
@@ -367,16 +367,17 @@ var currentStateObj = async function() {
     currentEngine: await currentEngineObj(),
   };
   for (let engine of Services.search.getVisibleEngines()) {
     let uri = engine.getIconURLBySize(16, 16);
     state.engines.push({
       name: engine.name,
       iconBuffer: await arrayBufferFromDataURI(uri),
       hidden: false,
+      identifier: engine.identifier,
     });
   }
   return state;
 };
 
 var currentEngineObj = async function() {
   let engine = Services.search.currentEngine;
   let uriFavicon = engine.getIconURLBySize(16, 16);