From aabb5e983a6409cafdb88e7d6718246c0c2f4c6e Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 24 May 2012 16:31:54 +0100 Subject: [PATCH] Bug 722845 - Part 4: Add PB information to wyciwyg channels. r=jduell --- netwerk/base/src/PrivateBrowsingConsumer.h | 4 ++-- netwerk/protocol/ftp/FTPChannelChild.cpp | 2 +- netwerk/protocol/ftp/nsFtpConnectionThread.cpp | 9 +++++++-- netwerk/protocol/http/HttpChannelChild.cpp | 2 +- netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl | 3 ++- netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp | 7 ++++--- netwerk/protocol/wyciwyg/WyciwygChannelChild.h | 2 ++ netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp | 6 +++++- netwerk/protocol/wyciwyg/WyciwygChannelParent.h | 3 ++- netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp | 14 +++++++++++--- netwerk/protocol/wyciwyg/nsWyciwygChannel.h | 5 ++++- 11 files changed, 41 insertions(+), 16 deletions(-) diff --git a/netwerk/base/src/PrivateBrowsingConsumer.h b/netwerk/base/src/PrivateBrowsingConsumer.h index f8b28a02963..2572d5a0d7c 100644 --- a/netwerk/base/src/PrivateBrowsingConsumer.h +++ b/netwerk/base/src/PrivateBrowsingConsumer.h @@ -53,7 +53,7 @@ class PrivateBrowsingConsumer : public nsIPrivateBrowsingConsumer NS_IMETHOD GetUsingPrivateBrowsing(bool *aUsingPB) { - *aUsingPB = (mOverride ? mUsingPB : UsingPrivateBrowsing()); + *aUsingPB = (mOverride ? mUsingPB : UsingPrivateBrowsingInternal()); return NS_OK; } @@ -66,7 +66,7 @@ class PrivateBrowsingConsumer : public nsIPrivateBrowsingConsumer } protected: - bool UsingPrivateBrowsing() + bool UsingPrivateBrowsingInternal() { nsCOMPtr loadContext; NS_QueryNotificationCallbacks(mSelf, loadContext); diff --git a/netwerk/protocol/ftp/FTPChannelChild.cpp b/netwerk/protocol/ftp/FTPChannelChild.cpp index ec87a22f766..df3a6d7796c 100644 --- a/netwerk/protocol/ftp/FTPChannelChild.cpp +++ b/netwerk/protocol/ftp/FTPChannelChild.cpp @@ -161,7 +161,7 @@ FTPChannelChild::AsyncOpen(::nsIStreamListener* listener, nsISupports* aContext) mLoadGroup->AddRequest(this, nsnull); 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 // us until OnStopRequest is called. diff --git a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp index 368b66a9c86..38c0016d6c5 100644 --- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp +++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp @@ -2217,14 +2217,19 @@ nsFtpState::CheckCache() if (!cache) return false; + bool isPrivate = mChannel->UsePrivateBrowsing(); + const char* sessionName = isPrivate ? "FTP-private" : "FTP"; + nsCacheStoragePolicy policy = + isPrivate ? nsICache::STORE_IN_MEMORY : nsICache::STORE_ANYWHERE; nsCOMPtr session; - cache->CreateSession("FTP", - nsICache::STORE_ANYWHERE, + cache->CreateSession(sessionName, + policy, nsICache::STREAM_BASED, getter_AddRefs(session)); if (!session) return false; session->SetDoomEntriesIfExpired(false); + session->SetIsPrivate(isPrivate); // Set cache access requested: nsCacheAccessMode accessReq; diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index 5b024d6d810..aa385c6a137 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -1041,7 +1041,7 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext) mPriority, mRedirectionLimit, mAllowPipelining, mForceAllowThirdPartyCookie, mSendResumeAt, mStartPos, mEntityID, mChooseApplicationCache, - appCacheClientId, mAllowSpdy, UsingPrivateBrowsing()); + appCacheClientId, mAllowSpdy, UsePrivateBrowsing()); return NS_OK; } diff --git a/netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl b/netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl index d754e2b43aa..04daf283af4 100644 --- a/netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl +++ b/netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl @@ -21,7 +21,8 @@ parent: Init(URI uri); AsyncOpen(URI originalURI, - PRUint32 loadFlags); + PRUint32 loadFlags, + bool usingPrivateBrowsing); // methods corresponding to those of nsIWyciwygChannel WriteToCacheEntry(nsString data); diff --git a/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp b/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp index 15b0969a61d..9250c56317a 100644 --- a/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp +++ b/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp @@ -24,7 +24,8 @@ NS_IMPL_ISUPPORTS3(WyciwygChannelChild, WyciwygChannelChild::WyciwygChannelChild() - : mStatus(NS_OK) + : PrivateBrowsingConsumer(this) + , mStatus(NS_OK) , mIsPending(false) , mCanceled(false) , mLoadFlags(LOAD_NORMAL) @@ -32,7 +33,7 @@ WyciwygChannelChild::WyciwygChannelChild() , mCharsetSource(kCharsetUninitialized) , mState(WCC_NEW) , mIPCOpen(false) - , mEventQ(this) + , mEventQ(NS_ISUPPORTS_CAST(nsIWyciwygChannel*, this)) { LOG(("Creating WyciwygChannelChild @%x\n", this)); } @@ -561,7 +562,7 @@ WyciwygChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aConte if (mLoadGroup) mLoadGroup->AddRequest(this, nsnull); - SendAsyncOpen(IPC::URI(mOriginalURI), mLoadFlags); + SendAsyncOpen(IPC::URI(mOriginalURI), mLoadFlags, UsePrivateBrowsing()); mState = WCC_OPENED; diff --git a/netwerk/protocol/wyciwyg/WyciwygChannelChild.h b/netwerk/protocol/wyciwyg/WyciwygChannelChild.h index e2485101fb9..645b14e13f3 100644 --- a/netwerk/protocol/wyciwyg/WyciwygChannelChild.h +++ b/netwerk/protocol/wyciwyg/WyciwygChannelChild.h @@ -10,6 +10,7 @@ #include "nsIWyciwygChannel.h" #include "nsIChannel.h" #include "nsIProgressEventSink.h" +#include "PrivateBrowsingConsumer.h" namespace mozilla { namespace net { @@ -34,6 +35,7 @@ enum WyciwygChannelChildState { // Header file contents class WyciwygChannelChild : public PWyciwygChannelChild , public nsIWyciwygChannel + , public PrivateBrowsingConsumer { public: NS_DECL_ISUPPORTS diff --git a/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp b/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp index e2a70b2d128..cf29735b9a3 100644 --- a/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp +++ b/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp @@ -78,7 +78,8 @@ WyciwygChannelParent::RecvInit(const IPC::URI& aURI) bool WyciwygChannelParent::RecvAsyncOpen(const IPC::URI& aOriginal, - const PRUint32& aLoadFlags) + const PRUint32& aLoadFlags, + const bool& aUsingPrivateBrowsing) { nsCOMPtr original(aOriginal); @@ -97,6 +98,9 @@ WyciwygChannelParent::RecvAsyncOpen(const IPC::URI& aOriginal, if (NS_FAILED(rv)) return SendCancelEarly(rv); + static_cast(mChannel.get())-> + OverridePrivateBrowsing(aUsingPrivateBrowsing); + rv = mChannel->AsyncOpen(this, nsnull); if (NS_FAILED(rv)) return SendCancelEarly(rv); diff --git a/netwerk/protocol/wyciwyg/WyciwygChannelParent.h b/netwerk/protocol/wyciwyg/WyciwygChannelParent.h index 87422d79d46..cc38b3f39f3 100644 --- a/netwerk/protocol/wyciwyg/WyciwygChannelParent.h +++ b/netwerk/protocol/wyciwyg/WyciwygChannelParent.h @@ -28,7 +28,8 @@ public: protected: virtual bool RecvInit(const IPC::URI& uri); virtual bool RecvAsyncOpen(const IPC::URI& original, - const PRUint32& loadFlags); + const PRUint32& loadFlags, + const bool& usingPrivateBrowsing); virtual bool RecvWriteToCacheEntry(const nsString& data); virtual bool RecvCloseCacheEntry(const nsresult& reason); virtual bool RecvSetCharsetAndSource(const PRInt32& source, diff --git a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp index c2524bf72fe..d54073935aa 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp +++ b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp @@ -81,10 +81,12 @@ private: // nsWyciwygChannel methods nsWyciwygChannel::nsWyciwygChannel() - : mStatus(NS_OK), + : PrivateBrowsingConsumer(this), + mStatus(NS_OK), mIsPending(false), mCharsetAndSourceSet(false), mNeedToWriteCharset(false), + mPrivate(false), mCharsetSource(kCharsetUninitialized), mContentLength(-1), mLoadFlags(LOAD_NORMAL) @@ -396,6 +398,9 @@ nsWyciwygChannel::WriteToCacheEntry(const nsAString &aData) if (NS_FAILED(rv)) return rv; + // UsePrivateBrowsing deals with non-threadsafe objects + mPrivate = UsePrivateBrowsing(); + return mCacheIOTarget->Dispatch(new nsWyciwygWriteEvent(this, aData, spec), NS_DISPATCH_NORMAL); } @@ -665,18 +670,21 @@ nsWyciwygChannel::OpenCacheEntry(const nsACString & aCacheKey, // honor security settings nsCacheStoragePolicy storagePolicy; - if (mLoadFlags & INHIBIT_PERSISTENT_CACHING) + if (mPrivate || mLoadFlags & INHIBIT_PERSISTENT_CACHING) storagePolicy = nsICache::STORE_IN_MEMORY; else storagePolicy = nsICache::STORE_ANYWHERE; nsCOMPtr cacheSession; // 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)); if (!cacheSession) return NS_ERROR_FAILURE; + cacheSession->SetIsPrivate(mPrivate); + if (aAccessMode == nsICache::ACCESS_WRITE) rv = cacheSession->OpenCacheEntry(aCacheKey, aAccessMode, false, getter_AddRefs(mCacheEntry)); diff --git a/netwerk/protocol/wyciwyg/nsWyciwygChannel.h b/netwerk/protocol/wyciwyg/nsWyciwygChannel.h index 7b76376bb08..4d1a5970bf4 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygChannel.h +++ b/netwerk/protocol/wyciwyg/nsWyciwygChannel.h @@ -24,6 +24,7 @@ #include "nsICacheEntryDescriptor.h" #include "nsIURI.h" #include "nsIEventTarget.h" +#include "PrivateBrowsingConsumer.h" extern PRLogModuleInfo * gWyciwygLog; @@ -31,7 +32,8 @@ extern PRLogModuleInfo * gWyciwygLog; class nsWyciwygChannel: public nsIWyciwygChannel, public nsIStreamListener, - public nsICacheListener + public nsICacheListener, + public mozilla::net::PrivateBrowsingConsumer { public: NS_DECL_ISUPPORTS @@ -70,6 +72,7 @@ protected: bool mIsPending; bool mCharsetAndSourceSet; bool mNeedToWriteCharset; + bool mPrivate; PRInt32 mCharsetSource; nsCString mCharset; PRInt32 mContentLength;