Bug 1233982 - Do not fetch autofill icons from the network. r=adw draft
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 07 Jan 2016 17:25:09 +0100
changeset 321471 75cecbf47a833da15a0ee8176ca5a90d5c166141
parent 320820 eae9f44f7444407a28ab3b876032eceebe19310c
child 512902 75e3e5447fb470a19956eb82fad389f4f4b379dd
push id9381
push usermak77@bonardo.net
push dateWed, 13 Jan 2016 16:42:00 +0000
reviewersadw
bugs1233982
milestone46.0a1
Bug 1233982 - Do not fetch autofill icons from the network. r=adw
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/tests/unifiedcomplete/test_remotetabmatches.js
toolkit/components/places/tests/unifiedcomplete/test_typed.js
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -1242,16 +1242,19 @@ Search.prototype = {
       // is a string URL)
       if (!icon) {
         try {
           let favicon = yield PlacesUtils.promiseFaviconLinkUrl(url);
           if (favicon) {
             icon = favicon.spec;
           }
         } catch (ex) {} // no favicon for this URL.
+      } else {
+        icon = PlacesUtils.favicons
+                          .getFaviconLinkForIcon(NetUtil.newURI(icon)).spec;
       }
 
       let match = {
         // We include the deviceName in the action URL so we can render it in
         // the URLBar.
         value: makeActionURL("remotetab", { url, deviceName }),
         comment: title || url,
         style: "action",
@@ -1461,17 +1464,20 @@ Search.prototype = {
         !untrimmedHost.toLowerCase().includes(this._trimmedOriginalSearchString.toLowerCase())) {
       untrimmedHost = null;
     }
 
     match.value = this._strippedPrefix + trimmedHost;
     // Remove the trailing slash.
     match.comment = stripHttpAndTrim(trimmedHost);
     match.finalCompleteValue = untrimmedHost;
-    match.icon = faviconUrl;
+    if (faviconUrl) {
+      match.icon = PlacesUtils.favicons
+                              .getFaviconLinkForIcon(NetUtil.newURI(faviconUrl)).spec;
+    }
     // Although this has a frecency, this query is executed before any other
     // queries that would result in frecency matches.
     match.frecency = frecency;
     match.style = "autofill";
     return match;
   },
 
   _processUrlRow: function (row) {
@@ -1500,17 +1506,20 @@ Search.prototype = {
     if (untrimmedURL &&
         !untrimmedURL.toLowerCase().includes(this._trimmedOriginalSearchString.toLowerCase())) {
       untrimmedURL = null;
      }
 
     match.value = this._strippedPrefix + url;
     match.comment = url;
     match.finalCompleteValue = untrimmedURL;
-    match.icon = faviconUrl;
+    if (faviconUrl) {
+      match.icon = PlacesUtils.favicons
+                              .getFaviconLinkForIcon(NetUtil.newURI(faviconUrl)).spec;
+    }
     // Although this has a frecency, this query is executed before any other
     // queries that would result in frecency matches.
     match.frecency = frecency;
     match.style = "autofill";
     return match;
   },
 
   _processRow: function (row) {
--- a/toolkit/components/places/tests/unifiedcomplete/test_remotetabmatches.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_remotetabmatches.js
@@ -110,17 +110,17 @@ add_task(function* test_maximal() {
   });
 
   yield check_autocomplete({
     search: "ex",
     searchParam: "enable-actions",
     matches: [ makeSearchMatch("ex", { heuristic: true }),
                makeRemoteTabMatch("http://example.com/", "My Phone",
                                   { title: "An Example",
-                                    icon: "http://favicon"
+                                    icon: "moz-anno:favicon:http://favicon"
                                   }),
              ],
   });
 });
 
 add_task(function* test_matches_title() {
   // URL doesn't match search expression, should still match the title.
   configureEngine({
--- a/toolkit/components/places/tests/unifiedcomplete/test_typed.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_typed.js
@@ -1,35 +1,41 @@
 /* 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/. */
 
 // First do searches with typed behavior forced to false, so later tests will
 // ensure autocomplete is able to dinamically switch behavior.
 
+const FAVICON_HREF = NetUtil.newURI(do_get_file("../favicons/favicon-normal16.png")).spec;
+
 add_task(function* test_domain() {
   do_print("Searching for domain should autoFill it");
   Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
   yield PlacesTestUtils.addVisits(NetUtil.newURI("http://mozilla.org/link/"));
+  yield setFaviconForHref("http://mozilla.org/link/", FAVICON_HREF);
   yield check_autocomplete({
     search: "moz",
     autofilled: "mozilla.org/",
-    completed:  "mozilla.org/"
+    completed: "mozilla.org/",
+    icon: "moz-anno:favicon:" + FAVICON_HREF
   });
   yield cleanup();
 });
 
 add_task(function* test_url() {
   do_print("Searching for url should autoFill it");
   Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
   yield PlacesTestUtils.addVisits(NetUtil.newURI("http://mozilla.org/link/"));
+  yield setFaviconForHref("http://mozilla.org/link/", FAVICON_HREF);
   yield check_autocomplete({
     search: "mozilla.org/li",
     autofilled: "mozilla.org/link/",
-    completed: "http://mozilla.org/link/"
+    completed: "http://mozilla.org/link/",
+    icon: "moz-anno:favicon:" + FAVICON_HREF
   });
   yield cleanup();
 });
 
 // Now do searches with typed behavior forced to true.
 
 add_task(function* test_untyped_domain() {
   do_print("Searching for non-typed domain should not autoFill it");