Bug 977177 - Update favicons API consumers. r=adw draft
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 28 Sep 2016 16:14:30 +0200
changeset 561150 fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
parent 561149 4d25966596dcdf63c9c872425c5bf147406d25ac
child 561151 029a6fcaa9dadda24f8d3ebc9b36c1a0ec6314c6
push id53651
push usermak77@bonardo.net
push dateWed, 12 Apr 2017 09:15:32 +0000
reviewersadw
bugs977177, 1347532, 1346139, 1337402
milestone55.0a1
Bug 977177 - Update favicons API consumers. r=adw Updates consumers to the new behavior. Some consumers are changed to use the "page-icon:" protocol, since it's not trivial to join the icons table and get a single result out of it. In most cases the join would return multiple results since a page can have multiple icon payloads. These consumers for now will return the biggest payload, bug 1347532 will fix some of them to properly pass a #size=NN fragment. Note that, even before, these were just "moz-anno:favicon:" uris, and the payload had to be fetched from the database. Some other consumers for now just fallback to the largest payload, by passing 0 to GetFaviconURLForPage. The favicon optimization still happens on the main-thread, bug 1346139 will handle that problem. Most of the changes involve handling the modified IconData objects, that now retain an array of payloads, rather than just one. But note that .ico files are not yet split into single frames, due to imagelib missing APIs that will be handled in bug 1337402. The other changes involve fixing queries to properly join with the new tables. Finally, note that thanks to the FOREIGN KEYS support, removing from moz_icons or moz_pages_w_icons will also remove relations from moz_icons_to_pages. The system only supports square icons, so icons are resized based on their larger side. This doesn't include new tests, those will be in a following changeset. MozReview-Commit-ID: JUkpquhpS8y
browser/components/customizableui/CustomizableWidgets.jsm
browser/components/places/content/browserPlacesViews.js
docshell/base/nsDocShell.cpp
testing/firefox-ui/tests/functional/locationbar/manifest.ini
testing/firefox-ui/tests/functional/locationbar/test_favicon_in_autocomplete.py
toolkit/components/alerts/nsAlertsService.cpp
toolkit/components/places/FaviconHelpers.cpp
toolkit/components/places/FaviconHelpers.h
toolkit/components/places/History.jsm
toolkit/components/places/PageIconProtocolHandler.js
toolkit/components/places/PlacesDBUtils.jsm
toolkit/components/places/PlacesUtils.jsm
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/mozIAsyncFavicons.idl
toolkit/components/places/nsAnnoProtocolHandler.cpp
toolkit/components/places/nsFaviconService.cpp
toolkit/components/places/nsFaviconService.h
toolkit/components/places/nsIFaviconService.idl
toolkit/components/places/nsNavBookmarks.cpp
toolkit/components/places/nsNavHistory.cpp
toolkit/components/places/nsNavHistory.h
toolkit/components/places/nsNavHistoryResult.cpp
toolkit/components/places/nsNavHistoryResult.h
toolkit/components/places/nsPlacesExpiration.js
toolkit/components/places/tests/browser/browser_favicon_setAndFetchFaviconForPage_failures.js
toolkit/components/places/tests/chrome/chrome.ini
toolkit/components/places/tests/chrome/head.js
toolkit/components/places/tests/chrome/test_favicon_annotations.xul
toolkit/components/places/tests/favicons/expected-favicon-big16.ico.png
toolkit/components/places/tests/favicons/expected-favicon-big4.jpg.png
toolkit/components/places/tests/favicons/expected-favicon-big48.ico.png
toolkit/components/places/tests/favicons/expected-favicon-big64.png.png
toolkit/components/places/tests/favicons/expected-favicon-scale160x3.jpg.png
toolkit/components/places/tests/favicons/expected-favicon-scale3x160.jpg.png
toolkit/components/places/tests/favicons/test_expireAllFavicons.js
toolkit/components/places/tests/favicons/test_favicons_conversions.js
toolkit/components/places/tests/favicons/test_replaceFaviconData.js
toolkit/components/places/tests/favicons/test_svg_favicon.js
toolkit/components/places/tests/favicons/xpcshell.ini
toolkit/components/places/tests/head_common.js
toolkit/components/places/tests/history/test_remove.js
toolkit/components/places/tests/history/test_removeVisitsByFilter.js
toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
toolkit/components/places/tests/unifiedcomplete/test_autofill_default_behavior.js
toolkit/components/places/tests/unifiedcomplete/test_typed.js
toolkit/components/places/tests/unit/test_history_clear.js
toolkit/components/places/tests/unit/test_preventive_maintenance.js
toolkit/components/places/tests/unit/test_promiseBookmarksTree.js
toolkit/components/places/tests/unit/test_svg_favicon.js
toolkit/components/places/tests/unit/xpcshell.ini
widget/windows/WinUtils.cpp
--- a/browser/components/customizableui/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/CustomizableWidgets.jsm
@@ -213,28 +213,24 @@ const CustomizableWidgets = [
             win.openUILink(item.getAttribute("targetURI"), aItemCommandEvent);
             CustomizableUI.hidePanelForNode(item);
           };
           let fragment = doc.createDocumentFragment();
           let row;
           while ((row = aResultSet.getNextRow())) {
             let uri = row.getResultByIndex(1);
             let title = row.getResultByIndex(2);
-            let icon = row.getResultByIndex(6);
 
             let item = doc.createElementNS(kNSXUL, "toolbarbutton");
             item.setAttribute("label", title || uri);
             item.setAttribute("targetURI", uri);
             item.setAttribute("class", "subviewbutton");
             item.addEventListener("command", onItemCommand);
             item.addEventListener("click", onItemCommand);
-            if (icon) {
-              let iconURL = "moz-anno:favicon:" + icon;
-              item.setAttribute("image", iconURL);
-            }
+            item.setAttribute("image", "page-icon:" + uri);
             fragment.appendChild(item);
           }
           items.appendChild(fragment);
         },
         handleError(aError) {
           log.debug("History view tried to show but had an error: " + aError);
         },
         handleCompletion(aReason) {
--- a/browser/components/places/content/browserPlacesViews.js
+++ b/browser/components/places/content/browserPlacesViews.js
@@ -503,24 +503,20 @@ PlacesViewBase.prototype = {
     let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
 
     // There's no UI representation for the root node, thus there's nothing to
     // be done when the icon changes.
     if (elt == this._rootElt)
       return;
 
     // Here we need the <menu>.
-    if (elt.localName == "menupopup")
+    if (elt.localName == "menupopup") {
       elt = elt.parentNode;
-
-    let icon = aPlacesNode.icon;
-    if (!icon)
-      elt.removeAttribute("image");
-    else if (icon != elt.getAttribute("image"))
-      elt.setAttribute("image", icon);
+    }
+    elt.setAttribute("image", aPlacesNode.icon);
   },
 
   nodeAnnotationChanged:
   function PVB_nodeAnnotationChanged(aPlacesNode, aAnno) {
     let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
 
     // All livemarks have a feedURI, so use it as our indicator of a livemark
     // being modified.
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -9598,17 +9598,17 @@ public:
     , mNewURI(aNewURI)
     , mLoadingPrincipal(aLoadingPrincipal)
     , mInPrivateBrowsing(aInPrivateBrowsing)
   {
   }
 
   NS_IMETHOD
   OnComplete(nsIURI* aFaviconURI, uint32_t aDataLen,
-             const uint8_t* aData, const nsACString& aMimeType) override
+             const uint8_t* aData, const nsACString& aMimeType, uint16_t aWidth) override
   {
     // Continue only if there is an associated favicon.
     if (!aFaviconURI) {
       return NS_OK;
     }
 
     MOZ_ASSERT(aDataLen == 0,
                "We weren't expecting the callback to deliver data.");
@@ -9657,17 +9657,17 @@ nsDocShell::CopyFavicon(nsIURI* aOldURI,
 #ifdef MOZ_PLACES
   nsCOMPtr<mozIAsyncFavicons> favSvc =
     do_GetService("@mozilla.org/browser/favicon-service;1");
   if (favSvc) {
     nsCOMPtr<nsIFaviconDataCallback> callback =
       new nsCopyFaviconCallback(favSvc, aNewURI,
                                 aLoadingPrincipal,
                                 aInPrivateBrowsing);
-    favSvc->GetFaviconURLForPage(aOldURI, callback);
+    favSvc->GetFaviconURLForPage(aOldURI, callback, 0);
   }
 #endif
 }
 
 class InternalLoadEvent : public Runnable
 {
 public:
   InternalLoadEvent(nsDocShell* aDocShell, nsIURI* aURI,
--- a/testing/firefox-ui/tests/functional/locationbar/manifest.ini
+++ b/testing/firefox-ui/tests/functional/locationbar/manifest.ini
@@ -1,9 +1,8 @@
 [DEFAULT]
 tags = local
 
 [test_access_locationbar.py]
 disabled = Bug 1168727 - Timeout when opening auto-complete popup
 [test_escape_autocomplete.py]
-[test_favicon_in_autocomplete.py]
 [test_suggest_bookmarks.py]
 
deleted file mode 100644
--- a/testing/firefox-ui/tests/functional/locationbar/test_favicon_in_autocomplete.py
+++ /dev/null
@@ -1,62 +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/.
-
-from firefox_puppeteer import PuppeteerMixin
-from marionette_driver import Wait
-from marionette_harness import MarionetteTestCase
-
-
-class TestFaviconInAutocomplete(PuppeteerMixin, MarionetteTestCase):
-
-    PREF_SUGGEST_SEARCHES = 'browser.urlbar.suggest.searches'
-    PREF_SUGGEST_BOOKMARK = 'browser.urlbar.suggest.bookmark'
-
-    def setUp(self):
-        super(TestFaviconInAutocomplete, self).setUp()
-
-        # Disable suggestions for searches and bookmarks to get results only for history
-        self.marionette.set_pref(self.PREF_SUGGEST_SEARCHES, False)
-        self.marionette.set_pref(self.PREF_SUGGEST_BOOKMARK, False)
-
-        self.puppeteer.places.remove_all_history()
-
-        self.test_urls = [self.marionette.absolute_url('layout/mozilla.html')]
-
-        self.test_string = 'mozilla'
-        self.test_favicon = 'mozilla_favicon.ico'
-
-        self.autocomplete_results = self.browser.navbar.locationbar.autocomplete_results
-
-    def tearDown(self):
-        try:
-            self.autocomplete_results.close(force=True)
-            self.marionette.clear_pref(self.PREF_SUGGEST_SEARCHES)
-            self.marionette.clear_pref(self.PREF_SUGGEST_BOOKMARK)
-        finally:
-            super(TestFaviconInAutocomplete, self).tearDown()
-
-    def test_favicon_in_autocomplete(self):
-        # Open the test page
-        def load_urls():
-            with self.marionette.using_context('content'):
-                self.marionette.navigate(self.test_urls[0])
-        self.puppeteer.places.wait_for_visited(self.test_urls, load_urls)
-
-        locationbar = self.browser.navbar.locationbar
-
-        # Clear the location bar, type the test string, check that autocomplete list opens
-        locationbar.clear()
-        locationbar.urlbar.send_keys(self.test_string)
-        self.assertEqual(locationbar.value, self.test_string)
-        Wait(self.marionette).until(lambda _: self.autocomplete_results.is_complete)
-
-        result = self.autocomplete_results.visible_results[1]
-
-        result_icon = self.marionette.execute_script("""
-          return arguments[0].image;
-        """, script_args=[result])
-
-        self.assertIn(self.test_favicon, result_icon)
-
-        self.autocomplete_results.close()
--- a/toolkit/components/alerts/nsAlertsService.cpp
+++ b/toolkit/components/alerts/nsAlertsService.cpp
@@ -44,17 +44,17 @@ public:
                nsIObserver* aAlertListener)
     : mBackend(aBackend)
     , mAlert(aAlert)
     , mAlertListener(aAlertListener)
   {}
 
   NS_IMETHOD
   OnComplete(nsIURI *aIconURI, uint32_t aIconSize, const uint8_t *aIconData,
-             const nsACString &aMimeType) override
+             const nsACString &aMimeType, uint16_t aWidth) override
   {
     nsresult rv = NS_ERROR_FAILURE;
     if (aIconSize > 0) {
       nsCOMPtr<nsIAlertsIconData> alertsIconData(do_QueryInterface(mBackend));
       if (alertsIconData) {
         rv = alertsIconData->ShowAlertWithIconData(mAlert, mAlertListener,
                                                    aIconSize, aIconData);
       }
@@ -106,19 +106,19 @@ ShowWithIconBackend(nsIAlertsService* aB
 
   nsCOMPtr<mozIAsyncFavicons> favicons(do_GetService(
     "@mozilla.org/browser/favicon-service;1"));
   NS_ENSURE_TRUE(favicons, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIFaviconDataCallback> callback =
     new IconCallback(aBackend, aAlert, aAlertListener);
   if (alertsIconData) {
-    return favicons->GetFaviconDataForPage(uri, callback);
+    return favicons->GetFaviconDataForPage(uri, callback, 0);
   }
-  return favicons->GetFaviconURLForPage(uri, callback);
+  return favicons->GetFaviconURLForPage(uri, callback, 0);
 #else
   return NS_ERROR_NOT_IMPLEMENTED;
 #endif // !MOZ_PLACES
 }
 
 nsresult
 ShowWithBackend(nsIAlertsService* aBackend, nsIAlertNotification* aAlert,
                 nsIObserver* aAlertListener, const nsAString& aPersistentData)
--- a/toolkit/components/places/FaviconHelpers.cpp
+++ b/toolkit/components/places/FaviconHelpers.cpp
@@ -18,63 +18,65 @@
 #include "nsNetUtil.h"
 #include "nsPrintfCString.h"
 #include "nsStreamUtils.h"
 #include "nsStringStream.h"
 #include "nsIPrivateBrowsingChannel.h"
 #include "nsISupportsPriority.h"
 #include "nsContentUtils.h"
 #include <algorithm>
+#include <deque>
 #include "mozilla/gfx/2D.h"
 #include "imgIContainer.h"
 #include "ImageOps.h"
-#include "imgLoader.h"
 #include "imgIEncoder.h"
 
 using namespace mozilla::places;
 using namespace mozilla::storage;
 
 namespace mozilla {
 namespace places {
 
 namespace {
 
 /**
- * Fetches information on a page from the Places database.
+ * Fetches information about a page from the database.
  *
- * @param aDBConn
+ * @param aDB
  *        Database connection to history tables.
  * @param _page
  *        Page that should be fetched.
  */
 nsresult
 FetchPageInfo(const RefPtr<Database>& aDB,
               PageData& _page)
 {
   MOZ_ASSERT(_page.spec.Length(), "Must have a non-empty spec!");
   MOZ_ASSERT(!NS_IsMainThread());
 
   // This query finds the bookmarked uri we want to set the icon for,
   // walking up to two redirect levels.
   nsCString query = nsPrintfCString(
-    "SELECT h.id, h.favicon_id, h.guid, ( "
+    "SELECT h.id, h.guid, ( "
       "SELECT h.url FROM moz_bookmarks b WHERE b.fk = h.id "
       "UNION ALL " // Union not directly bookmarked pages.
       "SELECT url FROM moz_places WHERE id = ( "
         "SELECT COALESCE(grandparent.place_id, parent.place_id) as r_place_id "
         "FROM moz_historyvisits dest "
         "LEFT JOIN moz_historyvisits parent ON parent.id = dest.from_visit "
                                           "AND dest.visit_type IN (%d, %d) "
         "LEFT JOIN moz_historyvisits grandparent ON parent.from_visit = grandparent.id "
           "AND parent.visit_type IN (%d, %d) "
         "WHERE dest.place_id = h.id "
         "AND EXISTS(SELECT 1 FROM moz_bookmarks b WHERE b.fk = r_place_id) "
         "LIMIT 1 "
       ") "
-    ") FROM moz_places h WHERE h.url_hash = hash(:page_url) AND h.url = :page_url",
+    ") "
+    "FROM moz_places h "
+    "WHERE h.url_hash = hash(:page_url) AND h.url = :page_url",
     nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
     nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY,
     nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
     nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY
   );
 
   nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(query);
   NS_ENSURE_STATE(stmt);
@@ -89,31 +91,25 @@ FetchPageInfo(const RefPtr<Database>& aD
   NS_ENSURE_SUCCESS(rv, rv);
   if (!hasResult) {
     // The page does not exist.
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   rv = stmt->GetInt64(0, &_page.id);
   NS_ENSURE_SUCCESS(rv, rv);
-  bool isNull;
-  rv = stmt->GetIsNull(1, &isNull);
+  rv = stmt->GetUTF8String(1, _page.guid);
   NS_ENSURE_SUCCESS(rv, rv);
-  // favicon_id can be nullptr.
-  if (!isNull) {
-    rv = stmt->GetInt64(1, &_page.iconId);
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
-  rv = stmt->GetUTF8String(2, _page.guid);
-  NS_ENSURE_SUCCESS(rv, rv);
-  rv = stmt->GetIsNull(3, &isNull);
+  // Bookmarked url can be nullptr.
+  bool isNull;
+  rv = stmt->GetIsNull(2, &isNull);
   NS_ENSURE_SUCCESS(rv, rv);
   // The page could not be bookmarked.
   if (!isNull) {
-    rv = stmt->GetUTF8String(3, _page.bookmarkedSpec);
+    rv = stmt->GetUTF8String(2, _page.bookmarkedSpec);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (!_page.canAddToHistory) {
     // Either history is disabled or the scheme is not supported.  In such a
     // case we want to update the icon only if the page is bookmarked.
 
     if (_page.bookmarkedSpec.IsEmpty()) {
@@ -131,146 +127,283 @@ FetchPageInfo(const RefPtr<Database>& aD
       }
     }
   }
 
   return NS_OK;
 }
 
 /**
- * Stores information on a icon in the database.
+ * Stores information about an icon in the database.
  *
- * @param aDBConn
+ * @param aDB
  *        Database connection to history tables.
  * @param aIcon
  *        Icon that should be stored.
+ * @param aMustReplace
+ *        If set to true, the function will bail out with NS_ERROR_NOT_AVAILABLE
+ *        if it can't find a previous stored icon to replace.
+ * @note Should be wrapped in a transaction.
  */
 nsresult
 SetIconInfo(const RefPtr<Database>& aDB,
-            const IconData& aIcon)
+            IconData& aIcon,
+            bool aMustReplace = false)
 {
   MOZ_ASSERT(!NS_IsMainThread());
+  MOZ_ASSERT(aIcon.payloads.Length() > 0);
+  MOZ_ASSERT(!aIcon.spec.IsEmpty());
 
-  nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(
-    "INSERT OR REPLACE INTO moz_favicons "
-      "(id, url, data, mime_type, expiration) "
-    "VALUES ((SELECT id FROM moz_favicons WHERE url = :icon_url), "
-            ":icon_url, :data, :mime_type, :expiration) "
+  // There are multiple cases possible at this point:
+  //   1. We must insert some payloads and no payloads exist in the table. This
+  //      would be a straight INSERT.
+  //   2. The table contains the same number of payloads we are inserting. This
+  //      would be a straight UPDATE.
+  //   3. The table contains more payloads than we are inserting. This would be
+  //      an UPDATE and a DELETE.
+  //   4. The table contains less payloads than we are inserting. This would be
+  //      an UPDATE and an INSERT.
+  // We can't just remove all the old entries and insert the new ones, cause
+  // we'd lose the referential integrity with pages.  For the same reason we
+  // cannot use INSERT OR REPLACE, since it's implemented as DELETE AND INSERT.
+  // Thus, we follow this strategy:
+  //   * SELECT all existing icon ids
+  //   * For each payload, either UPDATE OR INSERT reusing icon ids.
+  //   * If any previous icon ids is leftover, DELETE it.
+
+  nsCOMPtr<mozIStorageStatement> selectStmt = aDB->GetStatement(
+    "SELECT id FROM moz_icons "
+    "WHERE fixed_icon_url_hash = hash(fixup_url(:url)) "
+      "AND icon_url = :url "
   );
-  NS_ENSURE_STATE(stmt);
-  mozStorageStatementScoper scoper(stmt);
-  nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"), aIcon.spec);
+  NS_ENSURE_STATE(selectStmt);
+  mozStorageStatementScoper scoper(selectStmt);
+  nsresult rv = URIBinder::Bind(selectStmt, NS_LITERAL_CSTRING("url"), aIcon.spec);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = stmt->BindBlobByName(NS_LITERAL_CSTRING("data"),
-                            TO_INTBUFFER(aIcon.data), aIcon.data.Length());
-  NS_ENSURE_SUCCESS(rv, rv);
-  rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("mime_type"), aIcon.mimeType);
-  NS_ENSURE_SUCCESS(rv, rv);
-  rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("expiration"), aIcon.expiration);
-  NS_ENSURE_SUCCESS(rv, rv);
+  std::deque<int64_t> ids;
+  bool hasResult = false;
+  while (NS_SUCCEEDED(selectStmt->ExecuteStep(&hasResult)) && hasResult) {
+    int64_t id = selectStmt->AsInt64(0);
+    MOZ_ASSERT(id > 0);
+    ids.push_back(id);
+  }
+  if (aMustReplace && ids.empty()) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+
+  nsCOMPtr<mozIStorageStatement> insertStmt = aDB->GetStatement(
+    "INSERT INTO moz_icons "
+      "(icon_url, fixed_icon_url_hash, width, expire_ms, data) "
+    "VALUES (:url, hash(fixup_url(:url)), :width, :expire, :data) "
+  );
+  NS_ENSURE_STATE(insertStmt);
+  nsCOMPtr<mozIStorageStatement> updateStmt = aDB->GetStatement(
+    "UPDATE moz_icons SET width = :width, "
+                         "expire_ms = :expire, "
+                         "data = :data "
+    "WHERE id = :id "
+  );
+  NS_ENSURE_STATE(updateStmt);
 
-  rv = stmt->Execute();
-  NS_ENSURE_SUCCESS(rv, rv);
+  for (auto& payload : aIcon.payloads) {
+    // Sanity checks.
+    MOZ_ASSERT(payload.mimeType.EqualsLiteral(PNG_MIME_TYPE) ||
+              payload.mimeType.EqualsLiteral(SVG_MIME_TYPE),
+              "Only png and svg payloads are supported");
+    MOZ_ASSERT(!payload.mimeType.EqualsLiteral(SVG_MIME_TYPE) ||
+               payload.width == UINT16_MAX,
+              "SVG payloads should have max width");
+    MOZ_ASSERT(payload.width > 0, "Payload should have a width");
+#ifdef DEBUG
+    // Done to ensure we fetch the id. See the MOZ_ASSERT below.
+    payload.id = 0;
+#endif
+    if (!ids.empty()) {
+      // Pop the first existing id for reuse.
+      int64_t id = ids.front();
+      ids.pop_front();
+      mozStorageStatementScoper scoper(updateStmt);
+      rv = updateStmt->BindInt64ByName(NS_LITERAL_CSTRING("id"), id);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = updateStmt->BindInt32ByName(NS_LITERAL_CSTRING("width"),
+                                       payload.width);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = updateStmt->BindInt64ByName(NS_LITERAL_CSTRING("expire"),
+                                       aIcon.expiration / 1000);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = updateStmt->BindBlobByName(NS_LITERAL_CSTRING("data"),
+                                TO_INTBUFFER(payload.data),
+                                payload.data.Length());
+      rv = updateStmt->Execute();
+      NS_ENSURE_SUCCESS(rv, rv);
+      // Set the new payload id.
+      payload.id = id;
+    } else {
+      // Insert a new entry.
+      mozStorageStatementScoper scoper(insertStmt);
+      rv = URIBinder::Bind(insertStmt, NS_LITERAL_CSTRING("url"), aIcon.spec);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = insertStmt->BindInt32ByName(NS_LITERAL_CSTRING("width"),
+                                       payload.width);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = insertStmt->BindInt64ByName(NS_LITERAL_CSTRING("expire"),
+                                       aIcon.expiration / 1000);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = insertStmt->BindBlobByName(NS_LITERAL_CSTRING("data"),
+                                TO_INTBUFFER(payload.data),
+                                payload.data.Length());
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = insertStmt->Execute();
+      NS_ENSURE_SUCCESS(rv, rv);
+      // Set the new payload id.
+      payload.id = nsFaviconService::sLastInsertedIconId;
+    }
+    MOZ_ASSERT(payload.id > 0, "Payload should have an id");
+  }
+
+  if (!ids.empty()) {
+    // Remove any old leftover payload.
+    nsAutoCString sql("DELETE FROM moz_icons WHERE id IN (");
+    for (int64_t id : ids) {
+      sql.AppendInt(id);
+      sql.AppendLiteral(",");
+    }
+    sql.AppendLiteral(" 0)"); // Non-existing id to match the trailing comma.
+    nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(sql);
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
+    rv = stmt->Execute();
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   return NS_OK;
 }
 
 /**
- * Fetches information on a icon from the Places database.
+ * Fetches information on a icon url from the database.
  *
  * @param aDBConn
  *        Database connection to history tables.
+ * @param aPreferredWidth
+ *        The preferred size to fetch.
  * @param _icon
  *        Icon that should be fetched.
  */
 nsresult
 FetchIconInfo(const RefPtr<Database>& aDB,
-              IconData& _icon)
+              uint16_t aPreferredWidth,
+              IconData& _icon
+)
 {
   MOZ_ASSERT(_icon.spec.Length(), "Must have a non-empty spec!");
   MOZ_ASSERT(!NS_IsMainThread());
 
   if (_icon.status & ICON_STATUS_CACHED) {
+    // The icon data has already been set by ReplaceFaviconData.
     return NS_OK;
   }
 
   nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(
-    "SELECT id, expiration, data, mime_type "
-    "FROM moz_favicons WHERE url = :icon_url"
+    "/* do not warn (bug no: not worth having a compound index) */ "
+    "SELECT id, expire_ms, data, width "
+    "FROM moz_icons "
+    "WHERE fixed_icon_url_hash = hash(fixup_url(:url)) "
+      "AND icon_url = :url "
+    "ORDER BY width ASC "
   );
   NS_ENSURE_STATE(stmt);
   mozStorageStatementScoper scoper(stmt);
 
-  DebugOnly<nsresult> rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"),
+  DebugOnly<nsresult> rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("url"),
                                            _icon.spec);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 
-  bool hasResult;
-  rv = stmt->ExecuteStep(&hasResult);
-  MOZ_ASSERT(NS_SUCCEEDED(rv));
-  if (!hasResult) {
-    // The icon does not exist yet, bail out.
-    return NS_OK;
-  }
-
-  rv = stmt->GetInt64(0, &_icon.id);
-  MOZ_ASSERT(NS_SUCCEEDED(rv));
+  bool hasResult = false;
+  while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
+    IconPayload payload;
+    rv = stmt->GetInt64(0, &payload.id);
+    MOZ_ASSERT(NS_SUCCEEDED(rv));
 
-  // Expiration can be nullptr.
-  bool isNull;
-  rv = stmt->GetIsNull(1, &isNull);
-  MOZ_ASSERT(NS_SUCCEEDED(rv));
-  if (!isNull) {
-    rv = stmt->GetInt64(1, reinterpret_cast<int64_t*>(&_icon.expiration));
+    // Expiration can be nullptr.
+    bool isNull;
+    rv = stmt->GetIsNull(1, &isNull);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
-  }
+    if (!isNull) {
+      int64_t expire_ms;
+      rv = stmt->GetInt64(1, &expire_ms);
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
+      _icon.expiration = expire_ms * 1000;
+    }
 
-  // Data can be nullptr.
-  rv = stmt->GetIsNull(2, &isNull);
-  MOZ_ASSERT(NS_SUCCEEDED(rv));
-  if (!isNull) {
     uint8_t* data;
     uint32_t dataLen = 0;
     rv = stmt->GetBlob(2, &dataLen, &data);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
-    _icon.data.Adopt(TO_CHARBUFFER(data), dataLen);
-    // Read mime only if we have data.
-    rv = stmt->GetUTF8String(3, _icon.mimeType);
+
+    payload.data.Adopt(TO_CHARBUFFER(data), dataLen);
+    int32_t width;
+    rv = stmt->GetInt32(3, &width);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
+    payload.width = width;
+
+    if (payload.width == UINT16_MAX) {
+      payload.mimeType.AssignLiteral(SVG_MIME_TYPE);
+    } else {
+      payload.mimeType.AssignLiteral(PNG_MIME_TYPE);
+    }
+
+    if (aPreferredWidth == 0 || _icon.payloads.Length() == 0) {
+      _icon.payloads.AppendElement(payload);
+    } else if (payload.width >= aPreferredWidth) {
+      // Only retain the best matching payload.
+      _icon.payloads.ReplaceElementAt(0, payload);
+    } else {
+      break;
+    }
   }
 
   return NS_OK;
 }
 
 nsresult
-FetchIconURL(const RefPtr<Database>& aDB,
-             const nsACString& aPageSpec,
-             nsACString& aIconSpec)
+FetchIconPerSpec(const RefPtr<Database>& aDB,
+                 const nsACString& aPageSpec,
+                 IconData& aIconData,
+                 uint16_t aPreferredWidth)
 {
   MOZ_ASSERT(!aPageSpec.IsEmpty(), "Page spec must not be empty.");
   MOZ_ASSERT(!NS_IsMainThread());
 
-  aIconSpec.Truncate();
-
   nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(
-    "SELECT f.url "
-    "FROM moz_places h "
-    "JOIN moz_favicons f ON h.favicon_id = f.id "
-    "WHERE h.url_hash = hash(:page_url) AND h.url = :page_url"
+    "/* do not warn (bug no: not worth having a compound index) */ "
+    "SELECT width, icon_url "
+    "FROM moz_icons i "
+    "JOIN moz_icons_to_pages ON i.id = icon_id "
+    "JOIN moz_pages_w_icons p ON p.id = page_id "
+    "WHERE page_url_hash = hash(:url) AND page_url = :url "
+    "ORDER BY width DESC "
   );
   NS_ENSURE_STATE(stmt);
   mozStorageStatementScoper scoper(stmt);
 
-  nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"),
+  nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("url"),
                                 aPageSpec);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  // Return the biggest icon close to the preferred width. It may be bigger
+  // or smaller if the preferred width isn't found.
   bool hasResult;
-  if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
-    rv = stmt->GetUTF8String(0, aIconSpec);
+  while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
+    int32_t width;
+    rv = stmt->GetInt32(0, &width);
+    NS_ENSURE_SUCCESS(rv, rv);
+    if (width < aPreferredWidth && !aIconData.spec.IsEmpty()) {
+      break;
+    }
+    rv = stmt->GetUTF8String(1, aIconData.spec);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 /**
  * Tries to compute the expiration time for a icon from the channel.
@@ -302,50 +435,16 @@ GetExpirationTimeFromChannel(nsIChannel*
       }
     }
   }
   // If we did not obtain a time from the cache, use the cap value.
   return expiration < 0 ? PR_Now() + MAX_FAVICON_EXPIRATION
                         : expiration;
 }
 
-/**
- * Checks the icon and evaluates if it needs to be optimized.  In such a case it
- * will try to reduce its size through OptimizeFaviconImage method of the
- * favicons service.
- *
- * @param aIcon
- *        The icon to be evaluated.
- * @param aFaviconSvc
- *        Pointer to the favicons service.
- */
-nsresult
-OptimizeIconSize(IconData& aIcon,
-                 nsFaviconService* aFaviconSvc)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Even if the page provides a large image for the favicon (eg, a highres
-  // image or a multiresolution .ico file), don't try to store more data than
-  // needed.
-  nsAutoCString newData, newMimeType;
-  if (aIcon.data.Length() > MAX_FAVICON_FILESIZE) {
-    nsresult rv = aFaviconSvc->OptimizeFaviconImage(TO_INTBUFFER(aIcon.data),
-                                                    aIcon.data.Length(),
-                                                    aIcon.mimeType,
-                                                    newData,
-                                                    newMimeType);
-    if (NS_SUCCEEDED(rv) && newData.Length() < aIcon.data.Length()) {
-      aIcon.data = newData;
-      aIcon.mimeType = newMimeType;
-    }
-  }
-  return NS_OK;
-}
-
 } // namespace
 
 ////////////////////////////////////////////////////////////////////////////////
 //// AsyncFetchAndSetIconForPage
 
 NS_IMPL_ISUPPORTS_INHERITED(
   AsyncFetchAndSetIconForPage
 , Runnable
@@ -374,32 +473,31 @@ AsyncFetchAndSetIconForPage::AsyncFetchA
 NS_IMETHODIMP
 AsyncFetchAndSetIconForPage::Run()
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   // Try to fetch the icon from the database.
   RefPtr<Database> DB = Database::GetDatabase();
   NS_ENSURE_STATE(DB);
-  nsresult rv = FetchIconInfo(DB, mIcon);
+  nsresult rv = FetchIconInfo(DB, 0, mIcon);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  bool isInvalidIcon = mIcon.data.IsEmpty() ||
+  bool isInvalidIcon = !mIcon.payloads.Length() ||
                        (mIcon.expiration && PR_Now() > mIcon.expiration);
   bool fetchIconFromNetwork = mIcon.fetchMode == FETCH_ALWAYS ||
                               (mIcon.fetchMode == FETCH_IF_MISSING && isInvalidIcon);
 
   if (!fetchIconFromNetwork) {
     // There is already a valid icon or we don't want to fetch a new one,
     // directly proceed with association.
     RefPtr<AsyncAssociateIconToPage> event =
         new AsyncAssociateIconToPage(mIcon, mPage, mCallback);
-    DB->DispatchToAsyncThread(event);
-
-    return NS_OK;
+    // We're already on the async thread.
+    return event->Run();
   }
 
   // Fetch the icon from the network, the request starts from the main-thread.
   // When done this will associate the icon to the page and notify.
   nsCOMPtr<nsIRunnable> event =
     NewRunnableMethod(this, &AsyncFetchAndSetIconForPage::FetchFromNetwork);
   return NS_DispatchToMainThread(event);
 }
@@ -408,20 +506,20 @@ nsresult
 AsyncFetchAndSetIconForPage::FetchFromNetwork() {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mCanceled) {
     return NS_OK;
   }
 
   // Ensure data is cleared, since it's going to be overwritten.
-  if (mIcon.data.Length() > 0) {
-    mIcon.data.Truncate(0);
-    mIcon.mimeType.Truncate(0);
-  }
+  mIcon.payloads.Clear();
+
+  IconPayload payload;
+  mIcon.payloads.AppendElement(payload);
 
   nsCOMPtr<nsIURI> iconURI;
   nsresult rv = NS_NewURI(getter_AddRefs(iconURI), mIcon.spec);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIChannel> channel;
   rv = NS_NewChannel(getter_AddRefs(channel),
                      iconURI,
                      mLoadingPrincipal,
@@ -484,30 +582,32 @@ AsyncFetchAndSetIconForPage::OnStartRequ
 
 NS_IMETHODIMP
 AsyncFetchAndSetIconForPage::OnDataAvailable(nsIRequest* aRequest,
                                              nsISupports* aContext,
                                              nsIInputStream* aInputStream,
                                              uint64_t aOffset,
                                              uint32_t aCount)
 {
-  const size_t kMaxFaviconDownloadSize = 1 * 1024 * 1024;
-  if (mIcon.data.Length() + aCount > kMaxFaviconDownloadSize) {
-    mIcon.data.Truncate();
+  MOZ_ASSERT(mIcon.payloads.Length() == 1);
+  // Limit downloads to 500KB.
+  const size_t kMaxDownloadSize = 500 * 1024;
+  if (mIcon.payloads[0].data.Length() + aCount > kMaxDownloadSize) {
+    mIcon.payloads.Clear();
     return NS_ERROR_FILE_TOO_BIG;
   }
 
   nsAutoCString buffer;
   nsresult rv = NS_ConsumeStream(aInputStream, aCount, buffer);
   if (rv != NS_BASE_STREAM_WOULD_BLOCK && NS_FAILED(rv)) {
     return rv;
   }
 
-  if (!mIcon.data.Append(buffer, fallible)) {
-    mIcon.data.Truncate();
+  if (!mIcon.payloads[0].data.Append(buffer, fallible)) {
+    mIcon.payloads.Clear();
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
@@ -546,85 +646,88 @@ AsyncFetchAndSetIconForPage::OnStopReque
   }
 
   nsFaviconService* favicons = nsFaviconService::GetFaviconService();
   NS_ENSURE_STATE(favicons);
 
   nsresult rv;
 
   // If fetching the icon failed, add it to the failed cache.
-  if (NS_FAILED(aStatusCode) || mIcon.data.Length() == 0) {
+  if (NS_FAILED(aStatusCode) || mIcon.payloads.Length() == 0) {
     nsCOMPtr<nsIURI> iconURI;
     rv = NS_NewURI(getter_AddRefs(iconURI), mIcon.spec);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = favicons->AddFailedFavicon(iconURI);
     NS_ENSURE_SUCCESS(rv, rv);
     return NS_OK;
   }
 
   nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
   // aRequest should always QI to nsIChannel.
   MOZ_ASSERT(channel);
 
+  MOZ_ASSERT(mIcon.payloads.Length() == 1);
+  IconPayload& payload = mIcon.payloads[0];
+
   nsAutoCString contentType;
   channel->GetContentType(contentType);
-  // Bug 366324 - can't sniff SVG yet, so rely on server-specified type
-  if (contentType.EqualsLiteral("image/svg+xml")) {
-    mIcon.mimeType.AssignLiteral("image/svg+xml");
+  // Bug 366324 - We don't want to sniff for SVG, so rely on server-specified type.
+  if (contentType.EqualsLiteral(SVG_MIME_TYPE)) {
+    payload.mimeType.AssignLiteral(SVG_MIME_TYPE);
+    payload.width = UINT16_MAX;
   } else {
     NS_SniffContent(NS_DATA_SNIFFER_CATEGORY, aRequest,
-                    TO_INTBUFFER(mIcon.data), mIcon.data.Length(),
-                    mIcon.mimeType);
+                    TO_INTBUFFER(payload.data), payload.data.Length(),
+                    payload.mimeType);
   }
 
   // If the icon does not have a valid MIME type, add it to the failed cache.
-  if (mIcon.mimeType.IsEmpty()) {
+  if (payload.mimeType.IsEmpty()) {
     nsCOMPtr<nsIURI> iconURI;
     rv = NS_NewURI(getter_AddRefs(iconURI), mIcon.spec);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = favicons->AddFailedFavicon(iconURI);
     NS_ENSURE_SUCCESS(rv, rv);
     return NS_OK;
   }
 
   mIcon.expiration = GetExpirationTimeFromChannel(channel);
 
   // Telemetry probes to measure the favicon file sizes for each different file type.
   // This allow us to measure common file sizes while also observing each type popularity.
-  if (mIcon.mimeType.EqualsLiteral("image/png")) {
-    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_PNG_SIZES, mIcon.data.Length());
+  if (payload.mimeType.EqualsLiteral(PNG_MIME_TYPE)) {
+    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_PNG_SIZES, payload.data.Length());
   }
-  else if (mIcon.mimeType.EqualsLiteral("image/x-icon") ||
-           mIcon.mimeType.EqualsLiteral("image/vnd.microsoft.icon")) {
-    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_ICO_SIZES, mIcon.data.Length());
+  else if (payload.mimeType.EqualsLiteral("image/x-icon") ||
+           payload.mimeType.EqualsLiteral("image/vnd.microsoft.icon")) {
+    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_ICO_SIZES, payload.data.Length());
   }
-  else if (mIcon.mimeType.EqualsLiteral("image/jpeg") ||
-           mIcon.mimeType.EqualsLiteral("image/pjpeg")) {
-    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_JPEG_SIZES, mIcon.data.Length());
+  else if (payload.mimeType.EqualsLiteral("image/jpeg") ||
+           payload.mimeType.EqualsLiteral("image/pjpeg")) {
+    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_JPEG_SIZES, payload.data.Length());
   }
-  else if (mIcon.mimeType.EqualsLiteral("image/gif")) {
-    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_GIF_SIZES, mIcon.data.Length());
+  else if (payload.mimeType.EqualsLiteral("image/gif")) {
+    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_GIF_SIZES, payload.data.Length());
   }
-  else if (mIcon.mimeType.EqualsLiteral("image/bmp") ||
-           mIcon.mimeType.EqualsLiteral("image/x-windows-bmp")) {
-    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_BMP_SIZES, mIcon.data.Length());
+  else if (payload.mimeType.EqualsLiteral("image/bmp") ||
+           payload.mimeType.EqualsLiteral("image/x-windows-bmp")) {
+    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_BMP_SIZES, payload.data.Length());
   }
-  else if (mIcon.mimeType.EqualsLiteral("image/svg+xml")) {
-    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_SVG_SIZES, mIcon.data.Length());
+  else if (payload.mimeType.EqualsLiteral(SVG_MIME_TYPE)) {
+    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_SVG_SIZES, payload.data.Length());
   }
   else {
-    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_OTHER_SIZES, mIcon.data.Length());
+    mozilla::Telemetry::Accumulate(mozilla::Telemetry::PLACES_FAVICON_OTHER_SIZES, payload.data.Length());
   }
 
-  rv = OptimizeIconSize(mIcon, favicons);
+  rv = favicons->OptimizeIconSizes(mIcon);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // If over the maximum size allowed, don't save data to the database to
-  // avoid bloating it.
-  if (mIcon.data.Length() > nsIFaviconService::MAX_FAVICON_BUFFER_SIZE) {
+  // If there's not valid payload, don't store the icon into to the database.
+  if (mIcon.payloads.Length() == 0) {
     return NS_OK;
   }
 
   mIcon.status = ICON_STATUS_CHANGED;
 
   RefPtr<Database> DB = Database::GetDatabase();
   NS_ENSURE_STATE(DB);
   RefPtr<AsyncAssociateIconToPage> event =
@@ -640,16 +743,17 @@ AsyncFetchAndSetIconForPage::OnStopReque
 AsyncAssociateIconToPage::AsyncAssociateIconToPage(
   const IconData& aIcon
 , const PageData& aPage
 , const nsMainThreadPtrHandle<nsIFaviconDataCallback>& aCallback
 ) : mCallback(aCallback)
   , mIcon(aIcon)
   , mPage(aPage)
 {
+  // May be created in both threads.
 }
 
 NS_IMETHODIMP
 AsyncAssociateIconToPage::Run()
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   RefPtr<Database> DB = Database::GetDatabase();
@@ -661,68 +765,91 @@ AsyncAssociateIconToPage::Run()
     if (!mPage.canAddToHistory) {
       return NS_OK;
     }
   }
   else {
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
+  bool shouldUpdateIcon = mIcon.status & ICON_STATUS_CHANGED;
+  if (!shouldUpdateIcon) {
+    for (const auto& payload : mIcon.payloads) {
+      // If the entry is missing from the database, we should add it.
+      if (payload.id == 0) {
+        shouldUpdateIcon = true;
+        break;
+      }
+    }
+  }
+
   mozStorageTransaction transaction(DB->MainConn(), false,
                                     mozIStorageConnection::TRANSACTION_IMMEDIATE);
 
-  // If there is no entry for this icon, or the entry is obsolete, replace it.
-  if (mIcon.id == 0 || (mIcon.status & ICON_STATUS_CHANGED)) {
+  if (shouldUpdateIcon) {
     rv = SetIconInfo(DB, mIcon);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    // Get the new icon id.  Do this regardless mIcon.id, since other code
-    // could have added a entry before us.  Indeed we interrupted the thread
-    // after the previous call to FetchIconInfo.
     mIcon.status = (mIcon.status & ~(ICON_STATUS_CACHED)) | ICON_STATUS_SAVED;
-    rv = FetchIconInfo(DB, mIcon);
-    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // If the page does not have an id, don't try to insert a new one, cause we
   // don't know where the page comes from.  Not doing so we may end adding
   // a page that otherwise we'd explicitly ignore, like a POST or an error page.
   if (mPage.id == 0) {
+    rv = transaction.Commit();
+    NS_ENSURE_SUCCESS(rv, rv);
     return NS_OK;
   }
 
-  // Otherwise just associate the icon to the page, if needed.
-  if (mPage.iconId != mIcon.id) {
+  // First we need to create the page entry.
+  {
     nsCOMPtr<mozIStorageStatement> stmt;
-    if (mPage.id) {
-      stmt = DB->GetStatement(
-        "UPDATE moz_places SET favicon_id = :icon_id WHERE id = :page_id"
-      );
-      NS_ENSURE_STATE(stmt);
-      rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), mPage.id);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-    else {
-      stmt = DB->GetStatement(
-        "UPDATE moz_places SET favicon_id = :icon_id "
-        "WHERE url_hash = hash(:page_url) AND url = :page_url"
-      );
-      NS_ENSURE_STATE(stmt);
-      rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), mPage.spec);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-    rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("icon_id"), mIcon.id);
+    stmt = DB->GetStatement(
+      "INSERT OR IGNORE INTO moz_pages_w_icons (id, page_url, page_url_hash) "
+      "VALUES (:page_id, :page_url, hash(:page_url)) "
+    );
+    NS_ENSURE_STATE(stmt);
+    mozStorageStatementScoper scoper(stmt);
+    rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), mPage.id);
     NS_ENSURE_SUCCESS(rv, rv);
-
-    mozStorageStatementScoper scoper(stmt);
+    rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), mPage.spec);
+    NS_ENSURE_SUCCESS(rv, rv);
     rv = stmt->Execute();
     NS_ENSURE_SUCCESS(rv, rv);
+  }
 
-    mIcon.status |= ICON_STATUS_ASSOCIATED;
+  // Then we can create the relations.
+  nsCOMPtr<mozIStorageStatement> stmt;
+  stmt = DB->GetStatement(
+    "INSERT OR IGNORE INTO moz_icons_to_pages (page_id, icon_id) "
+    "VALUES (:page_id, :icon_id) "
+  );
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scoper(stmt);
+  nsCOMPtr<mozIStorageBindingParamsArray> paramsArray;
+  rv = stmt->NewBindingParamsArray(getter_AddRefs(paramsArray));
+  NS_ENSURE_SUCCESS(rv, rv);
+  for (const auto& payload : mIcon.payloads) {
+    nsCOMPtr<mozIStorageBindingParams> params;
+    rv = paramsArray->NewBindingParams(getter_AddRefs(params));
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = params->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), mPage.id);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = params->BindInt64ByName(NS_LITERAL_CSTRING("icon_id"), payload.id);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = paramsArray->AddParams(params);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
+  rv = stmt->BindParameters(paramsArray);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = stmt->Execute();
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  mIcon.status |= ICON_STATUS_ASSOCIATED;
 
   rv = transaction.Commit();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Finally, dispatch an event to the main thread to notify observers.
   nsCOMPtr<nsIRunnable> event = new NotifyIconObservers(mIcon, mPage, mCallback);
   rv = NS_DispatchToMainThread(event);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -730,117 +857,116 @@ AsyncAssociateIconToPage::Run()
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //// AsyncGetFaviconURLForPage
 
 AsyncGetFaviconURLForPage::AsyncGetFaviconURLForPage(
   const nsACString& aPageSpec
+, uint16_t aPreferredWidth
 , nsIFaviconDataCallback* aCallback
-) : mCallback(new nsMainThreadPtrHolder<nsIFaviconDataCallback>(aCallback))
+) : mPreferredWidth(aPreferredWidth == 0 ? UINT16_MAX : aPreferredWidth)
+  , mCallback(new nsMainThreadPtrHolder<nsIFaviconDataCallback>(aCallback))
 {
   MOZ_ASSERT(NS_IsMainThread());
   mPageSpec.Assign(aPageSpec);
 }
 
 NS_IMETHODIMP
 AsyncGetFaviconURLForPage::Run()
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   RefPtr<Database> DB = Database::GetDatabase();
   NS_ENSURE_STATE(DB);
-  nsAutoCString iconSpec;
-  nsresult rv = FetchIconURL(DB, mPageSpec, iconSpec);
+  IconData iconData;
+  nsresult rv = FetchIconPerSpec(DB, mPageSpec, iconData, mPreferredWidth);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Now notify our callback of the icon spec we retrieved, even if empty.
-  IconData iconData;
-  iconData.spec.Assign(iconSpec);
-
   PageData pageData;
   pageData.spec.Assign(mPageSpec);
 
   nsCOMPtr<nsIRunnable> event =
     new NotifyIconObservers(iconData, pageData, mCallback);
   rv = NS_DispatchToMainThread(event);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //// AsyncGetFaviconDataForPage
 
 AsyncGetFaviconDataForPage::AsyncGetFaviconDataForPage(
   const nsACString& aPageSpec
+,  uint16_t aPreferredWidth
 , nsIFaviconDataCallback* aCallback
-) : mCallback(new nsMainThreadPtrHolder<nsIFaviconDataCallback>(aCallback))
+) : mPreferredWidth(aPreferredWidth == 0 ? UINT16_MAX : aPreferredWidth)
+  , mCallback(new nsMainThreadPtrHolder<nsIFaviconDataCallback>(aCallback))
  {
   MOZ_ASSERT(NS_IsMainThread());
   mPageSpec.Assign(aPageSpec);
 }
 
 NS_IMETHODIMP
 AsyncGetFaviconDataForPage::Run()
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   RefPtr<Database> DB = Database::GetDatabase();
   NS_ENSURE_STATE(DB);
-  nsAutoCString iconSpec;
-  nsresult rv = FetchIconURL(DB, mPageSpec, iconSpec);
+  IconData iconData;
+  nsresult rv = FetchIconPerSpec(DB, mPageSpec, iconData, mPreferredWidth);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  IconData iconData;
-  iconData.spec.Assign(iconSpec);
-
-  PageData pageData;
-  pageData.spec.Assign(mPageSpec);
-
-  if (!iconSpec.IsEmpty()) {
-    rv = FetchIconInfo(DB, iconData);
+  if (!iconData.spec.IsEmpty()) {
+    rv = FetchIconInfo(DB, mPreferredWidth, iconData);
     if (NS_FAILED(rv)) {
       iconData.spec.Truncate();
     }
   }
 
+  PageData pageData;
+  pageData.spec.Assign(mPageSpec);
+
   nsCOMPtr<nsIRunnable> event =
     new NotifyIconObservers(iconData, pageData, mCallback);
   rv = NS_DispatchToMainThread(event);
   NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //// AsyncReplaceFaviconData
 
 AsyncReplaceFaviconData::AsyncReplaceFaviconData(const IconData &aIcon)
   : mIcon(aIcon)
 {
+  MOZ_ASSERT(NS_IsMainThread());
 }
 
 NS_IMETHODIMP
 AsyncReplaceFaviconData::Run()
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   RefPtr<Database> DB = Database::GetDatabase();
   NS_ENSURE_STATE(DB);
-  IconData dbIcon;
-  dbIcon.spec.Assign(mIcon.spec);
-  nsresult rv = FetchIconInfo(DB, dbIcon);
-  NS_ENSURE_SUCCESS(rv, rv);
 
-  if (!dbIcon.id) {
+  mozStorageTransaction transaction(DB->MainConn(), false,
+                                    mozIStorageConnection::TRANSACTION_IMMEDIATE);
+  nsresult rv = SetIconInfo(DB, mIcon, true);
+  if (rv == NS_ERROR_NOT_AVAILABLE) {
+    // There's no previous icon to replace, we don't need to do anything.
     return NS_OK;
   }
-
-  rv = SetIconInfo(DB, mIcon);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = transaction.Commit();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We can invalidate the cache version since we now persist the icon.
   nsCOMPtr<nsIRunnable> event =
     NewRunnableMethod(this, &AsyncReplaceFaviconData::RemoveIconDataCacheEntry);
   rv = NS_DispatchToMainThread(event);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -891,22 +1017,28 @@ NotifyIconObservers::Run()
       // Notify observers only if something changed.
       if (mIcon.status & ICON_STATUS_SAVED ||
           mIcon.status & ICON_STATUS_ASSOCIATED) {
         SendGlobalNotifications(iconURI);
       }
     }
   }
 
-  if (mCallback) {
-    (void)mCallback->OnComplete(iconURI, mIcon.data.Length(),
-                                TO_INTBUFFER(mIcon.data), mIcon.mimeType);
+  if (!mCallback) {
+    return NS_OK;
   }
 
-  return NS_OK;
+  if (mIcon.payloads.Length() > 0) {
+    IconPayload& payload = mIcon.payloads[0];
+    return mCallback->OnComplete(iconURI, payload.data.Length(),
+                                 TO_INTBUFFER(payload.data), payload.mimeType,
+                                 payload.width);
+  }
+  return mCallback->OnComplete(iconURI, 0, TO_INTBUFFER(EmptyCString()),
+                               EmptyCString(), 0);
 }
 
 void
 NotifyIconObservers::SendGlobalNotifications(nsIURI* aIconURI)
 {
   nsCOMPtr<nsIURI> pageURI;
   MOZ_ALWAYS_SUCCEEDS(NS_NewURI(getter_AddRefs(pageURI), mPage.spec));
   if (pageURI) {
--- a/toolkit/components/places/FaviconHelpers.h
+++ b/toolkit/components/places/FaviconHelpers.h
@@ -10,16 +10,17 @@
 #include "nsIChannelEventSink.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIStreamListener.h"
 #include "mozIPlacesPendingOperation.h"
 #include "nsThreadUtils.h"
 #include "nsProxyRelease.h"
 #include "imgITools.h"
 #include "imgIContainer.h"
+#include "imgLoader.h"
 
 class nsIPrincipal;
 
 #include "Database.h"
 #include "mozilla/storage.h"
 
 #define ICON_STATUS_UNKNOWN 0
 #define ICON_STATUS_CHANGED 1 << 0
@@ -54,56 +55,70 @@ namespace places {
  */
 enum AsyncFaviconFetchMode {
   FETCH_NEVER = 0
 , FETCH_IF_MISSING
 , FETCH_ALWAYS
 };
 
 /**
- * Data cache for a icon entry.
+ * Represents one of the payloads (frames) of an icon entry.
+ */
+struct IconPayload
+{
+  IconPayload()
+  : id(0)
+  , width(0)
+  {
+    data.SetIsVoid(true);
+    mimeType.SetIsVoid(true);
+  }
+
+  int64_t id;
+  uint16_t width;
+  nsCString data;
+  nsCString mimeType;
+};
+
+/**
+ * Represents an icon entry.
  */
 struct IconData
 {
   IconData()
-  : id(0)
-  , expiration(0)
+  : expiration(0)
   , fetchMode(FETCH_NEVER)
   , status(ICON_STATUS_UNKNOWN)
   {
   }
 
-  int64_t id;
   nsCString spec;
-  nsCString data;
-  nsCString mimeType;
   PRTime expiration;
   enum AsyncFaviconFetchMode fetchMode;
   uint16_t status; // This is a bitset, see ICON_STATUS_* defines above.
+  nsTArray<IconPayload> payloads;
 };
 
 /**
  * Data cache for a page entry.
  */
 struct PageData
 {
   PageData()
   : id(0)
   , canAddToHistory(true)
-  , iconId(0)
   {
     guid.SetIsVoid(true);
   }
 
   int64_t id;
   nsCString spec;
   nsCString bookmarkedSpec;
   nsString revHost;
   bool canAddToHistory; // False for disabled history and unsupported schemas.
-  int64_t iconId;
   nsCString guid;
 };
 
 /**
  * Async fetches icon from database or network, associates it with the required
  * page and finally notifies the change.
  */
 class AsyncFetchAndSetIconForPage final : public Runnable
@@ -194,21 +209,25 @@ public:
 
   /**
    * Constructor.
    *
    * @param aPageSpec
    *        URL of the page whose favicon's URL we're fetching
    * @param aCallback
    *        function to be called once finished
+   * @param aPreferredWidth
+   *        The preferred size for the icon
    */
   AsyncGetFaviconURLForPage(const nsACString& aPageSpec,
+                            uint16_t aPreferredWidth,
                             nsIFaviconDataCallback* aCallback);
 
 private:
+  uint16_t mPreferredWidth;
   nsMainThreadPtrHandle<nsIFaviconDataCallback> mCallback;
   nsCString mPageSpec;
 };
 
 
 /**
  * Asynchronously tries to get the URL and data of a page's favicon, then
  * notifies the given observer.
@@ -218,23 +237,28 @@ class AsyncGetFaviconDataForPage final :
 public:
   NS_DECL_NSIRUNNABLE
 
   /**
    * Constructor.
    *
    * @param aPageSpec
    *        URL of the page whose favicon URL and data we're fetching
+   * @param aPreferredWidth
+   *        The preferred size of the icon.  We will try to return an icon close
+   *        to this size.
    * @param aCallback
    *        function to be called once finished
    */
   AsyncGetFaviconDataForPage(const nsACString& aPageSpec,
+                             uint16_t aPreferredWidth,
                              nsIFaviconDataCallback* aCallback);
 
 private:
+  uint16_t mPreferredWidth;
   nsMainThreadPtrHandle<nsIFaviconDataCallback> mCallback;
   nsCString mPageSpec;
 };
 
 class AsyncReplaceFaviconData final : public Runnable
 {
 public:
   NS_DECL_NSIRUNNABLE
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -155,19 +155,17 @@ this.History = Object.freeze({
    *      A promise resolved once the operation is complete.
    * @resolves (PageInfo)
    *      A PageInfo object populated with data after the insert is complete.
    * @rejects (Error)
    *      Rejects if the insert was unsuccessful.
    *
    * @throws (Error)
    *      If the `url` specified was for a protocol that should not be
-   *      stored (e.g. "chrome:", "mailbox:", "about:", "imap:", "news:",
-   *      "moz-anno:", "view-source:", "resource:", "data:", "wyciwyg:",
-   *      "javascript:", "blob:").
+   *      stored (@see nsNavHistory::CanAddURI).
    * @throws (Error)
    *      If `pageInfo` has an unexpected type.
    * @throws (Error)
    *      If `pageInfo` does not have a `url`.
    * @throws (Error)
    *      If `pageInfo` does not have a `visits` property or if the
    *      value of `visits` is ill-typed or is an empty array.
    * @throws (Error)
@@ -211,19 +209,17 @@ this.History = Object.freeze({
    * @return (Promise)
    *      A promise resolved once the operation is complete.
    * @resolves (null)
    * @rejects (Error)
    *      Rejects if all of the inserts were unsuccessful.
    *
    * @throws (Error)
    *      If the `url` specified was for a protocol that should not be
-   *      stored (e.g. "chrome:", "mailbox:", "about:", "imap:", "news:",
-   *      "moz-anno:", "view-source:", "resource:", "data:", "wyciwyg:",
-   *      "javascript:", "blob:").
+   *      stored (@see nsNavHistory::CanAddURI).
    * @throws (Error)
    *      If `pageInfos` has an unexpected type.
    * @throws (Error)
    *      If a `pageInfo` does not have a `url`.
    * @throws (Error)
    *      If a `PageInfo` does not have a `visits` property or if the
    *      value of `visits` is ill-typed or is an empty array.
    * @throws (Error)
@@ -701,19 +697,20 @@ var cleanupPages = Task.async(function*(
     // async race conditions.
     yield db.execute(`DELETE FROM moz_places WHERE id IN ( ${ idsList } )
                       AND foreign_count = 0 AND last_visit_date ISNULL`);
     // Hosts accumulated during the places delete are updated through a trigger
     // (see nsPlacesTriggers.h).
     yield db.executeCached(`DELETE FROM moz_updatehosts_temp`);
 
     // Expire orphans.
-    yield db.executeCached(`
-      DELETE FROM moz_favicons WHERE NOT EXISTS
-        (SELECT 1 FROM moz_places WHERE favicon_id = moz_favicons.id)`);
+    yield db.executeCached(`DELETE FROM moz_pages_w_icons
+                            WHERE page_url_hash NOT IN (SELECT url_hash FROM moz_places)`);
+    yield db.executeCached(`DELETE FROM moz_icons
+                            WHERE id NOT IN (SELECT icon_id FROM moz_icons_to_pages)`);
     yield db.execute(`DELETE FROM moz_annos
                       WHERE place_id IN ( ${ idsList } )`);
     yield db.execute(`DELETE FROM moz_inputhistory
                       WHERE place_id IN ( ${ idsList } )`);
   }
 });
 
 /**
--- a/toolkit/components/places/PageIconProtocolHandler.js
+++ b/toolkit/components/places/PageIconProtocolHandler.js
@@ -36,16 +36,26 @@ function streamDefaultFavicon(uri, loadI
     let defaultIconChannel = makeDefaultFaviconChannel(uri, loadInfo);
     defaultIconChannel.asyncOpen2(listener);
   } catch (ex) {
     Cu.reportError(ex);
     outputStream.close();
   }
 }
 
+function serveIcon(pipe, data, len) {
+  // Pass the icon data to the output stream.
+  let stream = Cc["@mozilla.org/binaryoutputstream;1"]
+                 .createInstance(Ci.nsIBinaryOutputStream);
+  stream.setOutputStream(pipe.outputStream);
+  stream.writeByteArray(data, len);
+  stream.close();
+  pipe.outputStream.close();
+}
+
 function PageIconProtocolHandler() {
 }
 
 PageIconProtocolHandler.prototype = {
   get scheme() {
     return "page-icon";
   },
 
@@ -78,35 +88,26 @@ PageIconProtocolHandler.prototype = {
       let channel = Cc["@mozilla.org/network/input-stream-channel;1"]
                       .createInstance(Ci.nsIInputStreamChannel);
       channel.QueryInterface(Ci.nsIChannel);
       channel.setURI(uri);
       channel.contentStream = pipe.inputStream;
       channel.loadInfo = loadInfo;
 
       let pageURI = NetUtil.newURI(uri.path);
-      PlacesUtils.favicons.getFaviconDataForPage(pageURI, (iconuri, len, data, mime) => {
+      PlacesUtils.favicons.getFaviconDataForPage(pageURI, (iconURI, len, data, mimeType) => {
+        channel.contentType = mimeType;
         if (len == 0) {
-          channel.contentType = "image/png";
           streamDefaultFavicon(uri, loadInfo, pipe.outputStream);
-          return;
-        }
-
-        try {
-          channel.contentType = mime;
-          // Pass the icon data to the output stream.
-          let stream = Cc["@mozilla.org/binaryoutputstream;1"]
-                         .createInstance(Ci.nsIBinaryOutputStream);
-          stream.setOutputStream(pipe.outputStream);
-          stream.writeByteArray(data, len);
-          stream.close();
-          pipe.outputStream.close();
-        } catch (ex) {
-          channel.contentType = "image/png";
-          streamDefaultFavicon(uri, loadInfo, pipe.outputStream);
+        } else {
+          try {
+            serveIcon(pipe, data, len);
+          } catch (ex) {
+            streamDefaultFavicon(uri, loadInfo, pipe.outputStream);
+          }
         }
       });
 
       return channel;
     } catch (ex) {
       return makeDefaultFaviconChannel(uri, loadInfo);
     }
   },
--- a/toolkit/components/places/PlacesDBUtils.jsm
+++ b/toolkit/components/places/PlacesDBUtils.jsm
@@ -588,23 +588,27 @@ this.PlacesDBUtils = {
        WHERE length(title) = 0 AND type = :folder_type
          AND parent = :tags_folder`
     );
     fixEmptyNamedTags.params["empty_title"] = "(notitle)";
     fixEmptyNamedTags.params["folder_type"] = PlacesUtils.bookmarks.TYPE_FOLDER;
     fixEmptyNamedTags.params["tags_folder"] = PlacesUtils.tagsFolderId;
     cleanupStatements.push(fixEmptyNamedTags);
 
-    // MOZ_FAVICONS
-    // E.1 remove orphan icons
+    // MOZ_ICONS
+    // E.1 remove orphan icon entries.
+    let deleteOrphanIconPages = DBConn.createAsyncStatement(
+      `DELETE FROM moz_pages_w_icons WHERE page_url_hash NOT IN (
+         SELECT url_hash FROM moz_places
+       )`);
+    cleanupStatements.push(deleteOrphanIconPages);
+
     let deleteOrphanIcons = DBConn.createAsyncStatement(
-      `DELETE FROM moz_favicons WHERE id IN (
-         SELECT id FROM moz_favicons f
-         WHERE NOT EXISTS
-           (SELECT id FROM moz_places WHERE favicon_id = f.id LIMIT 1)
+      `DELETE FROM moz_icons WHERE id NOT IN (
+         SELECT icon_id FROM moz_icons_to_pages
        )`);
     cleanupStatements.push(deleteOrphanIcons);
 
     // MOZ_HISTORYVISITS
     // F.1 remove orphan visits
     let deleteOrphanVisits = DBConn.createAsyncStatement(
       `DELETE FROM moz_historyvisits WHERE id IN (
          SELECT id FROM moz_historyvisits v
@@ -649,26 +653,16 @@ this.PlacesDBUtils = {
       `DELETE FROM moz_keywords WHERE id IN (
          SELECT id FROM moz_keywords k
          WHERE NOT EXISTS
            (SELECT 1 FROM moz_places h WHERE k.place_id = h.id)
        )`);
     cleanupStatements.push(deleteUnusedKeywords);
 
     // MOZ_PLACES
-    // L.1 fix wrong favicon ids
-    let fixInvalidFaviconIds = DBConn.createAsyncStatement(
-      `UPDATE moz_places SET favicon_id = NULL WHERE id IN (
-         SELECT id FROM moz_places h
-         WHERE favicon_id NOT NULL
-           AND NOT EXISTS
-             (SELECT id FROM moz_favicons WHERE id = h.favicon_id LIMIT 1)
-       )`);
-    cleanupStatements.push(fixInvalidFaviconIds);
-
     // L.2 recalculate visit_count and last_visit_date
     let fixVisitStats = DBConn.createAsyncStatement(
       `UPDATE moz_places
        SET visit_count = (SELECT count(*) FROM moz_historyvisits
                           WHERE place_id = moz_places.id AND visit_type NOT IN (0,4,7,8,9)),
            last_visit_date = (SELECT MAX(visit_date) FROM moz_historyvisits
                               WHERE place_id = moz_places.id)
        WHERE id IN (
--- a/toolkit/components/places/PlacesUtils.jsm
+++ b/toolkit/components/places/PlacesUtils.jsm
@@ -1864,32 +1864,35 @@ this.PlacesUtils = {
          UNION ALL
          SELECT b2.fk, level + 1, b2.type, b2.id, b2.guid, b2.parent,
                 descendants.guid, b2.position, b2.title, b2.dateAdded,
                 b2.lastModified
          FROM moz_bookmarks b2
          JOIN descendants ON b2.parent = descendants.id AND b2.id <> :tags_folder)
        SELECT d.level, d.id, d.guid, d.parent, d.parentGuid, d.type,
               d.position AS [index], d.title, d.dateAdded, d.lastModified,
-              h.url, f.url AS iconuri,
+              h.url, (SELECT icon_url FROM moz_icons i
+                      JOIN moz_icons_to_pages ON icon_id = i.id
+                      JOIN moz_pages_w_icons pi ON page_id = pi.id
+                      WHERE pi.page_url_hash = hash(h.url) AND pi.page_url = h.url
+                      ORDER BY width DESC LIMIT 1) AS iconuri,
               (SELECT GROUP_CONCAT(t.title, ',')
                FROM moz_bookmarks b2
                JOIN moz_bookmarks t ON t.id = +b2.parent AND t.parent = :tags_folder
                WHERE b2.fk = h.id
               ) AS tags,
               EXISTS (SELECT 1 FROM moz_items_annos
                       WHERE item_id = d.id LIMIT 1) AS has_annos,
               (SELECT a.content FROM moz_annos a
                JOIN moz_anno_attributes n ON a.anno_attribute_id = n.id
                WHERE place_id = h.id AND n.name = :charset_anno
               ) AS charset
        FROM descendants d
        LEFT JOIN moz_bookmarks b3 ON b3.id = d.parent
        LEFT JOIN moz_places h ON h.id = d.fk
-       LEFT JOIN moz_favicons f ON f.id = h.favicon_id
        ORDER BY d.level, d.parent, d.position`;
 
 
     if (!aItemGuid)
       aItemGuid = this.bookmarks.rootGuid;
 
     let hasExcludeItemsCallback =
       aOptions.hasOwnProperty("excludeItemsCallback");
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -89,25 +89,24 @@ const REGEXP_USER_CONTEXT_ID = /(?:^| )u
 
 // Regex used to match one or more whitespace.
 const REGEXP_SPACES = /\s+/;
 
 // Sqlite result row index constants.
 const QUERYINDEX_QUERYTYPE     = 0;
 const QUERYINDEX_URL           = 1;
 const QUERYINDEX_TITLE         = 2;
-const QUERYINDEX_ICONURL       = 3;
-const QUERYINDEX_BOOKMARKED    = 4;
-const QUERYINDEX_BOOKMARKTITLE = 5;
-const QUERYINDEX_TAGS          = 6;
-const QUERYINDEX_VISITCOUNT    = 7;
-const QUERYINDEX_TYPED         = 8;
-const QUERYINDEX_PLACEID       = 9;
-const QUERYINDEX_SWITCHTAB     = 10;
-const QUERYINDEX_FRECENCY      = 11;
+const QUERYINDEX_BOOKMARKED    = 3;
+const QUERYINDEX_BOOKMARKTITLE = 4;
+const QUERYINDEX_TAGS          = 5;
+const QUERYINDEX_VISITCOUNT    = 6;
+const QUERYINDEX_TYPED         = 7;
+const QUERYINDEX_PLACEID       = 8;
+const QUERYINDEX_SWITCHTAB     = 9;
+const QUERYINDEX_FRECENCY      = 10;
 
 // This SQL query fragment provides the following:
 //   - whether the entry is bookmarked (QUERYINDEX_BOOKMARKED)
 //   - the bookmark title, if it is a bookmark (QUERYINDEX_BOOKMARKTITLE)
 //   - the tags associated with a bookmarked entry (QUERYINDEX_TAGS)
 const SQL_BOOKMARK_TAGS_FRAGMENT =
   `EXISTS(SELECT 1 FROM moz_bookmarks WHERE fk = h.id) AS bookmarked,
    ( SELECT title FROM moz_bookmarks WHERE fk = h.id AND title NOTNULL
@@ -120,20 +119,19 @@ const SQL_BOOKMARK_TAGS_FRAGMENT =
    ) AS tags`;
 
 // TODO bug 412736: in case of a frecency tie, we might break it with h.typed
 // and h.visit_count.  That is slower though, so not doing it yet...
 // NB: as a slight performance optimization, we only evaluate the "btitle"
 // and "tags" queries for bookmarked entries.
 function defaultQuery(conditions = "") {
   let query =
-    `SELECT :query_type, h.url, h.title, f.url, ${SQL_BOOKMARK_TAGS_FRAGMENT},
+    `SELECT :query_type, h.url, h.title, ${SQL_BOOKMARK_TAGS_FRAGMENT},
             h.visit_count, h.typed, h.id, t.open_count, h.frecency
      FROM moz_places h
-     LEFT JOIN moz_favicons f ON f.id = h.favicon_id
      LEFT JOIN moz_openpages_temp t
             ON t.url = h.url
            AND t.userContextId = :userContextId
      WHERE h.frecency <> 0
        AND AUTOCOMPLETE_MATCH(:searchString, h.url,
                               CASE WHEN bookmarked THEN
                                 IFNULL(btitle, h.title)
                               ELSE h.title END,
@@ -145,61 +143,55 @@ function defaultQuery(conditions = "") {
                               :matchBehavior, :searchBehavior)
        ${conditions}
      ORDER BY h.frecency DESC, h.id DESC
      LIMIT :maxResults`;
   return query;
 }
 
 const SQL_SWITCHTAB_QUERY =
-  `SELECT :query_type, t.url, t.url, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+  `SELECT :query_type, t.url, t.url, NULL, NULL, NULL, NULL, NULL, NULL,
           t.open_count, NULL
    FROM moz_openpages_temp t
    LEFT JOIN moz_places h ON h.url_hash = hash(t.url) AND h.url = t.url
    WHERE h.id IS NULL
      AND t.userContextId = :userContextId
      AND AUTOCOMPLETE_MATCH(:searchString, t.url, t.url, NULL,
                             NULL, NULL, NULL, t.open_count,
                             :matchBehavior, :searchBehavior)
    ORDER BY t.ROWID DESC
    LIMIT :maxResults`;
 
 const SQL_ADAPTIVE_QUERY =
   `/* do not warn (bug 487789) */
-   SELECT :query_type, h.url, h.title, f.url, ${SQL_BOOKMARK_TAGS_FRAGMENT},
+   SELECT :query_type, h.url, h.title, ${SQL_BOOKMARK_TAGS_FRAGMENT},
           h.visit_count, h.typed, h.id, t.open_count, h.frecency
    FROM (
      SELECT ROUND(MAX(use_count) * (1 + (input = :search_string)), 1) AS rank,
             place_id
      FROM moz_inputhistory
      WHERE input BETWEEN :search_string AND :search_string || X'FFFF'
      GROUP BY place_id
    ) AS i
    JOIN moz_places h ON h.id = i.place_id
-   LEFT JOIN moz_favicons f ON f.id = h.favicon_id
    LEFT JOIN moz_openpages_temp t
           ON t.url = h.url
          AND t.userContextId = :userContextId
    WHERE AUTOCOMPLETE_MATCH(NULL, h.url,
                             IFNULL(btitle, h.title), tags,
                             h.visit_count, h.typed, bookmarked,
                             t.open_count,
                             :matchBehavior, :searchBehavior)
    ORDER BY rank DESC, h.frecency DESC`;
 
 
 function hostQuery(conditions = "") {
   let query =
     `/* do not warn (bug NA): not worth to index on (typed, frecency) */
-     SELECT :query_type, host || '/', IFNULL(prefix, '') || host || '/',
-            ( SELECT f.url FROM moz_favicons f
-              JOIN moz_places h ON h.favicon_id = f.id
-              WHERE rev_host = get_unreversed_host(host || '.') || '.'
-                 OR rev_host = get_unreversed_host(host || '.') || '.www.'
-            ) AS favicon_url,
+     SELECT :query_type, host || '/', IFNULL(prefix, 'http://') || host || '/',
             NULL, NULL, NULL, NULL, NULL, NULL, NULL, frecency
      FROM moz_hosts
      WHERE host BETWEEN :searchString AND :searchString || X'FFFF'
      AND frecency <> 0
      ${conditions}
      ORDER BY frecency DESC
      LIMIT 1`;
   return query;
@@ -207,22 +199,17 @@ function hostQuery(conditions = "") {
 
 const SQL_HOST_QUERY = hostQuery();
 
 const SQL_TYPED_HOST_QUERY = hostQuery("AND typed = 1");
 
 function bookmarkedHostQuery(conditions = "") {
   let query =
     `/* do not warn (bug NA): not worth to index on (typed, frecency) */
-     SELECT :query_type, host || '/', IFNULL(prefix, '') || host || '/',
-            ( SELECT f.url FROM moz_favicons f
-              JOIN moz_places h ON h.favicon_id = f.id
-              WHERE rev_host = get_unreversed_host(host || '.') || '.'
-                 OR rev_host = get_unreversed_host(host || '.') || '.www.'
-            ) AS favicon_url,
+     SELECT :query_type, host || '/', IFNULL(prefix, 'http://') || host || '/',
             ( SELECT foreign_count > 0 FROM moz_places
               WHERE rev_host = get_unreversed_host(host || '.') || '.'
                  OR rev_host = get_unreversed_host(host || '.') || '.www.'
             ) AS bookmarked, NULL, NULL, NULL, NULL, NULL, NULL, frecency
      FROM moz_hosts
      WHERE host BETWEEN :searchString AND :searchString || X'FFFF'
      AND bookmarked
      AND frecency <> 0
@@ -233,21 +220,20 @@ function bookmarkedHostQuery(conditions 
 }
 
 const SQL_BOOKMARKED_HOST_QUERY = bookmarkedHostQuery();
 
 const SQL_BOOKMARKED_TYPED_HOST_QUERY = bookmarkedHostQuery("AND typed = 1");
 
 function urlQuery(conditions = "") {
   return `/* do not warn (bug no): cannot use an index to sort */
-          SELECT :query_type, h.url, NULL, f.url AS favicon_url,
+          SELECT :query_type, h.url, NULL,
             foreign_count > 0 AS bookmarked,
             NULL, NULL, NULL, NULL, NULL, NULL, h.frecency
           FROM moz_places h
-          LEFT JOIN moz_favicons f ON h.favicon_id = f.id
           WHERE (rev_host = :revHost OR rev_host = :revHost || "www.")
           AND h.frecency <> 0
           AND fixup_url(h.url) BETWEEN :searchString AND :searchString || X'FFFF'
           ${conditions}
           ORDER BY h.frecency DESC, h.id DESC
           LIMIT 1`;
 }
 
@@ -1387,17 +1373,22 @@ Search.prototype = {
       url,
       input: this._originalSearchString,
       postData,
     });
     let value = this._enableActions ? actionURL : url;
     // The title will end up being "host: queryString"
     let comment = entry.url.host;
 
-    this._addMatch({ value, comment, style, frecency: FRECENCY_DEFAULT });
+    this._addMatch({
+      value,
+      comment,
+      icon: "page-icon:" + url,
+      style,
+      frecency: FRECENCY_DEFAULT });
     return true;
   },
 
   *_matchSearchEngineUrl() {
     if (!Prefs.autofillSearchEngines)
       return false;
 
     let match = yield PlacesSearchAutocompleteProvider.findMatchByToken(
@@ -1528,22 +1519,17 @@ Search.prototype = {
   },
 
   *_matchRemoteTabs() {
     let matches = yield PlacesRemoteTabsAutocompleteProvider.getMatches(this._originalSearchString);
     for (let {url, title, icon, deviceName} of matches) {
       // It's rare that Sync supplies the icon for the page (but if it does, it
       // 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.
+        icon = "page-icon:" + 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.
@@ -1616,26 +1602,19 @@ Search.prototype = {
       input: this._originalSearchString,
     });
 
     let match = {
       value,
       comment: displayURL,
       style: "action visiturl",
       frecency: 0,
+      icon: "page-icon:" + escapedURL
     };
 
-    try {
-      let favicon = yield PlacesUtils.promiseFaviconLinkUrl(uri);
-      if (favicon)
-        match.icon = favicon.spec;
-    } catch (e) {
-      // It's possible we don't have a favicon for this - and that's ok.
-    }
-
     this._addMatch(match);
     return true;
   },
 
   _onResultRow(row) {
     if (this._localMatchesCount == 0) {
       TelemetryStopwatch.finish(TELEMETRY_1ST_RESULT, this);
     }
@@ -1779,46 +1758,43 @@ Search.prototype = {
       this._localMatchesCount++;
     }
     return index;
   },
 
   _processHostRow(row) {
     let match = {};
     let strippedHost = row.getResultByIndex(QUERYINDEX_URL);
-    let unstrippedHost = row.getResultByIndex(QUERYINDEX_TITLE);
+    let url = row.getResultByIndex(QUERYINDEX_TITLE);
+    let unstrippedHost = stripHttpAndTrim(url, false);
     let frecency = row.getResultByIndex(QUERYINDEX_FRECENCY);
-    let faviconUrl = row.getResultByIndex(QUERYINDEX_ICONURL);
 
     // If the unfixup value doesn't preserve the user's input just
     // ignore it and complete to the found host.
     if (!unstrippedHost.toLowerCase().includes(this._trimmedOriginalSearchString.toLowerCase())) {
       unstrippedHost = null;
     }
 
     match.value = this._strippedPrefix + strippedHost;
     match.finalCompleteValue = unstrippedHost;
 
-    if (faviconUrl) {
-      match.icon = PlacesUtils.favicons
-                              .getFaviconLinkForIcon(NetUtil.newURI(faviconUrl)).spec;
-    }
+    match.icon = "page-icon:" + url;
+
     // 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(row) {
     let url = row.getResultByIndex(QUERYINDEX_URL);
     let strippedUrl = stripPrefix(url);
     let prefix = url.substr(0, url.length - strippedUrl.length);
     let frecency = row.getResultByIndex(QUERYINDEX_FRECENCY);
-    let faviconUrl = row.getResultByIndex(QUERYINDEX_ICONURL);
 
     // We must complete the URL up to the next separator (which is /, ? or #).
     let searchString = stripPrefix(this._trimmedOriginalSearchString);
     let separatorIndex = strippedUrl.slice(searchString.length)
                                     .search(/[\/\?\#]/);
     if (separatorIndex != -1) {
       separatorIndex += searchString.length;
       if (strippedUrl[separatorIndex] == "/") {
@@ -1830,37 +1806,33 @@ Search.prototype = {
     let match = {
       value: this._strippedPrefix + strippedUrl,
       // Although this has a frecency, this query is executed before any other
       // queries that would result in frecency matches.
       frecency,
       style: "autofill"
     };
 
-    if (faviconUrl) {
-      match.icon = PlacesUtils.favicons
-                              .getFaviconLinkForIcon(NetUtil.newURI(faviconUrl)).spec;
-    }
-
     // Complete to the found url only if its untrimmed value preserves the
     // user's input.
     if (url.toLowerCase().includes(this._trimmedOriginalSearchString.toLowerCase())) {
       match.finalCompleteValue = prefix + strippedUrl;
     }
 
+    match.icon = "page-icon:" + (match.finalCompleteValue || match.value);
+
     return match;
   },
 
   _processRow(row) {
     let match = {};
     match.placeId = row.getResultByIndex(QUERYINDEX_PLACEID);
     let escapedURL = row.getResultByIndex(QUERYINDEX_URL);
     let openPageCount = row.getResultByIndex(QUERYINDEX_SWITCHTAB) || 0;
     let historyTitle = row.getResultByIndex(QUERYINDEX_TITLE) || "";
-    let iconurl = row.getResultByIndex(QUERYINDEX_ICONURL) || "";
     let bookmarked = row.getResultByIndex(QUERYINDEX_BOOKMARKED);
     let bookmarkTitle = bookmarked ?
       row.getResultByIndex(QUERYINDEX_BOOKMARKTITLE) : null;
     let tags = row.getResultByIndex(QUERYINDEX_TAGS) || "";
     let frecency = row.getResultByIndex(QUERYINDEX_FRECENCY);
 
     // If actions are enabled and the page is open, add only the switch-to-tab
     // result.  Otherwise, add the normal result.
@@ -1906,20 +1878,17 @@ Search.prototype = {
       }
     }
 
     if (action)
       match.style = "action " + action;
 
     match.value = url;
     match.comment = title;
-    if (iconurl) {
-      match.icon = PlacesUtils.favicons
-                              .getFaviconLinkForIcon(NetUtil.newURI(iconurl)).spec;
-    }
+    match.icon = "page-icon:" + escapedURL;
     match.frecency = frecency;
 
     return match;
   },
 
   /**
    * @return a string consisting of the search query to be used based on the
    * previously set urlbar suggestion preferences.
--- a/toolkit/components/places/mozIAsyncFavicons.idl
+++ b/toolkit/components/places/mozIAsyncFavicons.idl
@@ -58,16 +58,17 @@ interface mozIAsyncFavicons : nsISupport
    */
   mozIPlacesPendingOperation setAndFetchFaviconForPage(
     in nsIURI aPageURI,
     in nsIURI aFaviconURI,
     in boolean aForceReload,
     in unsigned long aFaviconLoadType,
     [optional] in nsIFaviconDataCallback aCallback,
     [optional] in nsIPrincipal aLoadingPrincipal);
+
   /**
    * Sets the data for a given favicon URI either by replacing existing data in
    * the database or taking the place of otherwise fetched icon data when
    * calling setAndFetchFaviconForPage later.
    *
    * Favicon data for favicon URIs that are not associated with a page URI via
    * setAndFetchFaviconForPage will be stored in memory, but may be expired at
    * any time, so you should make an effort to associate favicon URIs with page
@@ -138,37 +139,45 @@ interface mozIAsyncFavicons : nsISupport
    * Retrieves the favicon URI associated to the given page, if any.
    *
    * @param aPageURI
    *        URI of the page whose favicon URI we're looking up.
    * @param aCallback
    *        This callback is always invoked to notify the result of the lookup.
    *        The aURI parameter will be the favicon URI, or null when no favicon
    *        is associated with the page or an error occurred while fetching it.
+   * @param aPreferredWidth
+   *        The preferred icon width, 0 for the biggest available.
    *
    * @note When the callback is invoked, aDataLen will be always 0, aData will
    *       be an empty array, and aMimeType will be an empty string, regardless
    *       of whether a favicon is associated with the page.
    *
    * @see nsIFaviconDataCallback in nsIFaviconService.idl.
    */
   void getFaviconURLForPage(in nsIURI aPageURI,
-                            in nsIFaviconDataCallback aCallback);
+                            in nsIFaviconDataCallback aCallback,
+                            [optional] in unsigned short aPreferredWidth);
 
   /**
    * Retrieves the favicon URI and data associated to the given page, if any.
+   * If the page icon is not available, it will try to return the root domain
+   * icon data, when it's known.
    *
    * @param aPageURI
    *        URI of the page whose favicon URI and data we're looking up.
    * @param aCallback
    *        This callback is always invoked to notify the result of the lookup.  The aURI
    *        parameter will be the favicon URI, or null when no favicon is
    *        associated with the page or an error occurred while fetching it.  If
    *        aURI is not null, the other parameters may contain the favicon data.
    *        However, if no favicon data is currently associated with the favicon
    *        URI, aDataLen will be 0, aData will be an empty array, and aMimeType
    *        will be an empty string.
+   * @param aPreferredWidth
+   *        The preferred icon width, 0 for the biggest available.
    *
    * @see nsIFaviconDataCallback in nsIFaviconService.idl.
    */
   void getFaviconDataForPage(in nsIURI aPageURI,
-                             in nsIFaviconDataCallback aCallback);
+                             in nsIFaviconDataCallback aCallback,
+                             [optional] in unsigned short aPreferredWidth);
 };
--- a/toolkit/components/places/nsAnnoProtocolHandler.cpp
+++ b/toolkit/components/places/nsAnnoProtocolHandler.cpp
@@ -28,16 +28,17 @@
 #include "nsInputStreamPump.h"
 #include "nsContentUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsStringStream.h"
 #include "SimpleChannel.h"
 #include "mozilla/ScopeExit.h"
 #include "mozilla/storage.h"
 #include "Helpers.h"
+#include "FaviconHelpers.h"
 
 using namespace mozilla;
 using namespace mozilla::places;
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Global Functions
 
 /**
@@ -60,119 +61,115 @@ GetDefaultIcon(nsILoadInfo *aLoadInfo, n
 namespace {
 
 /**
  * An instance of this class is passed to the favicon service as the callback
  * for getting favicon data from the database.  We'll get this data back in
  * HandleResult, and on HandleCompletion, we'll close our output stream which
  * will close the original channel for the favicon request.
  *
- * However, if an error occurs at any point, we do not set mReturnDefaultIcon to
- * false, so we will open up another channel to get the default favicon, and
- * pass that along to our output stream in HandleCompletion.  If anything
- * happens at that point, the world must be against us, so we return nothing.
+ * However, if an error occurs at any point and we don't have mData, we will
+ * just fallback to the default favicon.  If anything happens at that point, the
+ * world must be against us, so we can do nothing.
  */
 class faviconAsyncLoader : public AsyncStatementCallback
 {
 public:
-  faviconAsyncLoader(nsIChannel *aChannel, nsIStreamListener *aListener) :
-      mChannel(aChannel)
+  faviconAsyncLoader(nsIChannel *aChannel, nsIStreamListener *aListener)
+    : mChannel(aChannel)
     , mListener(aListener)
   {
-    NS_ASSERTION(aChannel,
-                 "Not providing a channel will result in crashes!");
-    NS_ASSERTION(aListener,
-                 "Not providing a stream listener will result in crashes!");
+    MOZ_ASSERT(aChannel, "Not providing a channel will result in crashes!");
+    MOZ_ASSERT(aListener, "Not providing a stream listener will result in crashes!");
+    // Set the default content type.
+    Unused << mChannel->SetContentType(NS_LITERAL_CSTRING(PNG_MIME_TYPE));
   }
 
   //////////////////////////////////////////////////////////////////////////////
   //// mozIStorageStatementCallback
 
   NS_IMETHOD HandleResult(mozIStorageResultSet *aResultSet) override
   {
-    // We will only get one row back in total, so we do not need to loop.
     nsCOMPtr<mozIStorageRow> row;
-    nsresult rv = aResultSet->GetNextRow(getter_AddRefs(row));
-    NS_ENSURE_SUCCESS(rv, rv);
+    while (NS_SUCCEEDED(aResultSet->GetNextRow(getter_AddRefs(row))) && row) {
+      // TODO: For now just return the biggest icon, that is the first one.
+      // Later this should allow to return a specific size.
+      if (!mData.IsEmpty()) {
+        return NS_OK;
+      }
 
-    // We do not allow favicons without a MIME type, so we'll return the default
-    // icon.
-    nsAutoCString mimeType;
-    (void)row->GetUTF8String(1, mimeType);
-    NS_ENSURE_FALSE(mimeType.IsEmpty(), NS_OK);
+      int32_t width;
+      nsresult rv = row->GetInt32(1, &width);
+      NS_ENSURE_SUCCESS(rv, rv);
 
-    // Set our mimeType now that we know it.
-    rv = mChannel->SetContentType(mimeType);
-    NS_ENSURE_SUCCESS(rv, rv);
+      // Eventually override the default mimeType for svg.
+      if (width == UINT16_MAX) {
+        rv = mChannel->SetContentType(NS_LITERAL_CSTRING(SVG_MIME_TYPE));
+        NS_ENSURE_SUCCESS(rv, rv);
+      }
 
-    // Obtain the binary blob that contains our favicon data.
-    uint8_t *favicon;
-    uint32_t size = 0;
-    rv = row->GetBlob(0, &size, &favicon);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIInputStream> stream;
-    rv = NS_NewByteInputStream(getter_AddRefs(stream),
-                               reinterpret_cast<char*>(favicon),
-                               size, NS_ASSIGNMENT_ADOPT);
-    if (NS_FAILED(rv)) {
-      free(favicon);
-      return rv;
+      // Obtain the binary blob that contains our favicon data.
+      uint8_t *data;
+      uint32_t dataLen;
+      rv = row->GetBlob(0, &dataLen, &data);
+      NS_ENSURE_SUCCESS(rv, rv);
+      mData.Adopt(TO_CHARBUFFER(data), dataLen);
     }
 
-    RefPtr<nsInputStreamPump> pump;
-    rv = nsInputStreamPump::Create(getter_AddRefs(pump), stream, -1, -1, 0, 0,
-                                   true);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    MOZ_DIAGNOSTIC_ASSERT(mListener);
-    NS_ENSURE_TRUE(mListener, NS_ERROR_UNEXPECTED);
-
-    rv = pump->AsyncRead(mListener, nullptr);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    mListener = nullptr;
     return NS_OK;
   }
 
   NS_IMETHOD HandleCompletion(uint16_t aReason) override
   {
-    // If we've already written our icon data to the channel, there's nothing
-    // more to do. If we didn't, then return the default icon instead.
-    if (!mListener)
-      return NS_OK;
+    MOZ_DIAGNOSTIC_ASSERT(mListener);
+    NS_ENSURE_TRUE(mListener, NS_ERROR_UNEXPECTED);
 
+    nsresult rv;
+    // Ensure we'll break possible cycles with the listener.
     auto cleanup = MakeScopeExit([&] () {
       mListener = nullptr;
     });
 
+    if (!mData.IsEmpty()) {
+      nsCOMPtr<nsIInputStream> stream;
+      rv = NS_NewCStringInputStream(getter_AddRefs(stream), mData);
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
+      if (NS_SUCCEEDED(rv)) {
+        RefPtr<nsInputStreamPump> pump;
+        rv = nsInputStreamPump::Create(getter_AddRefs(pump), stream, -1, -1, 0, 0,
+                                      true);
+        MOZ_ASSERT(NS_SUCCEEDED(rv));
+        if (NS_SUCCEEDED(rv)) {
+          return pump->AsyncRead(mListener, nullptr);
+        }
+      }
+    }
+
+    // Fallback to the default favicon.
     // we should pass the loadInfo of the original channel along
     // to the new channel. Note that mChannel can not be null,
     // constructor checks that.
     nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
     nsCOMPtr<nsIChannel> newChannel;
-    nsresult rv = GetDefaultIcon(loadInfo, getter_AddRefs(newChannel));
-
+    rv = GetDefaultIcon(loadInfo, getter_AddRefs(newChannel));
     if (NS_FAILED(rv)) {
       mListener->OnStartRequest(mChannel, nullptr);
       mListener->OnStopRequest(mChannel, nullptr, rv);
       return rv;
     }
-
-    mChannel->SetContentType(NS_LITERAL_CSTRING("image/png"));
-
     return newChannel->AsyncOpen2(mListener);
   }
 
 protected:
   virtual ~faviconAsyncLoader() {}
 
 private:
   nsCOMPtr<nsIChannel> mChannel;
   nsCOMPtr<nsIStreamListener> mListener;
+  nsCString mData;
 };
 
 } // namespace
 
 ////////////////////////////////////////////////////////////////////////////////
 //// nsAnnoProtocolHandler
 
 NS_IMPL_ISUPPORTS(nsAnnoProtocolHandler, nsIProtocolHandler)
--- a/toolkit/components/places/nsFaviconService.cpp
+++ b/toolkit/components/places/nsFaviconService.cpp
@@ -113,42 +113,41 @@ nsFaviconService::Init()
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFaviconService::ExpireAllFavicons()
 {
+  NS_ENSURE_STATE(mDB);
+
+  nsCOMPtr<mozIStorageAsyncStatement> removePagesStmt = mDB->GetAsyncStatement(
+    "DELETE FROM moz_pages_w_icons"
+  );
+  NS_ENSURE_STATE(removePagesStmt);
+  nsCOMPtr<mozIStorageAsyncStatement> removeIconsStmt = mDB->GetAsyncStatement(
+    "DELETE FROM moz_icons"
+  );
+  NS_ENSURE_STATE(removeIconsStmt);
   nsCOMPtr<mozIStorageAsyncStatement> unlinkIconsStmt = mDB->GetAsyncStatement(
-    "UPDATE moz_places "
-    "SET favicon_id = NULL "
-    "WHERE favicon_id NOT NULL"
+    "DELETE FROM moz_icons_to_pages"
   );
   NS_ENSURE_STATE(unlinkIconsStmt);
-  nsCOMPtr<mozIStorageAsyncStatement> removeIconsStmt = mDB->GetAsyncStatement(
-    "DELETE FROM moz_favicons WHERE id NOT IN ("
-      "SELECT favicon_id FROM moz_places WHERE favicon_id NOT NULL "
-    ")"
-  );
-  NS_ENSURE_STATE(removeIconsStmt);
 
   mozIStorageBaseStatement* stmts[] = {
-    unlinkIconsStmt.get()
+    removePagesStmt.get()
   , removeIconsStmt.get()
+  , unlinkIconsStmt.get()
   };
   nsCOMPtr<mozIStoragePendingStatement> ps;
   RefPtr<ExpireFaviconsStatementCallbackNotifier> callback =
     new ExpireFaviconsStatementCallbackNotifier();
-  nsresult rv = mDB->MainConn()->ExecuteAsync(
-    stmts, ArrayLength(stmts), callback, getter_AddRefs(ps)
-  );
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return NS_OK;
+  return mDB->MainConn()->ExecuteAsync(stmts, ArrayLength(stmts),
+                                       callback, getter_AddRefs(ps));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //// nsITimerCallback
 
 NS_IMETHODIMP
 nsFaviconService::Notify(nsITimer* timer)
 {
@@ -219,20 +218,22 @@ nsFaviconService::SetAndFetchFaviconForP
   NS_ENSURE_ARG(aFaviconURI);
   NS_ENSURE_ARG_POINTER(_canceler);
 
   // If a favicon is in the failed cache, only load it during a forced reload.
   bool previouslyFailed;
   nsresult rv = IsFailedFavicon(aFaviconURI, &previouslyFailed);
   NS_ENSURE_SUCCESS(rv, rv);
   if (previouslyFailed) {
-    if (aForceReload)
+    if (aForceReload) {
       RemoveFailedFavicon(aFaviconURI);
-    else
+    }
+    else {
       return NS_OK;
+    }
   }
 
   nsCOMPtr<nsIPrincipal> loadingPrincipal = aLoadingPrincipal;
   MOZ_ASSERT(loadingPrincipal, "please provide aLoadingPrincipal for this favicon");
   if (!loadingPrincipal) {
     // Let's default to the nullPrincipal if no loadingPrincipal is provided.
     const char16_t* params[] = {
       u"nsFaviconService::setAndFetchFaviconForPage()",
@@ -243,46 +244,47 @@ nsFaviconService::SetAndFetchFaviconForP
                                     nullptr, // aDocument
                                     nsContentUtils::eNECKO_PROPERTIES,
                                     "APIDeprecationWarning",
                                     params, ArrayLength(params));
     loadingPrincipal = NullPrincipal::Create();
   }
   NS_ENSURE_TRUE(loadingPrincipal, NS_ERROR_FAILURE);
 
-  // Check if the icon already exists and fetch it from the network, if needed.
-  // Finally associate the icon to the requested page if not yet associated.
   bool loadPrivate = aFaviconLoadType == nsIFaviconService::FAVICON_LOAD_PRIVATE;
 
+  // Build page data.
   PageData page;
   rv = aPageURI->GetSpec(page.spec);
   NS_ENSURE_SUCCESS(rv, rv);
   // URIs can arguably miss a host.
-  (void)GetReversedHostname(aPageURI, page.revHost);
+  Unused << GetReversedHostname(aPageURI, page.revHost);
   bool canAddToHistory;
   nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
   NS_ENSURE_TRUE(navHistory, NS_ERROR_OUT_OF_MEMORY);
   rv = navHistory->CanAddURI(aPageURI, &canAddToHistory);
   NS_ENSURE_SUCCESS(rv, rv);
   page.canAddToHistory = !!canAddToHistory && !loadPrivate;
 
+  // Build icon data.
   IconData icon;
+  // If we have an in-memory icon payload, it overwrites the actual request.
   UnassociatedIconHashKey* iconKey = mUnassociatedIcons.GetEntry(aFaviconURI);
   if (iconKey) {
     icon = iconKey->iconData;
     mUnassociatedIcons.RemoveEntry(iconKey);
   } else {
     icon.fetchMode = aForceReload ? FETCH_ALWAYS : FETCH_IF_MISSING;
     rv = aFaviconURI->GetSpec(icon.spec);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // If the page url points to an image, the icon's url will be the same.
-  // In future evaluate to store a resample of the image.  For now avoid that
-  // for database size concerns.
+  // TODO (Bug 403651): store a resample of the image.  For now avoid that
+  // for database size and UX concerns.
   // Don't store favicons for error pages too.
   if (icon.spec.Equals(page.spec) ||
       icon.spec.Equals(FAVICON_ERRORPAGE_URL)) {
     return NS_OK;
   }
 
   RefPtr<AsyncFetchAndSetIconForPage> event =
     new AsyncFetchAndSetIconForPage(icon, page, loadPrivate,
@@ -305,18 +307,21 @@ nsFaviconService::ReplaceFaviconData(nsI
                                     const uint8_t* aData,
                                     uint32_t aDataLen,
                                     const nsACString& aMimeType,
                                     PRTime aExpiration)
 {
   MOZ_ASSERT(NS_IsMainThread());
   NS_ENSURE_ARG(aFaviconURI);
   NS_ENSURE_ARG(aData);
-  NS_ENSURE_TRUE(aDataLen > 0, NS_ERROR_INVALID_ARG);
-  NS_ENSURE_TRUE(aMimeType.Length() > 0, NS_ERROR_INVALID_ARG);
+  NS_ENSURE_ARG(aDataLen > 0);
+  NS_ENSURE_ARG(aMimeType.Length() > 0);
+  NS_ENSURE_ARG(imgLoader::SupportImageWithMimeType(PromiseFlatCString(aMimeType).get(),
+                                                     AcceptedMimeTypes::IMAGES));
+
   if (aExpiration == 0) {
     aExpiration = PR_Now() + MAX_FAVICON_EXPIRATION;
   }
 
   UnassociatedIconHashKey* iconKey = mUnassociatedIcons.PutEntry(aFaviconURI);
   if (!iconKey) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
@@ -334,32 +339,32 @@ nsFaviconService::ReplaceFaviconData(nsI
 
   IconData* iconData = &(iconKey->iconData);
   iconData->expiration = aExpiration;
   iconData->status = ICON_STATUS_CACHED;
   iconData->fetchMode = FETCH_NEVER;
   nsresult rv = aFaviconURI->GetSpec(iconData->spec);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // If the page provided a large image for the favicon (eg, a highres image
-  // or a multiresolution .ico file), we don't want to store more data than
-  // needed.
-  if (aDataLen > MAX_FAVICON_FILESIZE) {
-    rv = OptimizeFaviconImage(aData, aDataLen, aMimeType, iconData->data, iconData->mimeType);
-    NS_ENSURE_SUCCESS(rv, rv);
+  IconPayload payload;
+  payload.mimeType = aMimeType;
+  payload.data.Assign(TO_CHARBUFFER(aData), aDataLen);
+  // There may already be a previous payload, so ensure to only have one.
+  iconData->payloads.Clear();
+  iconData->payloads.AppendElement(payload);
 
-    if (iconData->data.Length() > nsIFaviconService::MAX_FAVICON_BUFFER_SIZE) {
-      // We cannot optimize this favicon size and we are over the maximum size
-      // allowed, so we will not save data to the db to avoid bloating it.
-      mUnassociatedIcons.RemoveEntry(aFaviconURI);
-      return NS_ERROR_FAILURE;
-    }
-  } else {
-    iconData->mimeType.Assign(aMimeType);
-    iconData->data.Assign(TO_CHARBUFFER(aData), aDataLen);
+  rv = OptimizeIconSizes(*iconData);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // If there's not valid payload, don't store the icon into to the database.
+  if ((*iconData).payloads.Length() == 0) {
+    // We cannot optimize this favicon size and we are over the maximum size
+    // allowed, so we will not save data to the db to avoid bloating it.
+    mUnassociatedIcons.RemoveEntry(aFaviconURI);
+    return NS_ERROR_FAILURE;
   }
 
   // If the database contains an icon at the given url, we will update the
   // database immediately so that the associated pages are kept in sync.
   // Otherwise, do nothing and let the icon be picked up from the memory hash.
   RefPtr<AsyncReplaceFaviconData> event = new AsyncReplaceFaviconData(*iconData);
   RefPtr<Database> DB = Database::GetDatabase();
   NS_ENSURE_STATE(DB);
@@ -459,50 +464,52 @@ nsFaviconService::ReplaceFaviconDataFrom
   free(buffer);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFaviconService::GetFaviconURLForPage(nsIURI *aPageURI,
-                                       nsIFaviconDataCallback* aCallback)
+                                       nsIFaviconDataCallback* aCallback,
+                                       uint16_t aPreferredWidth)
 {
   MOZ_ASSERT(NS_IsMainThread());
   NS_ENSURE_ARG(aPageURI);
   NS_ENSURE_ARG(aCallback);
 
   nsAutoCString pageSpec;
   nsresult rv = aPageURI->GetSpec(pageSpec);
   NS_ENSURE_SUCCESS(rv, rv);
 
   RefPtr<AsyncGetFaviconURLForPage> event =
-    new AsyncGetFaviconURLForPage(pageSpec, aCallback);
+    new AsyncGetFaviconURLForPage(pageSpec, aPreferredWidth, aCallback);
 
   RefPtr<Database> DB = Database::GetDatabase();
   NS_ENSURE_STATE(DB);
   DB->DispatchToAsyncThread(event);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFaviconService::GetFaviconDataForPage(nsIURI* aPageURI,
-                                        nsIFaviconDataCallback* aCallback)
+                                        nsIFaviconDataCallback* aCallback,
+                                        uint16_t aPreferredWidth)
 {
   MOZ_ASSERT(NS_IsMainThread());
   NS_ENSURE_ARG(aPageURI);
   NS_ENSURE_ARG(aCallback);
 
   nsAutoCString pageSpec;
   nsresult rv = aPageURI->GetSpec(pageSpec);
   NS_ENSURE_SUCCESS(rv, rv);
 
   RefPtr<AsyncGetFaviconDataForPage> event =
-    new AsyncGetFaviconDataForPage(pageSpec, aCallback);
+    new AsyncGetFaviconDataForPage(pageSpec, aPreferredWidth, aCallback);
   RefPtr<Database> DB = Database::GetDatabase();
   NS_ENSURE_STATE(DB);
   DB->DispatchToAsyncThread(event);
 
   return NS_OK;
 }
 
 nsresult
@@ -582,23 +589,17 @@ nsFaviconService::IsFailedFavicon(nsIURI
 //    This computes a favicon URL with string input and using the cached
 //    default one to minimize parsing.
 
 nsresult
 nsFaviconService::GetFaviconLinkForIconString(const nsCString& aSpec,
                                               nsIURI** aOutput)
 {
   if (aSpec.IsEmpty()) {
-    // default icon for empty strings
-    if (! mDefaultIcon) {
-      nsresult rv = NS_NewURI(getter_AddRefs(mDefaultIcon),
-                              NS_LITERAL_CSTRING(FAVICON_DEFAULT_URL));
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-    return mDefaultIcon->Clone(aOutput);
+    return GetDefaultFavicon(aOutput);
   }
 
   if (StringBeginsWith(aSpec, NS_LITERAL_CSTRING("chrome:"))) {
     // pass through for chrome URLs, since they can be referenced without
     // this service
     return NS_NewURI(aOutput, aSpec);
   }
 
@@ -622,74 +623,123 @@ nsFaviconService::GetFaviconSpecForIconS
   } else if (StringBeginsWith(aSpec, NS_LITERAL_CSTRING("chrome:"))) {
     aOutput = aSpec;
   } else {
     aOutput.AssignLiteral("moz-anno:" FAVICON_ANNOTATION_NAME ":");
     aOutput += aSpec;
   }
 }
 
-
-// nsFaviconService::OptimizeFaviconImage
-//
-// Given a blob of data (a image file already read into a buffer), optimize
-// its size by recompressing it as a 16x16 PNG.
+/**
+ * Checks the icon and evaluates if it needs to be optimized.
+ *
+ * @param aIcon
+ *        The icon to be evaluated.
+ */
 nsresult
-nsFaviconService::OptimizeFaviconImage(const uint8_t* aData, uint32_t aDataLen,
-                                       const nsACString& aMimeType,
-                                       nsACString& aNewData,
-                                       nsACString& aNewMimeType)
+nsFaviconService::OptimizeIconSizes(IconData& aIcon)
 {
-  nsresult rv;
+  // TODO (bug 1346139): move optimization to the async thread.
+  MOZ_ASSERT(NS_IsMainThread());
+  // There should only be a single payload at this point, it may have to be
+  // split though, if it's an ico file.
+  MOZ_ASSERT(aIcon.payloads.Length() == 1);
+
+  // Even if the page provides a large image for the favicon (eg, a highres
+  // image or a multiresolution .ico file), don't try to store more data than
+  // needed.
+  IconPayload payload = aIcon.payloads[0];
+  if (payload.mimeType.EqualsLiteral(SVG_MIME_TYPE)) {
+    // Nothing to optimize, but check the payload size.
+    if (payload.data.Length() >= nsIFaviconService::MAX_FAVICON_BUFFER_SIZE) {
+      aIcon.payloads.Clear();
+    }
+    return NS_OK;
+  }
+
+  // Make space for the optimized payloads.
+  aIcon.payloads.Clear();
 
   nsCOMPtr<nsIInputStream> stream;
-  rv = NS_NewByteInputStream(getter_AddRefs(stream),
-                reinterpret_cast<const char*>(aData), aDataLen,
-                NS_ASSIGNMENT_DEPEND);
+  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
+                                      payload.data.get(),
+                                      payload.data.Length(),
+                                      NS_ASSIGNMENT_DEPEND);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // decode image
   nsCOMPtr<imgIContainer> container;
-  rv = GetImgTools()->DecodeImageData(stream, aMimeType, getter_AddRefs(container));
+  rv = GetImgTools()->DecodeImageData(stream, payload.mimeType,
+                                      getter_AddRefs(container));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  aNewMimeType.AssignLiteral(PNG_MIME_TYPE);
+  IconPayload newPayload;
+  newPayload.mimeType = NS_LITERAL_CSTRING(PNG_MIME_TYPE);
+  // TODO: for ico files we should extract every single payload.
+  int32_t width;
+  rv = container->GetWidth(&width);
+  NS_ENSURE_SUCCESS(rv, rv);
+  int32_t height;
+  rv = container->GetHeight(&height);
+  NS_ENSURE_SUCCESS(rv, rv);
+  // For non-square images, pick the largest side.
+  int32_t originalSize = std::max(width, height);
+  newPayload.width = originalSize;
+  for (uint16_t size : sFaviconSizes) {
+    if (size <= originalSize) {
+      newPayload.width = size;
+      break;
+    }
+  }
 
-  // scale and recompress
-  nsCOMPtr<nsIInputStream> iconStream;
-  rv = GetImgTools()->EncodeScaledImage(container, aNewMimeType,
-                                        DEFAULT_FAVICON_SIZE,
-                                        DEFAULT_FAVICON_SIZE,
-                                        EmptyString(),
-                                        getter_AddRefs(iconStream));
-  NS_ENSURE_SUCCESS(rv, rv);
+  // If the original payload is png and the size is the same, no reason to
+  // rescale the image.
+  if (newPayload.mimeType.Equals(payload.mimeType) &&
+      newPayload.width == originalSize) {
+    newPayload.data = payload.data;
+  } else {
+    // scale and recompress
+    nsCOMPtr<nsIInputStream> iconStream;
+    rv = GetImgTools()->EncodeScaledImage(container,
+                                          newPayload.mimeType,
+                                          newPayload.width,
+                                          newPayload.width,
+                                          EmptyString(),
+                                          getter_AddRefs(iconStream));
+    NS_ENSURE_SUCCESS(rv, rv);
+    // Read the stream into the new buffer.
+    rv = NS_ConsumeStream(iconStream, UINT32_MAX, newPayload.data);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
-  // Read the stream into a new buffer.
-  rv = NS_ConsumeStream(iconStream, UINT32_MAX, aNewData);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (newPayload.data.Length() < nsIFaviconService::MAX_FAVICON_BUFFER_SIZE) {
+    aIcon.payloads.AppendElement(newPayload);
+  }
 
   return NS_OK;
 }
 
 nsresult
 nsFaviconService::GetFaviconDataAsync(nsIURI* aFaviconURI,
                                       mozIStorageStatementCallback *aCallback)
 {
-  NS_ASSERTION(aCallback, "Doesn't make sense to call this without a callback");
+  MOZ_ASSERT(aCallback, "Doesn't make sense to call this without a callback");
+
   nsCOMPtr<mozIStorageAsyncStatement> stmt = mDB->GetAsyncStatement(
-    "SELECT f.data, f.mime_type FROM moz_favicons f WHERE url = :icon_url"
+    "SELECT data, width FROM moz_icons "
+    "WHERE fixed_icon_url_hash = hash(fixup_url(:url)) AND icon_url = :url "
+    "ORDER BY width DESC"
   );
   NS_ENSURE_STATE(stmt);
 
   // Ignore the ref part of the URI before querying the database because
   // we may have added a media fragment for rendering purposes.
-
   nsAutoCString faviconURI;
   aFaviconURI->GetSpecIgnoringRef(faviconURI);
-  nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"), faviconURI);
+  nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("url"), faviconURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<mozIStoragePendingStatement> pendingStatement;
   return stmt->ExecuteAsync(aCallback, getter_AddRefs(pendingStatement));
 }
 
 void // static
 nsFaviconService::ConvertUnsupportedPayloads(mozIStorageConnection* aDBConn)
--- a/toolkit/components/places/nsFaviconService.h
+++ b/toolkit/components/places/nsFaviconService.h
@@ -23,22 +23,16 @@
 #include "mozilla/Attributes.h"
 
 #include "FaviconHelpers.h"
 
 // The target dimension in pixels for favicons we store, in reverse order.
 static uint16_t sFaviconSizes[8] = {
   256, 192, 144, 96, 64, 48, 32, 16
 };
-// Default size when preferred size is unknown, doubled for hi-dpi.
-#define DEFAULT_FAVICON_SIZE 32
-
-// Favicons bigger than this (in bytes) will not be stored in the database.  We
-// expect that most 32x32 PNG favicons will be no larger due to compression.
-#define MAX_FAVICON_FILESIZE 3072 /* 3 KiB */
 
 // forward class definitions
 class mozIStorageStatementCallback;
 
 class UnassociatedIconHashKey : public nsURIHashKey
 {
 public:
   explicit UnassociatedIconHashKey(const nsIURI* aURI)
@@ -90,19 +84,17 @@ public:
    * Fetch and migrate favicons from an unsupported payload to a supported one.
    */
   static void ConvertUnsupportedPayloads(mozIStorageConnection* aDBConn);
 
   // addition to API for strings to prevent excessive parsing of URIs
   nsresult GetFaviconLinkForIconString(const nsCString& aIcon, nsIURI** aOutput);
   void GetFaviconSpecForIconString(const nsCString& aIcon, nsACString& aOutput);
 
-  nsresult OptimizeFaviconImage(const uint8_t* aData, uint32_t aDataLen,
-                                const nsACString& aMimeType,
-                                nsACString& aNewData, nsACString& aNewMimeType);
+  nsresult OptimizeIconSizes(mozilla::places::IconData& aIcon);
 
   /**
    * Obtains the favicon data asynchronously.
    *
    * @param aFaviconURI
    *        The URI representing the favicon we are looking for.
    * @param aCallback
    *        The callback where results or errors will be dispatch to.  In the
--- a/toolkit/components/places/nsIFaviconService.idl
+++ b/toolkit/components/places/nsIFaviconService.idl
@@ -14,17 +14,17 @@ interface nsIFaviconService : nsISupport
   const unsigned long FAVICON_LOAD_PRIVATE = 1;
   // The favicon is being loaded from a non-private browsing window
   const unsigned long FAVICON_LOAD_NON_PRIVATE = 2;
 
   /**
    * The limit in bytes of the size of favicons in memory and passed via the
    * favicon protocol.
    */
-  const unsigned long MAX_FAVICON_BUFFER_SIZE = 10240;
+  const unsigned long MAX_FAVICON_BUFFER_SIZE = 35840;
 
   /**
    * For a given icon URI, this will return a URI that will result in the image.
    * In most cases, this is an annotation URI.  For chrome URIs, this will do
    * nothing but returning the input URI.
    *
    * No validity checking is done. If you pass an icon URI that we've never
    * seen, you'll get back a URI that references an invalid icon. The moz-anno
@@ -116,25 +116,29 @@ interface nsIFaviconDataCallback : nsISu
    *        favicon URI, or the callback is notifying a failure.
    * @param aDataLen
    *        Size of the icon data in bytes.  Notice that a value of 0 does not
    *        necessarily mean that we don't have an icon.
    * @param aData
    *        Icon data, or an empty array if aDataLen is 0.
    * @param aMimeType
    *        Mime type of the icon, or an empty string if aDataLen is 0.
+   * @param aWidth
+   *        Width of the icon. 0 if the width is unknown or if the icon is
+   *        vectorial.
    *
    * @note If you want to open a network channel to access the favicon, it's
    *       recommended that you call the getFaviconLinkForIcon method to convert
    *       the "favicon URI" into a "favicon link URI".
    */
   void onComplete(in nsIURI aFaviconURI,
                   in unsigned long aDataLen,
                   [const,array,size_is(aDataLen)] in octet aData,
-                  in AUTF8String aMimeType);
+                  in AUTF8String aMimeType,
+                  in unsigned short aWidth);
 };
 
 %{C++
 
 /**
  * Notification sent when all favicons are expired.
  */
 #define NS_PLACES_FAVICONS_EXPIRED_TOPIC_ID "places-favicons-expired"
--- a/toolkit/components/places/nsNavBookmarks.cpp
+++ b/toolkit/components/places/nsNavBookmarks.cpp
@@ -1103,22 +1103,21 @@ nsNavBookmarks::GetDescendantChildren(in
     // Collect children informations.
     // Select all children of a given folder, sorted by position.
     // This is a LEFT JOIN because not all bookmarks types have a place.
     // We construct a result where the first columns exactly match
     // kGetInfoIndex_* order, and additionally contains columns for position,
     // item_child, and folder_child from moz_bookmarks.
     nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
       "SELECT h.id, h.url, IFNULL(b.title, h.title), h.rev_host, h.visit_count, "
-             "h.last_visit_date, f.url, b.id, b.dateAdded, b.lastModified, "
+             "h.last_visit_date, null, b.id, b.dateAdded, b.lastModified, "
              "b.parent, null, h.frecency, h.hidden, h.guid, null, null, null, "
              "b.guid, b.position, b.type, b.fk, b.syncStatus "
       "FROM moz_bookmarks b "
       "LEFT JOIN moz_places h ON b.fk = h.id "
-      "LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
       "WHERE b.parent = :parent "
       "ORDER BY b.position ASC"
     );
     NS_ENSURE_STATE(stmt);
     mozStorageStatementScoper scoper(stmt);
 
     rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -2142,22 +2141,21 @@ nsNavBookmarks::QueryFolderChildren(
 
   // Select all children of a given folder, sorted by position.
   // This is a LEFT JOIN because not all bookmarks types have a place.
   // We construct a result where the first columns exactly match those returned
   // by mDBGetURLPageInfo, and additionally contains columns for position,
   // item_child, and folder_child from moz_bookmarks.
   nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
     "SELECT h.id, h.url, IFNULL(b.title, h.title), h.rev_host, h.visit_count, "
-           "h.last_visit_date, f.url, b.id, b.dateAdded, b.lastModified, "
+           "h.last_visit_date, null, b.id, b.dateAdded, b.lastModified, "
            "b.parent, null, h.frecency, h.hidden, h.guid, null, null, null, "
            "b.guid, b.position, b.type, b.fk "
     "FROM moz_bookmarks b "
     "LEFT JOIN moz_places h ON b.fk = h.id "
-    "LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
     "WHERE b.parent = :parent "
     "ORDER BY b.position ASC"
   );
   NS_ENSURE_STATE(stmt);
   mozStorageStatementScoper scoper(stmt);
 
   nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -2280,22 +2278,21 @@ nsNavBookmarks::QueryFolderChildrenAsync
 
   // Select all children of a given folder, sorted by position.
   // This is a LEFT JOIN because not all bookmarks types have a place.
   // We construct a result where the first columns exactly match those returned
   // by mDBGetURLPageInfo, and additionally contains columns for position,
   // item_child, and folder_child from moz_bookmarks.
   nsCOMPtr<mozIStorageAsyncStatement> stmt = mDB->GetAsyncStatement(
     "SELECT h.id, h.url, IFNULL(b.title, h.title), h.rev_host, h.visit_count, "
-           "h.last_visit_date, f.url, b.id, b.dateAdded, b.lastModified, "
+           "h.last_visit_date, null, b.id, b.dateAdded, b.lastModified, "
            "b.parent, null, h.frecency, h.hidden, h.guid, null, null, null, "
            "b.guid, b.position, b.type, b.fk "
     "FROM moz_bookmarks b "
     "LEFT JOIN moz_places h ON b.fk = h.id "
-    "LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
     "WHERE b.parent = :parent "
     "ORDER BY b.position ASC"
   );
   NS_ENSURE_STATE(stmt);
 
   nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -1275,17 +1275,17 @@ nsNavHistory::ExecuteQueries(nsINavHisto
       // This is a perf hack to generate an empty query that skips filtering.
       options->SetExcludeItems(true);
     }
   }
 
   if (!rootNode) {
     // Either this is not a folder shortcut, or is a broken one.  In both cases
     // just generate a query node.
-    rootNode = new nsNavHistoryQueryResultNode(EmptyCString(), EmptyCString(),
+    rootNode = new nsNavHistoryQueryResultNode(EmptyCString(),
                                                queries, options);
   }
 
   // Create the result that will hold nodes.  Inject batching status into it.
   RefPtr<nsNavHistoryResult> result;
   rv = nsNavHistoryResult::NewHistoryResult(aQueries, aQueryCount, options,
                                             rootNode, isBatching(),
                                             getter_AddRefs(result));
@@ -1512,21 +1512,20 @@ PlacesSQLQueryBuilder::SelectAsURI()
     case nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY:
       GetTagsSqlFragment(history->GetTagsFolder(),
                          NS_LITERAL_CSTRING("h.id"),
                          mHasSearchTerms,
                          tagsSqlFragment);
 
       mQueryString = NS_LITERAL_CSTRING(
         "SELECT h.id, h.url, h.title AS page_title, h.rev_host, h.visit_count, "
-        "h.last_visit_date, f.url, null, null, null, null, ") +
+        "h.last_visit_date, null, null, null, null, null, ") +
         tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
         "null, null, null "
         "FROM moz_places h "
-        "LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
         // WHERE 1 is a no-op since additonal conditions will start with AND.
         "WHERE 1 "
           "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
           "{ADDITIONAL_CONDITIONS} ");
       break;
 
     case nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS:
       if (mResultType == nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS) {
@@ -1538,48 +1537,46 @@ PlacesSQLQueryBuilder::SelectAsURI()
 
         GetTagsSqlFragment(history->GetTagsFolder(),
                            NS_LITERAL_CSTRING("b2.fk"),
                            mHasSearchTerms,
                            tagsSqlFragment);
 
         mQueryString = NS_LITERAL_CSTRING(
           "SELECT b2.fk, h.url, COALESCE(b2.title, h.title) AS page_title, "
-            "h.rev_host, h.visit_count, h.last_visit_date, f.url, b2.id, "
+            "h.rev_host, h.visit_count, h.last_visit_date, null, b2.id, "
             "b2.dateAdded, b2.lastModified, b2.parent, ") +
             tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
             "null, null, null, b2.guid, b2.position, b2.type, b2.fk "
           "FROM moz_bookmarks b2 "
           "JOIN (SELECT b.fk "
                 "FROM moz_bookmarks b "
                 // ADDITIONAL_CONDITIONS will filter on parent.
                 "WHERE b.type = 1 {ADDITIONAL_CONDITIONS} "
                 ") AS seed ON b2.fk = seed.fk "
           "JOIN moz_places h ON h.id = b2.fk "
-          "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
           "WHERE NOT EXISTS ( "
             "SELECT id FROM moz_bookmarks WHERE id = b2.parent AND parent = ") +
                 nsPrintfCString("%" PRId64, history->GetTagsFolder()) +
           NS_LITERAL_CSTRING(") "
           "ORDER BY b2.fk DESC, b2.lastModified DESC");
       }
       else {
         GetTagsSqlFragment(history->GetTagsFolder(),
                            NS_LITERAL_CSTRING("b.fk"),
                            mHasSearchTerms,
                            tagsSqlFragment);
         mQueryString = NS_LITERAL_CSTRING(
           "SELECT b.fk, h.url, COALESCE(b.title, h.title) AS page_title, "
-            "h.rev_host, h.visit_count, h.last_visit_date, f.url, b.id, "
+            "h.rev_host, h.visit_count, h.last_visit_date, null, b.id, "
             "b.dateAdded, b.lastModified, b.parent, ") +
             tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid,"
             "null, null, null, b.guid, b.position, b.type, b.fk "
           "FROM moz_bookmarks b "
           "JOIN moz_places h ON b.fk = h.id "
-          "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
           "WHERE NOT EXISTS "
               "(SELECT id FROM moz_bookmarks "
                 "WHERE id = b.parent AND parent = ") +
                   nsPrintfCString("%" PRId64, history->GetTagsFolder()) +
               NS_LITERAL_CSTRING(") "
             "{ADDITIONAL_CONDITIONS}");
       }
       break;
@@ -1597,22 +1594,21 @@ PlacesSQLQueryBuilder::SelectAsVisit()
   NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
   nsAutoCString tagsSqlFragment;
   GetTagsSqlFragment(history->GetTagsFolder(),
                      NS_LITERAL_CSTRING("h.id"),
                      mHasSearchTerms,
                      tagsSqlFragment);
   mQueryString = NS_LITERAL_CSTRING(
     "SELECT h.id, h.url, h.title AS page_title, h.rev_host, h.visit_count, "
-      "v.visit_date, f.url, null, null, null, null, ") +
+      "v.visit_date, null, null, null, null, null, ") +
       tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
       "v.id, v.from_visit, v.visit_type "
     "FROM moz_places h "
     "JOIN moz_historyvisits v ON h.id = v.place_id "
-    "LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
     // WHERE 1 is a no-op since additonal conditions will start with AND.
     "WHERE 1 "
       "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
       "{ADDITIONAL_CONDITIONS} ");
 
   return NS_OK;
 }
 
@@ -2126,21 +2122,20 @@ nsNavHistory::ConstructQueryString(
   if (IsOptimizableHistoryQuery(aQueries, aOptions,
         nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING) ||
       IsOptimizableHistoryQuery(aQueries, aOptions,
         nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING)) {
     // Generate an optimized query for the history menu and most visited
     // smart bookmark.
     queryString = NS_LITERAL_CSTRING(
       "SELECT h.id, h.url, h.title AS page_title, h.rev_host, h.visit_count, h.last_visit_date, "
-          "f.url, null, null, null, null, ") +
+          "null, null, null, null, null, ") +
           tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
           "null, null, null "
         "FROM moz_places h "
-        "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
         "WHERE h.hidden = 0 "
           "AND EXISTS (SELECT id FROM moz_historyvisits WHERE place_id = h.id "
                        "AND visit_type NOT IN ") +
                        nsPrintfCString("(0,%d,%d) ",
                                        nsINavHistoryService::TRANSITION_EMBED,
                                        nsINavHistoryService::TRANSITION_FRAMED_LINK) +
                        NS_LITERAL_CSTRING("LIMIT 1) "
           "{QUERY_OPTIONS} "
@@ -3792,21 +3787,16 @@ nsNavHistory::RowToResult(mozIStorageVal
   // title
   nsAutoCString title;
   rv = aRow->GetUTF8String(kGetInfoIndex_Title, title);
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t accessCount = aRow->AsInt32(kGetInfoIndex_VisitCount);
   PRTime time = aRow->AsInt64(kGetInfoIndex_VisitDate);
 
-  // favicon
-  nsAutoCString favicon;
-  rv = aRow->GetUTF8String(kGetInfoIndex_FaviconURL, favicon);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   // itemId
   int64_t itemId = aRow->AsInt64(kGetInfoIndex_ItemId);
   int64_t parentId = -1;
   if (itemId == 0) {
     // This is not a bookmark.  For non-bookmarks we use a -1 itemId value.
     // Notice ids in sqlite tables start from 1, so itemId cannot ever be 0.
     itemId = -1;
   }
@@ -3837,17 +3827,17 @@ nsNavHistory::RowToResult(mozIStorageVal
 
     nsAutoCString guid;
     if (itemId != -1) {
       rv = aRow->GetUTF8String(nsNavBookmarks::kGetChildrenIndex_Guid, guid);
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
     RefPtr<nsNavHistoryResultNode> resultNode;
-    rv = QueryRowToResult(itemId, guid, url, title, accessCount, time, favicon,
+    rv = QueryRowToResult(itemId, guid, url, title, accessCount, time,
                           getter_AddRefs(resultNode));
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (itemId != -1 ||
         aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_TAG_QUERY) {
       // RESULTS_AS_TAG_QUERY has date columns
       resultNode->mDateAdded = aRow->AsInt64(kGetInfoIndex_ItemDateAdded);
       resultNode->mLastModified = aRow->AsInt64(kGetInfoIndex_ItemLastModified);
@@ -3859,17 +3849,17 @@ nsNavHistory::RowToResult(mozIStorageVal
       }
     }
 
     resultNode.forget(aResult);
     return rv;
   } else if (aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_URI ||
              aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS) {
     RefPtr<nsNavHistoryResultNode> resultNode =
-      new nsNavHistoryResultNode(url, title, accessCount, time, favicon);
+      new nsNavHistoryResultNode(url, title, accessCount, time);
 
     if (itemId != -1) {
       resultNode->mItemId = itemId;
       resultNode->mFolderId = parentId;
       resultNode->mDateAdded = aRow->AsInt64(kGetInfoIndex_ItemDateAdded);
       resultNode->mLastModified = aRow->AsInt64(kGetInfoIndex_ItemLastModified);
 
       rv = aRow->GetUTF8String(nsNavBookmarks::kGetChildrenIndex_Guid,
@@ -3891,17 +3881,17 @@ nsNavHistory::RowToResult(mozIStorageVal
     NS_ENSURE_SUCCESS(rv, rv);
 
     resultNode.forget(aResult);
     return NS_OK;
   }
 
   if (aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_VISIT) {
     RefPtr<nsNavHistoryResultNode> resultNode =
-      new nsNavHistoryResultNode(url, title, accessCount, time, favicon);
+      new nsNavHistoryResultNode(url, title, accessCount, time);
 
     nsAutoString tags;
     rv = aRow->GetString(kGetInfoIndex_ItemTags, tags);
     if (!tags.IsVoid())
       resultNode->mTags.Assign(tags);
 
     rv = aRow->GetUTF8String(kGetInfoIndex_Guid, resultNode->mPageGuid);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -3932,18 +3922,18 @@ nsNavHistory::RowToResult(mozIStorageVal
 //    Called by RowToResult when the URI is a place: URI to generate the proper
 //    folder or query node.
 
 nsresult
 nsNavHistory::QueryRowToResult(int64_t itemId,
                                const nsACString& aBookmarkGuid,
                                const nsACString& aURI,
                                const nsACString& aTitle,
-                               uint32_t aAccessCount, PRTime aTime,
-                               const nsACString& aFavicon,
+                               uint32_t aAccessCount,
+                               PRTime aTime,
                                nsNavHistoryResultNode** aNode)
 {
   MOZ_ASSERT((itemId != -1 && !aBookmarkGuid.IsEmpty()) ||
              (itemId == -1 && aBookmarkGuid.IsEmpty()));
 
   nsCOMArray<nsNavHistoryQuery> queries;
   nsCOMPtr<nsNavHistoryQueryOptions> options;
   nsresult rv = QueryStringToQueryArray(aURI, &queries,
@@ -3976,28 +3966,27 @@ nsNavHistory::QueryRowToResult(int64_t i
         // concrete folder title).
         if (!aTitle.IsVoid()) {
           resultNode->mTitle = aTitle;
         }
       }
     }
     else {
       // This is a regular query.
-      resultNode = new nsNavHistoryQueryResultNode(aTitle, EmptyCString(),
-                                                   aTime, queries, options);
+      resultNode = new nsNavHistoryQueryResultNode(aTitle, aTime, queries, options);
       resultNode->mItemId = itemId;
     }
   }
 
   if (NS_FAILED(rv)) {
     NS_WARNING("Generating a generic empty node for a broken query!");
     // This is a broken query, that either did not parse or points to not
     // existing data.  We don't want to return failure since that will kill the
     // whole result.  Instead make a generic empty query node.
-    resultNode = new nsNavHistoryQueryResultNode(aTitle, aFavicon, aURI);
+    resultNode = new nsNavHistoryQueryResultNode(aTitle, aURI);
     resultNode->mItemId = itemId;
     // This is a perf hack to generate an empty query that skips filtering.
     resultNode->GetAsQuery()->Options()->SetExcludeItems(true);
   }
 
   resultNode.forget(aNode);
   return NS_OK;
 }
@@ -4021,37 +4010,35 @@ nsNavHistory::VisitIdToResultNode(int64_
   switch (aOptions->ResultType())
   {
     case nsNavHistoryQueryOptions::RESULTS_AS_VISIT:
     case nsNavHistoryQueryOptions::RESULTS_AS_FULL_VISIT:
       // visit query - want exact visit time
       // Should match kGetInfoIndex_* (see GetQueryResults)
       statement = mDB->GetStatement(NS_LITERAL_CSTRING(
         "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
-               "v.visit_date, f.url, null, null, null, null, "
+               "v.visit_date, null, null, null, null, null, "
                ) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
               "v.id, v.from_visit, v.visit_type "
         "FROM moz_places h "
         "JOIN moz_historyvisits v ON h.id = v.place_id "
-        "LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
         "WHERE v.id = :visit_id ")
       );
       break;
 
     case nsNavHistoryQueryOptions::RESULTS_AS_URI:
       // URL results - want last visit time
       // Should match kGetInfoIndex_* (see GetQueryResults)
       statement = mDB->GetStatement(NS_LITERAL_CSTRING(
         "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
-               "h.last_visit_date, f.url, null, null, null, null, "
+               "h.last_visit_date, null, null, null, null, null, "
                ) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
               "null, null, null "
         "FROM moz_places h "
         "JOIN moz_historyvisits v ON h.id = v.place_id "
-        "LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
         "WHERE v.id = :visit_id ")
       );
       break;
 
     default:
       // Query base types like RESULTS_AS_*_QUERY handle additions
       // by registering their own observers when they are expanded.
       return NS_OK;
@@ -4082,23 +4069,22 @@ nsNavHistory::BookmarkIdToResultNode(int
                                      nsNavHistoryResultNode** aResult)
 {
   nsAutoCString tagsFragment;
   GetTagsSqlFragment(GetTagsFolder(), NS_LITERAL_CSTRING("h.id"),
                      true, tagsFragment);
   // Should match kGetInfoIndex_*
   nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(NS_LITERAL_CSTRING(
       "SELECT b.fk, h.url, COALESCE(b.title, h.title), "
-             "h.rev_host, h.visit_count, h.last_visit_date, f.url, b.id, "
+             "h.rev_host, h.visit_count, h.last_visit_date, null, b.id, "
              "b.dateAdded, b.lastModified, b.parent, "
              ) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
              "null, null, null, b.guid, b.position, b.type, b.fk "
       "FROM moz_bookmarks b "
       "JOIN moz_places h ON b.fk = h.id "
-      "LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
       "WHERE b.id = :item_id ")
   );
   NS_ENSURE_STATE(stmt);
   mozStorageStatementScoper scoper(stmt);
 
   nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"),
                                       aBookmarkId);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -4123,23 +4109,22 @@ nsNavHistory::URIToResultNode(nsIURI* aU
                               nsNavHistoryResultNode** aResult)
 {
   nsAutoCString tagsFragment;
   GetTagsSqlFragment(GetTagsFolder(), NS_LITERAL_CSTRING("h.id"),
                      true, tagsFragment);
   // Should match kGetInfoIndex_*
   nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(NS_LITERAL_CSTRING(
     "SELECT h.id, :page_url, COALESCE(b.title, h.title), "
-           "h.rev_host, h.visit_count, h.last_visit_date, f.url, "
+           "h.rev_host, h.visit_count, h.last_visit_date, null, "
            "b.id, b.dateAdded, b.lastModified, b.parent, "
            ) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
            "null, null, null, b.guid, b.position, b.type, b.fk "
     "FROM moz_places h "
     "LEFT JOIN moz_bookmarks b ON b.fk = h.id "
-    "LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
     "WHERE h.url_hash = hash(:page_url) AND h.url = :page_url ")
   );
   NS_ENSURE_STATE(stmt);
   mozStorageStatementScoper scoper(stmt);
 
   nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/toolkit/components/places/nsNavHistory.h
+++ b/toolkit/components/places/nsNavHistory.h
@@ -253,18 +253,18 @@ public:
   // The row must contain the full set of columns.
   nsresult RowToResult(mozIStorageValueArray* aRow,
                        nsNavHistoryQueryOptions* aOptions,
                        nsNavHistoryResultNode** aResult);
   nsresult QueryRowToResult(int64_t aItemId,
                             const nsACString& aBookmarkGuid,
                             const nsACString& aURI,
                             const nsACString& aTitle,
-                            uint32_t aAccessCount, PRTime aTime,
-                            const nsACString& aFavicon,
+                            uint32_t aAccessCount,
+                            PRTime aTime,
                             nsNavHistoryResultNode** aNode);
 
   nsresult VisitIdToResultNode(int64_t visitId,
                                nsNavHistoryQueryOptions* aOptions,
                                nsNavHistoryResultNode** aResult);
 
   nsresult BookmarkIdToResultNode(int64_t aBookmarkId,
                                   nsNavHistoryQueryOptions* aOptions,
--- a/toolkit/components/places/nsNavHistoryResult.cpp
+++ b/toolkit/components/places/nsNavHistoryResult.cpp
@@ -83,24 +83,23 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY(nsINavHistoryResultNode)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNavHistoryResultNode)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNavHistoryResultNode)
 
 nsNavHistoryResultNode::nsNavHistoryResultNode(
     const nsACString& aURI, const nsACString& aTitle, uint32_t aAccessCount,
-    PRTime aTime, const nsACString& aIconURI) :
+    PRTime aTime) :
   mParent(nullptr),
   mURI(aURI),
   mTitle(aTitle),
   mAreTagsSorted(false),
   mAccessCount(aAccessCount),
   mTime(aTime),
-  mFaviconURI(aIconURI),
   mBookmarkIndex(-1),
   mItemId(-1),
   mFolderId(-1),
   mVisitId(-1),
   mFromVisitId(-1),
   mDateAdded(0),
   mLastModified(0),
   mIndentLevel(-1),
@@ -110,24 +109,23 @@ nsNavHistoryResultNode::nsNavHistoryResu
 {
   mTags.SetIsVoid(true);
 }
 
 
 NS_IMETHODIMP
 nsNavHistoryResultNode::GetIcon(nsACString& aIcon)
 {
-  if (mFaviconURI.IsEmpty()) {
-    aIcon.Truncate();
+  if (this->IsContainer() || mURI.IsEmpty()) {
     return NS_OK;
   }
 
-  nsFaviconService* faviconService = nsFaviconService::GetFaviconService();
-  NS_ENSURE_TRUE(faviconService, NS_ERROR_OUT_OF_MEMORY);
-  faviconService->GetFaviconSpecForIconString(mFaviconURI, aIcon);
+  aIcon.AppendLiteral("page-icon:");
+  aIcon.Append(mURI);
+
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsNavHistoryResultNode::GetParent(nsINavHistoryContainerResultNode** aParent)
 {
   NS_IF_ADDREF(*aParent = mParent);
@@ -340,34 +338,32 @@ NS_IMPL_ADDREF_INHERITED(nsNavHistoryCon
 NS_IMPL_RELEASE_INHERITED(nsNavHistoryContainerResultNode, nsNavHistoryResultNode)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsNavHistoryContainerResultNode)
   NS_INTERFACE_MAP_STATIC_AMBIGUOUS(nsNavHistoryContainerResultNode)
   NS_INTERFACE_MAP_ENTRY(nsINavHistoryContainerResultNode)
 NS_INTERFACE_MAP_END_INHERITING(nsNavHistoryResultNode)
 
 nsNavHistoryContainerResultNode::nsNavHistoryContainerResultNode(
-    const nsACString& aURI, const nsACString& aTitle,
-    const nsACString& aIconURI, uint32_t aContainerType,
+    const nsACString& aURI, const nsACString& aTitle, uint32_t aContainerType,
     nsNavHistoryQueryOptions* aOptions) :
-  nsNavHistoryResultNode(aURI, aTitle, 0, 0, aIconURI),
+  nsNavHistoryResultNode(aURI, aTitle, 0, 0),
   mResult(nullptr),
   mContainerType(aContainerType),
   mExpanded(false),
   mOptions(aOptions),
   mAsyncCanceledState(NOT_CANCELED)
 {
 }
 
 nsNavHistoryContainerResultNode::nsNavHistoryContainerResultNode(
     const nsACString& aURI, const nsACString& aTitle,
-    PRTime aTime,
-    const nsACString& aIconURI, uint32_t aContainerType,
+    PRTime aTime, uint32_t aContainerType,
     nsNavHistoryQueryOptions* aOptions) :
-  nsNavHistoryResultNode(aURI, aTitle, 0, aTime, aIconURI),
+  nsNavHistoryResultNode(aURI, aTitle, 0, aTime),
   mResult(nullptr),
   mContainerType(aContainerType),
   mExpanded(false),
   mOptions(aOptions),
   mAsyncCanceledState(NOT_CANCELED)
 {
 }
 
@@ -1758,33 +1754,31 @@ nsNavHistoryContainerResultNode::FindNod
  * a message without doing a requery.  For complex changes or complex queries,
  * we give up and requery.
  */
 NS_IMPL_ISUPPORTS_INHERITED(nsNavHistoryQueryResultNode,
                             nsNavHistoryContainerResultNode,
                             nsINavHistoryQueryResultNode)
 
 nsNavHistoryQueryResultNode::nsNavHistoryQueryResultNode(
-    const nsACString& aTitle, const nsACString& aIconURI,
-    const nsACString& aQueryURI) :
-  nsNavHistoryContainerResultNode(aQueryURI, aTitle, aIconURI,
+    const nsACString& aTitle, const nsACString& aQueryURI) :
+  nsNavHistoryContainerResultNode(aQueryURI, aTitle,
                                   nsNavHistoryResultNode::RESULT_TYPE_QUERY,
                                   nullptr),
   mLiveUpdate(QUERYUPDATE_COMPLEX_WITH_BOOKMARKS),
   mHasSearchTerms(false),
   mContentsValid(false),
   mBatchChanges(0)
 {
 }
 
 nsNavHistoryQueryResultNode::nsNavHistoryQueryResultNode(
-    const nsACString& aTitle, const nsACString& aIconURI,
-    const nsCOMArray<nsNavHistoryQuery>& aQueries,
+    const nsACString& aTitle, const nsCOMArray<nsNavHistoryQuery>& aQueries,
     nsNavHistoryQueryOptions* aOptions) :
-  nsNavHistoryContainerResultNode(EmptyCString(), aTitle, aIconURI,
+  nsNavHistoryContainerResultNode(EmptyCString(), aTitle,
                                   nsNavHistoryResultNode::RESULT_TYPE_QUERY,
                                   aOptions),
   mQueries(aQueries),
   mContentsValid(false),
   mBatchChanges(0),
   mTransitions(mQueries[0]->Transitions())
 {
   NS_ASSERTION(aQueries.Count() > 0, "Must have at least one query");
@@ -1803,21 +1797,21 @@ nsNavHistoryQueryResultNode::nsNavHistor
       uint32_t transition = mTransitions.SafeElementAt(j, 0);
       if (transition && !queryTransitions.Contains(transition))
         mTransitions.RemoveElement(transition);
     }
   }
 }
 
 nsNavHistoryQueryResultNode::nsNavHistoryQueryResultNode(
-    const nsACString& aTitle, const nsACString& aIconURI,
+    const nsACString& aTitle,
     PRTime aTime,
     const nsCOMArray<nsNavHistoryQuery>& aQueries,
     nsNavHistoryQueryOptions* aOptions) :
-  nsNavHistoryContainerResultNode(EmptyCString(), aTitle, aTime, aIconURI,
+  nsNavHistoryContainerResultNode(EmptyCString(), aTitle, aTime,
                                   nsNavHistoryResultNode::RESULT_TYPE_QUERY,
                                   aOptions),
   mQueries(aQueries),
   mContentsValid(false),
   mBatchChanges(0),
   mTransitions(mQueries[0]->Transitions())
 {
   NS_ASSERTION(aQueries.Count() > 0, "Must have at least one query");
@@ -2710,22 +2704,19 @@ nsNavHistoryQueryResultNode::OnClearHist
 {
   nsresult rv = Refresh();
   NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 
 static nsresult setFaviconCallback(nsNavHistoryResultNode* aNode,
-                                   const void* aClosure,
+                                   const void * aClosure,
                                    const nsNavHistoryResult* aResult)
 {
-  const nsCString* newFavicon = static_cast<const nsCString*>(aClosure);
-  aNode->mFaviconURI = *newFavicon;
-
   if (aResult && (!aNode->mParent || aNode->mParent->AreChildrenVisible()))
     NOTIFY_RESULT_OBSERVERS(aResult, NodeIconChanged(aNode));
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
@@ -2735,23 +2726,22 @@ nsNavHistoryQueryResultNode::OnPageChang
                                            const nsACString& aGUID)
 {
   nsAutoCString spec;
   nsresult rv = aURI->GetSpec(spec);
   NS_ENSURE_SUCCESS(rv, rv);
 
   switch (aChangedAttribute) {
     case nsINavHistoryObserver::ATTRIBUTE_FAVICON: {
-      NS_ConvertUTF16toUTF8 newFavicon(aNewValue);
       bool onlyOneEntry = (mOptions->ResultType() ==
                              nsINavHistoryQueryOptions::RESULTS_AS_URI ||
                              mOptions->ResultType() ==
                              nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS);
       UpdateURIs(true, onlyOneEntry, false, spec, setFaviconCallback,
-                 &newFavicon);
+                 nullptr);
       break;
     }
     default:
       NS_WARNING("Unknown page changed notification");
   }
   return NS_OK;
 }
 
@@ -3026,17 +3016,17 @@ nsNavHistoryQueryResultNode::OnItemMoved
 NS_IMPL_ISUPPORTS_INHERITED(nsNavHistoryFolderResultNode,
                             nsNavHistoryContainerResultNode,
                             nsINavHistoryQueryResultNode,
                             mozIStorageStatementCallback)
 
 nsNavHistoryFolderResultNode::nsNavHistoryFolderResultNode(
     const nsACString& aTitle, nsNavHistoryQueryOptions* aOptions,
     int64_t aFolderId) :
-  nsNavHistoryContainerResultNode(EmptyCString(), aTitle, EmptyCString(),
+  nsNavHistoryContainerResultNode(EmptyCString(), aTitle,
                                   nsNavHistoryResultNode::RESULT_TYPE_FOLDER,
                                   aOptions),
   mContentsValid(false),
   mTargetFolderItemId(aFolderId),
   mIsRegisteredFolderObserver(false)
 {
   mItemId = aFolderId;
 }
@@ -3761,17 +3751,16 @@ nsNavHistoryResultNode::OnItemChanged(in
   else if (aProperty.EqualsLiteral("uri")) {
     // clear the tags string as well
     mTags.SetIsVoid(true);
     mURI = aNewValue;
     if (shouldNotify)
       NOTIFY_RESULT_OBSERVERS(result, NodeURIChanged(this, mURI));
   }
   else if (aProperty.EqualsLiteral("favicon")) {
-    mFaviconURI = aNewValue;
     if (shouldNotify)
       NOTIFY_RESULT_OBSERVERS(result, NodeIconChanged(this));
   }
   else if (aProperty.EqualsLiteral("cleartime")) {
     mTime = 0;
     if (shouldNotify) {
       NOTIFY_RESULT_OBSERVERS(result,
                               NodeHistoryDetailsChanged(this, 0, mAccessCount));
@@ -4002,17 +3991,17 @@ nsNavHistoryFolderResultNode::OnItemMove
 }
 
 
 /**
  * Separator nodes do not hold any data.
  */
 nsNavHistorySeparatorResultNode::nsNavHistorySeparatorResultNode()
   : nsNavHistoryResultNode(EmptyCString(), EmptyCString(),
-                           0, 0, EmptyCString())
+                           0, 0)
 {
 }
 
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsNavHistoryResult)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsNavHistoryResult)
   tmp->StopObserving();
--- a/toolkit/components/places/nsNavHistoryResult.h
+++ b/toolkit/components/places/nsNavHistoryResult.h
@@ -252,18 +252,17 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsNavHisto
     { return nsNavHistoryResultNode::GetFromVisitId(aFromVisitId); } \
   NS_IMETHOD GetVisitType(uint32_t* aVisitType) override \
     { return nsNavHistoryResultNode::GetVisitType(aVisitType); }
 
 class nsNavHistoryResultNode : public nsINavHistoryResultNode
 {
 public:
   nsNavHistoryResultNode(const nsACString& aURI, const nsACString& aTitle,
-                         uint32_t aAccessCount, PRTime aTime,
-                         const nsACString& aIconURI);
+                         uint32_t aAccessCount, PRTime aTime);
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_NAVHISTORYRESULTNODE_IID)
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(nsNavHistoryResultNode)
 
   NS_IMPLEMENT_SIMPLE_RESULTNODE
   NS_IMETHOD GetIcon(nsACString& aIcon) override;
@@ -362,17 +361,16 @@ public:
 
   RefPtr<nsNavHistoryContainerResultNode> mParent;
   nsCString mURI; // not necessarily valid for containers, call GetUri
   nsCString mTitle;
   nsString mTags;
   bool mAreTagsSorted;
   uint32_t mAccessCount;
   int64_t mTime;
-  nsCString mFaviconURI;
   int32_t mBookmarkIndex;
   int64_t mItemId;
   int64_t mFolderId;
   int64_t mVisitId;
   int64_t mFromVisitId;
   PRTime mDateAdded;
   PRTime mLastModified;
 
@@ -431,23 +429,20 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsNavHisto
   { 0x6e3bf8d3, 0x22aa, 0x4065, { 0x86, 0xbc, 0x37, 0x46, 0xb5, 0xb3, 0x2c, 0xe8 } }
 
 class nsNavHistoryContainerResultNode : public nsNavHistoryResultNode,
                                         public nsINavHistoryContainerResultNode
 {
 public:
   nsNavHistoryContainerResultNode(
     const nsACString& aURI, const nsACString& aTitle,
-    const nsACString& aIconURI, uint32_t aContainerType,
-    nsNavHistoryQueryOptions* aOptions);
+    uint32_t aContainerType, nsNavHistoryQueryOptions* aOptions);
   nsNavHistoryContainerResultNode(
     const nsACString& aURI, const nsACString& aTitle,
-    PRTime aTime,
-    const nsACString& aIconURI, uint32_t aContainerType,
-    nsNavHistoryQueryOptions* aOptions);
+    PRTime aTime, uint32_t aContainerType, nsNavHistoryQueryOptions* aOptions);
 
   virtual nsresult Refresh();
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_NAVHISTORYCONTAINERRESULTNODE_IID)
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsNavHistoryContainerResultNode, nsNavHistoryResultNode)
   NS_FORWARD_COMMON_RESULTNODE_TO_BASE
@@ -620,24 +615,21 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsNavHisto
 //    bookmark notifications.
 
 class nsNavHistoryQueryResultNode final : public nsNavHistoryContainerResultNode,
                                           public nsINavHistoryQueryResultNode,
                                           public nsINavBookmarkObserver
 {
 public:
   nsNavHistoryQueryResultNode(const nsACString& aTitle,
-                              const nsACString& aIconURI,
                               const nsACString& aQueryURI);
   nsNavHistoryQueryResultNode(const nsACString& aTitle,
-                              const nsACString& aIconURI,
                               const nsCOMArray<nsNavHistoryQuery>& aQueries,
                               nsNavHistoryQueryOptions* aOptions);
   nsNavHistoryQueryResultNode(const nsACString& aTitle,
-                              const nsACString& aIconURI,
                               PRTime aTime,
                               const nsCOMArray<nsNavHistoryQuery>& aQueries,
                               nsNavHistoryQueryOptions* aOptions);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_FORWARD_COMMON_RESULTNODE_TO_BASE
   NS_IMETHOD GetType(uint32_t* type) override
     { *type = nsNavHistoryResultNode::RESULT_TYPE_QUERY; return NS_OK; }
--- a/toolkit/components/places/nsPlacesExpiration.js
+++ b/toolkit/components/places/nsPlacesExpiration.js
@@ -264,25 +264,34 @@ const EXPIRATION_QUERIES = {
   // (see nsPlacesTriggers.h).
   QUERY_UPDATE_HOSTS: {
     sql: `DELETE FROM moz_updatehosts_temp`,
     actions: ACTION.CLEAR_HISTORY | ACTION.TIMED | ACTION.TIMED_OVERLIMIT |
              ACTION.SHUTDOWN_DIRTY | ACTION.IDLE_DIRTY | ACTION.IDLE_DAILY |
              ACTION.DEBUG
   },
 
+  // Expire orphan pages from the icons database.
+  QUERY_EXPIRE_FAVICONS_PAGES: {
+    sql: `DELETE FROM moz_pages_w_icons
+          WHERE page_url_hash NOT IN (
+            SELECT url_hash FROM moz_places
+          )`,
+    actions: ACTION.TIMED_OVERLIMIT | ACTION.CLEAR_HISTORY |
+             ACTION.SHUTDOWN_DIRTY | ACTION.IDLE_DIRTY | ACTION.IDLE_DAILY |
+             ACTION.DEBUG
+  },
+
   // Expire orphan icons from the database.
   QUERY_EXPIRE_FAVICONS: {
-    sql: `DELETE FROM moz_favicons WHERE id IN (
-            SELECT f.id FROM moz_favicons f
-            LEFT JOIN moz_places h ON f.id = h.favicon_id
-            WHERE h.favicon_id IS NULL
-            LIMIT :limit_favicons
+    sql: `DELETE FROM moz_icons
+          WHERE id NOT IN (
+            SELECT icon_id FROM moz_icons_to_pages
           )`,
-    actions: ACTION.TIMED | ACTION.TIMED_OVERLIMIT | ACTION.CLEAR_HISTORY |
+    actions: ACTION.TIMED_OVERLIMIT | ACTION.CLEAR_HISTORY |
              ACTION.SHUTDOWN_DIRTY | ACTION.IDLE_DIRTY | ACTION.IDLE_DAILY |
              ACTION.DEBUG
   },
 
   // Expire orphan page annotations from the database.
   QUERY_EXPIRE_ANNOS: {
     sql: `DELETE FROM moz_annos WHERE id in (
             SELECT a.id FROM moz_annos a
@@ -991,19 +1000,16 @@ nsPlacesExpiration.prototype = {
           aLimit == LIMIT.DEBUG && baseLimit == -1 ? 0 : baseLimit;
         break;
       case "QUERY_FIND_URIS_TO_EXPIRE":
         params.limit_uris = baseLimit;
         break;
       case "QUERY_SILENT_EXPIRE_ORPHAN_URIS":
         params.limit_uris = baseLimit;
         break;
-      case "QUERY_EXPIRE_FAVICONS":
-        params.limit_favicons = baseLimit;
-        break;
       case "QUERY_EXPIRE_ANNOS":
         // Each page may have multiple annos.
         params.limit_annos = baseLimit * EXPIRE_AGGRESSIVITY_MULTIPLIER;
         break;
       case "QUERY_EXPIRE_ANNOS_WITH_POLICY":
       case "QUERY_EXPIRE_ITEMS_ANNOS_WITH_POLICY":
         let microNow = Date.now() * 1000;
         ANNOS_EXPIRE_POLICIES.forEach(function(policy) {
--- a/toolkit/components/places/tests/browser/browser_favicon_setAndFetchFaviconForPage_failures.js
+++ b/toolkit/components/places/tests/browser/browser_favicon_setAndFetchFaviconForPage_failures.js
@@ -33,29 +33,29 @@ function test() {
   // This function is called after calling finish() on the test.
   registerCleanupFunction(function() {
     windowsToClose.forEach(function(aWin) {
       aWin.close();
     });
   });
 
   function checkFavIconsDBCount(aCallback) {
-    let stmt = DBConn().createAsyncStatement("SELECT url FROM moz_favicons");
+    let stmt = DBConn().createAsyncStatement("SELECT icon_url FROM moz_icons");
     stmt.executeAsync({
       handleResult: function final_handleResult(aResultSet) {
         while (aResultSet.getNextRow()) {
           favIconsResultCount++;
         }
       },
       handleError: function final_handleError(aError) {
         throw ("Unexpected error (" + aError.result + "): " + aError.message);
       },
       handleCompletion: function final_handleCompletion(aReason) {
         // begin testing
-        info("Previous records in moz_favicons: " + favIconsResultCount);
+        info("Previous records in moz_icons: " + favIconsResultCount);
         if (aCallback) {
           aCallback();
         }
       }
     });
     stmt.finalize();
   }
 
@@ -168,21 +168,21 @@ function test() {
 
   function testFinalVerification(aWindow, aCallback) {
     // Only the last test should raise the onPageChanged notification,
     // executing the waitForFaviconChanged callback.
     waitForFaviconChanged(lastPageURI, favIcon32URI, aWindow,
       function final_callback() {
         // Check that only one record corresponding to the last favicon is present.
         let resultCount = 0;
-        let stmt = DBConn().createAsyncStatement("SELECT url FROM moz_favicons");
+        let stmt = DBConn().createAsyncStatement("SELECT icon_url FROM moz_icons");
         stmt.executeAsync({
           handleResult: function final_handleResult(aResultSet) {
 
-            // If the moz_favicons DB had been previously loaded (before our
+            // If the moz_icons DB had been previously loaded (before our
             // test began), we should focus only in the URI we are testing and
             // skip the URIs not related to our test.
             if (favIconsResultCount > 0) {
               for (let row; (row = aResultSet.getNextRow()); ) {
                 if (favIcon32URI.spec === row.getResultByIndex(0)) {
                   is(favIcon32URI.spec, row.getResultByIndex(0),
                     "Check equal favicons");
                   resultCount++;
--- a/toolkit/components/places/tests/chrome/chrome.ini
+++ b/toolkit/components/places/tests/chrome/chrome.ini
@@ -1,12 +1,13 @@
 [DEFAULT]
+support-files = head.js
 
 [test_303567.xul]
 [test_341972a.xul]
 [test_341972b.xul]
 [test_342484.xul]
 [test_371798.xul]
 [test_381357.xul]
 [test_favicon_annotations.xul]
 [test_reloadLivemarks.xul]
 [test_browser_disableglobalhistory.xul]
-support-files = browser_disableglobalhistory.xul
\ No newline at end of file
+support-files = browser_disableglobalhistory.xul
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/chrome/head.js
@@ -0,0 +1,10 @@
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
+  "resource://testing-common/PlacesTestUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+  "resource://gre/modules/PlacesUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+  "resource://gre/modules/Task.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
+  "resource://gre/modules/NetUtil.jsm");
--- a/toolkit/components/places/tests/chrome/test_favicon_annotations.xul
+++ b/toolkit/components/places/tests/chrome/test_favicon_annotations.xul
@@ -12,153 +12,127 @@
         onload="test();">
 
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"/>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+  <script type="application/javascript" src="head.js" />
 
   <script type="application/javascript">
   <![CDATA[
 
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 var Cr = Components.results;
 
-let fs = Cc["@mozilla.org/browser/favicon-service;1"].
-         getService(Ci.nsIFaviconService);
-
-// Test descriptions that will be printed in the case of failure.
-let testDescriptions = [
-  "moz-anno URI with no data in the database loads default icon",
-  "URI added to the database is properly loaded",
-];
+let tests = [
+  {
+    desc: "moz-anno URI with no data in the database loads default icon",
+    url: "http://mozilla.org/2009/made-up-favicon/places-rocks/",
+    expectedIcon: PlacesUtils.favicons.defaultFavicon.spec,
+  },
+  {
+    desc: "URI added to the database is properly loaded",
+    url: "http://mozilla.org/should-be-barney/",
+    expectedIcon: "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%06%00%00%00%1F%F3%FFa%00%00%00%04gAMA%00%00%AF%C87%05%8A%E9%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%01%D6IDATx%DAb%FC%FF%FF%3F%03%25%00%20%80%98%909%EF%DF%BFg%EF%EC%EC%FC%AD%AC%AC%FC%DF%95%91%F1%BF%89%89%C9%7F%20%FF%D7%EA%D5%AB%B7%DF%BBwO%16%9B%01%00%01%C4%00r%01%08%9F9s%C6%CD%D8%D8%F8%BF%0B%03%C3%FF3%40%BC%0A%88%EF%02q%1A%10%BB%40%F1%AAU%ABv%C1%D4%C30%40%00%81%89%993g%3E%06%1A%F6%3F%14%AA%11D%97%03%F1%7Fc%08%0D%E2%2B))%FD%17%04%89%A1%19%00%10%40%0C%D00%F8%0F3%00%C8%F8%BF%1B%E4%0Ac%88a%E5%60%17%19%FF%0F%0D%0D%05%1B%02v%D9%DD%BB%0A0%03%00%02%08%AC%B9%A3%A3%E3%17%03%D4v%90%01%EF%18%106%C3%0Cz%07%C5%BB%A1%DE%82y%07%20%80%A0%A6%08B%FCn%0C1%60%26%D4%20d%C3VA%C3%06%26%BE%0A%EA-%80%00%82%B9%E0%F7L4%0D%EF%90%F8%C6%60%2F%0A%82%BD%01%13%07%0700%D0%01%02%88%11%E4%02P%B41%DC%BB%C7%D0%014%0D%E8l%06W%20%06%BA%88%A1%1C%1AS%15%40%7C%16%CA6.%2Fgx%BFg%0F%83%CB%D9%B3%0C%7B%80%7C%80%00%02%BB%00%E8%9F%ED%20%1B%3A%A0%A6%9F%81%DA%DC%01%C5%B0%80%ED%80%FA%BF%BC%BC%FC%3F%83%12%90%9D%96%F6%1F%20%80%18%DE%BD%7B%C7%0E%8E%05AD%20%FEGr%A6%A0%A0%E0%7F%25P%80%02%9D%0F%D28%13%18%23%C6%C0%B0%02E%3D%C8%F5%00%01%04%8F%05P%A8%BA%40my%87%E4%12c%A8%8D%20%8B%D0%D3%00%08%03%04%10%9C%01R%E4%82d%3B%C8%A0%99%C6%90%90%C6%A5%19%84%01%02%08%9E%17%80%C9x%F7%7B%A0%DBVC%F9%A0%C0%5C%7D%16%2C%CE%00%F4%C6O%5C%99%09%20%800L%04y%A5%03%1A%95%A0%80%05%05%14.%DBA%18%20%80%18)%CD%CE%00%01%06%00%0C'%94%C7%C0k%C9%2C%00%00%00%00IEND%AEB%60%82",
+  },
 
-// URIs to load (will be compared with expectedURIs of the same index).
-let testURIs = [
-  "http://mozilla.org/2009/made-up-favicon/places-rocks/",
-  "http://mozilla.org/should-be-barney/",
 ];
 
-// URIs to load for expected results.
-let expectedURIs = [
-  fs.defaultFavicon.spec,
-  "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%06%00%00%00%1F%F3%FFa%00%00%00%04gAMA%00%00%AF%C87%05%8A%E9%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%01%D6IDATx%DAb%FC%FF%FF%3F%03%25%00%20%80%98%909%EF%DF%BFg%EF%EC%EC%FC%AD%AC%AC%FC%DF%95%91%F1%BF%89%89%C9%7F%20%FF%D7%EA%D5%AB%B7%DF%BBwO%16%9B%01%00%01%C4%00r%01%08%9F9s%C6%CD%D8%D8%F8%BF%0B%03%C3%FF3%40%BC%0A%88%EF%02q%1A%10%BB%40%F1%AAU%ABv%C1%D4%C30%40%00%81%89%993g%3E%06%1A%F6%3F%14%AA%11D%97%03%F1%7Fc%08%0D%E2%2B))%FD%17%04%89%A1%19%00%10%40%0C%D00%F8%0F3%00%C8%F8%BF%1B%E4%0Ac%88a%E5%60%17%19%FF%0F%0D%0D%05%1B%02v%D9%DD%BB%0A0%03%00%02%08%AC%B9%A3%A3%E3%17%03%D4v%90%01%EF%18%106%C3%0Cz%07%C5%BB%A1%DE%82y%07%20%80%A0%A6%08B%FCn%0C1%60%26%D4%20d%C3VA%C3%06%26%BE%0A%EA-%80%00%82%B9%E0%F7L4%0D%EF%90%F8%C6%60%2F%0A%82%BD%01%13%07%0700%D0%01%02%88%11%E4%02P%B41%DC%BB%C7%D0%014%0D%E8l%06W%20%06%BA%88%A1%1C%1AS%15%40%7C%16%CA6.%2Fgx%BFg%0F%83%CB%D9%B3%0C%7B%80%7C%80%00%02%BB%00%E8%9F%ED%20%1B%3A%A0%A6%9F%81%DA%DC%01%C5%B0%80%ED%80%FA%BF%BC%BC%FC%3F%83%12%90%9D%96%F6%1F%20%80%18%DE%BD%7B%C7%0E%8E%05AD%20%FEGr%A6%A0%A0%E0%7F%25P%80%02%9D%0F%D28%13%18%23%C6%C0%B0%02E%3D%C8%F5%00%01%04%8F%05P%A8%BA%40my%87%E4%12c%A8%8D%20%8B%D0%D3%00%08%03%04%10%9C%01R%E4%82d%3B%C8%A0%99%C6%90%90%C6%A5%19%84%01%02%08%9E%17%80%C9x%F7%7B%A0%DBVC%F9%A0%C0%5C%7D%16%2C%CE%00%F4%C6O%5C%99%09%20%800L%04y%A5%03%1A%95%A0%80%05%05%14.%DBA%18%20%80%18)%CD%CE%00%01%06%00%0C'%94%C7%C0k%C9%2C%00%00%00%00IEND%AEB%60%82",
-];
-
-
 /**
  * The event listener placed on our test windows used to determine when it is
  * safe to compare the two windows.
  */
 let _results = [];
 function loadEventHandler()
 {
   _results.push(snapshotWindow(window));
-
   loadNextTest();
 }
 
 /**
  * This runs the comparison.
  */
 function compareResults(aIndex, aImage1, aImage2)
 {
   let [correct, data1, data2] = compareSnapshots(aImage1, aImage2, true);
   SimpleTest.ok(correct,
-                "Test '" + testDescriptions[aIndex] + "' matches expectations. " +
+                "Test '" + tests[aIndex].desc + "' matches expectations. " +
                 "Data from window 1 is '" + data1 + "'. " +
                 "Data from window 2 is '" + data2 + "'");
 }
 
 /**
  * Loads the next set of URIs to compare against.
  */
 let _counter = -1;
 function loadNextTest()
 {
   _counter++;
   // If we have no more tests, finish.
-  if (_counter / 2 == testDescriptions.length) {
+  if (_counter / 2 == tests.length) {
     for (let i = 0; i < _results.length; i = i + 2)
       compareResults(i / 2, _results[i], _results[i + 1]);
 
     SimpleTest.finish();
     return;
   }
 
   let nextURI = function() {
     let index = Math.floor(_counter / 2);
     if ((_counter % 2) == 0)
-      return "moz-anno:favicon:" + testURIs[index];
-    return expectedURIs[index];
+      return "moz-anno:favicon:" + tests[index].url;
+    return tests[index].expectedIcon;
   }
 
   let img = document.getElementById("favicon");
   img.setAttribute("src", nextURI());
 }
 
 function test()
 {
   SimpleTest.waitForExplicitFinish();
-  let db = Cc["@mozilla.org/browser/nav-history-service;1"].
-           getService(Ci.nsPIPlacesDatabase).
-           DBConnection;
+  Task.spawn(function* () {
+    yield PlacesTestUtils.clearHistory();
 
-  // Empty any old favicons
-  db.executeSimpleSQL("DELETE FROM moz_favicons");
-
-  let ios = Cc["@mozilla.org/network/io-service;1"].
-            getService(Ci.nsIIOService);
-  let uri = function(aSpec) {
-    return ios.newURI(aSpec);
-  };
+    info("Inserting new visit");
+    yield PlacesUtils.history.insert({
+      url: "http://example.com/favicon_annotations",
+      visits: [{
+        transition: PlacesUtils.history.TRANSITIONS.TYPED
+      }]
+    });
 
-  let pageURI = uri("http://example.com/favicon_annotations");
-  let history = Cc["@mozilla.org/browser/history;1"]
-                  .getService(Ci.mozIAsyncHistory);
-  history.updatePlaces(
-    {
-      uri: pageURI,
-      visits: [{ transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED,
-                 visitDate: Date.now() * 1000
-              }],
-    },
-    {
-      handleError: function UP_handleError() {
-        ok(false, "Unexpected error in adding visit.");
-      },
-      handleResult: function () {},
-      handleCompletion: function UP_handleCompletion() {
-        // Set the favicon data.  Note that the "moz-anno:" protocol requires
-        // the favicon to be stored in the database, but the
-        // replaceFaviconDataFromDataURL function will not save the favicon
-        // unless it is associated with a page.  Thus, we must associate the
-        // icon with a page explicitly in order for it to be visible through
-        // the protocol.
-        var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"]
-                                .createInstance(Ci.nsIPrincipal);
+    // Set the favicon data.  Note that the "moz-anno:" protocol requires
+    // the favicon to be stored in the database, but the
+    // replaceFaviconDataFromDataURL function will not save the favicon
+    // unless it is associated with a page.  Thus, we must associate the
+    // icon with a page explicitly in order for it to be visible through
+    // the protocol.
+    info("Replace favicon data");
+    var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"]
+                            .createInstance(Ci.nsIPrincipal);
+    PlacesUtils.favicons.replaceFaviconDataFromDataURL(
+      NetUtil.newURI(tests[1].url),
+      tests[1].expectedIcon,
+      (Date.now() + 86400) * 1000,
+      systemPrincipal);
+    info("Set favicon data");
+    PlacesUtils.favicons.setAndFetchFaviconForPage(
+      NetUtil.newURI("http://example.com/favicon_annotations"),
+      NetUtil.newURI(tests[1].url),
+      true, PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, null,
+      systemPrincipal);
 
-        fs.replaceFaviconDataFromDataURL(uri(testURIs[1]), expectedURIs[1],
-                                         (Date.now() + 60 * 60 * 24 * 1000) * 1000,
-                                         systemPrincipal);
-
-        fs.setAndFetchFaviconForPage(pageURI, uri(testURIs[1]), true,
-                                     fs.FAVICON_LOAD_NON_PRIVATE,
-                                     null, systemPrincipal);
-
-        // And start our test process.
-        loadNextTest();
-      }
-    }
-  );
-
-
+    // And start our test process.
+    loadNextTest();
+  }.bind(this));
 }
 
   ]]>
   </script>
 
   <body xmlns="http://www.w3.org/1999/xhtml">
     <img id="favicon" onload="loadEventHandler();"/>
     <p id="display"></p>
new file mode 100644
index 0000000000000000000000000000000000000000..e9e520cb6cf6546bd1ec021ee99741681579889a
GIT binary patch
literal 330
zc$@)B0k!^#P)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV0003INkl<ZIE}TE
zv2g=23<NJgh*$-%1=PY8*aA~U?BTNyR0s?BW>mpC;QyPF?2!T+31>LG#o<8dudB62
zN{Nt&2wH3O-gzs$-|s{OA+bp;`&py`lYR%S>kTub?7|{(l_17hBvMMa`_BL~I|1yS
zw-~Ui#HJwUOiGDG;zitA!^~KA0Q&BHfSBNA9tXhP$Luj4&4L4VWOCds`&g%g=k7Bg
zB;1{x^P`gp1e|MICc*Uycx<B9N{KkbmYLCe$K6lSHVNmuBbQn$3Q<ZK4$KU9f0=!g
zxLhuTM9!I7D~o~%v932Bw$OWjvA#{V-~Pl}EAgCs>`8x8y?0^{XYQVJ{tPgKj_}-l
c1ofZw1@I&!G(_A|qyPW_07*qoM6N<$f*u2q)Bpeg
index 9932c18fb87eb07c97aa59a7711f60d98db3cc57..c9db4979a6eb73c5b7313a7655e8ca93e00ce05d
GIT binary patch
literal 79
zc%17D@N?(olHy`uVBq!ia0vp^EFjFm1|(O0oL2{=#5`RbLpWw8CnO~N=x>w!cbFlM
cF@=X=(P`<Y(Sn;-0#z`0y85}Sb4q9e0Iwbt^8f$<
index 9f16bef4338110c5775c8e51693c5e5e3e2432d0..0d6c1b14a0306baa609f5d3545b4118a637e4e8c
GIT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sh;VarGcqxm(%9Je<?Gj_%a^MI!{F!7&*`^r
z-@bh7)~sjGo|%}LE!(%xZtK>qE7z^_OHEBZb^3I0RMf0Tj~><k`nI2ei9?}blo%w$
dg8$+R_D?SI6mVz`kOpQW22WQ%mvv4FO#txFDWL!W
--- a/toolkit/components/places/tests/favicons/test_expireAllFavicons.js
+++ b/toolkit/components/places/tests/favicons/test_expireAllFavicons.js
@@ -7,27 +7,27 @@
 const TEST_PAGE_URI = NetUtil.newURI("http://example.com/");
 const BOOKMARKED_PAGE_URI = NetUtil.newURI("http://example.com/bookmarked");
 
 add_task(function* test_expireAllFavicons() {
   // Add a visited page.
   yield PlacesTestUtils.addVisits({ uri: TEST_PAGE_URI, transition: TRANSITION_TYPED });
 
   // Set a favicon for our test page.
-  yield promiseSetIconForPage(TEST_PAGE_URI, SMALLPNG_DATA_URI);
+  yield setFaviconForPage(TEST_PAGE_URI, SMALLPNG_DATA_URI);
 
   // Add a page with a bookmark.
   yield PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.toolbarGuid,
     url: BOOKMARKED_PAGE_URI,
     title: "Test bookmark"
   });
 
   // Set a favicon for our bookmark.
-  yield promiseSetIconForPage(BOOKMARKED_PAGE_URI, SMALLPNG_DATA_URI);
+  yield setFaviconForPage(BOOKMARKED_PAGE_URI, SMALLPNG_DATA_URI);
 
   // Start expiration only after data has been saved in the database.
   let promise = promiseTopicObserved(PlacesUtils.TOPIC_FAVICONS_EXPIRED);
   PlacesUtils.favicons.expireAllFavicons();
   yield promise;
 
   // Check that the favicons for the pages we added were removed.
   yield promiseFaviconMissingForPage(TEST_PAGE_URI);
--- a/toolkit/components/places/tests/favicons/test_favicons_conversions.js
+++ b/toolkit/components/places/tests/favicons/test_favicons_conversions.js
@@ -76,19 +76,19 @@ add_test(function test_storing_a_normal_
   // 32x32 png, 344 bytes.
   // optimized: no
   checkFaviconDataConversion("favicon-normal32.png", "image/png", 344,
                              false, false, run_next_test);
 });
 
 add_test(function test_storing_a_big_16x16_icon() {
   //  in: 16x16 ico, 1406 bytes.
-  // optimized: no
+  // optimized: yes
   checkFaviconDataConversion("favicon-big16.ico", "image/x-icon", 1406,
-                             false, false, run_next_test);
+                             true, false, run_next_test);
 });
 
 add_test(function test_storing_an_oversize_4x4_icon() {
   //  in: 4x4 jpg, 4751 bytes.
   // optimized: yes
   checkFaviconDataConversion("favicon-big4.jpg", "image/jpeg", 4751,
                              true, false, run_next_test);
 });
--- a/toolkit/components/places/tests/favicons/test_replaceFaviconData.js
+++ b/toolkit/components/places/tests/favicons/test_replaceFaviconData.js
@@ -69,16 +69,17 @@ add_task(function* test_replaceFaviconDa
 
   iconsvc.replaceFaviconData(favicon.uri, favicon.data, favicon.data.length,
     favicon.mimetype);
 
   let deferSetAndFetchFavicon = Promise.defer();
   iconsvc.setAndFetchFaviconForPage(pageURI, favicon.uri, true,
     PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
     function test_replaceFaviconData_validHistoryURI_check(aURI, aDataLen, aData, aMimeType) {
+dump("GOT " + aMimeType + "\n");
       checkCallbackSucceeded(aMimeType, aData, favicon.mimetype, favicon.data);
       checkFaviconDataForPage(
         pageURI, favicon.mimetype, favicon.data,
         function test_replaceFaviconData_validHistoryURI_callback() {
           favicon.file.remove(false);
           deferSetAndFetchFavicon.resolve();
         });
     }, systemPrincipal);
@@ -185,51 +186,32 @@ add_task(function* test_replaceFaviconDa
     }, systemPrincipal);
   yield deferSetAndFetchFavicon.promise;
 
   yield PlacesTestUtils.clearHistory();
 });
 
 add_task(function* test_replaceFaviconData_badInputs() {
   do_print("test replaceFaviconData to throw on bad inputs");
-
-  let favicon = createFavicon("favicon8.png");
-
-  let ex = null;
-  try {
-    iconsvc.replaceFaviconData(
-      favicon.uri, favicon.data, favicon.data.length, "");
-  } catch (e) {
-    ex = e;
-  } finally {
-    do_check_true(!!ex);
-  }
+  let icon = createFavicon("favicon8.png");
 
-  ex = null;
-  try {
-    iconsvc.replaceFaviconData(
-      null, favicon.data, favicon.data.length, favicon.mimeType);
-  } catch (e) {
-    ex = e;
-  } finally {
-    do_check_true(!!ex);
-  }
+  Assert.throws(
+    () => iconsvc.replaceFaviconData(icon.uri, icon.data, icon.data.length, ""),
+    /NS_ERROR_ILLEGAL_VALUE/);
+  Assert.throws(
+    () => iconsvc.replaceFaviconData(icon.uri, icon.data, icon.data.length, "not-an-image"),
+    /NS_ERROR_ILLEGAL_VALUE/);
+  Assert.throws(
+    () => iconsvc.replaceFaviconData(null, icon.data, icon.data.length, icon.mimetype),
+    /NS_ERROR_ILLEGAL_VALUE/);
+  Assert.throws(
+    () => iconsvc.replaceFaviconData(icon.uri, null, 0, icon.mimetype),
+    /NS_ERROR_ILLEGAL_VALUE/);
 
-  ex = null;
-  try {
-    iconsvc.replaceFaviconData(
-      favicon.uri, null, 0, favicon.mimeType);
-  } catch (e) {
-    ex = e;
-  } finally {
-    do_check_true(!!ex);
-  }
-
-  favicon.file.remove(false);
-
+  icon.file.remove(false);
   yield PlacesTestUtils.clearHistory();
 });
 
 add_task(function* test_replaceFaviconData_twiceReplace() {
   do_print("test replaceFaviconData on multiple replacements");
 
   let pageURI = uri("http://test5.bar/");
   yield PlacesTestUtils.addVisits(pageURI);
rename from toolkit/components/places/tests/unit/test_svg_favicon.js
rename to toolkit/components/places/tests/favicons/test_svg_favicon.js
--- a/toolkit/components/places/tests/unit/test_svg_favicon.js
+++ b/toolkit/components/places/tests/favicons/test_svg_favicon.js
@@ -4,20 +4,21 @@ add_task(function* () {
   // First, add a history entry or else Places can't save a favicon.
   yield PlacesTestUtils.addVisits({
     uri: PAGEURI,
     transition: TRANSITION_LINK,
     visitDate: Date.now() * 1000
   });
 
   yield new Promise(resolve => {
-    function onSetComplete(aURI, aDataLen, aData, aMimeType) {
+    function onSetComplete(aURI, aDataLen, aData, aMimeType, aWidth) {
       equal(aURI.spec, SMALLSVG_DATA_URI.spec, "setFavicon aURI check");
       equal(aDataLen, 263, "setFavicon aDataLen check");
       equal(aMimeType, "image/svg+xml", "setFavicon aMimeType check");
+      dump(aWidth);
       resolve();
     }
 
     PlacesUtils.favicons.setAndFetchFaviconForPage(PAGEURI, SMALLSVG_DATA_URI,
                                                    false,
                                                    PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
                                                    onSetComplete,
                                                    Services.scriptSecurityManager.getSystemPrincipal());
--- a/toolkit/components/places/tests/favicons/xpcshell.ini
+++ b/toolkit/components/places/tests/favicons/xpcshell.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 head = head_favicons.js
 skip-if = toolkit == 'android'
 support-files =
   expected-favicon-big32.jpg.png
   expected-favicon-big4.jpg.png
+  expected-favicon-big16.ico.png
   expected-favicon-big48.ico.png
   expected-favicon-big64.png.png
   expected-favicon-scale160x3.jpg.png
   expected-favicon-scale3x160.jpg.png
   favicon-big16.ico
   favicon-big32.jpg
   favicon-big4.jpg
   favicon-big48.ico
@@ -22,8 +23,9 @@ support-files =
 [test_favicons_conversions.js]
 [test_getFaviconDataForPage.js]
 [test_getFaviconURLForPage.js]
 [test_moz-anno_favicon_mime_type.js]
 [test_page-icon_protocol.js]
 [test_query_result_favicon_changed_on_child.js]
 [test_replaceFaviconData.js]
 [test_replaceFaviconDataFromDataURL.js]
+[test_svg_favicon.js]
--- a/toolkit/components/places/tests/head_common.js
+++ b/toolkit/components/places/tests/head_common.js
@@ -814,33 +814,16 @@ function promiseIsURIVisited(aURI) {
 
   PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
     deferred.resolve(aIsVisited);
   });
 
   return deferred.promise;
 }
 
-/**
- * Asynchronously set the favicon associated with a page.
- * @param aPageURI
- *        The page's URI
- * @param aIconURI
- *        The URI of the favicon to be set.
- */
-function promiseSetIconForPage(aPageURI, aIconURI) {
-  let deferred = Promise.defer();
-  PlacesUtils.favicons.setAndFetchFaviconForPage(
-    aPageURI, aIconURI, true,
-    PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
-    () => { deferred.resolve(); },
-    Services.scriptSecurityManager.getSystemPrincipal());
-  return deferred.promise;
-}
-
 function checkBookmarkObject(info) {
   do_check_valid_places_guid(info.guid);
   do_check_valid_places_guid(info.parentGuid);
   Assert.ok(typeof info.index == "number", "index should be a number");
   Assert.ok(info.dateAdded.constructor.name == "Date", "dateAdded should be a Date");
   Assert.ok(info.lastModified.constructor.name == "Date", "lastModified should be a Date");
   Assert.ok(info.lastModified >= info.dateAdded, "lastModified should never be smaller than dateAdded");
   Assert.ok(typeof info.type == "number", "type should be a number");
@@ -868,8 +851,56 @@ function compareAscending(a, b) {
     return -1;
   }
   return 0;
 }
 
 function sortBy(array, prop) {
   return array.sort((a, b) => compareAscending(a[prop], b[prop]));
 }
+
+/**
+ * Asynchronously set the favicon associated with a page.
+ * @param page
+ *        The page's URL
+ * @param icon
+ *        The URL of the favicon to be set.
+ */
+function setFaviconForPage(page, icon) {
+  let pageURI = page instanceof Ci.nsIURI ? page
+                                          : NetUtil.newURI(new URL(page).href);
+  let iconURI = icon instanceof Ci.nsIURI ? icon
+                                          : NetUtil.newURI(new URL(icon).href);
+  return new Promise(resolve => {
+    PlacesUtils.favicons.setAndFetchFaviconForPage(
+      pageURI, iconURI, true,
+      PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
+      resolve,
+      Services.scriptSecurityManager.getSystemPrincipal()
+    );
+  });
+}
+
+/**
+ * Asynchronously compares contents from 2 favicon urls.
+ */
+function* compareFavicons(icon1, icon2, msg) {
+  icon1 = new URL(icon1 instanceof Ci.nsIURI ? icon1.spec : icon1);
+  icon2 = new URL(icon2 instanceof Ci.nsIURI ? icon2.spec : icon2);
+
+  function getIconData(icon) {
+    new Promise((resolve, reject) => {
+      NetUtil.asyncFetch({
+        uri: icon.href, loadUsingSystemPrincipal: true,
+        contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE_FAVICON
+      }, function(inputStream, status) {
+          if (!Components.isSuccessCode(status))
+            reject();
+          let size = inputStream.available();
+          resolve(NetUtil.readInputStreamToString(inputStream, size));
+      });
+    });
+  }
+
+  let data1 = yield getIconData(icon1);
+  let data2 = yield getIconData(icon2);
+  Assert.deepEqual(data1, data2, msg);
+}
--- a/toolkit/components/places/tests/history/test_remove.js
+++ b/toolkit/components/places/tests/history/test_remove.js
@@ -347,13 +347,16 @@ add_task(function* test_orphans() {
   PlacesUtils.favicons.setAndFetchFaviconForPage(
     uri, SMALLPNG_DATA_URI, true, PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
     null, Services.scriptSecurityManager.getSystemPrincipal());
   PlacesUtils.annotations.setPageAnnotation(uri, "test", "restval", 0,
                                             PlacesUtils.annotations.EXPIRE_NEVER);
 
   yield PlacesUtils.history.remove(uri);
   Assert.ok(!(yield PlacesTestUtils.isPageInDB(uri)), "Page should have been removed");
+
   let db = yield PlacesUtils.promiseDBConnection();
   let rows = yield db.execute(`SELECT (SELECT count(*) FROM moz_annos) +
-                                      (SELECT count(*) FROM moz_favicons) AS count`);
+                                      (SELECT count(*) FROM moz_icons) +
+                                      (SELECT count(*) FROM moz_pages_w_icons) +
+                                      (SELECT count(*) FROM moz_icons_to_pages) AS count`);
   Assert.equal(rows[0].getResultByName("count"), 0, "Should not find orphans");
 });
--- a/toolkit/components/places/tests/history/test_removeVisitsByFilter.js
+++ b/toolkit/components/places/tests/history/test_removeVisitsByFilter.js
@@ -335,11 +335,13 @@ add_task(function* test_orphans() {
   PlacesUtils.annotations.setPageAnnotation(uri, "test", "restval", 0,
                                             PlacesUtils.annotations.EXPIRE_NEVER);
 
   yield PlacesUtils.history.removeVisitsByFilter({ beginDate: new Date(1999, 9, 9, 9, 9),
                                                    endDate: new Date() });
   Assert.ok(!(yield PlacesTestUtils.isPageInDB(uri)), "Page should have been removed");
   let db = yield PlacesUtils.promiseDBConnection();
   let rows = yield db.execute(`SELECT (SELECT count(*) FROM moz_annos) +
-                                      (SELECT count(*) FROM moz_favicons) AS count`);
+                                      (SELECT count(*) FROM moz_icons) +
+                                      (SELECT count(*) FROM moz_pages_w_icons) +
+                                      (SELECT count(*) FROM moz_icons_to_pages) AS count`);
   Assert.equal(rows[0].getResultByName("count"), 0, "Should not find orphans");
 });
--- a/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
+++ b/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
@@ -19,20 +19,16 @@ Cu.import("resource://testing-common/htt
   let uri = Services.io.newFileURI(commonFile);
   Services.scriptloader.loadSubScript(uri.spec, this);
 }
 
 // Put any other stuff relative to this test folder below.
 
 const TITLE_SEARCH_ENGINE_SEPARATOR = " \u00B7\u2013\u00B7 ";
 
-function run_test() {
-  run_next_test();
-}
-
 function* cleanup() {
   Services.prefs.clearUserPref("browser.urlbar.autocomplete.enabled");
   Services.prefs.clearUserPref("browser.urlbar.autoFill");
   Services.prefs.clearUserPref("browser.urlbar.autoFill.typed");
   Services.prefs.clearUserPref("browser.urlbar.autoFill.searchEngines");
   let suggestPrefs = [
     "history",
     "bookmark",
@@ -106,17 +102,17 @@ AutoCompleteInput.prototype = {
   onTextEntered: () => false,
   onTextReverted: () => false,
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput])
 }
 
 // A helper for check_autocomplete to check a specific match against data from
 // the controller.
-function _check_autocomplete_matches(match, result) {
+function* _check_autocomplete_matches(match, result) {
   let { uri, title, tags, style } = match;
   if (tags)
     title += " \u2013 " + tags.sort().join(", ");
   if (style)
     style = style.sort();
   else
     style = ["favicon"];
 
@@ -128,18 +124,19 @@ function _check_autocomplete_matches(mat
 
   let actualStyle = result.style.split(/\s+/).sort();
   if (style)
     Assert.equal(actualStyle.toString(), style.toString(), "Match should have expected style");
   if (uri.spec.startsWith("moz-action:")) {
     Assert.ok(actualStyle.includes("action"), "moz-action results should always have 'action' in their style");
   }
 
-  if (match.icon)
-    Assert.equal(result.image, match.icon, "Match should have expected image");
+  if (match.icon) {
+    yield compareFavicons(result.image, match.icon, "Match should have the expected icon");
+  }
 
   return true;
 }
 
 function* check_autocomplete(test) {
   // At this point frecency could still be updating due to latest pages
   // updates.
   // This is not a problem in real life, but autocomplete tests should
@@ -202,17 +199,17 @@ function* check_autocomplete(test) {
         do_print("Checking first match is first autocomplete entry")
         let result = {
           value: controller.getValueAt(0),
           comment: controller.getCommentAt(0),
           style: controller.getStyleAt(0),
           image: controller.getImageAt(0),
         }
         do_print(`First match is "${result.value}", "${result.comment}"`);
-        Assert.ok(_check_autocomplete_matches(matches[0], result), "first item is correct");
+        Assert.ok(yield _check_autocomplete_matches(matches[0], result), "first item is correct");
         do_print("Checking rest of the matches");
       }
 
       for (let i = firstIndexToCheck; i < controller.matchCount; i++) {
         let result = {
           value: controller.getValueAt(i),
           comment: controller.getCommentAt(i),
           style: controller.getStyleAt(i),
@@ -221,17 +218,17 @@ function* check_autocomplete(test) {
         do_print(`Found value: "${result.value}", comment: "${result.comment}", style: "${result.style}" in results...`);
         let lowerBound = test.checkSorting ? i : firstIndexToCheck;
         let upperBound = test.checkSorting ? i + 1 : matches.length;
         let found = false;
         for (let j = lowerBound; j < upperBound; ++j) {
           // Skip processed expected results
           if (matches[j] == undefined)
             continue;
-          if (_check_autocomplete_matches(matches[j], result)) {
+          if (yield _check_autocomplete_matches(matches[j], result)) {
             do_print("Got a match at index " + j + "!");
             // Make it undefined so we don't process it again
             matches[j] = undefined;
             found = true;
             break;
           }
         }
 
@@ -427,29 +424,16 @@ function makeExtensionMatch(extra = {}) 
       content: extra.content,
       keyword: extra.keyword,
     }),
     title: extra.description,
     style,
   };
 }
 
-function setFaviconForHref(href, iconHref) {
-  return new Promise(resolve => {
-    PlacesUtils.favicons.setAndFetchFaviconForPage(
-      NetUtil.newURI(href),
-      NetUtil.newURI(iconHref),
-      true,
-      PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
-      resolve,
-      Services.scriptSecurityManager.getSystemPrincipal()
-    );
-  });
-}
-
 function makeTestServer(port = -1) {
   let httpServer = new HttpServer();
   httpServer.start(port);
   do_register_cleanup(() => httpServer.stop(() => {}));
   return httpServer;
 }
 
 function* addTestEngine(basename, httpServer = undefined) {
--- a/toolkit/components/places/tests/unifiedcomplete/test_autofill_default_behavior.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_autofill_default_behavior.js
@@ -19,19 +19,19 @@ add_task(function* test_default_behavior
     { uri: uri2, title: "visited" },
     { uri: uri4, title: "tpbk", transition: TRANSITION_TYPED },
     { uri: uri6, title: "secure", transition: TRANSITION_TYPED },
   ]);
   yield addBookmark( { uri: uri3, title: "bookmarked" } );
   yield addBookmark( { uri: uri4, title: "tpbk" } );
   yield addBookmark( { uri: uri5, title: "title", tags: ["foo"] } );
 
-  yield setFaviconForHref(uri1.spec, "chrome://global/skin/icons/info.svg");
-  yield setFaviconForHref(uri3.spec, "chrome://global/skin/icons/error-16.png");
-  yield setFaviconForHref(uri6.spec, "chrome://global/skin/icons/question-16.png");
+  yield setFaviconForPage(uri1, "chrome://global/skin/icons/info.svg");
+  yield setFaviconForPage(uri3, "chrome://global/skin/icons/error-16.png");
+  yield setFaviconForPage(uri6, "chrome://global/skin/icons/question-16.png");
 
   // RESTRICT TO HISTORY.
   Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
   Services.prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", false);
   Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
 
   do_print("Restrict history, common visit, should not autoFill");
   yield check_autocomplete({
@@ -218,18 +218,18 @@ add_task(function* test_default_behavior
   yield PlacesTestUtils.addVisits([
     { uri: uri1, title: "typed", transition: TRANSITION_TYPED },
     { uri: uri2, title: "visited" },
     { uri: uri4, title: "tpbk", transition: TRANSITION_TYPED },
   ]);
   yield addBookmark( { uri: uri3, title: "bookmarked" } );
   yield addBookmark( { uri: uri4, title: "tpbk" } );
 
-  yield setFaviconForHref(uri1.spec, "chrome://global/skin/icons/info.svg");
-  yield setFaviconForHref(uri3.spec, "chrome://global/skin/icons/error-16.png");
+  yield setFaviconForPage(uri1, "chrome://global/skin/icons/info.svg");
+  yield setFaviconForPage(uri3, "chrome://global/skin/icons/error-16.png");
 
   // RESTRICT TO HISTORY.
   Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
   Services.prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", false);
   Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
   Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", true);
   Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", false);
 
--- a/toolkit/components/places/tests/unifiedcomplete/test_typed.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_typed.js
@@ -6,31 +6,31 @@
 // 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 setFaviconForPage("http://mozilla.org/link/", FAVICON_HREF);
   yield check_autocomplete({
     search: "moz",
     autofilled: "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 setFaviconForPage("http://mozilla.org/link/", FAVICON_HREF);
   yield check_autocomplete({
     search: "mozilla.org/li",
     autofilled: "mozilla.org/link/",
     completed: "http://mozilla.org/link/",
     icon: "moz-anno:favicon:" + FAVICON_HREF
   });
   yield cleanup();
 });
--- a/toolkit/components/places/tests/unit/test_history_clear.js
+++ b/toolkit/components/places/tests/unit/test_history_clear.js
@@ -133,18 +133,27 @@ add_task(function* test_history_clear() 
     `SELECT h.id FROM moz_places h WHERE
        url_hash NOT BETWEEN hash('place', 'prefix_lo') AND hash('place', 'prefix_hi')
        AND NOT EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1`);
   do_check_false(stmt.executeStep());
   stmt.finalize();
 
   // Check that we only have favicons for retained places
   stmt = mDBConn.createStatement(
-    `SELECT f.id FROM moz_favicons f WHERE NOT EXISTS
-       (SELECT id FROM moz_places WHERE favicon_id = f.id) LIMIT 1`);
+    `SELECT 1
+     FROM moz_pages_w_icons
+     LEFT JOIN moz_places h ON url_hash = page_url_hash AND url = page_url
+     WHERE h.id ISNULL`);
+  do_check_false(stmt.executeStep());
+  stmt.finalize();
+  stmt = mDBConn.createStatement(
+    `SELECT 1
+     FROM moz_icons WHERE id NOT IN (
+       SELECT icon_id FROM moz_icons_to_pages
+     )`);
   do_check_false(stmt.executeStep());
   stmt.finalize();
 
   // Check that we only have annotations for retained places
   stmt = mDBConn.createStatement(
     `SELECT a.id FROM moz_annos a WHERE NOT EXISTS
        (SELECT id FROM moz_places WHERE id = a.place_id) LIMIT 1`);
   do_check_false(stmt.executeStep());
--- a/toolkit/components/places/tests/unit/test_preventive_maintenance.js
+++ b/toolkit/components/places/tests/unit/test_preventive_maintenance.js
@@ -31,28 +31,44 @@ var defaultBookmarksMaxId = 0;
 function cleanDatabase() {
   mDBConn.executeSimpleSQL("DELETE FROM moz_places");
   mDBConn.executeSimpleSQL("DELETE FROM moz_historyvisits");
   mDBConn.executeSimpleSQL("DELETE FROM moz_anno_attributes");
   mDBConn.executeSimpleSQL("DELETE FROM moz_annos");
   mDBConn.executeSimpleSQL("DELETE FROM moz_items_annos");
   mDBConn.executeSimpleSQL("DELETE FROM moz_inputhistory");
   mDBConn.executeSimpleSQL("DELETE FROM moz_keywords");
-  mDBConn.executeSimpleSQL("DELETE FROM moz_favicons");
+  mDBConn.executeSimpleSQL("DELETE FROM moz_icons");
+  mDBConn.executeSimpleSQL("DELETE FROM moz_pages_w_icons");
   mDBConn.executeSimpleSQL("DELETE FROM moz_bookmarks WHERE id > " + defaultBookmarksMaxId);
 }
 
 function addPlace(aUrl, aFavicon) {
+  let href = new URL(aUrl || "http://www.mozilla.org").href;
   let stmt = mDBConn.createStatement(
-    "INSERT INTO moz_places (url, url_hash, favicon_id) VALUES (:url, hash(:url), :favicon)");
-  stmt.params["url"] = aUrl || "http://www.mozilla.org";
-  stmt.params["favicon"] = aFavicon || null;
+    "INSERT INTO moz_places (url, url_hash) VALUES (:url, hash(:url))");
+  stmt.params["url"] = href;
   stmt.execute();
   stmt.finalize();
-  return mDBConn.lastInsertRowID;
+  let id = mDBConn.lastInsertRowID;
+  if (aFavicon) {
+    stmt = mDBConn.createStatement(
+      "INSERT INTO moz_pages_w_icons (page_url, page_url_hash) VALUES (:url, hash(:url))");
+    stmt.params["url"] = href;
+    stmt.execute();
+    stmt.finalize();
+    stmt = mDBConn.createStatement(
+      "INSERT INTO moz_icons_to_pages (page_id, icon_id) " +
+      "VALUES ((SELECT id FROM moz_pages_w_icons WHERE page_url_hash = hash(:url)), :favicon)");
+    stmt.params["url"] = href;
+    stmt.params["favicon"] = aFavicon;
+    stmt.execute();
+    stmt.finalize();
+  }
+  return id;
 }
 
 function addBookmark(aPlaceId, aType, aParent, aKeywordId, aFolderType, aTitle) {
   let stmt = mDBConn.createStatement(
     `INSERT INTO moz_bookmarks (fk, type, parent, keyword_id, folder_type,
                                 title, guid)
      VALUES (:place_id, :type, :parent, :keyword_id, :folder_type, :title,
              GENERATE_GUID())`);
@@ -784,45 +800,57 @@ tests.push({
     stmt.finalize();
   }
 });
 
 // ------------------------------------------------------------------------------
 
 tests.push({
   name: "E.1",
-  desc: "Remove orphan icons",
+  desc: "Remove orphan icon entries",
 
   _placeId: null,
 
   setup() {
     // Insert favicon entries
-    let stmt = mDBConn.createStatement("INSERT INTO moz_favicons (id, url) VALUES(:favicon_id, :url)");
+    let stmt = mDBConn.createStatement("INSERT INTO moz_icons (id, icon_url, fixed_icon_url_hash) VALUES(:favicon_id, :url, hash(fixup_url(:url)))");
     stmt.params["favicon_id"] = 1;
     stmt.params["url"] = "http://www1.mozilla.org/favicon.ico";
     stmt.execute();
     stmt.reset();
     stmt.params["favicon_id"] = 2;
     stmt.params["url"] = "http://www2.mozilla.org/favicon.ico";
     stmt.execute();
     stmt.finalize();
+    // Insert orphan page.
+    stmt = mDBConn.createStatement("INSERT INTO moz_pages_w_icons (id, page_url, page_url_hash) VALUES(:page_id, :url, hash(:url))");
+    stmt.params["page_id"] = 99;
+    stmt.params["url"] = "http://w99.mozilla.org/";
+    stmt.execute();
+    stmt.finalize();
+
     // Insert a place using the existing favicon entry
     this._placeId = addPlace("http://www.mozilla.org", 1);
   },
 
   check() {
     // Check that used icon is still there
-    let stmt = mDBConn.createStatement("SELECT id FROM moz_favicons WHERE id = :favicon_id");
+    let stmt = mDBConn.createStatement("SELECT id FROM moz_icons WHERE id = :favicon_id");
     stmt.params["favicon_id"] = 1;
     do_check_true(stmt.executeStep());
     stmt.reset();
     // Check that unused icon has been removed
     stmt.params["favicon_id"] = 2;
     do_check_false(stmt.executeStep());
     stmt.finalize();
+    // Check that the orphan page is gone.
+    stmt = mDBConn.createStatement("SELECT id FROM moz_pages_w_icons WHERE id = :page_id");
+    stmt.params["page_id"] = 99;
+    do_check_false(stmt.executeStep());
+    stmt.finalize();
   }
 });
 
 // ------------------------------------------------------------------------------
 
 tests.push({
   name: "F.1",
   desc: "Remove orphan visits",
@@ -1019,60 +1047,16 @@ tests.push({
     let stmt = mDBConn.createStatement("SELECT id FROM moz_keywords WHERE keyword = :keyword");
     // Check that "unused" keyword has gone
     stmt.params["keyword"] = "unused";
     do_check_false(stmt.executeStep());
     stmt.finalize();
   }
 });
 
-
-// ------------------------------------------------------------------------------
-
-tests.push({
-  name: "L.1",
-  desc: "Fix wrong favicon ids",
-
-  _validIconPlaceId: null,
-  _invalidIconPlaceId: null,
-
-  setup() {
-    // Insert a favicon entry
-    let stmt = mDBConn.createStatement("INSERT INTO moz_favicons (id, url) VALUES(1, :url)");
-    stmt.params["url"] = "http://www.mozilla.org/favicon.ico";
-    stmt.execute();
-    stmt.finalize();
-    // Insert a place using the existing favicon entry
-    this._validIconPlaceId = addPlace("http://www1.mozilla.org", 1);
-
-    // Insert a place using a nonexistent favicon entry
-    this._invalidIconPlaceId = addPlace("http://www2.mozilla.org", 1337);
-  },
-
-  check() {
-    // Check that bogus favicon is not there
-    let stmt = mDBConn.createStatement("SELECT id FROM moz_places WHERE favicon_id = :favicon_id");
-    stmt.params["favicon_id"] = 1337;
-    do_check_false(stmt.executeStep());
-    stmt.reset();
-    // Check that valid favicon is still there
-    stmt.params["favicon_id"] = 1;
-    do_check_true(stmt.executeStep());
-    stmt.finalize();
-    // Check that place entries are there
-    stmt = mDBConn.createStatement("SELECT id FROM moz_places WHERE id = :place_id");
-    stmt.params["place_id"] = this._validIconPlaceId;
-    do_check_true(stmt.executeStep());
-    stmt.reset();
-    stmt.params["place_id"] = this._invalidIconPlaceId;
-    do_check_true(stmt.executeStep());
-    stmt.finalize();
-  }
-});
-
 // ------------------------------------------------------------------------------
 
 tests.push({
   name: "L.2",
   desc: "Recalculate visit_count and last_visit_date",
 
   *setup() {
     function setVisitCount(aURL, aValue) {
@@ -1180,18 +1164,16 @@ tests.push({
             let url = row.getResultByIndex(0);
             do_check_true(/redirecting/.test(url));
             this._count++;
           }
         },
         handleError(aError) {
         },
         handleCompletion(aReason) {
-          dump_table("moz_places");
-          dump_table("moz_historyvisits");
           do_check_eq(aReason, Ci.mozIStorageStatementCallback.REASON_FINISHED);
           do_check_eq(this._count, 2);
           resolve();
         }
       });
       stmt.finalize();
     });
   }
--- a/toolkit/components/places/tests/unit/test_promiseBookmarksTree.js
+++ b/toolkit/components/places/tests/unit/test_promiseBookmarksTree.js
@@ -129,18 +129,17 @@ function* compareToNode(aItem, aNode, aI
       compare_prop("uri");
       // node.tags's format is "a, b" whilst promiseBoookmarksTree is "a,b"
       if (aNode.tags === null)
         check_unset("tags");
       else
         compare_prop_to_value("tags", aNode.tags.replace(/, /g, ","), false);
 
       if (aNode.icon) {
-        let nodeIconData = aNode.icon.replace("moz-anno:favicon:", "");
-        compare_prop_to_value("iconuri", nodeIconData);
+        compareFavicons(aNode.icon, aItem.iconuri);
       } else {
         check_unset(aItem.iconuri);
       }
 
       check_unset(...FOLDER_ONLY_PROPS);
 
       let itemURI = uri(aNode.uri);
       compare_prop_to_value("charset",
@@ -218,17 +217,17 @@ add_task(function* () {
   yield new_bookmark({ title: null,
                        parentGuid: folderGuid,
                        keyword: "test_keyword",
                        tags: ["TestTagA", "TestTagB"],
                        annotations: [{ name: "TestAnnoA", value: "TestVal2"}]});
   let urlWithCharsetAndFavicon = uri("http://charset.and.favicon");
   yield new_bookmark({ parentGuid: folderGuid, url: urlWithCharsetAndFavicon });
   yield PlacesUtils.setCharsetForURI(urlWithCharsetAndFavicon, "UTF-8");
-  yield promiseSetIconForPage(urlWithCharsetAndFavicon, SMALLPNG_DATA_URI);
+  yield setFaviconForPage(urlWithCharsetAndFavicon, SMALLPNG_DATA_URI);
   // Test the default places root without specifying it.
   yield test_promiseBookmarksTreeAgainstResult();
 
   // Do specify it
   yield test_promiseBookmarksTreeAgainstResult(PlacesUtils.bookmarks.rootGuid);
 
   // Exclude the bookmarks menu.
   // The calllback should be four times - once for the toolbar, once for
--- a/toolkit/components/places/tests/unit/xpcshell.ini
+++ b/toolkit/components/places/tests/unit/xpcshell.ini
@@ -116,17 +116,16 @@ skip-if = true
 [test_preventive_maintenance.js]
 [test_preventive_maintenance_checkAndFixDatabase.js]
 [test_preventive_maintenance_runTasks.js]
 [test_promiseBookmarksTree.js]
 [test_resolveNullBookmarkTitles.js]
 [test_result_sort.js]
 [test_resultsAsVisit_details.js]
 [test_sql_guid_functions.js]
-[test_svg_favicon.js]
 [test_sync_utils.js]
 [test_tag_autocomplete_search.js]
 [test_tagging.js]
 [test_telemetry.js]
 [test_update_frecency_after_delete.js]
 [test_utils_backups_create.js]
 [test_utils_getURLsForContainerNode.js]
 [test_utils_setAnnotationsFor.js]
--- a/widget/windows/WinUtils.cpp
+++ b/widget/windows/WinUtils.cpp
@@ -1224,17 +1224,18 @@ nsresult AsyncFaviconDataReady::OnFavico
 
   return channel->AsyncOpen2(listener);
 }
 
 NS_IMETHODIMP
 AsyncFaviconDataReady::OnComplete(nsIURI *aFaviconURI,
                                   uint32_t aDataLen,
                                   const uint8_t *aData, 
-                                  const nsACString &aMimeType)
+                                  const nsACString &aMimeType,
+                                  uint16_t aWidth)
 {
   if (!aDataLen || !aData) {
     if (mURLShortcut) {
       OnFaviconDataNotAvailable();
     }
     
     return NS_OK;
   }
@@ -1652,17 +1653,17 @@ nsresult
     do_GetService("@mozilla.org/browser/favicon-service;1"));
   NS_ENSURE_TRUE(favIconSvc, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIFaviconDataCallback> callback = 
     new mozilla::widget::AsyncFaviconDataReady(aFaviconPageURI, 
                                                aIOThread, 
                                                aURLShortcut);
 
-  favIconSvc->GetFaviconDataForPage(aFaviconPageURI, callback);
+  favIconSvc->GetFaviconDataForPage(aFaviconPageURI, callback, 0);
 #endif
   return NS_OK;
 }
 
 // Obtains the jump list 'ICO cache timeout in seconds' pref
 int32_t FaviconHelper::GetICOCacheSecondsTimeout() {
 
   // Only obtain the setting at most once from the pref service.