Bug 794597 - mozbrowser doesn't send auth request off a redirect. r=jdm

This commit is contained in:
Jason Duell 2012-10-09 16:46:24 -07:00
parent 390bdd5e03
commit e7f4733608
9 changed files with 67 additions and 43 deletions

View File

@ -59,18 +59,14 @@ void NeckoChild::DestroyNeckoChild()
}
}
PHttpChannelChild*
NeckoChild::AllocPHttpChannel(PBrowserChild* browser)
PHttpChannelChild*
NeckoChild::AllocPHttpChannel(PBrowserChild* browser,
const SerializedLoadContext& loadContext)
{
// This constructor is only used when PHttpChannel is constructed by
// the parent process, e.g. during a redirect. (Normally HttpChannelChild is
// created by nsHttpHandler::NewProxiedChannel(), and then creates the
// PHttpChannel in HttpChannelChild::AsyncOpen().)
// No need to store PBrowser. It is only needed by the parent.
HttpChannelChild* httpChannel = new HttpChannelChild();
httpChannel->AddIPDLReference();
return httpChannel;
// We don't allocate here: instead we always use IPDL constructor that takes
// an existing HttpChildChannel
NS_NOTREACHED("AllocPHttpChannel should not be called on child");
return nullptr;
}
bool

View File

@ -26,7 +26,8 @@ public:
static void DestroyNeckoChild();
protected:
virtual PHttpChannelChild* AllocPHttpChannel(PBrowserChild* iframeEmbedding);
virtual PHttpChannelChild* AllocPHttpChannel(PBrowserChild*,
const SerializedLoadContext&);
virtual bool DeallocPHttpChannel(PHttpChannelChild*);
virtual PCookieServiceChild* AllocPCookieService();
virtual bool DeallocPCookieService(PCookieServiceChild*);

View File

@ -33,15 +33,16 @@ NeckoParent::~NeckoParent()
{
}
PHttpChannelParent*
NeckoParent::AllocPHttpChannel(PBrowserParent* browser)
PHttpChannelParent*
NeckoParent::AllocPHttpChannel(PBrowserParent* browser,
const SerializedLoadContext& loadContext)
{
HttpChannelParent *p = new HttpChannelParent(browser);
HttpChannelParent *p = new HttpChannelParent(browser, loadContext);
p->AddRef();
return p;
}
bool
bool
NeckoParent::DeallocPHttpChannel(PHttpChannelParent* channel)
{
HttpChannelParent *p = static_cast<HttpChannelParent *>(channel);

View File

@ -23,7 +23,8 @@ public:
virtual ~NeckoParent();
protected:
virtual PHttpChannelParent* AllocPHttpChannel(PBrowserParent* browser);
virtual PHttpChannelParent* AllocPHttpChannel(PBrowserParent*,
const SerializedLoadContext&);
virtual bool DeallocPHttpChannel(PHttpChannelParent*);
virtual PCookieServiceParent* AllocPCookieService();
virtual bool DeallocPCookieService(PCookieServiceParent*);

View File

@ -14,6 +14,10 @@ include protocol PFTPChannel;
include protocol PWebSocket;
include protocol PTCPSocket;
include "SerializedLoadContext.h";
using IPC::SerializedLoadContext;
namespace mozilla {
namespace net {
@ -33,6 +37,8 @@ parent:
__delete__();
PCookieService();
PHttpChannel(nullable PBrowser browser,
SerializedLoadContext loadContext);
PWyciwygChannel();
PFTPChannel();
PWebSocket(PBrowser browser);
@ -42,8 +48,6 @@ parent:
HTMLDNSPrefetch(nsString hostname, uint16_t flags);
CancelHTMLDNSPrefetch(nsString hostname, uint16_t flags, nsresult reason);
both:
PHttpChannel(nullable PBrowser browser);
};

View File

@ -807,8 +807,10 @@ HttpChannelChild::ConnectParent(uint32_t id)
// until OnStopRequest, or we do a redirect, or we hit an IPDL error.
AddIPDLReference();
if (!gNeckoChild->SendPHttpChannelConstructor(this, tabChild))
if (!gNeckoChild->SendPHttpChannelConstructor(
this, tabChild, IPC::SerializedLoadContext(this))) {
return NS_ERROR_FAILURE;
}
if (!SendConnectChannel(id))
return NS_ERROR_FAILURE;
@ -1037,7 +1039,8 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
// until OnStopRequest, or we do a redirect, or we hit an IPDL error.
AddIPDLReference();
gNeckoChild->SendPHttpChannelConstructor(this, tabChild);
gNeckoChild->SendPHttpChannelConstructor(this, tabChild,
IPC::SerializedLoadContext(this));
URIParams uri;
SerializeURI(mURI, uri);
@ -1055,7 +1058,7 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
mUploadStreamHasHeaders, mPriority, mRedirectionLimit,
mAllowPipelining, mForceAllowThirdPartyCookie, mSendResumeAt,
mStartPos, mEntityID, mChooseApplicationCache,
appCacheClientId, mAllowSpdy, IPC::SerializedLoadContext(this));
appCacheClientId, mAllowSpdy);
return NS_OK;
}

View File

@ -33,7 +33,8 @@ using namespace mozilla::ipc;
namespace mozilla {
namespace net {
HttpChannelParent::HttpChannelParent(PBrowserParent* iframeEmbedding)
HttpChannelParent::HttpChannelParent(PBrowserParent* iframeEmbedding,
const IPC::SerializedLoadContext& loadContext)
: mIPCClosed(false)
, mStoredStatus(NS_OK)
, mStoredProgress(0)
@ -41,6 +42,7 @@ HttpChannelParent::HttpChannelParent(PBrowserParent* iframeEmbedding)
, mSentRedirect1Begin(false)
, mSentRedirect1BeginFailed(false)
, mReceivedRedirect2Verify(false)
, mPBOverride(kPBOverride_Unset)
{
// Ensure gHttpHandler is initialized: we need the atom table up and running.
nsIHttpProtocolHandler* handler;
@ -48,6 +50,18 @@ HttpChannelParent::HttpChannelParent(PBrowserParent* iframeEmbedding)
NS_ASSERTION(handler, "no http handler");
mTabParent = static_cast<mozilla::dom::TabParent*>(iframeEmbedding);
if (loadContext.IsNotNull()) {
if (mTabParent) {
mLoadContext = new LoadContext(loadContext, mTabParent->GetOwnerElement());
} else {
mLoadContext = new LoadContext(loadContext);
}
} else if (loadContext.IsPrivateBitValid()) {
// Don't have channel yet: override PB status after we create it.
mPBOverride = loadContext.mUsePrivateBrowsing ? kPBOverride_Private
: kPBOverride_NotPrivate;
}
}
HttpChannelParent::~HttpChannelParent()
@ -124,8 +138,7 @@ HttpChannelParent::RecvAsyncOpen(const URIParams& aURI,
const nsCString& entityID,
const bool& chooseApplicationCache,
const nsCString& appCacheClientID,
const bool& allowSpdy,
const IPC::SerializedLoadContext& loadContext)
const bool& allowSpdy)
{
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
nsCOMPtr<nsIURI> originalUri = DeserializeURI(aOriginalURI);
@ -147,18 +160,10 @@ HttpChannelParent::RecvAsyncOpen(const URIParams& aURI,
if (NS_FAILED(rv))
return SendFailedAsyncOpen(rv);
if (loadContext.IsNotNull()) {
if (mTabParent)
mLoadContext = new LoadContext(loadContext, mTabParent->GetOwnerElement());
else
mLoadContext = new LoadContext(loadContext);
} else if (loadContext.IsPrivateBitValid()) {
nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(mChannel);
if (pbChannel)
pbChannel->SetPrivate(loadContext.mUsePrivateBrowsing);
}
nsHttpChannel *httpChan = static_cast<nsHttpChannel *>(mChannel.get());
if (mPBOverride != kPBOverride_Unset) {
httpChan->SetPrivate(mPBOverride == kPBOverride_Private ? true : false);
}
if (doResumeAt)
httpChan->ResumeAt(startPos, entityID);
@ -249,6 +254,14 @@ HttpChannelParent::RecvConnectChannel(const uint32_t& channelId)
rv = NS_LinkRedirectChannels(channelId, this, getter_AddRefs(mChannel));
LOG((" found channel %p, rv=%08x", mChannel.get(), rv));
if (mPBOverride != kPBOverride_Unset) {
// redirected-to channel may not support PB
nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(mChannel);
if (pbChannel) {
pbChannel->SetPrivate(mPBOverride == kPBOverride_Private ? true : false);
}
}
return true;
}

View File

@ -43,7 +43,8 @@ public:
NS_DECL_NSIPROGRESSEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
HttpChannelParent(mozilla::dom::PBrowserParent* iframeEmbedding);
HttpChannelParent(mozilla::dom::PBrowserParent* iframeEmbedding,
const IPC::SerializedLoadContext& loadContext);
virtual ~HttpChannelParent();
protected:
@ -65,8 +66,7 @@ protected:
const nsCString& entityID,
const bool& chooseApplicationCache,
const nsCString& appCacheClientID,
const bool& allowSpdy,
const IPC::SerializedLoadContext& loadContext) MOZ_OVERRIDE;
const bool& allowSpdy) MOZ_OVERRIDE;
virtual bool RecvConnectChannel(const uint32_t& channelId);
virtual bool RecvSetPriority(const uint16_t& priority);
@ -110,6 +110,14 @@ private:
bool mSentRedirect1BeginFailed : 1;
bool mReceivedRedirect2Verify : 1;
// Used to override channel Private Browsing status if needed.
enum PBOverrideStatus {
kPBOverride_Unset = 0,
kPBOverride_Private,
kPBOverride_NotPrivate
};
PBOverrideStatus mPBOverride;
nsCOMPtr<nsILoadContext> mLoadContext;
};

View File

@ -14,13 +14,11 @@ include protocol PBlob; //FIXME: bug #792908
include "mozilla/net/PHttpChannelParams.h";
include "mozilla/net/NeckoMessageUtils.h";
include "prio.h";
include "SerializedLoadContext.h";
using RequestHeaderTuples;
using nsHttpHeaderArray;
using nsHttpResponseHead;
using nsHttpAtom;
using IPC::SerializedLoadContext;
using PRNetAddr;
namespace mozilla {
@ -53,8 +51,7 @@ parent:
nsCString entityID,
bool chooseApplicationCache,
nsCString appCacheClientID,
bool allowSpdy,
SerializedLoadContext loadContext);
bool allowSpdy);
// Used to connect redirected-to channel on the parent with redirected-to
// channel on the child.