Bug 722845 - Part 4: Add PB information to wyciwyg channels. r=jduell

This commit is contained in:
Josh Matthews 2012-05-24 16:31:54 +01:00
Родитель 59f6cd5233
Коммит aabb5e983a
11 изменённых файлов: 41 добавлений и 16 удалений

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

@ -53,7 +53,7 @@ class PrivateBrowsingConsumer : public nsIPrivateBrowsingConsumer
NS_IMETHOD GetUsingPrivateBrowsing(bool *aUsingPB) NS_IMETHOD GetUsingPrivateBrowsing(bool *aUsingPB)
{ {
*aUsingPB = (mOverride ? mUsingPB : UsingPrivateBrowsing()); *aUsingPB = (mOverride ? mUsingPB : UsingPrivateBrowsingInternal());
return NS_OK; return NS_OK;
} }
@ -66,7 +66,7 @@ class PrivateBrowsingConsumer : public nsIPrivateBrowsingConsumer
} }
protected: protected:
bool UsingPrivateBrowsing() bool UsingPrivateBrowsingInternal()
{ {
nsCOMPtr<nsILoadContext> loadContext; nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(mSelf, loadContext); NS_QueryNotificationCallbacks(mSelf, loadContext);

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

@ -161,7 +161,7 @@ FTPChannelChild::AsyncOpen(::nsIStreamListener* listener, nsISupports* aContext)
mLoadGroup->AddRequest(this, nsnull); mLoadGroup->AddRequest(this, nsnull);
SendAsyncOpen(nsBaseChannel::URI(), mStartPos, mEntityID, SendAsyncOpen(nsBaseChannel::URI(), mStartPos, mEntityID,
IPC::InputStream(mUploadStream), UsingPrivateBrowsing()); IPC::InputStream(mUploadStream), UsePrivateBrowsing());
// The socket transport layer in the chrome process now has a logical ref to // The socket transport layer in the chrome process now has a logical ref to
// us until OnStopRequest is called. // us until OnStopRequest is called.

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

@ -2217,14 +2217,19 @@ nsFtpState::CheckCache()
if (!cache) if (!cache)
return false; return false;
bool isPrivate = mChannel->UsePrivateBrowsing();
const char* sessionName = isPrivate ? "FTP-private" : "FTP";
nsCacheStoragePolicy policy =
isPrivate ? nsICache::STORE_IN_MEMORY : nsICache::STORE_ANYWHERE;
nsCOMPtr<nsICacheSession> session; nsCOMPtr<nsICacheSession> session;
cache->CreateSession("FTP", cache->CreateSession(sessionName,
nsICache::STORE_ANYWHERE, policy,
nsICache::STREAM_BASED, nsICache::STREAM_BASED,
getter_AddRefs(session)); getter_AddRefs(session));
if (!session) if (!session)
return false; return false;
session->SetDoomEntriesIfExpired(false); session->SetDoomEntriesIfExpired(false);
session->SetIsPrivate(isPrivate);
// Set cache access requested: // Set cache access requested:
nsCacheAccessMode accessReq; nsCacheAccessMode accessReq;

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

@ -1041,7 +1041,7 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
mPriority, mRedirectionLimit, mAllowPipelining, mPriority, mRedirectionLimit, mAllowPipelining,
mForceAllowThirdPartyCookie, mSendResumeAt, mForceAllowThirdPartyCookie, mSendResumeAt,
mStartPos, mEntityID, mChooseApplicationCache, mStartPos, mEntityID, mChooseApplicationCache,
appCacheClientId, mAllowSpdy, UsingPrivateBrowsing()); appCacheClientId, mAllowSpdy, UsePrivateBrowsing());
return NS_OK; return NS_OK;
} }

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

@ -21,7 +21,8 @@ parent:
Init(URI uri); Init(URI uri);
AsyncOpen(URI originalURI, AsyncOpen(URI originalURI,
PRUint32 loadFlags); PRUint32 loadFlags,
bool usingPrivateBrowsing);
// methods corresponding to those of nsIWyciwygChannel // methods corresponding to those of nsIWyciwygChannel
WriteToCacheEntry(nsString data); WriteToCacheEntry(nsString data);

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

@ -24,7 +24,8 @@ NS_IMPL_ISUPPORTS3(WyciwygChannelChild,
WyciwygChannelChild::WyciwygChannelChild() WyciwygChannelChild::WyciwygChannelChild()
: mStatus(NS_OK) : PrivateBrowsingConsumer(this)
, mStatus(NS_OK)
, mIsPending(false) , mIsPending(false)
, mCanceled(false) , mCanceled(false)
, mLoadFlags(LOAD_NORMAL) , mLoadFlags(LOAD_NORMAL)
@ -32,7 +33,7 @@ WyciwygChannelChild::WyciwygChannelChild()
, mCharsetSource(kCharsetUninitialized) , mCharsetSource(kCharsetUninitialized)
, mState(WCC_NEW) , mState(WCC_NEW)
, mIPCOpen(false) , mIPCOpen(false)
, mEventQ(this) , mEventQ(NS_ISUPPORTS_CAST(nsIWyciwygChannel*, this))
{ {
LOG(("Creating WyciwygChannelChild @%x\n", this)); LOG(("Creating WyciwygChannelChild @%x\n", this));
} }
@ -561,7 +562,7 @@ WyciwygChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aConte
if (mLoadGroup) if (mLoadGroup)
mLoadGroup->AddRequest(this, nsnull); mLoadGroup->AddRequest(this, nsnull);
SendAsyncOpen(IPC::URI(mOriginalURI), mLoadFlags); SendAsyncOpen(IPC::URI(mOriginalURI), mLoadFlags, UsePrivateBrowsing());
mState = WCC_OPENED; mState = WCC_OPENED;

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

@ -10,6 +10,7 @@
#include "nsIWyciwygChannel.h" #include "nsIWyciwygChannel.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsIProgressEventSink.h" #include "nsIProgressEventSink.h"
#include "PrivateBrowsingConsumer.h"
namespace mozilla { namespace mozilla {
namespace net { namespace net {
@ -34,6 +35,7 @@ enum WyciwygChannelChildState {
// Header file contents // Header file contents
class WyciwygChannelChild : public PWyciwygChannelChild class WyciwygChannelChild : public PWyciwygChannelChild
, public nsIWyciwygChannel , public nsIWyciwygChannel
, public PrivateBrowsingConsumer
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS

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

@ -78,7 +78,8 @@ WyciwygChannelParent::RecvInit(const IPC::URI& aURI)
bool bool
WyciwygChannelParent::RecvAsyncOpen(const IPC::URI& aOriginal, WyciwygChannelParent::RecvAsyncOpen(const IPC::URI& aOriginal,
const PRUint32& aLoadFlags) const PRUint32& aLoadFlags,
const bool& aUsingPrivateBrowsing)
{ {
nsCOMPtr<nsIURI> original(aOriginal); nsCOMPtr<nsIURI> original(aOriginal);
@ -97,6 +98,9 @@ WyciwygChannelParent::RecvAsyncOpen(const IPC::URI& aOriginal,
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return SendCancelEarly(rv); return SendCancelEarly(rv);
static_cast<nsWyciwygChannel*>(mChannel.get())->
OverridePrivateBrowsing(aUsingPrivateBrowsing);
rv = mChannel->AsyncOpen(this, nsnull); rv = mChannel->AsyncOpen(this, nsnull);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return SendCancelEarly(rv); return SendCancelEarly(rv);

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

@ -28,7 +28,8 @@ public:
protected: protected:
virtual bool RecvInit(const IPC::URI& uri); virtual bool RecvInit(const IPC::URI& uri);
virtual bool RecvAsyncOpen(const IPC::URI& original, virtual bool RecvAsyncOpen(const IPC::URI& original,
const PRUint32& loadFlags); const PRUint32& loadFlags,
const bool& usingPrivateBrowsing);
virtual bool RecvWriteToCacheEntry(const nsString& data); virtual bool RecvWriteToCacheEntry(const nsString& data);
virtual bool RecvCloseCacheEntry(const nsresult& reason); virtual bool RecvCloseCacheEntry(const nsresult& reason);
virtual bool RecvSetCharsetAndSource(const PRInt32& source, virtual bool RecvSetCharsetAndSource(const PRInt32& source,

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

@ -81,10 +81,12 @@ private:
// nsWyciwygChannel methods // nsWyciwygChannel methods
nsWyciwygChannel::nsWyciwygChannel() nsWyciwygChannel::nsWyciwygChannel()
: mStatus(NS_OK), : PrivateBrowsingConsumer(this),
mStatus(NS_OK),
mIsPending(false), mIsPending(false),
mCharsetAndSourceSet(false), mCharsetAndSourceSet(false),
mNeedToWriteCharset(false), mNeedToWriteCharset(false),
mPrivate(false),
mCharsetSource(kCharsetUninitialized), mCharsetSource(kCharsetUninitialized),
mContentLength(-1), mContentLength(-1),
mLoadFlags(LOAD_NORMAL) mLoadFlags(LOAD_NORMAL)
@ -396,6 +398,9 @@ nsWyciwygChannel::WriteToCacheEntry(const nsAString &aData)
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
// UsePrivateBrowsing deals with non-threadsafe objects
mPrivate = UsePrivateBrowsing();
return mCacheIOTarget->Dispatch(new nsWyciwygWriteEvent(this, aData, spec), return mCacheIOTarget->Dispatch(new nsWyciwygWriteEvent(this, aData, spec),
NS_DISPATCH_NORMAL); NS_DISPATCH_NORMAL);
} }
@ -665,18 +670,21 @@ nsWyciwygChannel::OpenCacheEntry(const nsACString & aCacheKey,
// honor security settings // honor security settings
nsCacheStoragePolicy storagePolicy; nsCacheStoragePolicy storagePolicy;
if (mLoadFlags & INHIBIT_PERSISTENT_CACHING) if (mPrivate || mLoadFlags & INHIBIT_PERSISTENT_CACHING)
storagePolicy = nsICache::STORE_IN_MEMORY; storagePolicy = nsICache::STORE_IN_MEMORY;
else else
storagePolicy = nsICache::STORE_ANYWHERE; storagePolicy = nsICache::STORE_ANYWHERE;
nsCOMPtr<nsICacheSession> cacheSession; nsCOMPtr<nsICacheSession> cacheSession;
// Open a stream based cache session. // Open a stream based cache session.
rv = cacheService->CreateSession("wyciwyg", storagePolicy, true, const char* sessionName = mPrivate ? "wyciwyg-private" : "wyciwyg";
rv = cacheService->CreateSession(sessionName, storagePolicy, true,
getter_AddRefs(cacheSession)); getter_AddRefs(cacheSession));
if (!cacheSession) if (!cacheSession)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
cacheSession->SetIsPrivate(mPrivate);
if (aAccessMode == nsICache::ACCESS_WRITE) if (aAccessMode == nsICache::ACCESS_WRITE)
rv = cacheSession->OpenCacheEntry(aCacheKey, aAccessMode, false, rv = cacheSession->OpenCacheEntry(aCacheKey, aAccessMode, false,
getter_AddRefs(mCacheEntry)); getter_AddRefs(mCacheEntry));

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

@ -24,6 +24,7 @@
#include "nsICacheEntryDescriptor.h" #include "nsICacheEntryDescriptor.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsIEventTarget.h" #include "nsIEventTarget.h"
#include "PrivateBrowsingConsumer.h"
extern PRLogModuleInfo * gWyciwygLog; extern PRLogModuleInfo * gWyciwygLog;
@ -31,7 +32,8 @@ extern PRLogModuleInfo * gWyciwygLog;
class nsWyciwygChannel: public nsIWyciwygChannel, class nsWyciwygChannel: public nsIWyciwygChannel,
public nsIStreamListener, public nsIStreamListener,
public nsICacheListener public nsICacheListener,
public mozilla::net::PrivateBrowsingConsumer
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -70,6 +72,7 @@ protected:
bool mIsPending; bool mIsPending;
bool mCharsetAndSourceSet; bool mCharsetAndSourceSet;
bool mNeedToWriteCharset; bool mNeedToWriteCharset;
bool mPrivate;
PRInt32 mCharsetSource; PRInt32 mCharsetSource;
nsCString mCharset; nsCString mCharset;
PRInt32 mContentLength; PRInt32 mContentLength;