Bug 562444 - e10s: fix external app handler code to enable download manager and others over IPC, r=dwitte, sr=biesi, blocking-fennec2.0a1=mfinkle

This commit is contained in:
Brian Crowder 2010-08-17 20:19:24 -07:00
parent bcd5f25ef2
commit 10a55e53b3
14 changed files with 857 additions and 17 deletions

View File

@ -43,6 +43,7 @@ include protocol PDocumentRenderer;
include protocol PDocumentRendererShmem;
include protocol PDocumentRendererNativeID;
include protocol PGeolocationRequest;
include protocol PExternalHelperApp;
include "mozilla/TabTypes.h";
include "TabMessageUtils.h";
@ -71,6 +72,7 @@ rpc protocol PBrowser
manages PDocumentRendererShmem;
manages PDocumentRendererNativeID;
manages PGeolocationRequest;
manages PExternalHelperApp;
both:
AsyncMessage(nsString aMessage, nsString aJSON);
@ -119,6 +121,8 @@ parent:
__delete__();
PExternalHelperApp(URI uri, nsCString aMimeContentType, bool aForceSave, PRInt64 aContentLength);
child:
CreateWidget(MagicWindowHandle parentWidget);

View File

@ -54,6 +54,7 @@
#include "mozilla/ipc/DocumentRendererChild.h"
#include "mozilla/ipc/DocumentRendererShmemChild.h"
#include "mozilla/ipc/DocumentRendererNativeIDChild.h"
#include "mozilla/dom/ExternalHelperAppChild.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMWindowUtils.h"
@ -1287,3 +1288,24 @@ TabChildGlobal::GetPrincipal()
return nsnull;
return mTabChild->GetPrincipal();
}
PExternalHelperAppChild*
TabChild::AllocPExternalHelperApp(const IPC::URI& uri,
const nsCString& aMimeContentType,
const bool& aForceSave,
const PRInt64& aContentLength)
{
ExternalHelperAppChild *child = new ExternalHelperAppChild();
child->AddRef();
return child;
}
bool
TabChild::DeallocPExternalHelperApp(PExternalHelperAppChild* aService)
{
ExternalHelperAppChild *child = static_cast<ExternalHelperAppChild*>(aService);
child->Release();
return true;
}

View File

@ -223,6 +223,12 @@ public:
const nsTArray<int>&,
const nsTArray<nsString>&);
virtual bool DeallocPContentDialog(PContentDialogChild* aDialog);
virtual PExternalHelperAppChild *AllocPExternalHelperApp(
const IPC::URI& uri,
const nsCString& aMimeContentType,
const bool& aForceSave,
const PRInt64& aContentLength);
virtual bool DeallocPExternalHelperApp(PExternalHelperAppChild *aService);
static void ParamsToArrays(nsIDialogParamBlock* aParams,
nsTArray<int>& aIntParams,
nsTArray<nsString>& aStringParams);

View File

@ -36,6 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/dom/ExternalHelperAppParent.h"
#include "TabParent.h"
#include "mozilla/ipc/DocumentRendererParent.h"
@ -807,5 +808,25 @@ TabParent::GetFrameLoader() const
return frameLoaderOwner ? frameLoaderOwner->GetFrameLoader() : nsnull;
}
PExternalHelperAppParent*
TabParent::AllocPExternalHelperApp(const IPC::URI& uri,
const nsCString& aMimeContentType,
const bool& aForceSave,
const PRInt64& aContentLength)
{
ExternalHelperAppParent *parent = new ExternalHelperAppParent(uri, aContentLength);
parent->AddRef();
parent->Init(this, aMimeContentType, aForceSave);
return parent;
}
bool
TabParent::DeallocPExternalHelperApp(PExternalHelperAppParent* aService)
{
ExternalHelperAppParent *parent = static_cast<ExternalHelperAppParent *>(aService);
parent->Release();
return true;
}
} // namespace tabs
} // namespace mozilla

View File

@ -42,6 +42,7 @@
#include "mozilla/dom/PBrowserParent.h"
#include "mozilla/dom/PContentDialogParent.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/dom/PExternalHelperApp.h"
#include "jsapi.h"
#include "nsCOMPtr.h"
@ -100,11 +101,13 @@ class TabParent : public PBrowserParent
public:
TabParent();
virtual ~TabParent();
nsIDOMElement* GetOwnerElement() { return mFrameElement; }
void SetOwnerElement(nsIDOMElement* aElement) { mFrameElement = aElement; }
nsIBrowserDOMWindow *GetBrowserDOMWindow() { return mBrowserDOMWindow; }
void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserDOMWindow) {
mBrowserDOMWindow = aBrowserDOMWindow;
}
virtual bool RecvMoveFocus(const bool& aForward);
virtual bool RecvEvent(const RemoteDOMEvent& aEvent);
virtual bool RecvNotifyProgressChange(const PRInt64& aProgress,
@ -144,6 +147,13 @@ public:
return true;
}
virtual PExternalHelperAppParent* AllocPExternalHelperApp(
const IPC::URI& uri,
const nsCString& aMimeContentType,
const bool& aForceSave,
const PRInt64& aContentLength);
virtual bool DeallocPExternalHelperApp(PExternalHelperAppParent* aService);
void LoadURL(nsIURI* aURI);
void Move(PRUint32 x, PRUint32 y, PRUint32 width, PRUint32 height);
void Activate();

View File

@ -54,6 +54,7 @@ EXPORT_LIBRARY = 1
## When you add IPDL files to a source directory, list the directory here.
##
IPDLDIRS = \
uriloader/exthandler \
dom/src/geolocation \
dom/plugins \
dom/ipc \

View File

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/****** 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 IPC External Helper App module.
*
* The Initial Developer of the Original Code is
* Brian Crowder <crowderbt@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 "ExternalHelperAppChild.h"
#include "nsIInputStream.h"
#include "nsIRequest.h"
#include "nsNetUtil.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS2(ExternalHelperAppChild,
nsIStreamListener,
nsIRequestObserver)
ExternalHelperAppChild::ExternalHelperAppChild()
: mStatus(NS_OK)
{
}
ExternalHelperAppChild::~ExternalHelperAppChild()
{
}
//-----------------------------------------------------------------------------
// nsIStreamListener
//-----------------------------------------------------------------------------
NS_IMETHODIMP
ExternalHelperAppChild::OnDataAvailable(nsIRequest *request,
nsISupports *ctx,
nsIInputStream *input,
PRUint32 offset,
PRUint32 count)
{
if (NS_FAILED(mStatus))
return mStatus;
nsCString data;
nsresult rv = NS_ReadInputStreamToString(input, data, count);
if (NS_FAILED(rv))
return rv;
if (!SendOnDataAvailable(data, offset, count))
return NS_ERROR_UNEXPECTED;
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////////
// nsIRequestObserver
//////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
ExternalHelperAppChild::OnStartRequest(nsIRequest *request, nsISupports *ctx)
{
// FIXME: Eventually we should implement this:
// mHandler->OnStartRequest(request, ctx);
SendOnStartRequest();
return NS_OK;
}
NS_IMETHODIMP
ExternalHelperAppChild::OnStopRequest(nsIRequest *request,
nsISupports *ctx,
nsresult status)
{
// FIXME: Eventually we should implement this:
// mHandler->OnStopRequest(request, ctx, status);
SendOnStopRequest(status);
return NS_OK;
}
bool
ExternalHelperAppChild::RecvCancel(const nsresult& aStatus)
{
mStatus = aStatus;
return true;
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,68 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/****** 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 IPC External Helper App module.
*
* The Initial Developer of the Original Code is
* Brian Crowder <crowderbt@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 "mozilla/dom/PExternalHelperAppChild.h"
#include "nsIStreamListener.h"
namespace mozilla {
namespace dom {
class ExternalHelperAppChild : public PExternalHelperAppChild
, public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
ExternalHelperAppChild();
virtual ~ExternalHelperAppChild();
// Give the listener a real nsExternalAppHandler to complete processing on
// the child.
void SetHandler(nsIStreamListener *handler) { mHandler = handler; }
virtual bool RecvCancel(const nsresult& aStatus);
private:
nsCOMPtr<nsIStreamListener> mHandler;
nsresult mStatus;
};
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,316 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/****** 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 IPC External Helper App module.
*
* The Initial Developer of the Original Code is
* Brian Crowder <crowderbt@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 "ExternalHelperAppParent.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsCExternalHandlerService.h"
#include "nsIExternalHelperAppService.h"
#include "mozilla/dom/TabParent.h"
#include "nsIBrowserDOMWindow.h"
#include "nsStringStream.h"
#include "mozilla/unused.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS_INHERITED2(ExternalHelperAppParent,
nsHashPropertyBag,
nsIRequest,
nsIChannel)
ExternalHelperAppParent::ExternalHelperAppParent(
const IPC::URI& uri,
const PRInt64& aContentLength)
: mURI(uri)
, mPending(PR_FALSE)
, mLoadFlags(0)
, mStatus(NS_OK)
, mContentLength(aContentLength)
{
}
void
ExternalHelperAppParent::Init(TabParent *parent,
const nsCString& aMimeContentType,
const PRBool& aForceSave)
{
nsHashPropertyBag::Init();
NS_ASSERTION(parent, "must have a non-null TabParent");
nsCOMPtr<nsIContent> frame = do_QueryInterface(parent->GetOwnerElement());
nsCOMPtr<nsISupports> container = frame->GetOwnerDoc()->GetContainer();
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(container);
nsCOMPtr<nsIExternalHelperAppService> helperAppService =
do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID);
NS_ASSERTION(helperAppService, "No Helper App Service!");
SetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, mContentLength);
helperAppService->DoContent(aMimeContentType, this, ir,
aForceSave, getter_AddRefs(mListener));
}
bool
ExternalHelperAppParent::RecvOnStartRequest()
{
mPending = PR_TRUE;
mStatus = mListener->OnStartRequest(this, nsnull);
return true;
}
bool
ExternalHelperAppParent::RecvOnDataAvailable(const nsCString& data,
const PRUint32& offset,
const PRUint32& count)
{
if (NS_FAILED(mStatus))
return true;
NS_ASSERTION(mPending, "must be pending!");
nsCOMPtr<nsIInputStream> stringStream;
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(), count, NS_ASSIGNMENT_DEPEND);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create dependent string!");
mStatus = mListener->OnDataAvailable(this, nsnull, stringStream, offset, count);
return true;
}
bool
ExternalHelperAppParent::RecvOnStopRequest(const nsresult& code)
{
mPending = PR_FALSE;
mListener->OnStopRequest(this, nsnull,
(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
ExternalHelperAppParent::IsPending(PRBool *aResult)
{
*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)
{
*aLoadGroup = nsnull;
return NS_OK;
}
NS_IMETHODIMP
ExternalHelperAppParent::SetLoadGroup(nsILoadGroup* aLoadGroup)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
ExternalHelperAppParent::GetOwner(nsISupports* *aOwner)
{
*aOwner = nsnull;
return NS_OK;
}
NS_IMETHODIMP
ExternalHelperAppParent::SetOwner(nsISupports* aOwner)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
ExternalHelperAppParent::GetNotificationCallbacks(nsIInterfaceRequestor* *aCallbacks)
{
*aCallbacks = nsnull;
return NS_OK;
}
NS_IMETHODIMP
ExternalHelperAppParent::SetNotificationCallbacks(nsIInterfaceRequestor* aCallbacks)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
ExternalHelperAppParent::GetSecurityInfo(nsISupports * *aSecurityInfo)
{
*aSecurityInfo = nsnull;
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;
}
NS_IMETHODIMP
ExternalHelperAppParent::GetContentLength(PRInt32 *aContentLength)
{
if (mContentLength > PR_INT32_MAX || mContentLength < 0)
*aContentLength = -1;
else
*aContentLength = (PRInt32)mContentLength;
return NS_OK;
}
NS_IMETHODIMP
ExternalHelperAppParent::SetContentLength(PRInt32 aContentLength)
{
mContentLength = aContentLength;
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/****** 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 IPC External Helper App module.
*
* The Initial Developer of the Original Code is
* Brian Crowder <crowderbt@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 "mozilla/dom/PExternalHelperAppParent.h"
#include "nsIChannel.h"
#include "nsICancelable.h"
#include "nsHashPropertyBag.h"
namespace IPC {
class URI;
}
namespace mozilla {
namespace dom {
class TabParent;
class ExternalHelperAppParent : public PExternalHelperAppParent
, public nsHashPropertyBag
, public nsIChannel
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
bool RecvOnStartRequest();
bool RecvOnDataAvailable(const nsCString& data, const PRUint32& offset, const PRUint32& count);
bool RecvOnStopRequest(const nsresult& code);
ExternalHelperAppParent(const IPC::URI& uri, const PRInt64& contentLength);
void Init(TabParent *parent,
const nsCString& aMimeContentType,
const PRBool& aForceSave);
virtual ~ExternalHelperAppParent();
private:
nsCOMPtr<nsIStreamListener> mListener;
nsCOMPtr<nsIURI> mURI;
PRBool mPending;
nsLoadFlags mLoadFlags;
nsresult mStatus;
PRInt64 mContentLength;
};
} // namespace dom
} // namespace mozilla

View File

@ -89,6 +89,15 @@ endif
LOCAL_INCLUDES = -I$(srcdir)
ifdef MOZ_IPC
LOCAL_INCLUDES += -I$(topsrcdir)/dom/base \
-I$(topsrcdir)/dom/ipc \
-I$(topsrcdir)/content/base/src \
-I$(topsrcdir)/content/events/src \
-I$(topsrcdir)/netwerk/base/src \
-I$(topsrcdir)/netwerk/protocol/http
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
OSHELPER += nsGNOMERegistry.cpp
OSHELPER += nsMIMEInfoUnix.cpp
@ -117,9 +126,15 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
OSHELPER += nsMIMEInfoOS2.cpp
endif
EXPORTS_NAMESPACES = mozilla/dom
EXPORTS_mozilla/dom = \
ExternalHelperAppParent.h \
ExternalHelperAppChild.h
EXPORTS = \
$(OSDIR)/nsOSHelperAppService.h \
$(NULL)
$(NULL)
XPIDLSRCS = \
nsCExternalHandlerService.idl \
@ -138,6 +153,12 @@ CPPSRCS = \
$(OSHELPER) \
$(NULL)
ifdef MOZ_IPC
CPPSRCS += \
ExternalHelperAppChild.cpp \
ExternalHelperAppParent.cpp
endif
ifdef MOZ_ENABLE_DBUS
CPPSRCS += nsDBusHandlerApp.cpp
LOCAL_INCLUDES += $(TK_CFLAGS) $(MOZ_DBUS_CFLAGS)

View File

@ -0,0 +1,59 @@
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Crowder <crowderbt@gmail.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 protocol PBrowser;
namespace mozilla {
namespace dom {
protocol PExternalHelperApp
{
manager PBrowser;
parent:
OnStartRequest();
OnDataAvailable(nsCString data, PRUint32 offset, PRUint32 count);
OnStopRequest(nsresult code);
child:
Cancel(nsresult aStatus);
__delete__();
};
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,40 @@
# ***** 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 Geolocation code.
#
# The Initial Developer of the Original Code is
# the Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Brian Crowder <crowderbt@gmail.com> (Initial Developer)
#
# Alternatively, the contents of this file may be used under the terms of
# either 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 *****
IPDLSRCS = \
PExternalHelperApp.ipdl \
$(NULL)

View File

@ -47,6 +47,7 @@
#endif
#ifdef MOZ_IPC
#include "base/basictypes.h"
#include "mozilla/dom/ContentChild.h"
#include "nsXULAppAPI.h"
#endif
@ -137,6 +138,15 @@
#include "nsIPrivateBrowsingService.h"
#ifdef MOZ_IPC
#include "TabChild.h"
#include "nsXULAppAPI.h"
#include "nsPIDOMWindow.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDocShellTreeItem.h"
#include "ExternalHelperAppChild.h"
#endif
// Buffer file writes in 32kb chunks
#define BUFFERED_OUTPUT_SIZE (1024 * 32)
@ -156,6 +166,7 @@ PRLogModuleInfo* nsExternalHelperAppService::mLog = nsnull;
// Using level 3 here because the OSHelperAppServices use a log level
// of PR_LOG_DEBUG (4), and we want less detailed output here
// Using 3 instead of PR_LOG_WARN because we don't output warnings
#undef LOG
#define LOG(args) PR_LOG(mLog, 3, args)
#define LOG_ENABLED() PR_LOG_TEST(mLog, 3)
@ -616,6 +627,26 @@ nsExternalHelperAppService::~nsExternalHelperAppService()
gExtProtSvc = nsnull;
}
static PRInt64 GetContentLengthAsInt64(nsIRequest *request)
{
PRInt64 contentLength = -1;
nsresult rv;
nsCOMPtr<nsIPropertyBag2> props(do_QueryInterface(request, &rv));
if (props)
rv = props->GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, &contentLength);
if (NS_FAILED(rv)) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel) {
PRInt32 smallLen;
channel->GetContentLength(&smallLen);
contentLength = smallLen;
}
}
return contentLength;
}
NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeContentType,
nsIRequest *aRequest,
nsIInterfaceRequestor *aWindowContext,
@ -629,6 +660,60 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeConte
// Get the file extension and name that we will need later
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
nsCOMPtr<nsIURI> uri;
if (channel)
channel->GetURI(getter_AddRefs(uri));
#ifdef MOZ_IPC
PRInt64 contentLength = GetContentLengthAsInt64(aRequest);
if (XRE_GetProcessType() == GeckoProcessType_Content) {
// We need to get a hold of a TabChild so that we can begin forwarding
// this data to the parent. In the HTTP case, this is unfortunate, since
// we're actually passing data from parent->child->parent wastefully, but
// the Right Fix will eventually be to short-circuit those channels on the
// parent side based on some sort of subscription concept.
nsCOMPtr<nsIDocShell> docshell(do_GetInterface(aWindowContext));
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(docshell);
nsCOMPtr<nsIDocShellTreeOwner> owner;
item->GetTreeOwner(getter_AddRefs(owner));
NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE);
nsCOMPtr<nsITabChild> tabchild = do_GetInterface(owner);
if (!tabchild)
return NS_ERROR_FAILURE;
// Now we build a protocol for forwarding our data to the parent. The
// protocol will act as a listener on the child-side and create a "real"
// helperAppService listener on the parent-side, via another call to
// DoContent.
using mozilla::dom::TabChild;
using mozilla::dom::ExternalHelperAppChild;
TabChild *child = static_cast<TabChild*>(tabchild.get());
mozilla::dom::PExternalHelperAppChild *pc;
pc = child->SendPExternalHelperAppConstructor(IPC::URI(uri),
nsCString(aMimeContentType),
aForceSave, contentLength);
ExternalHelperAppChild *childListener = static_cast<ExternalHelperAppChild *>(pc);
NS_ADDREF(*aStreamListener = childListener);
// FIXME: Eventually we'll use this original listener to finish up client-side
// work, such as closing a no-longer-needed window. (Bug 588255)
// nsExternalAppHandler * handler = new nsExternalAppHandler(nsnull,
// EmptyCString(),
// aWindowContext,
// fileName,
// reason,
// aForceSave);
// if (!handler)
// return NS_ERROR_OUT_OF_MEMORY;
//
// childListener->SetHandler(handler);
return NS_OK;
}
#endif // MOZ_IPC
if (channel) {
// Check if we have a POST request, in which case we don't want to use
// the url's extension
@ -640,9 +725,6 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeConte
allowURLExt = !requestMethod.Equals("POST");
}
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
// Check if we had a query string - we don't want to check the URL
// extension if a query is present in the URI
// If we already know we don't want to check the URL extension, don't
@ -1282,7 +1364,6 @@ void nsExternalAppHandler::RetargetLoadNotifications(nsIRequest *request)
aChannel->SetLoadGroup(nsnull);
aChannel->SetNotificationCallbacks(nsnull);
}
/**
@ -1458,18 +1539,9 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
mIsFileChannel = fileChan != nsnull;
// Get content length
nsCOMPtr<nsIPropertyBag2> props(do_QueryInterface(request, &rv));
if (props) {
rv = props->GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH,
&mContentLength.mValue);
}
// If that failed, ask the channel
if (NS_FAILED(rv) && aChannel) {
PRInt32 len;
aChannel->GetContentLength(&len);
mContentLength = len;
}
mContentLength.mValue = GetContentLengthAsInt64(request);
nsCOMPtr<nsIPropertyBag2> props(do_QueryInterface(request, &rv));
// Determine whether a new window was opened specifically for this request
if (props) {
PRBool tmp = PR_FALSE;