2006-07-18 15:51:18 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-11-25 00:53:46 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2006-07-18 15:51:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the favicon service, which stores favicons for web pages with your
|
|
|
|
* history as you browse. It is also used to save the favicons for bookmarks.
|
|
|
|
*
|
|
|
|
* DANGER: The history query system makes assumptions about the favicon storage
|
|
|
|
* so that icons can be quickly generated for history/bookmark result sets. If
|
|
|
|
* you change the database layout at all, you will have to update both services.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsFaviconService.h"
|
2010-03-25 11:34:49 +00:00
|
|
|
|
2011-10-27 09:11:34 +00:00
|
|
|
#include "nsNavHistory.h"
|
2010-03-25 11:34:49 +00:00
|
|
|
#include "nsPlacesMacros.h"
|
|
|
|
#include "Helpers.h"
|
|
|
|
|
2006-07-18 15:51:18 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsStreamUtils.h"
|
2008-01-20 06:48:07 +00:00
|
|
|
#include "nsStringStream.h"
|
2008-07-03 18:07:56 +00:00
|
|
|
#include "plbase64.h"
|
2011-05-20 12:37:02 +00:00
|
|
|
#include "nsIClassInfoImpl.h"
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "mozilla/LoadInfo.h"
|
2011-10-27 09:11:34 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2015-02-17 18:09:50 +00:00
|
|
|
#include "nsILoadInfo.h"
|
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsContentUtils.h"
|
2017-03-22 10:38:40 +00:00
|
|
|
#include "NullPrincipal.h"
|
2006-07-18 15:51:18 +00:00
|
|
|
|
2014-08-06 13:31:21 +00:00
|
|
|
#define MAX_FAILED_FAVICONS 256
|
2009-11-11 11:04:11 +00:00
|
|
|
#define FAVICON_CACHE_REDUCE_COUNT 64
|
|
|
|
|
2014-08-06 13:31:21 +00:00
|
|
|
#define UNASSOCIATED_FAVICONS_LENGTH 32
|
2011-12-16 00:55:22 +00:00
|
|
|
|
|
|
|
// When replaceFaviconData is called, we store the icons in an in-memory cache
|
|
|
|
// instead of in storage. Icons in the cache are expired according to this
|
|
|
|
// interval.
|
|
|
|
#define UNASSOCIATED_ICON_EXPIRY_INTERVAL 60000
|
2008-12-11 20:01:10 +00:00
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
using namespace mozilla;
|
2009-11-11 11:04:14 +00:00
|
|
|
using namespace mozilla::places;
|
|
|
|
|
2010-03-25 11:34:49 +00:00
|
|
|
/**
|
|
|
|
* Used to notify a topic to system observers on async execute completion.
|
|
|
|
* Will throw on error.
|
|
|
|
*/
|
2009-11-11 11:04:14 +00:00
|
|
|
class ExpireFaviconsStatementCallbackNotifier : public AsyncStatementCallback
|
2009-02-28 13:17:36 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-03-20 13:25:19 +00:00
|
|
|
ExpireFaviconsStatementCallbackNotifier();
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHOD HandleCompletion(uint16_t aReason);
|
2009-02-28 13:17:36 +00:00
|
|
|
};
|
2006-07-18 15:51:18 +00:00
|
|
|
|
2017-03-28 15:30:28 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extracts and filters native sizes from the given container, based on the
|
|
|
|
* list of sizes we are supposed to retain.
|
|
|
|
* All calculation is done considering square sizes and the largest side.
|
|
|
|
* In case of multiple frames of the same size, only the first one is retained.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
GetFramesInfoForContainer(imgIContainer* aContainer,
|
|
|
|
nsTArray<FrameData>& aFramesInfo) {
|
|
|
|
// Don't extract frames from animated images.
|
|
|
|
bool animated;
|
|
|
|
nsresult rv = aContainer->GetAnimated(&animated);
|
|
|
|
if (NS_FAILED(rv) || !animated) {
|
|
|
|
nsTArray<nsIntSize> nativeSizes;
|
|
|
|
rv = aContainer->GetNativeSizes(nativeSizes);
|
|
|
|
if (NS_SUCCEEDED(rv) && nativeSizes.Length() > 1) {
|
|
|
|
for (uint32_t i = 0; i < nativeSizes.Length(); ++i) {
|
|
|
|
nsIntSize nativeSize = nativeSizes[i];
|
|
|
|
// Only retain square frames.
|
|
|
|
if (nativeSize.width != nativeSize.height) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Check if it's one of the sizes we care about.
|
|
|
|
auto end = std::end(sFaviconSizes);
|
|
|
|
uint16_t* matchingSize = std::find(std::begin(sFaviconSizes), end,
|
|
|
|
nativeSize.width);
|
|
|
|
if (matchingSize != end) {
|
|
|
|
// We must avoid duped sizes, an image could contain multiple frames of
|
|
|
|
// the same size, but we can only store one. We could use an hashtable,
|
|
|
|
// but considered the average low number of frames, we'll just do a
|
|
|
|
// linear search.
|
|
|
|
bool dupe = false;
|
|
|
|
for (const auto& frameInfo : aFramesInfo) {
|
|
|
|
if (frameInfo.width == *matchingSize) {
|
|
|
|
dupe = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!dupe) {
|
|
|
|
aFramesInfo.AppendElement(FrameData(i, *matchingSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFramesInfo.Length() == 0) {
|
|
|
|
// Always have at least the default size.
|
|
|
|
int32_t width;
|
|
|
|
rv = aContainer->GetWidth(&width);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
int32_t height;
|
|
|
|
rv = aContainer->GetHeight(&height);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// For non-square images, pick the largest side.
|
|
|
|
aFramesInfo.AppendElement(FrameData(0, std::max(width, height)));
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2010-03-25 11:34:49 +00:00
|
|
|
|
2009-12-01 13:00:45 +00:00
|
|
|
PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsFaviconService, gFaviconService)
|
2006-07-18 15:51:18 +00:00
|
|
|
|
2013-10-10 20:38:05 +00:00
|
|
|
NS_IMPL_CLASSINFO(nsFaviconService, nullptr, 0, NS_FAVICONSERVICE_CID)
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_CI(
|
2008-12-11 20:01:10 +00:00
|
|
|
nsFaviconService
|
|
|
|
, nsIFaviconService
|
2011-05-20 12:37:02 +00:00
|
|
|
, mozIAsyncFavicons
|
2011-12-16 00:55:22 +00:00
|
|
|
, nsITimerCallback
|
2008-12-11 20:01:10 +00:00
|
|
|
)
|
2006-07-18 15:51:18 +00:00
|
|
|
|
2010-01-08 12:57:49 +00:00
|
|
|
nsFaviconService::nsFaviconService()
|
2016-08-03 01:00:07 +00:00
|
|
|
: mFailedFaviconSerial(0)
|
2014-08-06 13:31:21 +00:00
|
|
|
, mFailedFavicons(MAX_FAILED_FAVICONS / 2)
|
|
|
|
, mUnassociatedIcons(UNASSOCIATED_FAVICONS_LENGTH)
|
2006-07-18 15:51:18 +00:00
|
|
|
{
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ASSERTION(!gFaviconService,
|
|
|
|
"Attempting to create two instances of the service!");
|
2006-07-18 15:51:18 +00:00
|
|
|
gFaviconService = this;
|
|
|
|
}
|
|
|
|
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2006-07-18 15:51:18 +00:00
|
|
|
nsFaviconService::~nsFaviconService()
|
|
|
|
{
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ASSERTION(gFaviconService == this,
|
|
|
|
"Deleting a non-singleton instance of the service");
|
2006-07-18 15:51:18 +00:00
|
|
|
if (gFaviconService == this)
|
2012-07-30 14:20:58 +00:00
|
|
|
gFaviconService = nullptr;
|
2006-07-18 15:51:18 +00:00
|
|
|
}
|
|
|
|
|
Bug 977177 - Move favicons to a separate store. r=adw
This patch moves favicons blobs to a separate database names favicons.sqlite.
The dabatase is then ATTACHED to the main Places connection, so that its tables
can be used as if they were all part of the same database.
The favicons.database contains 3 tables:
1. moz_pages_w_icons
This is the way to join with moz_places, through page_url_hash and page_url.
We are not using the place id to avoid possible mismatches between places.sqlite
and favicons.sqlite. This way the database is "portable" and reusable even
if places.sqlite changes.
2. moz_icons
Contains icons payloads, each payload can either be an SVG or a PNG. These
are the only stored formats, any other format is rescaled and converted to
PNG. ICO files are split into single frames and stored as multiple PNGs.
SVG are distinguishable through width == UINT16_MAX
In future the table will also contain mask-icon color for SVG and average
color for PNGs.
The fixed_icon_url_hash is "fixed" to allow quickly fetch root icons, that
means icons like "domain/favicon.ico" that can also be reused for any page
under that domain.
3. moz_icons_to_pages
This is the relation table between icons and pages.
Each page can have multiple icons, each icon can be used by multiple pages.
There is a FOREIGN_KEY constraint between this (child) table and icons
or pages (parents), so that it's not possible to insert non-existing ids
in this table, and if an entry is removed from a parent table, the relation
will be automatically removed from here.
Note though that removing from the relation table won't remove from the
parent tables.
Since the relations are now many-many, it's no more possible to simply join
places with the icons table and obtain a single icon, thus it's suggested that
consumers go through the "page-icon" protocol.
The migration process from the old favicons table is async and interruptible,
it will be restarted along with the favicons service until the temp preference
places.favicons.convertPayloads is set to true.
MozReview-Commit-ID: CUCoL9smRyt
--HG--
extra : rebase_source : 4d25966596dcdf63c9c872425c5bf147406d25ac
2016-11-14 15:22:46 +00:00
|
|
|
Atomic<int64_t> nsFaviconService::sLastInsertedIconId(0);
|
|
|
|
|
|
|
|
void // static
|
|
|
|
nsFaviconService::StoreLastInsertedId(const nsACString& aTable,
|
|
|
|
const int64_t aLastInsertedId) {
|
|
|
|
MOZ_ASSERT(aTable.EqualsLiteral("moz_icons"));
|
|
|
|
sLastInsertedIconId = aLastInsertedId;
|
|
|
|
}
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2006-07-18 15:51:18 +00:00
|
|
|
nsresult
|
|
|
|
nsFaviconService::Init()
|
|
|
|
{
|
2011-10-27 09:11:34 +00:00
|
|
|
mDB = Database::GetDatabase();
|
|
|
|
NS_ENSURE_STATE(mDB);
|
2006-07-18 15:51:18 +00:00
|
|
|
|
2011-12-16 00:55:22 +00:00
|
|
|
mExpireUnassociatedIconsTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
NS_ENSURE_STATE(mExpireUnassociatedIconsTimer);
|
|
|
|
|
Bug 977177 - Move favicons to a separate store. r=adw
This patch moves favicons blobs to a separate database names favicons.sqlite.
The dabatase is then ATTACHED to the main Places connection, so that its tables
can be used as if they were all part of the same database.
The favicons.database contains 3 tables:
1. moz_pages_w_icons
This is the way to join with moz_places, through page_url_hash and page_url.
We are not using the place id to avoid possible mismatches between places.sqlite
and favicons.sqlite. This way the database is "portable" and reusable even
if places.sqlite changes.
2. moz_icons
Contains icons payloads, each payload can either be an SVG or a PNG. These
are the only stored formats, any other format is rescaled and converted to
PNG. ICO files are split into single frames and stored as multiple PNGs.
SVG are distinguishable through width == UINT16_MAX
In future the table will also contain mask-icon color for SVG and average
color for PNGs.
The fixed_icon_url_hash is "fixed" to allow quickly fetch root icons, that
means icons like "domain/favicon.ico" that can also be reused for any page
under that domain.
3. moz_icons_to_pages
This is the relation table between icons and pages.
Each page can have multiple icons, each icon can be used by multiple pages.
There is a FOREIGN_KEY constraint between this (child) table and icons
or pages (parents), so that it's not possible to insert non-existing ids
in this table, and if an entry is removed from a parent table, the relation
will be automatically removed from here.
Note though that removing from the relation table won't remove from the
parent tables.
Since the relations are now many-many, it's no more possible to simply join
places with the icons table and obtain a single icon, thus it's suggested that
consumers go through the "page-icon" protocol.
The migration process from the old favicons table is async and interruptible,
it will be restarted along with the favicons service until the temp preference
places.favicons.convertPayloads is set to true.
MozReview-Commit-ID: CUCoL9smRyt
--HG--
extra : rebase_source : 4d25966596dcdf63c9c872425c5bf147406d25ac
2016-11-14 15:22:46 +00:00
|
|
|
// Check if there are still icon payloads to be converted.
|
|
|
|
bool shouldConvertPayloads =
|
|
|
|
Preferences::GetBool(PREF_CONVERT_PAYLOADS, false);
|
|
|
|
if (shouldConvertPayloads) {
|
|
|
|
ConvertUnsupportedPayloads(mDB->MainConn());
|
|
|
|
}
|
|
|
|
|
2006-07-18 15:51:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-27 09:11:34 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFaviconService::ExpireAllFavicons()
|
2010-01-08 12:57:49 +00:00
|
|
|
{
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
NS_ENSURE_STATE(mDB);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> removePagesStmt = mDB->GetAsyncStatement(
|
|
|
|
"DELETE FROM moz_pages_w_icons"
|
2011-10-27 09:11:34 +00:00
|
|
|
);
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
NS_ENSURE_STATE(removePagesStmt);
|
2011-10-27 09:11:34 +00:00
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> removeIconsStmt = mDB->GetAsyncStatement(
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
"DELETE FROM moz_icons"
|
2011-10-27 09:11:34 +00:00
|
|
|
);
|
|
|
|
NS_ENSURE_STATE(removeIconsStmt);
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> unlinkIconsStmt = mDB->GetAsyncStatement(
|
|
|
|
"DELETE FROM moz_icons_to_pages"
|
|
|
|
);
|
|
|
|
NS_ENSURE_STATE(unlinkIconsStmt);
|
2011-12-16 00:55:22 +00:00
|
|
|
|
2011-10-27 09:11:34 +00:00
|
|
|
mozIStorageBaseStatement* stmts[] = {
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
removePagesStmt.get()
|
2011-10-27 09:11:34 +00:00
|
|
|
, removeIconsStmt.get()
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
, unlinkIconsStmt.get()
|
2008-12-11 20:01:10 +00:00
|
|
|
};
|
|
|
|
nsCOMPtr<mozIStoragePendingStatement> ps;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ExpireFaviconsStatementCallbackNotifier> callback =
|
2013-03-20 13:25:19 +00:00
|
|
|
new ExpireFaviconsStatementCallbackNotifier();
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
return mDB->MainConn()->ExecuteAsync(stmts, ArrayLength(stmts),
|
|
|
|
callback, getter_AddRefs(ps));
|
2008-12-11 20:01:10 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 00:55:22 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsITimerCallback
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFaviconService::Notify(nsITimer* timer)
|
|
|
|
{
|
|
|
|
if (timer != mExpireUnassociatedIconsTimer.get()) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRTime now = PR_Now();
|
2015-07-14 14:06:29 +00:00
|
|
|
for (auto iter = mUnassociatedIcons.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
UnassociatedIconHashKey* iconKey = iter.Get();
|
|
|
|
if (now - iconKey->created >= UNASSOCIATED_ICON_EXPIRY_INTERVAL) {
|
|
|
|
iter.Remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 00:55:22 +00:00
|
|
|
// Re-init the expiry timer if the cache isn't empty.
|
|
|
|
if (mUnassociatedIcons.Count() > 0) {
|
|
|
|
mExpireUnassociatedIconsTimer->InitWithCallback(
|
|
|
|
this, UNASSOCIATED_ICON_EXPIRY_INTERVAL, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2008-12-11 20:01:10 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIFaviconService
|
2006-07-18 15:51:18 +00:00
|
|
|
|
2011-06-30 20:06:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFaviconService::GetDefaultFavicon(nsIURI** _retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
// not found, use default
|
|
|
|
if (!mDefaultIcon) {
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(mDefaultIcon),
|
|
|
|
NS_LITERAL_CSTRING(FAVICON_DEFAULT_URL));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return mDefaultIcon->Clone(_retval);
|
|
|
|
}
|
2006-07-18 15:53:12 +00:00
|
|
|
|
|
|
|
void
|
2008-05-08 04:26:10 +00:00
|
|
|
nsFaviconService::SendFaviconNotifications(nsIURI* aPageURI,
|
2011-06-30 20:06:56 +00:00
|
|
|
nsIURI* aFaviconURI,
|
|
|
|
const nsACString& aGUID)
|
2006-07-18 15:53:12 +00:00
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString faviconSpec;
|
2011-06-30 20:06:56 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
|
|
|
if (history && NS_SUCCEEDED(aFaviconURI->GetSpec(faviconSpec))) {
|
|
|
|
history->SendPageChangedNotification(aPageURI,
|
|
|
|
nsINavHistoryObserver::ATTRIBUTE_FAVICON,
|
|
|
|
NS_ConvertUTF8toUTF16(faviconSpec),
|
|
|
|
aGUID);
|
2006-07-18 15:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 12:39:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFaviconService::SetAndFetchFaviconForPage(nsIURI* aPageURI,
|
|
|
|
nsIURI* aFaviconURI,
|
|
|
|
bool aForceReload,
|
|
|
|
uint32_t aFaviconLoadType,
|
2015-11-24 21:32:22 +00:00
|
|
|
nsIFaviconDataCallback* aCallback,
|
2016-05-03 13:42:12 +00:00
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
mozIPlacesPendingOperation **_canceler)
|
2006-07-18 15:53:35 +00:00
|
|
|
{
|
2016-05-06 09:37:26 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aPageURI);
|
|
|
|
NS_ENSURE_ARG(aFaviconURI);
|
2016-05-03 13:42:12 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_canceler);
|
2007-11-22 00:44:33 +00:00
|
|
|
|
2010-11-16 01:13:37 +00:00
|
|
|
// If a favicon is in the failed cache, only load it during a forced reload.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool previouslyFailed;
|
2009-11-11 11:04:11 +00:00
|
|
|
nsresult rv = IsFailedFavicon(aFaviconURI, &previouslyFailed);
|
2006-07-18 15:53:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (previouslyFailed) {
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
if (aForceReload) {
|
2010-03-25 11:34:49 +00:00
|
|
|
RemoveFailedFavicon(aFaviconURI);
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-03-25 11:34:49 +00:00
|
|
|
return NS_OK;
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
}
|
2006-07-18 15:53:12 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 21:32:22 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> loadingPrincipal = aLoadingPrincipal;
|
|
|
|
MOZ_ASSERT(loadingPrincipal, "please provide aLoadingPrincipal for this favicon");
|
|
|
|
if (!loadingPrincipal) {
|
2016-08-23 08:30:28 +00:00
|
|
|
// Let's default to the nullPrincipal if no loadingPrincipal is provided.
|
2016-05-06 11:56:24 +00:00
|
|
|
const char16_t* params[] = {
|
2016-07-21 05:03:25 +00:00
|
|
|
u"nsFaviconService::setAndFetchFaviconForPage()",
|
|
|
|
u"nsFaviconService::setAndFetchFaviconForPage(..., [optional aLoadingPrincipal])"
|
2016-05-06 11:56:24 +00:00
|
|
|
};
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
|
|
|
NS_LITERAL_CSTRING("Security by Default"),
|
|
|
|
nullptr, // aDocument
|
|
|
|
nsContentUtils::eNECKO_PROPERTIES,
|
|
|
|
"APIDeprecationWarning",
|
|
|
|
params, ArrayLength(params));
|
2017-03-22 10:38:40 +00:00
|
|
|
loadingPrincipal = NullPrincipal::Create();
|
2015-11-24 21:32:22 +00:00
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(loadingPrincipal, NS_ERROR_FAILURE);
|
|
|
|
|
2016-05-03 13:42:12 +00:00
|
|
|
bool loadPrivate = aFaviconLoadType == nsIFaviconService::FAVICON_LOAD_PRIVATE;
|
2016-05-06 09:37:26 +00:00
|
|
|
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
// Build page data.
|
2016-05-06 09:37:26 +00:00
|
|
|
PageData page;
|
|
|
|
rv = aPageURI->GetSpec(page.spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// URIs can arguably miss a host.
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
Unused << GetReversedHostname(aPageURI, page.revHost);
|
2016-05-06 09:37:26 +00:00
|
|
|
bool canAddToHistory;
|
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_TRUE(navHistory, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = navHistory->CanAddURI(aPageURI, &canAddToHistory);
|
2006-07-18 15:51:18 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-05-06 09:37:26 +00:00
|
|
|
page.canAddToHistory = !!canAddToHistory && !loadPrivate;
|
|
|
|
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
// Build icon data.
|
2016-05-06 09:37:26 +00:00
|
|
|
IconData icon;
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
// If we have an in-memory icon payload, it overwrites the actual request.
|
2016-05-06 09:37:26 +00:00
|
|
|
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);
|
2017-03-30 13:16:41 +00:00
|
|
|
nsAutoCString path;
|
|
|
|
rv = aFaviconURI->GetPath(path);
|
|
|
|
if (NS_SUCCEEDED(rv) && path.EqualsLiteral("/favicon.ico")) {
|
|
|
|
icon.rootIcon = 1;
|
|
|
|
}
|
2016-05-06 09:37:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the page url points to an image, the icon's url will be the same.
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
// TODO (Bug 403651): store a resample of the image. For now avoid that
|
|
|
|
// for database size and UX concerns.
|
2016-05-06 09:37:26 +00:00
|
|
|
// Don't store favicons for error pages too.
|
|
|
|
if (icon.spec.Equals(page.spec) ||
|
|
|
|
icon.spec.Equals(FAVICON_ERRORPAGE_URL)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 15:51:18 +00:00
|
|
|
|
2016-05-06 09:37:26 +00:00
|
|
|
RefPtr<AsyncFetchAndSetIconForPage> event =
|
|
|
|
new AsyncFetchAndSetIconForPage(icon, page, loadPrivate,
|
|
|
|
aCallback, aLoadingPrincipal);
|
|
|
|
|
|
|
|
// Get the target thread and start the work.
|
2009-11-11 11:04:11 +00:00
|
|
|
// DB will be updated and observers notified when data has finished loading.
|
2016-05-06 09:37:26 +00:00
|
|
|
RefPtr<Database> DB = Database::GetDatabase();
|
|
|
|
NS_ENSURE_STATE(DB);
|
|
|
|
DB->DispatchToAsyncThread(event);
|
|
|
|
|
|
|
|
// Return this event to the caller to allow aborting an eventual fetch.
|
|
|
|
event.forget(_canceler);
|
|
|
|
|
2006-07-18 15:51:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-16 00:55:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFaviconService::ReplaceFaviconData(nsIURI* aFaviconURI,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint8_t* aData,
|
|
|
|
uint32_t aDataLen,
|
2011-12-16 00:55:22 +00:00
|
|
|
const nsACString& aMimeType,
|
|
|
|
PRTime aExpiration)
|
|
|
|
{
|
2016-05-06 09:37:26 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-12-16 00:55:22 +00:00
|
|
|
NS_ENSURE_ARG(aFaviconURI);
|
|
|
|
NS_ENSURE_ARG(aData);
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
NS_ENSURE_ARG(aDataLen > 0);
|
|
|
|
NS_ENSURE_ARG(aMimeType.Length() > 0);
|
|
|
|
NS_ENSURE_ARG(imgLoader::SupportImageWithMimeType(PromiseFlatCString(aMimeType).get(),
|
2017-03-30 13:16:41 +00:00
|
|
|
AcceptedMimeTypes::IMAGES_AND_DOCUMENTS));
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
|
2011-12-16 00:55:22 +00:00
|
|
|
if (aExpiration == 0) {
|
|
|
|
aExpiration = PR_Now() + MAX_FAVICON_EXPIRATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnassociatedIconHashKey* iconKey = mUnassociatedIcons.PutEntry(aFaviconURI);
|
|
|
|
if (!iconKey) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
iconKey->created = PR_Now();
|
|
|
|
|
|
|
|
// If the cache contains unassociated icons, an expiry timer should already exist, otherwise
|
|
|
|
// there may be a timer left hanging around, so make sure we fire a new one.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t unassociatedCount = mUnassociatedIcons.Count();
|
2011-12-16 00:55:22 +00:00
|
|
|
if (unassociatedCount == 1) {
|
|
|
|
mExpireUnassociatedIconsTimer->Cancel();
|
|
|
|
mExpireUnassociatedIconsTimer->InitWithCallback(
|
|
|
|
this, UNASSOCIATED_ICON_EXPIRY_INTERVAL, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-03-30 13:16:41 +00:00
|
|
|
nsAutoCString path;
|
|
|
|
rv = aFaviconURI->GetPath(path);
|
|
|
|
if (NS_SUCCEEDED(rv) && path.EqualsLiteral("/favicon.ico")) {
|
|
|
|
iconData->rootIcon = 1;
|
|
|
|
}
|
2011-12-16 00:55:22 +00:00
|
|
|
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
IconPayload payload;
|
|
|
|
payload.mimeType = aMimeType;
|
|
|
|
payload.data.Assign(TO_CHARBUFFER(aData), aDataLen);
|
2017-03-30 13:16:41 +00:00
|
|
|
if (payload.mimeType.EqualsLiteral(SVG_MIME_TYPE)) {
|
|
|
|
payload.width = UINT16_MAX;
|
|
|
|
}
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
// There may already be a previous payload, so ensure to only have one.
|
|
|
|
iconData->payloads.Clear();
|
|
|
|
iconData->payloads.AppendElement(payload);
|
2011-12-16 00:55:22 +00:00
|
|
|
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
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;
|
2011-12-16 00:55:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2016-05-06 09:37:26 +00:00
|
|
|
RefPtr<AsyncReplaceFaviconData> event = new AsyncReplaceFaviconData(*iconData);
|
|
|
|
RefPtr<Database> DB = Database::GetDatabase();
|
|
|
|
NS_ENSURE_STATE(DB);
|
|
|
|
DB->DispatchToAsyncThread(event);
|
2011-12-16 00:55:22 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-16 00:55:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFaviconService::ReplaceFaviconDataFromDataURL(nsIURI* aFaviconURI,
|
|
|
|
const nsAString& aDataURL,
|
2015-11-24 21:32:22 +00:00
|
|
|
PRTime aExpiration,
|
|
|
|
nsIPrincipal* aLoadingPrincipal)
|
2011-12-16 00:55:53 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aFaviconURI);
|
|
|
|
NS_ENSURE_TRUE(aDataURL.Length() > 0, NS_ERROR_INVALID_ARG);
|
|
|
|
if (aExpiration == 0) {
|
|
|
|
aExpiration = PR_Now() + MAX_FAVICON_EXPIRATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> dataURI;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(dataURI), aDataURL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Use the data: protocol handler to convert the data.
|
|
|
|
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsIProtocolHandler> protocolHandler;
|
|
|
|
rv = ioService->GetProtocolHandler("data", getter_AddRefs(protocolHandler));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-11-24 21:32:22 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> loadingPrincipal = aLoadingPrincipal;
|
|
|
|
MOZ_ASSERT(loadingPrincipal, "please provide aLoadingPrincipal for this favicon");
|
|
|
|
if (!loadingPrincipal) {
|
2016-08-23 08:30:28 +00:00
|
|
|
// Let's default to the nullPrincipal if no loadingPrincipal is provided.
|
2016-05-06 11:56:24 +00:00
|
|
|
const char16_t* params[] = {
|
2016-07-21 05:03:25 +00:00
|
|
|
u"nsFaviconService::ReplaceFaviconDataFromDataURL()",
|
|
|
|
u"nsFaviconService::ReplaceFaviconDataFromDataURL(..., [optional aLoadingPrincipal])"
|
2016-05-06 11:56:24 +00:00
|
|
|
};
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
|
|
|
NS_LITERAL_CSTRING("Security by Default"),
|
|
|
|
nullptr, // aDocument
|
|
|
|
nsContentUtils::eNECKO_PROPERTIES,
|
|
|
|
"APIDeprecationWarning",
|
|
|
|
params, ArrayLength(params));
|
|
|
|
|
2017-03-22 10:38:40 +00:00
|
|
|
loadingPrincipal = NullPrincipal::Create();
|
2015-11-24 21:32:22 +00:00
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(loadingPrincipal, NS_ERROR_FAILURE);
|
|
|
|
|
2015-02-17 18:09:50 +00:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo =
|
2015-11-24 21:32:22 +00:00
|
|
|
new mozilla::LoadInfo(loadingPrincipal,
|
2015-02-17 18:09:50 +00:00
|
|
|
nullptr, // aTriggeringPrincipal
|
|
|
|
nullptr, // aLoadingNode
|
2016-05-23 21:57:31 +00:00
|
|
|
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS |
|
|
|
|
nsILoadInfo::SEC_ALLOW_CHROME |
|
|
|
|
nsILoadInfo::SEC_DISALLOW_SCRIPT,
|
2016-10-13 07:43:54 +00:00
|
|
|
nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON);
|
2015-02-17 18:09:50 +00:00
|
|
|
|
2011-12-16 00:55:53 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2015-02-17 18:09:50 +00:00
|
|
|
rv = protocolHandler->NewChannel2(dataURI, loadInfo, getter_AddRefs(channel));
|
2011-12-16 00:55:53 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Blocking stream is OK for data URIs.
|
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
2016-05-23 21:57:31 +00:00
|
|
|
rv = channel->Open2(getter_AddRefs(stream));
|
2011-12-16 00:55:53 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t available64;
|
2012-08-11 02:44:11 +00:00
|
|
|
rv = stream->Available(&available64);
|
2011-12-16 00:55:53 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-09-28 06:57:33 +00:00
|
|
|
if (available64 == 0 || available64 > UINT32_MAX / sizeof(uint8_t))
|
2012-08-11 02:44:11 +00:00
|
|
|
return NS_ERROR_FILE_TOO_BIG;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t available = (uint32_t)available64;
|
2011-12-16 00:55:53 +00:00
|
|
|
|
|
|
|
// Read all the decoded data.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t* buffer = static_cast<uint8_t*>
|
2015-03-27 00:01:12 +00:00
|
|
|
(moz_xmalloc(sizeof(uint8_t) * available));
|
2011-12-16 00:55:53 +00:00
|
|
|
if (!buffer)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t numRead;
|
2011-12-16 00:55:53 +00:00
|
|
|
rv = stream->Read(TO_CHARBUFFER(buffer), available, &numRead);
|
|
|
|
if (NS_FAILED(rv) || numRead != available) {
|
2015-03-27 00:01:12 +00:00
|
|
|
free(buffer);
|
2011-12-16 00:55:53 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString mimeType;
|
2011-12-16 00:55:53 +00:00
|
|
|
rv = channel->GetContentType(mimeType);
|
|
|
|
if (NS_FAILED(rv)) {
|
2015-03-27 00:01:12 +00:00
|
|
|
free(buffer);
|
2011-12-16 00:55:53 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReplaceFaviconData can now do the dirty work.
|
|
|
|
rv = ReplaceFaviconData(aFaviconURI, buffer, available, mimeType, aExpiration);
|
2015-03-27 00:01:12 +00:00
|
|
|
free(buffer);
|
2011-12-16 00:55:53 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2011-05-20 12:37:02 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFaviconService::GetFaviconURLForPage(nsIURI *aPageURI,
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
nsIFaviconDataCallback* aCallback,
|
|
|
|
uint16_t aPreferredWidth)
|
2011-05-20 12:37:02 +00:00
|
|
|
{
|
2016-05-06 09:37:26 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-05-20 12:37:02 +00:00
|
|
|
NS_ENSURE_ARG(aPageURI);
|
|
|
|
NS_ENSURE_ARG(aCallback);
|
|
|
|
|
2016-05-06 09:37:26 +00:00
|
|
|
nsAutoCString pageSpec;
|
|
|
|
nsresult rv = aPageURI->GetSpec(pageSpec);
|
2011-05-20 12:37:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-03-28 09:50:53 +00:00
|
|
|
nsAutoCString pageHost;
|
|
|
|
// It's expected that some domains may not have a host.
|
|
|
|
Unused << aPageURI->GetHost(pageHost);
|
2016-05-06 09:37:26 +00:00
|
|
|
|
|
|
|
RefPtr<AsyncGetFaviconURLForPage> event =
|
2017-03-28 09:50:53 +00:00
|
|
|
new AsyncGetFaviconURLForPage(pageSpec, pageHost, aPreferredWidth, aCallback);
|
2016-05-06 09:37:26 +00:00
|
|
|
|
|
|
|
RefPtr<Database> DB = Database::GetDatabase();
|
|
|
|
NS_ENSURE_STATE(DB);
|
|
|
|
DB->DispatchToAsyncThread(event);
|
|
|
|
|
2011-05-20 12:37:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-31 14:28:17 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFaviconService::GetFaviconDataForPage(nsIURI* aPageURI,
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
nsIFaviconDataCallback* aCallback,
|
|
|
|
uint16_t aPreferredWidth)
|
2011-08-31 14:28:17 +00:00
|
|
|
{
|
2016-05-06 09:37:26 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-08-31 14:28:17 +00:00
|
|
|
NS_ENSURE_ARG(aPageURI);
|
|
|
|
NS_ENSURE_ARG(aCallback);
|
|
|
|
|
2016-05-06 09:37:26 +00:00
|
|
|
nsAutoCString pageSpec;
|
|
|
|
nsresult rv = aPageURI->GetSpec(pageSpec);
|
2011-08-31 14:28:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-03-28 09:50:53 +00:00
|
|
|
nsAutoCString pageHost;
|
|
|
|
// It's expected that some domains may not have a host.
|
|
|
|
Unused << aPageURI->GetHost(pageHost);
|
2016-05-06 09:37:26 +00:00
|
|
|
|
|
|
|
RefPtr<AsyncGetFaviconDataForPage> event =
|
2017-03-28 09:50:53 +00:00
|
|
|
new AsyncGetFaviconDataForPage(pageSpec, pageHost, aPreferredWidth, aCallback);
|
2016-05-06 09:37:26 +00:00
|
|
|
RefPtr<Database> DB = Database::GetDatabase();
|
|
|
|
NS_ENSURE_STATE(DB);
|
|
|
|
DB->DispatchToAsyncThread(event);
|
|
|
|
|
2011-08-31 14:28:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-05-20 12:37:02 +00:00
|
|
|
|
2006-07-18 15:51:18 +00:00
|
|
|
nsresult
|
2008-05-08 04:26:10 +00:00
|
|
|
nsFaviconService::GetFaviconLinkForIcon(nsIURI* aFaviconURI,
|
|
|
|
nsIURI** aOutputURI)
|
2006-07-18 15:51:18 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aFaviconURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(aOutputURI);
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString spec;
|
2008-05-08 04:26:10 +00:00
|
|
|
if (aFaviconURI) {
|
|
|
|
nsresult rv = aFaviconURI->GetSpec(spec);
|
2006-07-18 15:51:18 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-05-08 04:26:10 +00:00
|
|
|
return GetFaviconLinkForIconString(spec, aOutputURI);
|
2006-07-18 15:51:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2006-07-18 15:53:12 +00:00
|
|
|
NS_IMETHODIMP
|
2008-05-08 04:26:10 +00:00
|
|
|
nsFaviconService::AddFailedFavicon(nsIURI* aFaviconURI)
|
2006-07-18 15:53:12 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aFaviconURI);
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString spec;
|
2008-05-08 04:26:10 +00:00
|
|
|
nsresult rv = aFaviconURI->GetSpec(spec);
|
2006-07-18 15:53:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-05-18 17:30:49 +00:00
|
|
|
mFailedFavicons.Put(spec, mFailedFaviconSerial);
|
2006-07-18 15:53:12 +00:00
|
|
|
mFailedFaviconSerial ++;
|
|
|
|
|
2014-08-06 13:31:21 +00:00
|
|
|
if (mFailedFavicons.Count() > MAX_FAILED_FAVICONS) {
|
2006-07-18 15:53:12 +00:00
|
|
|
// need to expire some entries, delete the FAVICON_CACHE_REDUCE_COUNT number
|
|
|
|
// of items that are the oldest
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t threshold = mFailedFaviconSerial -
|
2014-08-06 13:31:21 +00:00
|
|
|
MAX_FAILED_FAVICONS + FAVICON_CACHE_REDUCE_COUNT;
|
2015-11-25 00:53:46 +00:00
|
|
|
for (auto iter = mFailedFavicons.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
if (iter.Data() < threshold) {
|
|
|
|
iter.Remove();
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 15:53:12 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2006-07-18 15:53:12 +00:00
|
|
|
NS_IMETHODIMP
|
2008-05-08 04:26:10 +00:00
|
|
|
nsFaviconService::RemoveFailedFavicon(nsIURI* aFaviconURI)
|
2006-07-18 15:53:12 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aFaviconURI);
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString spec;
|
2008-05-08 04:26:10 +00:00
|
|
|
nsresult rv = aFaviconURI->GetSpec(spec);
|
2006-07-18 15:53:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// we silently do nothing and succeed if the icon is not in the cache
|
|
|
|
mFailedFavicons.Remove(spec);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2006-07-18 15:53:12 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsFaviconService::IsFailedFavicon(nsIURI* aFaviconURI, bool* _retval)
|
2006-07-18 15:53:12 +00:00
|
|
|
{
|
2008-05-08 04:26:10 +00:00
|
|
|
NS_ENSURE_ARG(aFaviconURI);
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString spec;
|
2008-05-08 04:26:10 +00:00
|
|
|
nsresult rv = aFaviconURI->GetSpec(spec);
|
2006-07-18 15:53:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t serial;
|
2006-07-18 15:53:12 +00:00
|
|
|
*_retval = mFailedFavicons.Get(spec, &serial);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2006-07-18 15:51:18 +00:00
|
|
|
// nsFaviconService::GetFaviconLinkForIconString
|
|
|
|
//
|
|
|
|
// This computes a favicon URL with string input and using the cached
|
|
|
|
// default one to minimize parsing.
|
|
|
|
|
|
|
|
nsresult
|
2008-05-08 04:26:10 +00:00
|
|
|
nsFaviconService::GetFaviconLinkForIconString(const nsCString& aSpec,
|
|
|
|
nsIURI** aOutput)
|
2006-07-18 15:51:18 +00:00
|
|
|
{
|
|
|
|
if (aSpec.IsEmpty()) {
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
return GetDefaultFavicon(aOutput);
|
2006-07-18 15:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString annoUri;
|
2006-07-18 15:51:18 +00:00
|
|
|
annoUri.AssignLiteral("moz-anno:" FAVICON_ANNOTATION_NAME ":");
|
|
|
|
annoUri += aSpec;
|
|
|
|
return NS_NewURI(aOutput, annoUri);
|
|
|
|
}
|
|
|
|
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2006-07-18 15:51:18 +00:00
|
|
|
// nsFaviconService::GetFaviconSpecForIconString
|
|
|
|
//
|
|
|
|
// This computes a favicon spec for when you don't want a URI object (as in
|
|
|
|
// the tree view implementation), sparing all parsing and normalization.
|
|
|
|
void
|
2008-05-08 04:26:10 +00:00
|
|
|
nsFaviconService::GetFaviconSpecForIconString(const nsCString& aSpec,
|
|
|
|
nsACString& aOutput)
|
2006-07-18 15:51:18 +00:00
|
|
|
{
|
|
|
|
if (aSpec.IsEmpty()) {
|
|
|
|
aOutput.AssignLiteral(FAVICON_DEFAULT_URL);
|
|
|
|
} else if (StringBeginsWith(aSpec, NS_LITERAL_CSTRING("chrome:"))) {
|
|
|
|
aOutput = aSpec;
|
|
|
|
} else {
|
|
|
|
aOutput.AssignLiteral("moz-anno:" FAVICON_ANNOTATION_NAME ":");
|
|
|
|
aOutput += aSpec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
/**
|
|
|
|
* Checks the icon and evaluates if it needs to be optimized.
|
|
|
|
*
|
|
|
|
* @param aIcon
|
|
|
|
* The icon to be evaluated.
|
|
|
|
*/
|
2008-01-20 06:48:07 +00:00
|
|
|
nsresult
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
nsFaviconService::OptimizeIconSizes(IconData& aIcon)
|
2008-01-20 06:48:07 +00:00
|
|
|
{
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
// 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();
|
2008-01-20 06:48:07 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
|
|
|
|
payload.data.get(),
|
|
|
|
payload.data.Length(),
|
|
|
|
NS_ASSIGNMENT_DEPEND);
|
2008-01-20 06:48:07 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// decode image
|
|
|
|
nsCOMPtr<imgIContainer> container;
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
rv = GetImgTools()->DecodeImageData(stream, payload.mimeType,
|
|
|
|
getter_AddRefs(container));
|
2008-01-20 06:48:07 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-03-28 15:30:28 +00:00
|
|
|
// For ICO files, we must evaluate each of the frames we care about.
|
|
|
|
nsTArray<FrameData> framesInfo;
|
|
|
|
rv = GetFramesInfoForContainer(container, framesInfo);
|
2008-01-20 06:48:07 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-03-28 15:30:28 +00:00
|
|
|
|
|
|
|
for (const auto& frameInfo : framesInfo) {
|
|
|
|
IconPayload newPayload;
|
|
|
|
newPayload.mimeType = NS_LITERAL_CSTRING(PNG_MIME_TYPE);
|
|
|
|
newPayload.width = frameInfo.width;
|
|
|
|
for (uint16_t size : sFaviconSizes) {
|
|
|
|
if (size <= frameInfo.width) {
|
|
|
|
newPayload.width = size;
|
|
|
|
break;
|
|
|
|
}
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 15:30:28 +00:00
|
|
|
// 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 == frameInfo.width) {
|
|
|
|
newPayload.data = payload.data;
|
|
|
|
} else {
|
|
|
|
// Scale and recompress.
|
|
|
|
// Since EncodeScaledImage use SYNC_DECODE, it will pick the best frame.
|
|
|
|
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);
|
|
|
|
}
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
|
2017-03-28 15:30:28 +00:00
|
|
|
if (newPayload.data.Length() < nsIFaviconService::MAX_FAVICON_BUFFER_SIZE) {
|
|
|
|
aIcon.payloads.AppendElement(newPayload);
|
|
|
|
}
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
}
|
2008-01-20 06:48:07 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-12 21:49:37 +00:00
|
|
|
nsresult
|
2017-03-15 15:08:28 +00:00
|
|
|
nsFaviconService::GetFaviconDataAsync(const nsCString& aFaviconURI,
|
2009-03-12 21:49:37 +00:00
|
|
|
mozIStorageStatementCallback *aCallback)
|
|
|
|
{
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
MOZ_ASSERT(aCallback, "Doesn't make sense to call this without a callback");
|
|
|
|
|
2011-10-27 09:11:34 +00:00
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> stmt = mDB->GetAsyncStatement(
|
2017-03-15 15:08:28 +00:00
|
|
|
"/*Do not warn (bug no: not worth adding an index */ "
|
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
--HG--
rename : toolkit/components/places/tests/unit/test_svg_favicon.js => toolkit/components/places/tests/favicons/test_svg_favicon.js
extra : rebase_source : fa49c4a81d6ab6b34a2f19ee4175e889a6e9d734
2016-09-28 14:14:30 +00:00
|
|
|
"SELECT data, width FROM moz_icons "
|
|
|
|
"WHERE fixed_icon_url_hash = hash(fixup_url(:url)) AND icon_url = :url "
|
|
|
|
"ORDER BY width DESC"
|
2011-10-27 09:11:34 +00:00
|
|
|
);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
|
|
|
|
2017-03-15 15:08:28 +00:00
|
|
|
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("url"), aFaviconURI);
|
2009-03-12 21:49:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStoragePendingStatement> pendingStatement;
|
2010-01-08 12:57:49 +00:00
|
|
|
return stmt->ExecuteAsync(aCallback, getter_AddRefs(pendingStatement));
|
2009-03-12 21:49:37 +00:00
|
|
|
}
|
|
|
|
|
Bug 977177 - Move favicons to a separate store. r=adw
This patch moves favicons blobs to a separate database names favicons.sqlite.
The dabatase is then ATTACHED to the main Places connection, so that its tables
can be used as if they were all part of the same database.
The favicons.database contains 3 tables:
1. moz_pages_w_icons
This is the way to join with moz_places, through page_url_hash and page_url.
We are not using the place id to avoid possible mismatches between places.sqlite
and favicons.sqlite. This way the database is "portable" and reusable even
if places.sqlite changes.
2. moz_icons
Contains icons payloads, each payload can either be an SVG or a PNG. These
are the only stored formats, any other format is rescaled and converted to
PNG. ICO files are split into single frames and stored as multiple PNGs.
SVG are distinguishable through width == UINT16_MAX
In future the table will also contain mask-icon color for SVG and average
color for PNGs.
The fixed_icon_url_hash is "fixed" to allow quickly fetch root icons, that
means icons like "domain/favicon.ico" that can also be reused for any page
under that domain.
3. moz_icons_to_pages
This is the relation table between icons and pages.
Each page can have multiple icons, each icon can be used by multiple pages.
There is a FOREIGN_KEY constraint between this (child) table and icons
or pages (parents), so that it's not possible to insert non-existing ids
in this table, and if an entry is removed from a parent table, the relation
will be automatically removed from here.
Note though that removing from the relation table won't remove from the
parent tables.
Since the relations are now many-many, it's no more possible to simply join
places with the icons table and obtain a single icon, thus it's suggested that
consumers go through the "page-icon" protocol.
The migration process from the old favicons table is async and interruptible,
it will be restarted along with the favicons service until the temp preference
places.favicons.convertPayloads is set to true.
MozReview-Commit-ID: CUCoL9smRyt
--HG--
extra : rebase_source : 4d25966596dcdf63c9c872425c5bf147406d25ac
2016-11-14 15:22:46 +00:00
|
|
|
void // static
|
|
|
|
nsFaviconService::ConvertUnsupportedPayloads(mozIStorageConnection* aDBConn)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// Ensure imgTools are initialized, so that the image decoders can be used
|
|
|
|
// off the main thread.
|
|
|
|
nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
|
|
|
|
|
|
|
|
Preferences::SetBool(PREF_CONVERT_PAYLOADS, true);
|
|
|
|
MOZ_ASSERT(aDBConn);
|
|
|
|
if (aDBConn) {
|
|
|
|
RefPtr<FetchAndConvertUnsupportedPayloads> event =
|
|
|
|
new FetchAndConvertUnsupportedPayloads(aDBConn);
|
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetInterface(aDBConn);
|
|
|
|
MOZ_ASSERT(target);
|
|
|
|
if (target) {
|
|
|
|
(void)target->Dispatch(event, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 15:08:28 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFaviconService::PreferredSizeFromURI(nsIURI* aURI, uint16_t* _size)
|
|
|
|
{
|
|
|
|
*_size = UINT16_MAX;
|
|
|
|
nsAutoCString ref;
|
|
|
|
// Check for a ref first.
|
|
|
|
if (NS_FAILED(aURI->GetRef(ref)) || ref.Length() == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Look for a "size=" fragment.
|
|
|
|
int32_t start = ref.RFind("size=");
|
|
|
|
if (start >= 0 && ref.Length() > static_cast<uint32_t>(start) + 5) {
|
|
|
|
nsDependentCSubstring size;
|
|
|
|
// This is safe regardless, since Rebind checks start is not over Length().
|
|
|
|
size.Rebind(ref, start + 5);
|
|
|
|
// Check if the string contains any non-digit.
|
|
|
|
auto begin = size.BeginReading(), end = size.EndReading();
|
|
|
|
for (auto ch = begin; ch < end; ++ch) {
|
|
|
|
if (*ch < '0' || *ch > '9') {
|
|
|
|
// Not a digit.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Convert the string to an integer value.
|
|
|
|
nsresult rv;
|
|
|
|
uint16_t val = PromiseFlatCString(size).ToInteger(&rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*_size = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-28 13:17:36 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// ExpireFaviconsStatementCallbackNotifier
|
|
|
|
|
2013-03-20 13:25:19 +00:00
|
|
|
ExpireFaviconsStatementCallbackNotifier::ExpireFaviconsStatementCallbackNotifier()
|
2009-02-28 13:17:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-08 12:57:49 +00:00
|
|
|
|
2009-02-28 13:17:36 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
ExpireFaviconsStatementCallbackNotifier::HandleCompletion(uint16_t aReason)
|
2009-02-28 13:17:36 +00:00
|
|
|
{
|
|
|
|
// We should dispatch only if expiration has been successful.
|
|
|
|
if (aReason != mozIStorageStatementCallback::REASON_FINISHED)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
mozilla::services::GetObserverService();
|
2009-02-28 13:17:36 +00:00
|
|
|
if (observerService) {
|
2012-07-30 14:20:58 +00:00
|
|
|
(void)observerService->NotifyObservers(nullptr,
|
2009-02-28 13:17:36 +00:00
|
|
|
NS_PLACES_FAVICONS_EXPIRED_TOPIC_ID,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr);
|
2009-02-28 13:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|