Skip to content

Commit

Permalink
Bug 1303727 - Propagate whether we're dealing with a local file to th…
Browse files Browse the repository at this point in the history
…e parent. r=jduell

MozReview-Commit-ID: GSx2WgNKN4T

--HG--
extra : rebase_source : 016787d933cb092300a10bbb179b773fc2e76e6b
  • Loading branch information
mrbkap committed Jan 11, 2017
1 parent b825255 commit f55394a
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 8 deletions.
1 change: 1 addition & 0 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@ ContentChild::AllocPExternalHelperAppChild(const OptionalURIParams& uri,
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const int64_t& aContentLength,
const bool& aWasFileChannel,
const OptionalURIParams& aReferrer,
PBrowserChild* aBrowser)
{
Expand Down
1 change: 1 addition & 0 deletions dom/ipc/ContentChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class ContentChild final : public PContentChild
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const int64_t& aContentLength,
const bool& aWasFileChannel,
const OptionalURIParams& aReferrer,
PBrowserChild* aBrowser) override;

Expand Down
4 changes: 3 additions & 1 deletion dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2979,10 +2979,12 @@ ContentParent::AllocPExternalHelperAppParent(const OptionalURIParams& uri,
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const int64_t& aContentLength,
const bool& aWasFileChannel,
const OptionalURIParams& aReferrer,
PBrowserParent* aBrowser)
{
ExternalHelperAppParent *parent = new ExternalHelperAppParent(uri, aContentLength);
ExternalHelperAppParent *parent =
new ExternalHelperAppParent(uri, aContentLength, aWasFileChannel);
parent->AddRef();
parent->Init(this,
aMimeContentType,
Expand Down
1 change: 1 addition & 0 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ class ContentParent final : public PContentParent
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const int64_t& aContentLength,
const bool& aWasFileChannel,
const OptionalURIParams& aReferrer,
PBrowserParent* aBrowser) override;

Expand Down
1 change: 1 addition & 0 deletions dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ parent:
nsString aContentDispositionFilename,
bool aForceSave,
int64_t aContentLength,
bool aWasFileChannel,
OptionalURIParams aReferrer,
nullable PBrowser aBrowser);

Expand Down
7 changes: 5 additions & 2 deletions uriloader/exthandler/ExternalHelperAppParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ NS_IMPL_ISUPPORTS_INHERITED(ExternalHelperAppParent,
nsIMultiPartChannel,
nsIPrivateBrowsingChannel,
nsIResumableChannel,
nsIStreamListener)
nsIStreamListener,
nsIExternalHelperAppParent)

ExternalHelperAppParent::ExternalHelperAppParent(
const OptionalURIParams& uri,
const int64_t& aContentLength)
const int64_t& aContentLength,
const bool& aWasFileChannel)
: mURI(DeserializeURI(uri))
, mPending(false)
#ifdef DEBUG
Expand All @@ -48,6 +50,7 @@ ExternalHelperAppParent::ExternalHelperAppParent(
, mLoadFlags(0)
, mStatus(NS_OK)
, mContentLength(aContentLength)
, mWasFileChannel(aWasFileChannel)
{
}

Expand Down
26 changes: 25 additions & 1 deletion uriloader/exthandler/ExternalHelperAppParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ class PChannelDiverterParent;

namespace dom {

#define NS_IEXTERNALHELPERAPPPARENT_IID \
{ 0x127a01bc, 0x2a49, 0x46a8, \
{ 0x8c, 0x63, 0x4b, 0x5d, 0x3c, 0xa4, 0x07, 0x9c } }

class nsIExternalHelperAppParent : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IEXTERNALHELPERAPPPARENT_IID)

/**
* Returns true if this fake channel represented a file channel in the child.
*/
virtual bool WasFileChannel() = 0;
};

NS_DEFINE_STATIC_IID_ACCESSOR(nsIExternalHelperAppParent, NS_IEXTERNALHELPERAPPPARENT_IID)

class ContentParent;
class PBrowserParent;

Expand All @@ -38,6 +55,7 @@ class ExternalHelperAppParent : public PExternalHelperAppParent
, public nsIResumableChannel
, public nsIStreamListener
, public net::PrivateBrowsingChannel<ExternalHelperAppParent>
, public nsIExternalHelperAppParent
{
typedef mozilla::ipc::OptionalURIParams OptionalURIParams;

Expand All @@ -58,7 +76,12 @@ class ExternalHelperAppParent : public PExternalHelperAppParent

mozilla::ipc::IPCResult RecvDivertToParentUsing(PChannelDiverterParent* diverter) override;

ExternalHelperAppParent(const OptionalURIParams& uri, const int64_t& contentLength);
bool WasFileChannel() override {
return mWasFileChannel;
}

ExternalHelperAppParent(const OptionalURIParams& uri, const int64_t& contentLength,
const bool& wasFileChannel);
void Init(ContentParent *parent,
const nsCString& aMimeContentType,
const nsCString& aContentDisposition,
Expand All @@ -85,6 +108,7 @@ class ExternalHelperAppParent : public PExternalHelperAppParent
nsLoadFlags mLoadFlags;
nsresult mStatus;
int64_t mContentLength;
bool mWasFileChannel;
uint32_t mContentDisposition;
nsString mContentDispositionFilename;
nsCString mContentDispositionHeader;
Expand Down
21 changes: 17 additions & 4 deletions uriloader/exthandler/nsExternalHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ nsExternalHelperAppService::DoContentContentProcessHelper(const nsACString& aMim
nsCString disp;
nsCOMPtr<nsIURI> uri;
int64_t contentLength = -1;
bool wasFileChannel = false;
uint32_t contentDisposition = -1;
nsAutoString fileName;

Expand All @@ -715,8 +716,12 @@ nsExternalHelperAppService::DoContentContentProcessHelper(const nsACString& aMim
channel->GetContentDisposition(&contentDisposition);
channel->GetContentDispositionFilename(fileName);
channel->GetContentDispositionHeader(disp);

nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(aRequest));
wasFileChannel = fileChan != nullptr;
}


nsCOMPtr<nsIURI> referrer;
NS_GetReferrerFromChannel(channel, getter_AddRefs(referrer));

Expand All @@ -732,8 +737,9 @@ nsExternalHelperAppService::DoContentContentProcessHelper(const nsACString& aMim
child->SendPExternalHelperAppConstructor(uriParams,
nsCString(aMimeContentType),
disp, contentDisposition,
fileName, aForceSave,
contentLength, referrerParams,
fileName, aForceSave,
contentLength, wasFileChannel,
referrerParams,
mozilla::dom::TabChild::GetFrom(window));
ExternalHelperAppChild *childListener = static_cast<ExternalHelperAppChild *>(pc);

Expand Down Expand Up @@ -1627,11 +1633,18 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
mRequest = request;

nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);

nsresult rv;

nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(request));
mIsFileChannel = fileChan != nullptr;
if (!mIsFileChannel) {
// It's possible that this request came from the child process and the
// file channel actually lives there. If this returns true, then our
// mSourceUrl will be an nsIFileURL anyway.
nsCOMPtr<dom::nsIExternalHelperAppParent> parent(do_QueryInterface(request));
mIsFileChannel = parent && parent->WasFileChannel();
}

// Get content length
if (aChannel) {
Expand Down

0 comments on commit f55394a

Please sign in to comment.