зеркало из https://github.com/mozilla/gecko-dev.git
Bug 722845 - Part 2: Generalize channel private browsing information to a PB consumer interface. r=jduell
This commit is contained in:
Родитель
7ec8963d0c
Коммит
4a1921cd15
|
@ -58,6 +58,7 @@ XPIDLSRCS = \
|
|||
nsINetworkLinkService.idl \
|
||||
nsIPermission.idl \
|
||||
nsIPermissionManager.idl \
|
||||
nsIPrivateBrowsingConsumer.idl \
|
||||
nsIPrivateBrowsingService.idl \
|
||||
nsIProgressEventSink.idl \
|
||||
nsIPrompt.idl \
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Private Browsing.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* the Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Josh Matthews <josh@joshmatthews.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(5deb421c-592b-4375-b425-9ac11532aa30)]
|
||||
interface nsIPrivateBrowsingConsumer : nsISupports
|
||||
{
|
||||
readonly attribute boolean usingPrivateBrowsing;
|
||||
|
||||
%{C++
|
||||
/**
|
||||
* De-XPCOMed getter to make call-sites cleaner.
|
||||
*/
|
||||
bool UsePrivateBrowsing() {
|
||||
bool usingPB;
|
||||
GetUsingPrivateBrowsing(&usingPB);
|
||||
return usingPB;
|
||||
}
|
||||
%}
|
||||
};
|
|
@ -0,0 +1,89 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Private Browsing.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* the Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Josh Matthews <josh@joshmatthews.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef mozilla_net_PrivateBrowsingConsumer_h
|
||||
#define mozilla_net_PrivateBrowsingConsumer_h
|
||||
|
||||
#include "nsIPrivateBrowsingConsumer.h"
|
||||
#include "nsILoadContext.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
class PrivateBrowsingConsumer : public nsIPrivateBrowsingConsumer
|
||||
{
|
||||
public:
|
||||
PrivateBrowsingConsumer(nsIChannel* aSelf) : mSelf(aSelf), mUsingPB(false), mOverride(false) {}
|
||||
|
||||
NS_IMETHOD GetUsingPrivateBrowsing(bool *aUsingPB)
|
||||
{
|
||||
*aUsingPB = (mOverride ? mUsingPB : UsingPrivateBrowsing());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void OverridePrivateBrowsing(bool aUsingPrivateBrowsing)
|
||||
{
|
||||
MOZ_ASSERT(!mOverride);
|
||||
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
||||
mOverride = true;
|
||||
mUsingPB = aUsingPrivateBrowsing;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool UsingPrivateBrowsing()
|
||||
{
|
||||
nsCOMPtr<nsILoadContext> loadContext;
|
||||
NS_QueryNotificationCallbacks(mSelf, loadContext);
|
||||
return loadContext && loadContext->UsePrivateBrowsing();
|
||||
}
|
||||
|
||||
private:
|
||||
nsIChannel* mSelf;
|
||||
|
||||
// Private browsing capabilities can only be determined in content
|
||||
// processes, so when networking occurs these values are used in
|
||||
// lieu of UsingPrivateBrowsing().
|
||||
bool mUsingPB;
|
||||
bool mOverride;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // mozilla_net_PrivateBrowsingConsumer_h
|
|
@ -23,7 +23,8 @@ namespace mozilla {
|
|||
namespace net {
|
||||
|
||||
FTPChannelChild::FTPChannelChild(nsIURI* uri)
|
||||
: mIPCOpen(false)
|
||||
: PrivateBrowsingConsumer(this)
|
||||
, mIPCOpen(false)
|
||||
, ALLOW_THIS_IN_INITIALIZER_LIST(mEventQ(static_cast<nsIFTPChannel*>(this)))
|
||||
, mCanceled(false)
|
||||
, mSuspendCount(0)
|
||||
|
@ -160,7 +161,7 @@ FTPChannelChild::AsyncOpen(::nsIStreamListener* listener, nsISupports* aContext)
|
|||
mLoadGroup->AddRequest(this, nsnull);
|
||||
|
||||
SendAsyncOpen(nsBaseChannel::URI(), mStartPos, mEntityID,
|
||||
IPC::InputStream(mUploadStream));
|
||||
IPC::InputStream(mUploadStream), UsingPrivateBrowsing());
|
||||
|
||||
// The socket transport layer in the chrome process now has a logical ref to
|
||||
// us until OnStopRequest is called.
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "nsIProxiedChannel.h"
|
||||
#include "nsIResumableChannel.h"
|
||||
#include "nsIChildChannel.h"
|
||||
#include "PrivateBrowsingConsumer.h"
|
||||
|
||||
#include "nsIStreamListener.h"
|
||||
|
||||
|
@ -34,6 +35,7 @@ class FTPChannelChild : public PFTPChannelChild
|
|||
, public nsIResumableChannel
|
||||
, public nsIProxiedChannel
|
||||
, public nsIChildChannel
|
||||
, public PrivateBrowsingConsumer
|
||||
{
|
||||
public:
|
||||
typedef ::nsIStreamListener nsIStreamListener;
|
||||
|
|
|
@ -57,7 +57,8 @@ bool
|
|||
FTPChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
|
||||
const PRUint64& aStartPos,
|
||||
const nsCString& aEntityID,
|
||||
const IPC::InputStream& aUploadStream)
|
||||
const IPC::InputStream& aUploadStream,
|
||||
const bool& aUsePrivateBrowsing)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri(aURI);
|
||||
|
||||
|
@ -92,6 +93,8 @@ FTPChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
|
|||
if (NS_FAILED(rv))
|
||||
return SendFailedAsyncOpen(rv);
|
||||
|
||||
mChannel->OverridePrivateBrowsing(aUsePrivateBrowsing);
|
||||
|
||||
rv = mChannel->AsyncOpen(this, nsnull);
|
||||
if (NS_FAILED(rv))
|
||||
return SendFailedAsyncOpen(rv);
|
||||
|
|
|
@ -36,7 +36,8 @@ protected:
|
|||
NS_OVERRIDE virtual bool RecvAsyncOpen(const IPC::URI& uri,
|
||||
const PRUint64& startPos,
|
||||
const nsCString& entityID,
|
||||
const IPC::InputStream& uploadStream);
|
||||
const IPC::InputStream& uploadStream,
|
||||
const bool& aUsePrivateBrowsing);
|
||||
NS_OVERRIDE virtual bool RecvConnectChannel(const PRUint32& channelId);
|
||||
NS_OVERRIDE virtual bool RecvCancel(const nsresult& status);
|
||||
NS_OVERRIDE virtual bool RecvSuspend();
|
||||
|
|
|
@ -24,7 +24,7 @@ parent:
|
|||
__delete__();
|
||||
|
||||
AsyncOpen(URI uri, PRUint64 startPos, nsCString entityID,
|
||||
InputStream uploadStream);
|
||||
InputStream uploadStream, bool usePrivateBrowsing);
|
||||
ConnectChannel(PRUint32 channelId);
|
||||
Cancel(nsresult status);
|
||||
Suspend();
|
||||
|
|
|
@ -28,12 +28,14 @@
|
|||
#include "nsIResumableChannel.h"
|
||||
#include "nsHashPropertyBag.h"
|
||||
#include "nsFtpProtocolHandler.h"
|
||||
#include "PrivateBrowsingConsumer.h"
|
||||
|
||||
class nsFtpChannel : public nsBaseChannel,
|
||||
public nsIFTPChannel,
|
||||
public nsIUploadChannel,
|
||||
public nsIResumableChannel,
|
||||
public nsIProxiedChannel
|
||||
public nsIProxiedChannel,
|
||||
public mozilla::net::PrivateBrowsingConsumer
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -42,7 +44,8 @@ public:
|
|||
NS_DECL_NSIPROXIEDCHANNEL
|
||||
|
||||
nsFtpChannel(nsIURI *uri, nsIProxyInfo *pi)
|
||||
: mProxyInfo(pi)
|
||||
: mozilla::net::PrivateBrowsingConsumer(this)
|
||||
, mProxyInfo(pi)
|
||||
, mStartPos(0)
|
||||
, mResumeRequested(false)
|
||||
, mLastModifiedTime(0)
|
||||
|
|
|
@ -27,7 +27,8 @@ namespace mozilla {
|
|||
namespace net {
|
||||
|
||||
HttpBaseChannel::HttpBaseChannel()
|
||||
: mStartPos(LL_MAXUINT)
|
||||
: PrivateBrowsingConsumer(this)
|
||||
, mStartPos(LL_MAXUINT)
|
||||
, mStatus(NS_OK)
|
||||
, mLoadFlags(LOAD_NORMAL)
|
||||
, mPriority(PRIORITY_NORMAL)
|
||||
|
@ -140,17 +141,18 @@ HttpBaseChannel::Init(nsIURI *aURI,
|
|||
// HttpBaseChannel::nsISupports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED9(HttpBaseChannel,
|
||||
nsHashPropertyBag,
|
||||
nsIRequest,
|
||||
nsIChannel,
|
||||
nsIEncodedChannel,
|
||||
nsIHttpChannel,
|
||||
nsIHttpChannelInternal,
|
||||
nsIUploadChannel,
|
||||
nsIUploadChannel2,
|
||||
nsISupportsPriority,
|
||||
nsITraceableChannel)
|
||||
NS_IMPL_ISUPPORTS_INHERITED10(HttpBaseChannel,
|
||||
nsHashPropertyBag,
|
||||
nsIRequest,
|
||||
nsIChannel,
|
||||
nsIEncodedChannel,
|
||||
nsIHttpChannel,
|
||||
nsIHttpChannelInternal,
|
||||
nsIUploadChannel,
|
||||
nsIUploadChannel2,
|
||||
nsISupportsPriority,
|
||||
nsITraceableChannel,
|
||||
nsIPrivateBrowsingConsumer)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HttpBaseChannel::nsIRequest
|
||||
|
@ -1666,19 +1668,6 @@ HttpBaseChannel::SetupReplacementChannel(nsIURI *newURI,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
HttpBaseChannel::UsingPrivateBrowsing()
|
||||
{
|
||||
nsCOMPtr<nsILoadContext> loadContext;
|
||||
GetCallback(loadContext);
|
||||
if (!loadContext) {
|
||||
return false;
|
||||
}
|
||||
bool pb;
|
||||
loadContext->GetUsePrivateBrowsing(&pb);
|
||||
return pb;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
} // namespace net
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "nsIResumableChannel.h"
|
||||
#include "nsITraceableChannel.h"
|
||||
#include "mozilla/net/NeckoCommon.h"
|
||||
#include "PrivateBrowsingConsumer.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -49,6 +50,7 @@ class HttpBaseChannel : public nsHashPropertyBag
|
|||
, public nsISupportsPriority
|
||||
, public nsIResumableChannel
|
||||
, public nsITraceableChannel
|
||||
, public PrivateBrowsingConsumer
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -202,12 +204,6 @@ protected:
|
|||
bool preserveMethod,
|
||||
bool forProxy);
|
||||
|
||||
/**
|
||||
* Returns true if this channel is operating in private browsing mode,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool UsingPrivateBrowsing();
|
||||
|
||||
// Helper function to simplify getting notification callbacks.
|
||||
template <class T>
|
||||
void GetCallback(nsCOMPtr<T> &aResult)
|
||||
|
|
|
@ -100,8 +100,6 @@ nsHttpChannel::nsHttpChannel()
|
|||
, mFallingBack(false)
|
||||
, mWaitingForRedirectCallback(false)
|
||||
, mRequestTimeInitialized(false)
|
||||
, mOverridePrivateBrowsing(false)
|
||||
, mUsingPrivateBrowsing(false)
|
||||
, mDidReval(false)
|
||||
{
|
||||
LOG(("Creating nsHttpChannel [this=%p]\n", this));
|
||||
|
@ -5408,19 +5406,3 @@ nsHttpChannel::AsyncOnExamineCachedResponse()
|
|||
gHttpHandler->OnExamineCachedResponse(this);
|
||||
|
||||
}
|
||||
|
||||
bool
|
||||
nsHttpChannel::UsingPrivateBrowsing()
|
||||
{
|
||||
if (mOverridePrivateBrowsing)
|
||||
return mUsingPrivateBrowsing;
|
||||
return HttpBaseChannel::UsingPrivateBrowsing();
|
||||
}
|
||||
|
||||
void
|
||||
nsHttpChannel::OverridePrivateBrowsing(bool usingPrivateBrowsing)
|
||||
{
|
||||
MOZ_ASSERT(!mWasOpened);
|
||||
mOverridePrivateBrowsing = true;
|
||||
mUsingPrivateBrowsing = usingPrivateBrowsing;
|
||||
}
|
||||
|
|
|
@ -146,8 +146,11 @@ public: /* internal necko use only */
|
|||
* Returns true if this channel is operating in private browsing mode,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool UsingPrivateBrowsing();
|
||||
void OverridePrivateBrowsing(bool usingPrivateBrowsing);
|
||||
bool UsingPrivateBrowsing() {
|
||||
bool usingPB;
|
||||
GetUsingPrivateBrowsing(&usingPB);
|
||||
return usingPB;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef nsresult (nsHttpChannel::*nsContinueRedirectionFunc)(nsresult result);
|
||||
|
@ -339,12 +342,6 @@ private:
|
|||
// the cache entry's expiration time. Otherwise, it is not(see bug 567360).
|
||||
PRUint32 mRequestTimeInitialized : 1;
|
||||
|
||||
// Private browsing capabilities can only be determined in content
|
||||
// processes, so when networking occurs these values are used in
|
||||
// lieu of UsingPrivateBrowsing().
|
||||
PRUint32 mOverridePrivateBrowsing : 1;
|
||||
PRUint32 mUsingPrivateBrowsing : 1;
|
||||
|
||||
nsTArray<nsContinueRedirectionFunc> mRedirectFuncStack;
|
||||
|
||||
nsCOMPtr<nsICryptoHash> mHasher;
|
||||
|
|
|
@ -1128,6 +1128,12 @@ NS_IMETHODIMP_(nsrefcnt) Class::Release(void) \
|
|||
NS_INTERFACE_TABLE_INHERITED9(Class, i1, i2, i3, i4, i5, i6, i7, i8, i9) \
|
||||
NS_INTERFACE_TABLE_TAIL_INHERITING(Super)
|
||||
|
||||
#define NS_IMPL_QUERY_INTERFACE_INHERITED10(Class,Super,i1,i2,i3,i4,i5,i6, \
|
||||
i7,i8,i9,i10) \
|
||||
NS_INTERFACE_TABLE_HEAD(Class) \
|
||||
NS_INTERFACE_TABLE_INHERITED10(Class, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10) \
|
||||
NS_INTERFACE_TABLE_TAIL_INHERITING(Super)
|
||||
|
||||
/**
|
||||
* Convenience macros for implementing all nsISupports methods for
|
||||
* a simple class.
|
||||
|
@ -1250,6 +1256,11 @@ NS_IMETHODIMP_(nsrefcnt) Class::Release(void) \
|
|||
NS_IMPL_QUERY_INTERFACE_INHERITED9(Class, Super, i1, i2, i3, i4, i5, i6, i7, i8, i9) \
|
||||
NS_IMPL_ADDREF_INHERITED(Class, Super) \
|
||||
NS_IMPL_RELEASE_INHERITED(Class, Super) \
|
||||
|
||||
#define NS_IMPL_ISUPPORTS_INHERITED10(Class, Super, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10) \
|
||||
NS_IMPL_QUERY_INTERFACE_INHERITED10(Class, Super, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10) \
|
||||
NS_IMPL_ADDREF_INHERITED(Class, Super) \
|
||||
NS_IMPL_RELEASE_INHERITED(Class, Super) \
|
||||
/*
|
||||
* Macro to glue together a QI that starts with an interface table
|
||||
* and segues into an interface map (e.g. it uses singleton classinfo
|
||||
|
|
Загрузка…
Ссылка в новой задаче