Bug 1087726: Make JS callers of ios.newChannel call ios.newChannel2 in browser/ (r=gijs)

This commit is contained in:
Christoph Kerschbaumer 2014-10-24 14:36:11 -07:00
Родитель 2b846790d1
Коммит a4c18cd3ae
3 изменённых файлов: 45 добавлений и 24 удалений

Просмотреть файл

@ -1249,7 +1249,12 @@ nsContextMenu.prototype = {
// set up a channel to do the saving
var ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var channel = ioService.newChannelFromURI(makeURI(linkURL));
var channel = ioService.newChannelFromURI2(makeURI(linkURL),
doc,
null, // aLoadingPrincipal
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
if (channel instanceof Ci.nsIPrivateBrowsingChannel) {
let docIsPrivate = PrivateBrowsingUtils.isWindowPrivate(doc.defaultView);
channel.setPrivate(docIsPrivate);

Просмотреть файл

@ -189,7 +189,7 @@ function GetBookmarksResource(aProfileFolder) {
type: MigrationUtils.resourceTypes.BOOKMARKS,
migrate: function(aCallback) {
NetUtil.asyncFetch(bookmarksFile, MigrationUtils.wrapMigrateFunction(
NetUtil.asyncFetch2(bookmarksFile, MigrationUtils.wrapMigrateFunction(
function(aInputStream, aResultCode) {
if (!Components.isSuccessCode(aResultCode))
throw new Error("Could not read Bookmarks file");
@ -225,7 +225,12 @@ function GetBookmarksResource(aProfileFolder) {
}
}
}, null);
}, aCallback));
}, aCallback),
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
}
};
}

Просмотреть файл

@ -73,15 +73,20 @@ XPCOMUtils.defineLazyServiceGetter(this, "faviconSvc",
"nsIFaviconService");
// nsIURI -> imgIContainer
function _imageFromURI(uri, privateMode, callback) {
let channel = ioSvc.newChannelFromURI(uri);
function _imageFromURI(doc, uri, privateMode, callback) {
let channel = ioSvc.newChannelFromURI2(uri,
doc,
null, // aLoadingPrincipal
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
try {
channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
channel.setPrivate(privateMode);
} catch (e) {
// Ignore channels which do not support nsIPrivateBrowsingChannel
}
NetUtil.asyncFetch(channel, function(inputStream, resultCode) {
NetUtil.asyncFetch2(channel, function(inputStream, resultCode) {
if (!Components.isSuccessCode(resultCode))
return;
try {
@ -99,11 +104,11 @@ function _imageFromURI(uri, privateMode, callback) {
}
// string? -> imgIContainer
function getFaviconAsImage(iconurl, privateMode, callback) {
function getFaviconAsImage(doc, iconurl, privateMode, callback) {
if (iconurl)
_imageFromURI(NetUtil.newURI(iconurl), privateMode, callback);
_imageFromURI(doc, NetUtil.newURI(iconurl), privateMode, callback);
else
_imageFromURI(faviconSvc.defaultFavicon, privateMode, callback);
_imageFromURI(doc, faviconSvc.defaultFavicon, privateMode, callback);
}
// Snaps the given rectangle to be pixel-aligned at the given scale
@ -497,13 +502,16 @@ TabWindow.prototype = {
preview.visible = AeroPeek.enabled;
preview.active = this.tabbrowser.selectedTab == controller.tab;
// Grab the default favicon
getFaviconAsImage(null, PrivateBrowsingUtils.isWindowPrivate(this.win), function (img) {
// It is possible that we've already gotten the real favicon, so make sure
// we have not set one before setting this default one.
if (!preview.icon)
preview.icon = img;
});
getFaviconAsImage(
controller.linkedBrowser.contentWindow.document,
null,
PrivateBrowsingUtils.isWindowPrivate(this.win),
function (img) {
// It is possible that we've already gotten the real favicon, so make sure
// we have not set one before setting this default one.
if (!preview.icon)
preview.icon = img;
});
return preview;
},
@ -588,14 +596,17 @@ TabWindow.prototype = {
//// Browser progress listener
onLinkIconAvailable: function (aBrowser, aIconURL) {
let self = this;
getFaviconAsImage(aIconURL, PrivateBrowsingUtils.isWindowPrivate(this.win), function (img) {
let index = self.tabbrowser.browsers.indexOf(aBrowser);
// Only add it if we've found the index. The tab could have closed!
if (index != -1) {
let tab = self.tabbrowser.tabs[index];
self.previews.get(tab).icon = img;
}
});
getFaviconAsImage(
aBrowser.contentWindow.document,
aIconURL,PrivateBrowsingUtils.isWindowPrivate(this.win),
function (img) {
let index = self.tabbrowser.browsers.indexOf(aBrowser);
// Only add it if we've found the index. The tab could have closed!
if (index != -1) {
let tab = self.tabbrowser.tabs[index];
self.previews.get(tab).icon = img;
}
});
}
}