mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 741059 - Part 2: Use the nsIChannel::SetPrivate API to set the private bit on the favicon channel loads based on the knowledge of the caller of the favicon loading API; r=mak
This commit is contained in:
parent
d58d386309
commit
0c56f15dbc
@ -18,6 +18,10 @@
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsStreamUtils.h"
|
||||
#include "nsIPrivateBrowsingChannel.h"
|
||||
#if !(defined(MOZ_PER_WINDOW_PRIVATE_BROWSING)) && defined(DEBUG)
|
||||
#include "nsIPrivateBrowsingService.h"
|
||||
#endif
|
||||
|
||||
#define CONTENT_SNIFFING_SERVICES "content-sniffing-services"
|
||||
|
||||
@ -435,6 +439,7 @@ nsresult
|
||||
AsyncFetchAndSetIconForPage::start(nsIURI* aFaviconURI,
|
||||
nsIURI* aPageURI,
|
||||
enum AsyncFaviconFetchMode aFetchMode,
|
||||
uint32_t aFaviconLoadType,
|
||||
nsIFaviconDataCallback* aCallback)
|
||||
{
|
||||
NS_PRECONDITION(NS_IsMainThread(),
|
||||
@ -481,7 +486,7 @@ AsyncFetchAndSetIconForPage::start(nsIURI* aFaviconURI,
|
||||
// The event will swap owning pointers, thus we need a new pointer.
|
||||
nsCOMPtr<nsIFaviconDataCallback> callback(aCallback);
|
||||
nsRefPtr<AsyncFetchAndSetIconForPage> event =
|
||||
new AsyncFetchAndSetIconForPage(icon, page, callback);
|
||||
new AsyncFetchAndSetIconForPage(icon, page, aFaviconLoadType, callback);
|
||||
|
||||
// Get the target thread and start the work.
|
||||
nsRefPtr<Database> DB = Database::GetDatabase();
|
||||
@ -494,11 +499,26 @@ AsyncFetchAndSetIconForPage::start(nsIURI* aFaviconURI,
|
||||
AsyncFetchAndSetIconForPage::AsyncFetchAndSetIconForPage(
|
||||
IconData& aIcon
|
||||
, PageData& aPage
|
||||
, uint32_t aFaviconLoadType
|
||||
, nsCOMPtr<nsIFaviconDataCallback>& aCallback
|
||||
) : AsyncFaviconHelperBase(aCallback)
|
||||
, mIcon(aIcon)
|
||||
, mPage(aPage)
|
||||
, mFaviconLoadPrivate(aFaviconLoadType == nsIFaviconService::FAVICON_LOAD_PRIVATE)
|
||||
{
|
||||
#if !(defined(MOZ_PER_WINDOW_PRIVATE_BROWSING)) && defined(DEBUG)
|
||||
// This code makes sure that in global private browsing mode, the flag
|
||||
// passed to us matches the global PB mode. This can be removed when
|
||||
// per-window private browsing has been turned on.
|
||||
nsCOMPtr<nsIPrivateBrowsingService> pbService =
|
||||
do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
|
||||
if (pbService) {
|
||||
bool inPrivateBrowsing = false;
|
||||
if (NS_SUCCEEDED(pbService->GetPrivateBrowsingEnabled(&inPrivateBrowsing))) {
|
||||
MOZ_ASSERT(inPrivateBrowsing == mFaviconLoadPrivate);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
AsyncFetchAndSetIconForPage::~AsyncFetchAndSetIconForPage()
|
||||
@ -533,7 +553,7 @@ AsyncFetchAndSetIconForPage::Run()
|
||||
// Fetch the icon from network. When done this will associate the
|
||||
// icon to the page and notify.
|
||||
nsRefPtr<AsyncFetchAndSetIconFromNetwork> event =
|
||||
new AsyncFetchAndSetIconFromNetwork(mIcon, mPage, mCallback);
|
||||
new AsyncFetchAndSetIconFromNetwork(mIcon, mPage, mFaviconLoadPrivate, mCallback);
|
||||
|
||||
// Start the work on the main thread.
|
||||
rv = NS_DispatchToMainThread(event);
|
||||
@ -557,11 +577,13 @@ NS_IMPL_ISUPPORTS_INHERITED3(
|
||||
AsyncFetchAndSetIconFromNetwork::AsyncFetchAndSetIconFromNetwork(
|
||||
IconData& aIcon
|
||||
, PageData& aPage
|
||||
, bool aFaviconLoadPrivate
|
||||
, nsCOMPtr<nsIFaviconDataCallback>& aCallback
|
||||
)
|
||||
: AsyncFaviconHelperBase(aCallback)
|
||||
, mIcon(aIcon)
|
||||
, mPage(aPage)
|
||||
, mFaviconLoadPrivate(aFaviconLoadPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
@ -596,6 +618,11 @@ AsyncFetchAndSetIconFromNetwork::Run()
|
||||
NS_ENSURE_STATE(listenerRequestor);
|
||||
rv = mChannel->SetNotificationCallbacks(listenerRequestor);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(mChannel);
|
||||
if (pbChannel) {
|
||||
rv = pbChannel->SetPrivate(mFaviconLoadPrivate);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
rv = mChannel->AsyncOpen(this, nullptr);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -133,6 +133,7 @@ public:
|
||||
static nsresult start(nsIURI* aFaviconURI,
|
||||
nsIURI* aPageURI,
|
||||
enum AsyncFaviconFetchMode aFetchMode,
|
||||
uint32_t aFaviconLoadType,
|
||||
nsIFaviconDataCallback* aCallback);
|
||||
|
||||
/**
|
||||
@ -147,6 +148,7 @@ public:
|
||||
*/
|
||||
AsyncFetchAndSetIconForPage(IconData& aIcon,
|
||||
PageData& aPage,
|
||||
uint32_t aFaviconLoadType,
|
||||
nsCOMPtr<nsIFaviconDataCallback>& aCallback);
|
||||
|
||||
virtual ~AsyncFetchAndSetIconForPage();
|
||||
@ -154,6 +156,7 @@ public:
|
||||
protected:
|
||||
IconData mIcon;
|
||||
PageData mPage;
|
||||
const bool mFaviconLoadPrivate;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -186,6 +189,7 @@ public:
|
||||
*/
|
||||
AsyncFetchAndSetIconFromNetwork(IconData& aIcon,
|
||||
PageData& aPage,
|
||||
bool aFaviconLoadPrivate,
|
||||
nsCOMPtr<nsIFaviconDataCallback>& aCallback);
|
||||
|
||||
virtual ~AsyncFetchAndSetIconFromNetwork();
|
||||
@ -194,6 +198,7 @@ protected:
|
||||
IconData mIcon;
|
||||
PageData mPage;
|
||||
nsCOMPtr<nsIChannel> mChannel;
|
||||
const bool mFaviconLoadPrivate;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@ interface nsIFaviconDataCallback;
|
||||
* @status EXPERIMENTAL
|
||||
*/
|
||||
|
||||
[scriptable, uuid(f3530e8d-0016-4f56-91fe-28958a7ec296)]
|
||||
[scriptable, uuid(8849feef-0ead-4e9b-b63b-8d862c42a736)]
|
||||
interface mozIAsyncFavicons : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -48,6 +48,9 @@ interface mozIAsyncFavicons : nsISupports
|
||||
* don't have it or it has expired from the cache. Setting
|
||||
* aForceReload to true causes us to reload the favicon even if we
|
||||
* have a usable copy.
|
||||
* @param aFaviconLoadType
|
||||
* Set to FAVICON_LOAD_PRIVATE if the favicon is loaded from a private
|
||||
* browsing window. Set to FAVICON_LOAD_NON_PRIVATE otherwise.
|
||||
* @param aCallback
|
||||
* Once we're done setting and/or fetching the favicon, we invoke this
|
||||
* callback.
|
||||
@ -57,6 +60,7 @@ interface mozIAsyncFavicons : nsISupports
|
||||
void setAndFetchFaviconForPage(in nsIURI aPageURI,
|
||||
in nsIURI aFaviconURI,
|
||||
in boolean aForceReload,
|
||||
in unsigned long aFaviconLoadType,
|
||||
[optional] in nsIFaviconDataCallback aCallback);
|
||||
|
||||
/**
|
||||
|
@ -344,6 +344,7 @@ NS_IMETHODIMP
|
||||
nsFaviconService::SetAndLoadFaviconForPage(nsIURI* aPageURI,
|
||||
nsIURI* aFaviconURI,
|
||||
bool aForceReload,
|
||||
uint32_t aFaviconLoadType,
|
||||
nsIFaviconDataCallback* aCallback)
|
||||
{
|
||||
NS_ENSURE_ARG(aPageURI);
|
||||
@ -367,7 +368,7 @@ nsFaviconService::SetAndLoadFaviconForPage(nsIURI* aPageURI,
|
||||
// Finally associate the icon to the requested page if not yet associated.
|
||||
rv = AsyncFetchAndSetIconForPage::start(
|
||||
aFaviconURI, aPageURI, aForceReload ? FETCH_ALWAYS : FETCH_IF_MISSING,
|
||||
aCallback
|
||||
aFaviconLoadType, aCallback
|
||||
);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -379,10 +380,12 @@ NS_IMETHODIMP
|
||||
nsFaviconService::SetAndFetchFaviconForPage(nsIURI* aPageURI,
|
||||
nsIURI* aFaviconURI,
|
||||
bool aForceReload,
|
||||
uint32_t aFaviconLoadType,
|
||||
nsIFaviconDataCallback* aCallback)
|
||||
{
|
||||
return SetAndLoadFaviconForPage(aPageURI, aFaviconURI,
|
||||
aForceReload, aCallback);
|
||||
aForceReload, aFaviconLoadType,
|
||||
aCallback);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -8,7 +8,7 @@
|
||||
interface nsIURI;
|
||||
interface nsIFaviconDataCallback;
|
||||
|
||||
[scriptable, uuid(2cf188f4-3c96-4bca-b668-36b25aaf7c1d)]
|
||||
[scriptable, uuid(8062a652-e0ea-4a50-b204-a0dde133de0e)]
|
||||
interface nsIFaviconService : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -34,6 +34,11 @@ interface nsIFaviconService : nsISupports
|
||||
void setFaviconUrlForPage(in nsIURI aPageURI,
|
||||
in nsIURI aFaviconURI);
|
||||
|
||||
// The favicon is being loaded from a private browsing window
|
||||
const unsigned long FAVICON_LOAD_PRIVATE = 1;
|
||||
// The favicon is being loaded from a non-private browsing window
|
||||
const unsigned long FAVICON_LOAD_NON_PRIVATE = 2;
|
||||
|
||||
/**
|
||||
* Same as SetFaviconUrlForPage except that this also attempts to fetch and
|
||||
* save the icon data by loading the favicon URI through an async network
|
||||
@ -63,6 +68,9 @@ interface nsIFaviconService : nsISupports
|
||||
* Unset is normal behavior, we will only try to reload the favicon
|
||||
* if we don't have it or if it has expired from the cache. If set,
|
||||
* it will always try to reload the favicon.
|
||||
* @param aFaviconLoadType
|
||||
* Set to FAVICON_LOAD_PRIVATE if the favicon is loaded from a private
|
||||
* browsing window. Set to FAVICON_LOAD_NON_PRIVATE otherwise.
|
||||
* @param aCallback
|
||||
* Once we're done setting and/or loading the favicon, we invoke this
|
||||
* callback.
|
||||
@ -74,6 +82,7 @@ interface nsIFaviconService : nsISupports
|
||||
void setAndLoadFaviconForPage(in nsIURI aPageURI,
|
||||
in nsIURI aFaviconURI,
|
||||
in boolean aForceReload,
|
||||
in unsigned long aFaviconLoadType,
|
||||
[optional] in nsIFaviconDataCallback aCallback);
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user