2010-08-17 20:19:24 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2010-08-17 20:19:24 -07:00
|
|
|
|
|
|
|
#include "ExternalHelperAppParent.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
#include "nsIExternalHelperAppService.h"
|
2010-09-15 15:55:08 -07:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2010-08-17 20:19:24 -07:00
|
|
|
#include "nsIBrowserDOMWindow.h"
|
|
|
|
#include "nsStringStream.h"
|
|
|
|
|
|
|
|
#include "mozilla/unused.h"
|
2011-06-21 08:37:46 -07:00
|
|
|
#include "mozilla/Util.h" // for DebugOnly
|
2010-08-17 20:19:24 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2010-09-13 11:17:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED4(ExternalHelperAppParent,
|
2010-08-17 20:19:24 -07:00
|
|
|
nsHashPropertyBag,
|
|
|
|
nsIRequest,
|
2010-09-03 10:16:01 -07:00
|
|
|
nsIChannel,
|
2010-09-13 11:17:00 -07:00
|
|
|
nsIMultiPartChannel,
|
2010-09-03 10:16:01 -07:00
|
|
|
nsIResumableChannel)
|
2010-08-17 20:19:24 -07:00
|
|
|
|
|
|
|
ExternalHelperAppParent::ExternalHelperAppParent(
|
|
|
|
const IPC::URI& uri,
|
2012-08-22 08:56:38 -07:00
|
|
|
const int64_t& aContentLength)
|
2010-08-17 20:19:24 -07:00
|
|
|
: mURI(uri)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mPending(false)
|
2010-08-17 20:19:24 -07:00
|
|
|
, mLoadFlags(0)
|
|
|
|
, mStatus(NS_OK)
|
|
|
|
, mContentLength(aContentLength)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-09-15 15:55:08 -07:00
|
|
|
ExternalHelperAppParent::Init(ContentParent *parent,
|
2010-08-17 20:19:24 -07:00
|
|
|
const nsCString& aMimeContentType,
|
2011-09-09 15:41:04 -07:00
|
|
|
const nsCString& aContentDispositionHeader,
|
2011-09-28 23:19:26 -07:00
|
|
|
const bool& aForceSave,
|
2010-11-21 11:21:59 -08:00
|
|
|
const IPC::URI& aReferrer)
|
2010-08-17 20:19:24 -07:00
|
|
|
{
|
|
|
|
nsHashPropertyBag::Init();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIExternalHelperAppService> helperAppService =
|
|
|
|
do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID);
|
|
|
|
NS_ASSERTION(helperAppService, "No Helper App Service!");
|
|
|
|
|
2010-08-30 13:20:39 -07:00
|
|
|
SetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, mContentLength);
|
2010-11-21 11:21:59 -08:00
|
|
|
if (aReferrer)
|
|
|
|
SetPropertyAsInterface(NS_LITERAL_STRING("docshell.internalReferrer"), aReferrer);
|
2011-09-09 15:41:04 -07:00
|
|
|
mContentDispositionHeader = aContentDispositionHeader;
|
|
|
|
NS_GetFilenameFromDisposition(mContentDispositionFilename, mContentDispositionHeader, mURI);
|
|
|
|
mContentDisposition = NS_GetContentDispositionFromHeader(mContentDispositionHeader, this);
|
2012-07-30 07:20:58 -07:00
|
|
|
helperAppService->DoContent(aMimeContentType, this, nullptr,
|
2010-08-17 20:19:24 -07:00
|
|
|
aForceSave, getter_AddRefs(mListener));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-08-23 09:29:33 -07:00
|
|
|
ExternalHelperAppParent::RecvOnStartRequest(const nsCString& entityID)
|
2010-08-17 20:19:24 -07:00
|
|
|
{
|
2010-08-23 09:29:33 -07:00
|
|
|
mEntityID = entityID;
|
2011-10-17 07:59:28 -07:00
|
|
|
mPending = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
mStatus = mListener->OnStartRequest(this, nullptr);
|
2010-08-17 20:19:24 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ExternalHelperAppParent::RecvOnDataAvailable(const nsCString& data,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t& offset,
|
|
|
|
const uint32_t& count)
|
2010-08-17 20:19:24 -07:00
|
|
|
{
|
|
|
|
if (NS_FAILED(mStatus))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
NS_ASSERTION(mPending, "must be pending!");
|
|
|
|
nsCOMPtr<nsIInputStream> stringStream;
|
2011-06-21 08:37:46 -07:00
|
|
|
DebugOnly<nsresult> rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(), count, NS_ASSIGNMENT_DEPEND);
|
2010-08-17 20:19:24 -07:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create dependent string!");
|
2012-07-30 07:20:58 -07:00
|
|
|
mStatus = mListener->OnDataAvailable(this, nullptr, stringStream, offset, count);
|
2010-08-17 20:19:24 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ExternalHelperAppParent::RecvOnStopRequest(const nsresult& code)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mPending = false;
|
2012-07-30 07:20:58 -07:00
|
|
|
mListener->OnStopRequest(this, nullptr,
|
2010-08-17 20:19:24 -07:00
|
|
|
(NS_SUCCEEDED(code) && NS_FAILED(mStatus)) ? mStatus : code);
|
|
|
|
unused << Send__delete__(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExternalHelperAppParent::~ExternalHelperAppParent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsIRequest implementation...
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetName(nsACString& aResult)
|
|
|
|
{
|
|
|
|
mURI->GetAsciiSpec(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
ExternalHelperAppParent::IsPending(bool *aResult)
|
2010-08-17 20:19:24 -07:00
|
|
|
{
|
|
|
|
*aResult = mPending;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetStatus(nsresult *aResult)
|
|
|
|
{
|
|
|
|
*aResult = mStatus;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::Cancel(nsresult aStatus)
|
|
|
|
{
|
|
|
|
mStatus = aStatus;
|
|
|
|
unused << SendCancel(aStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::Suspend()
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::Resume()
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsIChannel implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetOriginalURI(nsIURI * *aURI)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aURI = mURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::SetOriginalURI(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetURI(nsIURI **aURI)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aURI = mURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::Open(nsIInputStream **aResult)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::AsyncOpen(nsIStreamListener *aListener,
|
|
|
|
nsISupports *aContext)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
|
|
|
{
|
|
|
|
*aLoadFlags = mLoadFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::SetLoadFlags(nsLoadFlags aLoadFlags)
|
|
|
|
{
|
|
|
|
mLoadFlags = aLoadFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aLoadGroup = nullptr;
|
2010-08-17 20:19:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetOwner(nsISupports* *aOwner)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aOwner = nullptr;
|
2010-08-17 20:19:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::SetOwner(nsISupports* aOwner)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetNotificationCallbacks(nsIInterfaceRequestor* *aCallbacks)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aCallbacks = nullptr;
|
2010-08-17 20:19:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::SetNotificationCallbacks(nsIInterfaceRequestor* aCallbacks)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aSecurityInfo = nullptr;
|
2010-08-17 20:19:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetContentType(nsACString& aContentType)
|
|
|
|
{
|
|
|
|
aContentType.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::SetContentType(const nsACString& aContentType)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetContentCharset(nsACString& aContentCharset)
|
|
|
|
{
|
|
|
|
aContentCharset.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::SetContentCharset(const nsACString& aContentCharset)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-09-09 15:41:04 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
ExternalHelperAppParent::GetContentDisposition(uint32_t *aContentDisposition)
|
2011-09-09 15:41:04 -07:00
|
|
|
{
|
|
|
|
if (mContentDispositionHeader.IsEmpty())
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
*aContentDisposition = mContentDisposition;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetContentDispositionFilename(nsAString& aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
if (mContentDispositionFilename.IsEmpty())
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
aContentDispositionFilename = mContentDispositionFilename;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetContentDispositionHeader(nsACString& aContentDispositionHeader)
|
|
|
|
{
|
|
|
|
if (mContentDispositionHeader.IsEmpty())
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
aContentDispositionHeader = mContentDispositionHeader;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-17 20:19:24 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
ExternalHelperAppParent::GetContentLength(int32_t *aContentLength)
|
2010-08-17 20:19:24 -07:00
|
|
|
{
|
2010-08-30 13:20:39 -07:00
|
|
|
if (mContentLength > PR_INT32_MAX || mContentLength < 0)
|
|
|
|
*aContentLength = -1;
|
|
|
|
else
|
2012-08-22 08:56:38 -07:00
|
|
|
*aContentLength = (int32_t)mContentLength;
|
2010-08-17 20:19:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
ExternalHelperAppParent::SetContentLength(int32_t aContentLength)
|
2010-08-17 20:19:24 -07:00
|
|
|
{
|
|
|
|
mContentLength = aContentLength;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-23 09:29:33 -07:00
|
|
|
//
|
|
|
|
// nsIResumableChannel implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
ExternalHelperAppParent::ResumeAt(uint64_t startPos, const nsACString& entityID)
|
2010-08-23 09:29:33 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetEntityID(nsACString& aEntityID)
|
|
|
|
{
|
|
|
|
aEntityID = mEntityID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-13 11:17:00 -07:00
|
|
|
//
|
|
|
|
// nsIMultiPartChannel implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppParent::GetBaseChannel(nsIChannel* *aChannel)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
ExternalHelperAppParent::GetPartID(uint32_t* aPartID)
|
2010-09-13 11:17:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
ExternalHelperAppParent::GetIsLastPart(bool* aIsLastPart)
|
2010-09-13 11:17:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2010-08-17 20:19:24 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|