Bug 776174 - e10s: cleanup IPC nsILoader code. r=smaug, r=jdm

This commit is contained in:
Jason Duell 2012-08-06 21:47:48 -07:00
parent 7e4448be80
commit abdbb9d224
23 changed files with 377 additions and 579 deletions

View File

@ -0,0 +1,110 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/LoadContext.h"
#include "nsIScriptSecurityManager.h"
#include "nsServiceManagerUtils.h"
#include "nsContentUtils.h"
namespace mozilla {
NS_IMPL_ISUPPORTS1(LoadContext, nsILoadContext);
//-----------------------------------------------------------------------------
// LoadContext::nsILoadContext
//-----------------------------------------------------------------------------
NS_IMETHODIMP
LoadContext::GetAssociatedWindow(nsIDOMWindow**)
{
MOZ_ASSERT(mIsNotNull);
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
LoadContext::GetTopWindow(nsIDOMWindow**)
{
MOZ_ASSERT(mIsNotNull);
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
LoadContext::IsAppOfType(PRUint32, bool*)
{
MOZ_ASSERT(mIsNotNull);
// don't expect we need this in parent (Thunderbird/SeaMonkey specific?)
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
LoadContext::GetIsContent(bool* aIsContent)
{
MOZ_ASSERT(mIsNotNull);
NS_ENSURE_ARG_POINTER(aIsContent);
*aIsContent = mIsContent;
return NS_OK;
}
NS_IMETHODIMP
LoadContext::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
{
MOZ_ASSERT(mIsNotNull);
NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);
*aUsePrivateBrowsing = mUsePrivateBrowsing;
return NS_OK;
}
NS_IMETHODIMP
LoadContext::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
{
MOZ_ASSERT(mIsNotNull);
// We shouldn't need this on parent...
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
LoadContext::GetIsInBrowserElement(bool* aIsInBrowserElement)
{
MOZ_ASSERT(mIsNotNull);
NS_ENSURE_ARG_POINTER(aIsInBrowserElement);
*aIsInBrowserElement = mIsInBrowserElement;
return NS_OK;
}
NS_IMETHODIMP
LoadContext::GetAppId(PRUint32* aAppId)
{
MOZ_ASSERT(mIsNotNull);
NS_ENSURE_ARG_POINTER(aAppId);
*aAppId = mAppId;
return NS_OK;
}
NS_IMETHODIMP
LoadContext::GetExtendedOrigin(nsIURI* aUri, nsACString& aResult)
{
MOZ_ASSERT(mIsNotNull);
nsIScriptSecurityManager* ssmgr = nsContentUtils::GetSecurityManager();
return ssmgr->GetExtendedOrigin(aUri, mAppId, mIsInBrowserElement, aResult);
}
} // namespace mozilla

View File

@ -0,0 +1,49 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef LoadContext_h
#define LoadContext_h
#include "SerializedLoadContext.h"
namespace mozilla {
/**
* Class that provides nsILoadContext info in Parent process. Typically copied
* from Child via SerializedLoadContext.
*
* Note: this is not the "normal" or "original" nsILoadContext. That is
* typically provided by nsDocShell. This is only used when the original
* docshell is in a different process and we need to copy certain values from
* it.
*/
class LoadContext : public nsILoadContext
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSILOADCONTEXT
LoadContext(const IPC::SerializedLoadContext& toCopy)
: mIsNotNull(toCopy.mIsNotNull)
, mIsContent(toCopy.mIsContent)
, mUsePrivateBrowsing(toCopy.mUsePrivateBrowsing)
, mIsInBrowserElement(toCopy.mIsInBrowserElement)
, mAppId(toCopy.mAppId)
{}
private:
bool mIsNotNull;
bool mIsContent;
bool mUsePrivateBrowsing;
bool mIsInBrowserElement;
PRUint32 mAppId;
};
} // namespace mozilla
#endif // LoadContext_h

View File

@ -56,12 +56,14 @@ EXPORTS = \
nsDocShellLoadTypes.h \
nsILinkHandler.h \
nsIWebShellServices.h \
SerializedLoadContext.h \
$(NULL)
EXPORTS_NAMESPACES = mozilla
EXPORTS_mozilla = \
IHistory.h \
LoadContext.h \
$(NULL)
CPPSRCS = \
@ -75,6 +77,8 @@ CPPSRCS = \
nsWebNavigationInfo.cpp \
nsAboutRedirector.cpp \
nsDownloadHistory.cpp \
SerializedLoadContext.cpp \
LoadContext.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a

View File

@ -0,0 +1,54 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SerializedLoadContext.h"
#include "nsNetUtil.h"
#include "nsIChannel.h"
#include "nsIWebSocketChannel.h"
namespace IPC {
SerializedLoadContext::SerializedLoadContext(nsILoadContext* aLoadContext)
{
Init(aLoadContext);
}
SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel)
{
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(aChannel, loadContext);
Init(loadContext);
}
SerializedLoadContext::SerializedLoadContext(nsIWebSocketChannel* aChannel)
{
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(aChannel, loadContext);
Init(loadContext);
}
void
SerializedLoadContext::Init(nsILoadContext* aLoadContext)
{
if (aLoadContext) {
mIsNotNull = true;
aLoadContext->GetIsContent(&mIsContent);
aLoadContext->GetUsePrivateBrowsing(&mUsePrivateBrowsing);
aLoadContext->GetAppId(&mAppId);
aLoadContext->GetIsInBrowserElement(&mIsInBrowserElement);
} else {
mIsNotNull = false;
// none of below values really matter when mIsNotNull == false:
// we won't be GetInterfaced to nsILoadContext
mIsContent = true;
mUsePrivateBrowsing = false;
mAppId = 0;
mIsInBrowserElement = false;
}
}
} // namespace IPC

View File

@ -0,0 +1,85 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef SerializedLoadContext_h
#define SerializedLoadContext_h
#include "base/basictypes.h"
#include "IPC/IPCMessageUtils.h"
#include "nsIIPCSerializable.h"
#include "nsILoadContext.h"
/*
* This file contains the IPC::SerializedLoadContext class, which is used to
* copy data across IPDL from Child process contexts so it is available in the
* Parent.
*/
class nsIChannel;
class nsIWebSocketChannel;
namespace IPC {
class SerializedLoadContext
{
public:
SerializedLoadContext()
{
Init(nsnull);
}
SerializedLoadContext(nsILoadContext* aLoadContext);
SerializedLoadContext(nsIChannel* aChannel);
SerializedLoadContext(nsIWebSocketChannel* aChannel);
void Init(nsILoadContext* aLoadContext);
bool IsNotNull() const
{
return mIsNotNull;
}
// used to indicate if child-side LoadContext * was null.
bool mIsNotNull;
bool mIsContent;
bool mUsePrivateBrowsing;
bool mIsInBrowserElement;
PRUint32 mAppId;
};
// Function to serialize over IPDL
template<>
struct ParamTraits<SerializedLoadContext>
{
typedef SerializedLoadContext paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.mIsNotNull);
WriteParam(aMsg, aParam.mIsContent);
WriteParam(aMsg, aParam.mUsePrivateBrowsing);
WriteParam(aMsg, aParam.mAppId);
WriteParam(aMsg, aParam.mIsInBrowserElement);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) ||
!ReadParam(aMsg, aIter, &aResult->mIsContent) ||
!ReadParam(aMsg, aIter, &aResult->mUsePrivateBrowsing) ||
!ReadParam(aMsg, aIter, &aResult->mAppId) ||
!ReadParam(aMsg, aIter, &aResult->mIsInBrowserElement)) {
return false;
}
return true;
}
};
} // namespace IPC
#endif // SerializedLoadContext_h

View File

@ -1253,9 +1253,12 @@ NS_LoadPersistentPropertiesFromURISpec(nsIPersistentProperties **result,
* searches the channel's notificationCallbacks attribute, and if the interface
* is not found there, then it inspects the notificationCallbacks attribute of
* the channel's loadGroup.
*
* Note: templatized only because nsIWebSocketChannel is currently not an
* nsIChannel.
*/
inline void
NS_QueryNotificationCallbacks(nsIChannel *channel,
template <class T> inline void
NS_QueryNotificationCallbacks(T *channel,
const nsIID &iid,
void **result)
{
@ -1278,9 +1281,12 @@ NS_QueryNotificationCallbacks(nsIChannel *channel,
}
}
/* template helper */
template <class T> inline void
NS_QueryNotificationCallbacks(nsIChannel *channel,
// template helper:
// Note: "class C" templatized only because nsIWebSocketChannel is currently not
// an nsIChannel.
template <class C, class T> inline void
NS_QueryNotificationCallbacks(C *channel,
nsCOMPtr<T> &result)
{
NS_QueryNotificationCallbacks(channel, NS_GET_TEMPLATE_IID(T),

View File

@ -16,6 +16,7 @@
#include "nsStringStream.h"
#include "prio.h"
#include "mozilla/Util.h" // for DebugOnly
#include "SerializedLoadContext.h"
namespace IPC {

View File

@ -160,29 +160,8 @@ FTPChannelChild::AsyncOpen(::nsIStreamListener* listener, nsISupports* aContext)
if (mLoadGroup)
mLoadGroup->AddRequest(this, nullptr);
// Get info from nsILoadContext, if any
bool haveLoadContext = false;
bool isContent = false;
bool usePrivateBrowsing = false;
bool isInBrowserElement = false;
PRUint32 appId = 0;
nsCAutoString extendedOrigin;
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup,
NS_GET_IID(nsILoadContext),
getter_AddRefs(loadContext));
if (loadContext) {
haveLoadContext = true;
loadContext->GetIsContent(&isContent);
loadContext->GetUsePrivateBrowsing(&usePrivateBrowsing);
loadContext->GetIsInBrowserElement(&isInBrowserElement);
loadContext->GetAppId(&appId);
loadContext->GetExtendedOrigin(mURI, extendedOrigin);
}
SendAsyncOpen(nsBaseChannel::URI(), mStartPos, mEntityID,
IPC::InputStream(mUploadStream), haveLoadContext, isContent,
usePrivateBrowsing, isInBrowserElement, appId, extendedOrigin);
IPC::InputStream(mUploadStream), IPC::SerializedLoadContext(this));
// The socket transport layer in the chrome process now has a logical ref to
// us until OnStopRequest is called.

View File

@ -11,6 +11,7 @@
#include "nsISupportsPriority.h"
#include "nsIRedirectChannelRegistrar.h"
#include "nsFtpProtocolHandler.h"
#include "mozilla/LoadContext.h"
#undef LOG
#define LOG(args) PR_LOG(gFTPLog, PR_LOG_DEBUG, args)
@ -20,11 +21,6 @@ namespace net {
FTPChannelParent::FTPChannelParent()
: mIPCClosed(false)
, mHaveLoadContext(false)
, mIsContent(false)
, mUsePrivateBrowsing(false)
, mIsInBrowserElement(false)
, mAppId(0)
{
nsIProtocolHandler* handler;
CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "ftp", &handler);
@ -48,11 +44,10 @@ FTPChannelParent::ActorDestroy(ActorDestroyReason why)
// FTPChannelParent::nsISupports
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS5(FTPChannelParent,
NS_IMPL_ISUPPORTS4(FTPChannelParent,
nsIStreamListener,
nsIParentChannel,
nsIInterfaceRequestor,
nsILoadContext,
nsIRequestObserver);
//-----------------------------------------------------------------------------
@ -64,12 +59,7 @@ FTPChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
const PRUint64& aStartPos,
const nsCString& aEntityID,
const IPC::InputStream& aUploadStream,
const bool& haveLoadContext,
const bool& isContent,
const bool& usePrivateBrowsing,
const bool& isInBrowserElement,
const PRUint32& appId,
const nsCString& extendedOrigin)
const IPC::SerializedLoadContext& loadContext)
{
nsCOMPtr<nsIURI> uri(aURI);
@ -104,14 +94,8 @@ FTPChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
if (NS_FAILED(rv))
return SendFailedAsyncOpen(rv);
// fields needed to impersonate nsILoadContext
mHaveLoadContext = haveLoadContext;
mIsContent = isContent;
mUsePrivateBrowsing = usePrivateBrowsing;
mIsInBrowserElement = isInBrowserElement;
mAppId = appId;
mExtendedOrigin = extendedOrigin;
mChannel->SetNotificationCallbacks(this);
if (loadContext.IsNotNull())
mLoadContext = new LoadContext(loadContext);
rv = mChannel->AsyncOpen(this, nullptr);
if (NS_FAILED(rv))
@ -248,89 +232,16 @@ NS_IMETHODIMP
FTPChannelParent::GetInterface(const nsIID& uuid, void** result)
{
// Only support nsILoadContext if child channel's callbacks did too
if (uuid.Equals(NS_GET_IID(nsILoadContext)) && !mHaveLoadContext) {
return NS_NOINTERFACE;
if (uuid.Equals(NS_GET_IID(nsILoadContext)) && mLoadContext) {
NS_ADDREF(mLoadContext);
*result = static_cast<nsILoadContext*>(mLoadContext);
return NS_OK;
}
return QueryInterface(uuid, result);
}
//-----------------------------------------------------------------------------
// FTPChannelParent::nsILoadContext
//-----------------------------------------------------------------------------
NS_IMETHODIMP
FTPChannelParent::GetAssociatedWindow(nsIDOMWindow**)
{
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
FTPChannelParent::GetTopWindow(nsIDOMWindow**)
{
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
FTPChannelParent::IsAppOfType(PRUint32, bool*)
{
// don't expect we need this in parent (Thunderbird/SeaMonkey specific?)
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
FTPChannelParent::GetIsContent(bool *aIsContent)
{
NS_ENSURE_ARG_POINTER(aIsContent);
*aIsContent = mIsContent;
return NS_OK;
}
NS_IMETHODIMP
FTPChannelParent::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
{
NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);
*aUsePrivateBrowsing = mUsePrivateBrowsing;
return NS_OK;
}
NS_IMETHODIMP
FTPChannelParent::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
{
// We shouldn't need this on parent...
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
FTPChannelParent::GetIsInBrowserElement(bool* aIsInBrowserElement)
{
NS_ENSURE_ARG_POINTER(aIsInBrowserElement);
*aIsInBrowserElement = mIsInBrowserElement;
return NS_OK;
}
NS_IMETHODIMP
FTPChannelParent::GetAppId(PRUint32* aAppId)
{
NS_ENSURE_ARG_POINTER(aAppId);
*aAppId = mAppId;
return NS_OK;
}
NS_IMETHODIMP
FTPChannelParent::GetExtendedOrigin(nsIURI *aUri, nsACString &aResult)
{
aResult = mExtendedOrigin;
return NS_OK;
}
//---------------------
} // namespace net
} // namespace mozilla

View File

@ -22,7 +22,6 @@ namespace net {
class FTPChannelParent : public PFTPChannelParent
, public nsIParentChannel
, public nsIInterfaceRequestor
, public nsILoadContext
{
public:
NS_DECL_ISUPPORTS
@ -30,7 +29,6 @@ public:
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIPARENTCHANNEL
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSILOADCONTEXT
FTPChannelParent();
virtual ~FTPChannelParent();
@ -40,12 +38,7 @@ protected:
const PRUint64& startPos,
const nsCString& entityID,
const IPC::InputStream& uploadStream,
const bool& haveLoadContext,
const bool& isContent,
const bool& usingPrivateBrowsing,
const bool& isInBrowserElement,
const PRUint32& appId,
const nsCString& extendedOrigin) MOZ_OVERRIDE;
const IPC::SerializedLoadContext& loadContext) MOZ_OVERRIDE;
virtual bool RecvConnectChannel(const PRUint32& channelId) MOZ_OVERRIDE;
virtual bool RecvCancel(const nsresult& status) MOZ_OVERRIDE;
virtual bool RecvSuspend() MOZ_OVERRIDE;
@ -57,14 +50,7 @@ protected:
bool mIPCClosed;
// fields for impersonating nsILoadContext
bool mHaveLoadContext : 1;
bool mIsContent : 1;
bool mUsePrivateBrowsing : 1;
bool mIsInBrowserElement : 1;
PRUint32 mAppId;
nsCString mExtendedOrigin;
nsCOMPtr<nsILoadContext> mLoadContext;
};
} // namespace net

View File

@ -11,6 +11,7 @@ include "mozilla/net/NeckoMessageUtils.h";
using IPC::URI;
using IPC::InputStream;
using IPC::SerializedLoadContext;
using PRTime;
namespace mozilla {
@ -27,12 +28,8 @@ parent:
PRUint64 startPos,
nsCString entityID,
InputStream uploadStream,
bool haveLoadContext,
bool isContent,
bool usePrivateBrowsing,
bool isInBrowserElement,
PRUint32 appID,
nsCString extendedOrigin);
SerializedLoadContext loadContext);
ConnectChannel(PRUint32 channelId);
Cancel(nsresult status);
Suspend();

View File

@ -1015,24 +1015,6 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
}
}
// Get info from nsILoadContext, if any
bool haveLoadContext = false;
bool isContent = false;
bool usePrivateBrowsing = false;
bool isInBrowserElement = false;
PRUint32 appId = 0;
nsCAutoString extendedOrigin;
nsCOMPtr<nsILoadContext> loadContext;
GetCallback(loadContext);
if (loadContext) {
haveLoadContext = true;
loadContext->GetIsContent(&isContent);
loadContext->GetUsePrivateBrowsing(&usePrivateBrowsing);
loadContext->GetIsInBrowserElement(&isInBrowserElement);
loadContext->GetAppId(&appId);
loadContext->GetExtendedOrigin(mURI, extendedOrigin);
}
//
// Send request to the chrome process...
//
@ -1059,8 +1041,7 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
mPriority, mRedirectionLimit, mAllowPipelining,
mForceAllowThirdPartyCookie, mSendResumeAt,
mStartPos, mEntityID, mChooseApplicationCache,
appCacheClientId, mAllowSpdy, haveLoadContext, isContent,
usePrivateBrowsing, isInBrowserElement, appId, extendedOrigin);
appCacheClientId, mAllowSpdy, IPC::SerializedLoadContext(this));
return NS_OK;
}

View File

@ -22,6 +22,7 @@
#include "nsIApplicationCacheService.h"
#include "nsIOfflineCacheUpdate.h"
#include "nsIRedirectChannelRegistrar.h"
#include "mozilla/LoadContext.h"
#include "prinit.h"
namespace mozilla {
@ -35,11 +36,6 @@ HttpChannelParent::HttpChannelParent(PBrowserParent* iframeEmbedding)
, mSentRedirect1Begin(false)
, mSentRedirect1BeginFailed(false)
, mReceivedRedirect2Verify(false)
, mHaveLoadContext(false)
, mIsContent(false)
, mUsePrivateBrowsing(false)
, mIsInBrowserElement(false)
, mAppId(0)
{
// Ensure gHttpHandler is initialized: we need the atom table up and running.
nsIHttpProtocolHandler* handler;
@ -67,8 +63,7 @@ HttpChannelParent::ActorDestroy(ActorDestroyReason why)
// HttpChannelParent::nsISupports
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS7(HttpChannelParent,
nsILoadContext,
NS_IMPL_ISUPPORTS6(HttpChannelParent,
nsIInterfaceRequestor,
nsIProgressEventSink,
nsIRequestObserver,
@ -92,8 +87,10 @@ HttpChannelParent::GetInterface(const nsIID& aIID, void **result)
}
// Only support nsILoadContext if child channel's callbacks did too
if (aIID.Equals(NS_GET_IID(nsILoadContext)) && !mHaveLoadContext) {
return NS_NOINTERFACE;
if (aIID.Equals(NS_GET_IID(nsILoadContext)) && mLoadContext) {
NS_ADDREF(mLoadContext);
*result = static_cast<nsILoadContext*>(mLoadContext);
return NS_OK;
}
return QueryInterface(aIID, result);
@ -123,12 +120,7 @@ HttpChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
const bool& chooseApplicationCache,
const nsCString& appCacheClientID,
const bool& allowSpdy,
const bool& haveLoadContext,
const bool& isContent,
const bool& usePrivateBrowsing,
const bool& isInBrowserElement,
const PRUint32& appId,
const nsCString& extendedOrigin)
const IPC::SerializedLoadContext& loadContext)
{
nsCOMPtr<nsIURI> uri(aURI);
nsCOMPtr<nsIURI> originalUri(aOriginalURI);
@ -150,13 +142,8 @@ HttpChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
if (NS_FAILED(rv))
return SendFailedAsyncOpen(rv);
// fields needed to impersonate nsILoadContext
mHaveLoadContext = haveLoadContext;
mIsContent = isContent;
mUsePrivateBrowsing = usePrivateBrowsing;
mIsInBrowserElement = isInBrowserElement;
mAppId = appId;
mExtendedOrigin = extendedOrigin;
if (loadContext.IsNotNull())
mLoadContext = new LoadContext(loadContext);
nsHttpChannel *httpChan = static_cast<nsHttpChannel *>(mChannel.get());
@ -608,79 +595,4 @@ HttpChannelParent::CompleteRedirect(bool succeeded)
return NS_OK;
}
//-----------------------------------------------------------------------------
// HttpChannelParent::nsILoadContext
//-----------------------------------------------------------------------------
NS_IMETHODIMP
HttpChannelParent::GetAssociatedWindow(nsIDOMWindow**)
{
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
HttpChannelParent::GetTopWindow(nsIDOMWindow**)
{
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
HttpChannelParent::IsAppOfType(PRUint32, bool*)
{
// don't expect we need this in parent (Thunderbird/SeaMonkey specific?)
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
HttpChannelParent::GetIsContent(bool *aIsContent)
{
NS_ENSURE_ARG_POINTER(aIsContent);
*aIsContent = mIsContent;
return NS_OK;
}
NS_IMETHODIMP
HttpChannelParent::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
{
NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);
*aUsePrivateBrowsing = mUsePrivateBrowsing;
return NS_OK;
}
NS_IMETHODIMP
HttpChannelParent::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
{
// We shouldn't need this on parent...
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
HttpChannelParent::GetIsInBrowserElement(bool* aIsInBrowserElement)
{
NS_ENSURE_ARG_POINTER(aIsInBrowserElement);
*aIsInBrowserElement = mIsInBrowserElement;
return NS_OK;
}
NS_IMETHODIMP
HttpChannelParent::GetAppId(PRUint32* aAppId)
{
NS_ENSURE_ARG_POINTER(aAppId);
*aAppId = mAppId;
return NS_OK;
}
NS_IMETHODIMP
HttpChannelParent::GetExtendedOrigin(nsIURI *aUri, nsACString &aResult)
{
aResult = mExtendedOrigin;
return NS_OK;
}
}} // mozilla::net

View File

@ -31,7 +31,6 @@ class HttpChannelParent : public PHttpChannelParent
, public nsIParentRedirectingChannel
, public nsIProgressEventSink
, public nsIInterfaceRequestor
, public nsILoadContext
{
public:
NS_DECL_ISUPPORTS
@ -41,7 +40,6 @@ public:
NS_DECL_NSIPARENTREDIRECTINGCHANNEL
NS_DECL_NSIPROGRESSEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSILOADCONTEXT
HttpChannelParent(PBrowserParent* iframeEmbedding);
virtual ~HttpChannelParent();
@ -66,12 +64,7 @@ protected:
const bool& chooseApplicationCache,
const nsCString& appCacheClientID,
const bool& allowSpdy,
const bool & haveLoadContext,
const bool & isContent,
const bool& usingPrivateBrowsing,
const bool& isInBrowserElement,
const PRUint32& appId,
const nsCString& extendedOrigin);
const IPC::SerializedLoadContext& loadContext) MOZ_OVERRIDE;
virtual bool RecvConnectChannel(const PRUint32& channelId);
virtual bool RecvSetPriority(const PRUint16& priority);
@ -115,14 +108,7 @@ private:
bool mSentRedirect1BeginFailed : 1;
bool mReceivedRedirect2Verify : 1;
// fields for impersonating nsILoadContext
bool mHaveLoadContext : 1;
bool mIsContent : 1;
bool mUsePrivateBrowsing : 1;
bool mIsInBrowserElement : 1;
PRUint32 mAppId;
nsCString mExtendedOrigin;
nsCOMPtr<nsILoadContext> mLoadContext;
};
} // namespace net

View File

@ -17,6 +17,7 @@ using nsHttpResponseHead;
using nsHttpAtom;
using IPC::URI;
using IPC::InputStream;
using IPC::SerializedLoadContext;
using PRNetAddr;
namespace mozilla {
@ -50,13 +51,7 @@ parent:
bool chooseApplicationCache,
nsCString appCacheClientID,
bool allowSpdy,
// Fields for imitating a nsILoadContext
bool haveLoadContext,
bool isContent,
bool usePrivateBrowsing,
bool isInBrowserElement,
PRUint32 appID,
nsCString extendedOrigin);
SerializedLoadContext loadContext);
// Used to connect redirected-to channel on the parent with redirected-to
// channel on the child.

View File

@ -12,6 +12,7 @@ include "mozilla/net/NeckoMessageUtils.h";
using IPC::URI;
using IPC::InputStream;
using IPC::SerializedLoadContext;
namespace mozilla {
namespace net {
@ -26,13 +27,7 @@ parent:
nsCString aOrigin,
nsCString aProtocol,
bool aSecure,
// Fields for imitating a nsILoadContext
bool haveLoadContext,
bool isContent,
bool usePrivateBrowsing,
bool isInBrowserElement,
PRUint32 appID,
nsCString extendedOrigin);
SerializedLoadContext loadContext);
Close(PRUint16 code, nsCString reason);
SendMsg(nsCString aMsg);
SendBinaryMsg(nsCString aMsg);

View File

@ -328,33 +328,12 @@ WebSocketChannelChild::AsyncOpen(nsIURI *aURI,
tabChild = static_cast<mozilla::dom::TabChild*>(iTabChild.get());
}
// Get info from nsILoadContext, if any
bool haveLoadContext = false;
bool isContent = false;
bool usePrivateBrowsing = false;
bool isInBrowserElement = false;
PRUint32 appId = 0;
nsCAutoString extendedOrigin;
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup,
NS_GET_IID(nsILoadContext),
getter_AddRefs(loadContext));
if (loadContext) {
haveLoadContext = true;
loadContext->GetIsContent(&isContent);
loadContext->GetUsePrivateBrowsing(&usePrivateBrowsing);
loadContext->GetIsInBrowserElement(&isInBrowserElement);
loadContext->GetAppId(&appId);
loadContext->GetExtendedOrigin(mURI, extendedOrigin);
}
// Corresponding release in DeallocPWebSocket
AddIPDLReference();
gNeckoChild->SendPWebSocketConstructor(this, tabChild);
if (!SendAsyncOpen(aURI, nsCString(aOrigin), mProtocol, mEncrypted,
haveLoadContext, isContent, usePrivateBrowsing,
isInBrowserElement, appId, extendedOrigin))
IPC::SerializedLoadContext(this)))
return NS_ERROR_UNEXPECTED;
mOriginalURI = aURI;

View File

@ -7,23 +7,18 @@
#include "WebSocketLog.h"
#include "WebSocketChannelParent.h"
#include "nsIAuthPromptProvider.h"
#include "mozilla/LoadContext.h"
namespace mozilla {
namespace net {
NS_IMPL_THREADSAFE_ISUPPORTS3(WebSocketChannelParent,
NS_IMPL_THREADSAFE_ISUPPORTS2(WebSocketChannelParent,
nsIWebSocketListener,
nsILoadContext,
nsIInterfaceRequestor)
WebSocketChannelParent::WebSocketChannelParent(nsIAuthPromptProvider* aAuthProvider)
: mAuthProvider(aAuthProvider)
, mIPCOpen(true)
, mHaveLoadContext(false)
, mIsContent(false)
, mUsePrivateBrowsing(false)
, mIsInBrowserElement(false)
, mAppId(0)
{
#if defined(PR_LOGGING)
if (!webSocketLog)
@ -49,12 +44,7 @@ WebSocketChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
const nsCString& aOrigin,
const nsCString& aProtocol,
const bool& aSecure,
const bool& haveLoadContext,
const bool& isContent,
const bool& usePrivateBrowsing,
const bool& isInBrowserElement,
const PRUint32& appId,
const nsCString& extendedOrigin)
const IPC::SerializedLoadContext& loadContext)
{
LOG(("WebSocketChannelParent::RecvAsyncOpen() %p\n", this));
nsresult rv;
@ -68,13 +58,9 @@ WebSocketChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
if (NS_FAILED(rv))
goto fail;
// fields needed to impersonate nsILoadContext
mHaveLoadContext = haveLoadContext;
mIsContent = isContent;
mUsePrivateBrowsing = usePrivateBrowsing;
mIsInBrowserElement = isInBrowserElement;
mAppId = appId;
mExtendedOrigin = extendedOrigin;
if (loadContext.IsNotNull())
mLoadContext = new LoadContext(loadContext);
rv = mChannel->SetNotificationCallbacks(this);
if (NS_FAILED(rv))
goto fail;
@ -229,89 +215,15 @@ WebSocketChannelParent::GetInterface(const nsIID & iid, void **result)
iid, result);
// Only support nsILoadContext if child channel's callbacks did too
if (iid.Equals(NS_GET_IID(nsILoadContext)) && !mHaveLoadContext) {
return NS_NOINTERFACE;
if (iid.Equals(NS_GET_IID(nsILoadContext)) && mLoadContext) {
NS_ADDREF(mLoadContext);
*result = static_cast<nsILoadContext*>(mLoadContext);
return NS_OK;
}
return QueryInterface(iid, result);
}
//-----------------------------------------------------------------------------
// WebSocketChannelParent::nsILoadContext
//-----------------------------------------------------------------------------
NS_IMETHODIMP
WebSocketChannelParent::GetAssociatedWindow(nsIDOMWindow**)
{
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
WebSocketChannelParent::GetTopWindow(nsIDOMWindow**)
{
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
WebSocketChannelParent::IsAppOfType(PRUint32, bool*)
{
// don't expect we need this in parent (Thunderbird/SeaMonkey specific?)
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
WebSocketChannelParent::GetIsContent(bool *aIsContent)
{
NS_ENSURE_ARG_POINTER(aIsContent);
*aIsContent = mIsContent;
return NS_OK;
}
NS_IMETHODIMP
WebSocketChannelParent::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
{
NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);
*aUsePrivateBrowsing = mUsePrivateBrowsing;
return NS_OK;
}
NS_IMETHODIMP
WebSocketChannelParent::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
{
// We shouldn't need this on parent...
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
WebSocketChannelParent::GetIsInBrowserElement(bool* aIsInBrowserElement)
{
NS_ENSURE_ARG_POINTER(aIsInBrowserElement);
*aIsInBrowserElement = mIsInBrowserElement;
return NS_OK;
}
NS_IMETHODIMP
WebSocketChannelParent::GetAppId(PRUint32* aAppId)
{
NS_ENSURE_ARG_POINTER(aAppId);
*aAppId = mAppId;
return NS_OK;
}
NS_IMETHODIMP
WebSocketChannelParent::GetExtendedOrigin(nsIURI *aUri,
nsACString &aResult)
{
aResult = mExtendedOrigin;
return NS_OK;
}
} // namespace net
} // namespace mozilla

View File

@ -21,14 +21,12 @@ namespace net {
class WebSocketChannelParent : public PWebSocketParent,
public nsIWebSocketListener,
public nsIInterfaceRequestor,
public nsILoadContext
public nsIInterfaceRequestor
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBSOCKETLISTENER
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSILOADCONTEXT
WebSocketChannelParent(nsIAuthPromptProvider* aAuthProvider);
@ -37,12 +35,7 @@ class WebSocketChannelParent : public PWebSocketParent,
const nsCString& aOrigin,
const nsCString& aProtocol,
const bool& aSecure,
const bool& haveLoadContext,
const bool& isContent,
const bool& usingPrivateBrowsing,
const bool& isInBrowserElement,
const PRUint32& appId,
const nsCString& extendedOrigin);
const IPC::SerializedLoadContext& loadContext);
bool RecvClose(const PRUint16 & code, const nsCString & reason);
bool RecvSendMsg(const nsCString& aMsg);
bool RecvSendBinaryMsg(const nsCString& aMsg);
@ -54,16 +47,9 @@ class WebSocketChannelParent : public PWebSocketParent,
nsCOMPtr<nsIAuthPromptProvider> mAuthProvider;
nsCOMPtr<nsIWebSocketChannel> mChannel;
nsCOMPtr<nsILoadContext> mLoadContext;
bool mIPCOpen;
// fields for impersonating nsILoadContext
bool mHaveLoadContext : 1;
bool mIsContent : 1;
bool mUsePrivateBrowsing : 1;
bool mIsInBrowserElement : 1;
PRUint32 mAppId;
nsCString mExtendedOrigin;
};
} // namespace net

View File

@ -7,6 +7,7 @@ include protocol PNecko;
include "mozilla/net/NeckoMessageUtils.h";
using IPC::URI;
using IPC::SerializedLoadContext;
namespace mozilla {
namespace net {
@ -20,15 +21,9 @@ parent:
__delete__();
Init(URI uri);
AsyncOpen(URI originalURI,
PRUint32 loadFlags,
// Fields for imitating a nsILoadContext
bool haveLoadContext,
bool isContent,
bool usePrivateBrowsing,
bool isInBrowserElement,
PRUint32 appID,
nsCString extendedOrigin);
AsyncOpen(URI originalURI,
PRUint32 loadFlags,
SerializedLoadContext loadContext);
// methods corresponding to those of nsIWyciwygChannel
WriteToCacheEntry(nsString data);

View File

@ -562,28 +562,8 @@ WyciwygChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aConte
if (mLoadGroup)
mLoadGroup->AddRequest(this, nullptr);
// Get info from nsILoadContext, if any
bool haveLoadContext = false;
bool isContent = false;
bool usePrivateBrowsing = false;
bool isInBrowserElement = false;
PRUint32 appId = 0;
nsCAutoString extendedOrigin;
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup,
NS_GET_IID(nsILoadContext),
getter_AddRefs(loadContext));
if (loadContext) {
haveLoadContext = true;
loadContext->GetIsContent(&isContent);
loadContext->GetUsePrivateBrowsing(&usePrivateBrowsing);
loadContext->GetIsInBrowserElement(&isInBrowserElement);
loadContext->GetAppId(&appId);
loadContext->GetExtendedOrigin(mURI, extendedOrigin);
}
SendAsyncOpen(IPC::URI(mOriginalURI), mLoadFlags, haveLoadContext, isContent,
usePrivateBrowsing, isInBrowserElement, appId, extendedOrigin);
SendAsyncOpen(IPC::URI(mOriginalURI), mLoadFlags,
IPC::SerializedLoadContext(this));
mState = WCC_OPENED;

View File

@ -11,17 +11,13 @@
#include "nsCharsetSource.h"
#include "nsISerializable.h"
#include "nsSerializationHelper.h"
#include "mozilla/LoadContext.h"
namespace mozilla {
namespace net {
WyciwygChannelParent::WyciwygChannelParent()
: mIPCClosed(false)
, mHaveLoadContext(false)
, mIsContent(false)
, mUsePrivateBrowsing(false)
, mIsInBrowserElement(false)
, mAppId(0)
{
#if defined(PR_LOGGING)
if (!gWyciwygLog)
@ -45,10 +41,9 @@ WyciwygChannelParent::ActorDestroy(ActorDestroyReason why)
// WyciwygChannelParent::nsISupports
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS4(WyciwygChannelParent,
NS_IMPL_ISUPPORTS3(WyciwygChannelParent,
nsIStreamListener,
nsIInterfaceRequestor,
nsILoadContext,
nsIRequestObserver);
//-----------------------------------------------------------------------------
@ -86,12 +81,7 @@ WyciwygChannelParent::RecvInit(const IPC::URI& aURI)
bool
WyciwygChannelParent::RecvAsyncOpen(const IPC::URI& aOriginal,
const PRUint32& aLoadFlags,
const bool& haveLoadContext,
const bool& isContent,
const bool& usePrivateBrowsing,
const bool& isInBrowserElement,
const PRUint32& appId,
const nsCString& extendedOrigin)
const IPC::SerializedLoadContext& loadContext)
{
nsCOMPtr<nsIURI> original(aOriginal);
@ -110,14 +100,8 @@ WyciwygChannelParent::RecvAsyncOpen(const IPC::URI& aOriginal,
if (NS_FAILED(rv))
return SendCancelEarly(rv);
// fields needed to impersonate nsILoadContext
mHaveLoadContext = haveLoadContext;
mIsContent = isContent;
mUsePrivateBrowsing = usePrivateBrowsing;
mIsInBrowserElement = isInBrowserElement;
mAppId = appId;
mExtendedOrigin = extendedOrigin;
mChannel->SetNotificationCallbacks(this);
if (loadContext.IsNotNull())
mLoadContext = new LoadContext(loadContext);
rv = mChannel->AsyncOpen(this, nullptr);
if (NS_FAILED(rv))
@ -267,88 +251,14 @@ NS_IMETHODIMP
WyciwygChannelParent::GetInterface(const nsIID& uuid, void** result)
{
// Only support nsILoadContext if child channel's callbacks did too
if (uuid.Equals(NS_GET_IID(nsILoadContext)) && !mHaveLoadContext) {
return NS_NOINTERFACE;
if (uuid.Equals(NS_GET_IID(nsILoadContext)) && mLoadContext) {
NS_ADDREF(mLoadContext);
*result = static_cast<nsILoadContext*>(mLoadContext);
return NS_OK;
}
return QueryInterface(uuid, result);
}
//-----------------------------------------------------------------------------
// WyciwygChannelParent::nsILoadContext
//-----------------------------------------------------------------------------
NS_IMETHODIMP
WyciwygChannelParent::GetAssociatedWindow(nsIDOMWindow**)
{
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
WyciwygChannelParent::GetTopWindow(nsIDOMWindow**)
{
// can't support this in the parent process
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
WyciwygChannelParent::IsAppOfType(PRUint32, bool*)
{
// don't expect we need this in parent (Thunderbird/SeaMonkey specific?)
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
WyciwygChannelParent::GetIsContent(bool *aIsContent)
{
NS_ENSURE_ARG_POINTER(aIsContent);
*aIsContent = mIsContent;
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelParent::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
{
NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);
*aUsePrivateBrowsing = mUsePrivateBrowsing;
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelParent::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
{
// We shouldn't need this on parent...
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
WyciwygChannelParent::GetIsInBrowserElement(bool* aIsInBrowserElement)
{
NS_ENSURE_ARG_POINTER(aIsInBrowserElement);
*aIsInBrowserElement = mIsInBrowserElement;
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelParent::GetAppId(PRUint32* aAppId)
{
NS_ENSURE_ARG_POINTER(aAppId);
*aAppId = mAppId;
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelParent::GetExtendedOrigin(nsIURI *aUri,
nsACString &aResult)
{
aResult = mExtendedOrigin;
return NS_OK;
}
}} // mozilla::net

View File

@ -19,14 +19,12 @@ namespace net {
class WyciwygChannelParent : public PWyciwygChannelParent
, public nsIStreamListener
, public nsIInterfaceRequestor
, public nsILoadContext
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSILOADCONTEXT
WyciwygChannelParent();
virtual ~WyciwygChannelParent();
@ -35,12 +33,7 @@ protected:
virtual bool RecvInit(const IPC::URI& uri);
virtual bool RecvAsyncOpen(const IPC::URI& original,
const PRUint32& loadFlags,
const bool& haveLoadContext,
const bool& isContent,
const bool& usingPrivateBrowsing,
const bool& isInBrowserElement,
const PRUint32& appId,
const nsCString& extendedOrigin);
const IPC::SerializedLoadContext& loadContext);
virtual bool RecvWriteToCacheEntry(const nsString& data);
virtual bool RecvCloseCacheEntry(const nsresult& reason);
virtual bool RecvSetCharsetAndSource(const PRInt32& source,
@ -52,15 +45,7 @@ protected:
nsCOMPtr<nsIWyciwygChannel> mChannel;
bool mIPCClosed;
// fields for impersonating nsILoadContext
bool mHaveLoadContext : 1;
bool mIsContent : 1;
bool mUsePrivateBrowsing : 1;
bool mIsInBrowserElement : 1;
PRUint32 mAppId;
nsCString mExtendedOrigin;
nsCOMPtr<nsILoadContext> mLoadContext;
};
} // namespace net