2016-06-30 16:17:44 +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/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
2017-01-17 15:48:17 +00:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2016-06-30 16:17:44 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
|
|
|
"resource://gre/modules/PlacesUtils.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
|
|
|
|
"resource://gre/modules/NetUtil.jsm");
|
|
|
|
|
|
|
|
function makeDefaultFaviconChannel(uri, loadInfo) {
|
|
|
|
let channel = Services.io.newChannelFromURIWithLoadInfo(
|
|
|
|
PlacesUtils.favicons.defaultFavicon, loadInfo);
|
|
|
|
channel.originalURI = uri;
|
2017-05-03 07:31:05 +00:00
|
|
|
channel.contentType = PlacesUtils.favicons.defaultFaviconMimeType;
|
2016-06-30 16:17:44 +00:00
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
2017-05-03 07:31:05 +00:00
|
|
|
function streamDefaultFavicon(uri, loadInfo, outputStream, originalChannel) {
|
2016-06-30 16:17:44 +00:00
|
|
|
try {
|
|
|
|
// Open up a new channel to get that data, and push it to our output stream.
|
|
|
|
// Create a listener to hand data to the pipe's output stream.
|
|
|
|
let listener = Cc["@mozilla.org/network/simple-stream-listener;1"]
|
|
|
|
.createInstance(Ci.nsISimpleStreamListener);
|
|
|
|
listener.init(outputStream, {
|
|
|
|
onStartRequest(request, context) {},
|
|
|
|
onStopRequest(request, context, statusCode) {
|
|
|
|
// We must close the outputStream regardless.
|
|
|
|
outputStream.close();
|
|
|
|
}
|
|
|
|
});
|
2017-05-03 07:31:05 +00:00
|
|
|
originalChannel.contentType = PlacesUtils.favicons.defaultFaviconMimeType;
|
2016-06-30 16:17:44 +00:00
|
|
|
let defaultIconChannel = makeDefaultFaviconChannel(uri, loadInfo);
|
|
|
|
defaultIconChannel.asyncOpen2(listener);
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
outputStream.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
function serveIcon(pipe, data, len) {
|
|
|
|
// Pass the icon data to the output stream.
|
|
|
|
let stream = Cc["@mozilla.org/binaryoutputstream;1"]
|
|
|
|
.createInstance(Ci.nsIBinaryOutputStream);
|
|
|
|
stream.setOutputStream(pipe.outputStream);
|
|
|
|
stream.writeByteArray(data, len);
|
|
|
|
stream.close();
|
|
|
|
pipe.outputStream.close();
|
|
|
|
}
|
|
|
|
|
2016-06-30 16:17:44 +00:00
|
|
|
function PageIconProtocolHandler() {
|
|
|
|
}
|
|
|
|
|
|
|
|
PageIconProtocolHandler.prototype = {
|
|
|
|
get scheme() {
|
|
|
|
return "page-icon";
|
|
|
|
},
|
|
|
|
|
|
|
|
get defaultPort() {
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
get protocolFlags() {
|
|
|
|
return Ci.nsIProtocolHandler.URI_NORELATIVE |
|
|
|
|
Ci.nsIProtocolHandler.URI_NOAUTH |
|
|
|
|
Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD |
|
|
|
|
Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE;
|
|
|
|
},
|
|
|
|
|
|
|
|
newURI(spec, originCharset, baseURI) {
|
|
|
|
let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
|
|
|
|
uri.spec = spec;
|
|
|
|
return uri;
|
|
|
|
},
|
|
|
|
|
|
|
|
newChannel2(uri, loadInfo) {
|
|
|
|
try {
|
|
|
|
// Create a pipe that will give us an output stream that we can use once
|
|
|
|
// we got all the favicon data.
|
|
|
|
let pipe = Cc["@mozilla.org/pipe;1"]
|
|
|
|
.createInstance(Ci.nsIPipe);
|
2016-08-03 01:00:07 +00:00
|
|
|
pipe.init(true, true, 0, Ci.nsIFaviconService.MAX_FAVICON_BUFFER_SIZE);
|
2016-06-30 16:17:44 +00:00
|
|
|
|
|
|
|
// Create our channel.
|
2017-01-17 15:48:17 +00:00
|
|
|
let channel = Cc["@mozilla.org/network/input-stream-channel;1"]
|
2016-06-30 16:17:44 +00:00
|
|
|
.createInstance(Ci.nsIInputStreamChannel);
|
|
|
|
channel.QueryInterface(Ci.nsIChannel);
|
|
|
|
channel.setURI(uri);
|
|
|
|
channel.contentStream = pipe.inputStream;
|
|
|
|
channel.loadInfo = loadInfo;
|
|
|
|
|
2017-07-29 11:50:21 +00:00
|
|
|
let pageURI = NetUtil.newURI(uri.pathQueryRef.replace(/[&#]size=[^&]+$/, ""));
|
2017-03-15 15:08:28 +00:00
|
|
|
let preferredSize = PlacesUtils.favicons.preferredSizeFromURI(uri);
|
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
|
|
|
PlacesUtils.favicons.getFaviconDataForPage(pageURI, (iconURI, len, data, mimeType) => {
|
2016-06-30 16:17:44 +00:00
|
|
|
if (len == 0) {
|
2017-05-03 07:31:05 +00:00
|
|
|
streamDefaultFavicon(uri, loadInfo, pipe.outputStream, channel);
|
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 {
|
|
|
|
try {
|
2017-05-03 07:31:05 +00:00
|
|
|
channel.contentType = mimeType;
|
2017-08-01 10:59:12 +00:00
|
|
|
channel.contentLength = len;
|
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
|
|
|
serveIcon(pipe, data, len);
|
|
|
|
} catch (ex) {
|
2017-05-03 07:31:05 +00:00
|
|
|
streamDefaultFavicon(uri, loadInfo, pipe.outputStream, channel);
|
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
|
|
|
}
|
2016-06-30 16:17:44 +00:00
|
|
|
}
|
2017-03-15 15:08:28 +00:00
|
|
|
}, preferredSize);
|
2016-06-30 16:17:44 +00:00
|
|
|
|
|
|
|
return channel;
|
|
|
|
} catch (ex) {
|
|
|
|
return makeDefaultFaviconChannel(uri, loadInfo);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
newChannel(uri) {
|
|
|
|
return this.newChannel2(uri, null);
|
|
|
|
},
|
|
|
|
|
|
|
|
allowPort(port, scheme) {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{60a1f7c6-4ff9-4a42-84d3-5a185faa6f32}"),
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsIProtocolHandler
|
|
|
|
])
|
|
|
|
};
|
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PageIconProtocolHandler]);
|