Bug 1196013 - Use channel->ascynOpen2 in toolkit/components/places. r=billm r=sicking r=mak

This commit is contained in:
Christoph Kerschbaumer 2016-05-23 23:57:31 +02:00
Родитель 6850e09718
Коммит 031a59734b
7 изменённых файлов: 35 добавлений и 43 удалений

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

@ -165,41 +165,6 @@ this.ContentLinkHandler = {
getLinkIconURI: function(aLink) {
let targetDoc = aLink.ownerDocument;
var uri = BrowserUtils.makeURI(aLink.href, targetDoc.characterSet);
// Verify that the load of this icon is legal.
// Some error or special pages can load their favicon.
// To be on the safe side, only allow chrome:// favicons.
var isAllowedPage = [
/^about:neterror\?/,
/^about:blocked\?/,
/^about:certerror\?/,
/^about:home$/,
].some(re => re.test(targetDoc.documentURI));
if (!isAllowedPage || !uri.schemeIs("chrome")) {
var ssm = Services.scriptSecurityManager;
try {
ssm.checkLoadURIWithPrincipal(targetDoc.nodePrincipal, uri,
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
} catch(e) {
return null;
}
}
try {
var contentPolicy = Cc["@mozilla.org/layout/content-policy;1"].
getService(Ci.nsIContentPolicy);
} catch(e) {
return null; // Refuse to load if we can't do a security check.
}
// Security says okay, now ask content policy
if (contentPolicy.shouldLoad(Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE,
uri, targetDoc.documentURIObject,
aLink, aLink.type, null)
!= Ci.nsIContentPolicy.ACCEPT)
return null;
try {
uri.userPass = "";
} catch(e) {

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

@ -92,6 +92,9 @@ DoCheckLoadURIChecks(nsIURI* aURI, nsILoadInfo* aLoadInfo)
if (aLoadInfo->GetAllowChrome()) {
flags |= nsIScriptSecurityManager::ALLOW_CHROME;
}
if (aLoadInfo->GetDisallowScript()) {
flags |= nsIScriptSecurityManager::DISALLOW_SCRIPT;
}
bool isImageInEditorType = IsImageLoadInEditorAppType(aLoadInfo);

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

@ -464,6 +464,15 @@ LoadInfo::GetAllowChrome(bool* aResult)
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetDisallowScript(bool* aResult)
{
*aResult =
(mSecurityFlags & nsILoadInfo::SEC_DISALLOW_SCRIPT);
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetDontFollowRedirects(bool* aResult)
{

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

@ -147,6 +147,11 @@ interface nsILoadInfo : nsISupports
*/
const unsigned long SEC_ALLOW_CHROME = (1<<10);
/**
* Disallow access to javascript: uris.
*/
const unsigned long SEC_DISALLOW_SCRIPT = (1<<11);
/**
* Don't follow redirects. Instead the redirect response is returned
* as a successful response for the channel.
@ -158,7 +163,7 @@ interface nsILoadInfo : nsISupports
* the response body might not be available.
* This can happen if the redirect was cached.
*/
const unsigned long SEC_DONT_FOLLOW_REDIRECTS = (1<<11);
const unsigned long SEC_DONT_FOLLOW_REDIRECTS = (1<<12);
/**
* Force private browsing. Setting this flag the private browsing can be
@ -167,7 +172,7 @@ interface nsILoadInfo : nsISupports
* If the flag is true, even if a document context is present,
* GetUsePrivateBrowsing will always return true.
*/
const unsigned long SEC_FORCE_PRIVATE_BROWSING = (1<<12);
const unsigned long SEC_FORCE_PRIVATE_BROWSING = (1<<13);
/**
* The SEC_FORCE_INHERIT_PRINCIPAL flag may be dropped when a load info
@ -175,7 +180,7 @@ interface nsILoadInfo : nsISupports
* flag is also present. This flag is set if SEC_FORCE_INHERIT_PRINCIPAL was
* dropped.
*/
const unsigned long SEC_FORCE_INHERIT_PRINCIPAL_WAS_DROPPED = (1<<13);
const unsigned long SEC_FORCE_INHERIT_PRINCIPAL_WAS_DROPPED = (1<<14);
/**
* The loadingPrincipal is the principal that is responsible for the load.
@ -313,6 +318,12 @@ interface nsILoadInfo : nsISupports
*/
[infallible] readonly attribute boolean allowChrome;
/**
* If disallowScript is true, then use nsIScriptSecurityManager::DISALLOW_SCRIPT
* when calling CheckLoadURIWithPrincipal().
*/
[infallible] readonly attribute boolean disallowScript;
/**
* Returns true if SEC_DONT_FOLLOW_REDIRECTS is set.
*/

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

@ -419,7 +419,9 @@ AsyncFetchAndSetIconForPage::FetchFromNetwork() {
rv = NS_NewChannel(getter_AddRefs(channel),
iconURI,
mLoadingPrincipal,
nsILoadInfo::SEC_NORMAL,
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS |
nsILoadInfo::SEC_ALLOW_CHROME |
nsILoadInfo::SEC_DISALLOW_SCRIPT,
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
NS_ENSURE_SUCCESS(rv, rv);
@ -439,7 +441,7 @@ AsyncFetchAndSetIconForPage::FetchFromNetwork() {
priorityChannel->AdjustPriority(nsISupportsPriority::PRIORITY_LOWEST);
}
return channel->AsyncOpen(this, nullptr);
return channel->AsyncOpen2(this);
}
NS_IMETHODIMP

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

@ -159,7 +159,7 @@ public:
rv = GetDefaultIcon(loadInfo, getter_AddRefs(newChannel));
NS_ENSURE_SUCCESS(rv, mOutputStream->Close());
rv = newChannel->AsyncOpen(listener, nullptr);
rv = newChannel->AsyncOpen2(listener);
NS_ENSURE_SUCCESS(rv, mOutputStream->Close());
return NS_OK;

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

@ -416,7 +416,9 @@ nsFaviconService::ReplaceFaviconDataFromDataURL(nsIURI* aFaviconURI,
new mozilla::LoadInfo(loadingPrincipal,
nullptr, // aTriggeringPrincipal
nullptr, // aLoadingNode
nsILoadInfo::SEC_NORMAL,
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS |
nsILoadInfo::SEC_ALLOW_CHROME |
nsILoadInfo::SEC_DISALLOW_SCRIPT,
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
nsCOMPtr<nsIChannel> channel;
@ -425,7 +427,7 @@ nsFaviconService::ReplaceFaviconDataFromDataURL(nsIURI* aFaviconURI,
// Blocking stream is OK for data URIs.
nsCOMPtr<nsIInputStream> stream;
rv = channel->Open(getter_AddRefs(stream));
rv = channel->Open2(getter_AddRefs(stream));
NS_ENSURE_SUCCESS(rv, rv);
uint64_t available64;