This patch was autogenerated by my decomponents.py
It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.
It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.
It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)
MozReview-Commit-ID: DeSHcClQ7cG
133 lines
4.3 KiB
JavaScript
133 lines
4.3 KiB
JavaScript
/* 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";
|
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "PlacesUtils",
|
|
"resource://gre/modules/PlacesUtils.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "NetUtil",
|
|
"resource://gre/modules/NetUtil.jsm");
|
|
|
|
function makeDefaultFaviconChannel(uri, loadInfo) {
|
|
let channel = Services.io.newChannelFromURIWithLoadInfo(
|
|
PlacesUtils.favicons.defaultFavicon, loadInfo);
|
|
channel.originalURI = uri;
|
|
channel.contentType = PlacesUtils.favicons.defaultFaviconMimeType;
|
|
return channel;
|
|
}
|
|
|
|
function streamDefaultFavicon(uri, loadInfo, outputStream, originalChannel) {
|
|
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();
|
|
}
|
|
});
|
|
originalChannel.contentType = PlacesUtils.favicons.defaultFaviconMimeType;
|
|
let defaultIconChannel = makeDefaultFaviconChannel(uri, loadInfo);
|
|
defaultIconChannel.asyncOpen2(listener);
|
|
} catch (ex) {
|
|
Cu.reportError(ex);
|
|
outputStream.close();
|
|
}
|
|
}
|
|
|
|
function serveIcon(pipe, data, len) {
|
|
// Pass the icon data to the output stream.
|
|
let stream = Cc["@mozilla.org/binaryoutputstream;1"]
|
|
.createInstance(Ci.nsIBinaryOutputStream);
|
|
stream.setOutputStream(pipe.outputStream);
|
|
stream.writeByteArray(data, len);
|
|
stream.close();
|
|
pipe.outputStream.close();
|
|
}
|
|
|
|
function PageIconProtocolHandler() {
|
|
}
|
|
|
|
PageIconProtocolHandler.prototype = {
|
|
get scheme() {
|
|
return "page-icon";
|
|
},
|
|
|
|
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) {
|
|
return Cc["@mozilla.org/network/simple-uri-mutator;1"]
|
|
.createInstance(Ci.nsIURIMutator)
|
|
.setSpec(spec)
|
|
.finalize();
|
|
},
|
|
|
|
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);
|
|
pipe.init(true, true, 0, Ci.nsIFaviconService.MAX_FAVICON_BUFFER_SIZE);
|
|
|
|
// Create our channel.
|
|
let channel = Cc["@mozilla.org/network/input-stream-channel;1"]
|
|
.createInstance(Ci.nsIInputStreamChannel);
|
|
channel.QueryInterface(Ci.nsIChannel);
|
|
channel.setURI(uri);
|
|
channel.contentStream = pipe.inputStream;
|
|
channel.loadInfo = loadInfo;
|
|
|
|
let pageURI = NetUtil.newURI(uri.pathQueryRef.replace(/[&#]size=[^&]+$/, ""));
|
|
let preferredSize = PlacesUtils.favicons.preferredSizeFromURI(uri);
|
|
PlacesUtils.favicons.getFaviconDataForPage(pageURI, (iconURI, len, data, mimeType) => {
|
|
if (len == 0) {
|
|
streamDefaultFavicon(uri, loadInfo, pipe.outputStream, channel);
|
|
} else {
|
|
try {
|
|
channel.contentType = mimeType;
|
|
channel.contentLength = len;
|
|
serveIcon(pipe, data, len);
|
|
} catch (ex) {
|
|
streamDefaultFavicon(uri, loadInfo, pipe.outputStream, channel);
|
|
}
|
|
}
|
|
}, preferredSize);
|
|
|
|
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]);
|