2009-06-30 11:51:05 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: sw=4 ts=4 et :
|
|
|
|
* ***** 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 Plugin App.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Chris Jones <jones.chris.g@gmail.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* 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 ***** */
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
#include "mozilla/plugins/NPAPIPluginParent.h"
|
2009-08-18 13:20:03 -07:00
|
|
|
#include "mozilla/plugins/NPBrowserStreamParent.h"
|
2009-07-02 09:54:22 -07:00
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
using mozilla::SharedLibrary;
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace plugins {
|
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
// HACKS
|
|
|
|
NPAPIPluginParent* NPAPIPluginParent::Shim::HACK_target;
|
2009-06-30 11:51:05 -07:00
|
|
|
|
|
|
|
SharedLibrary*
|
2009-07-02 09:54:22 -07:00
|
|
|
NPAPIPluginParent::LoadModule(const char* aFilePath, PRLibrary* aLibrary)
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
|
|
|
_MOZ_LOG(__FUNCTION__);
|
|
|
|
|
|
|
|
// Block on the child process being launched and initialized.
|
2009-07-02 09:54:22 -07:00
|
|
|
NPAPIPluginParent* parent = new NPAPIPluginParent(aFilePath);
|
2009-07-20 11:14:41 -07:00
|
|
|
parent->mSubprocess.Launch();
|
2009-07-02 09:54:22 -07:00
|
|
|
parent->Open(parent->mSubprocess.GetChannel());
|
2009-06-30 11:51:05 -07:00
|
|
|
|
|
|
|
// FIXME/cjones: leaking NPAPIPluginParents ...
|
|
|
|
return parent->mShim;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
NPAPIPluginParent::NPAPIPluginParent(const char* aFilePath) :
|
|
|
|
mFilePath(aFilePath),
|
|
|
|
mSubprocess(aFilePath),
|
|
|
|
ALLOW_THIS_IN_INITIALIZER_LIST(mShim(new Shim(this)))
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NPAPIPluginParent::~NPAPIPluginParent()
|
|
|
|
{
|
|
|
|
_MOZ_LOG(" (closing Shim ...)");
|
|
|
|
delete mShim;
|
|
|
|
}
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
NPPProtocolParent*
|
2009-07-29 14:12:15 -07:00
|
|
|
NPAPIPluginParent::NPPConstructor(const nsCString& aMimeType,
|
2009-07-02 09:54:22 -07:00
|
|
|
const uint16_t& aMode,
|
2009-07-29 14:12:15 -07:00
|
|
|
const nsTArray<nsCString>& aNames,
|
|
|
|
const nsTArray<nsCString>& aValues,
|
2009-07-02 09:54:22 -07:00
|
|
|
NPError* rv)
|
|
|
|
{
|
2009-08-18 13:20:03 -07:00
|
|
|
NS_ERROR("Not reachable!");
|
|
|
|
return NULL;
|
2009-07-02 09:54:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NPAPIPluginParent::NPPDestructor(NPPProtocolParent* __a,
|
|
|
|
NPError* rv)
|
|
|
|
{
|
2009-07-01 14:19:32 -07:00
|
|
|
_MOZ_LOG(__FUNCTION__);
|
|
|
|
delete __a;
|
2009-07-02 13:48:33 -07:00
|
|
|
return NS_OK;
|
2009-07-02 09:54:22 -07:00
|
|
|
}
|
|
|
|
|
2009-06-30 11:51:05 -07:00
|
|
|
void
|
2009-07-02 09:54:22 -07:00
|
|
|
NPAPIPluginParent::SetPluginFuncs(NPPluginFuncs* aFuncs)
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2009-07-02 09:54:22 -07:00
|
|
|
aFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
|
|
|
|
aFuncs->javaClass = nsnull;
|
|
|
|
|
|
|
|
// FIXME/cjones: /should/ dynamically allocate shim trampoline.
|
|
|
|
// but here we just HACK
|
|
|
|
aFuncs->newp = Shim::NPP_New;
|
|
|
|
aFuncs->destroy = Shim::NPP_Destroy;
|
|
|
|
aFuncs->setwindow = Shim::NPP_SetWindow;
|
|
|
|
aFuncs->newstream = Shim::NPP_NewStream;
|
2009-08-18 13:20:03 -07:00
|
|
|
aFuncs->destroystream = NPAPIPluginParent::NPP_DestroyStream;
|
|
|
|
aFuncs->asfile = NPAPIPluginParent::NPP_StreamAsFile;
|
|
|
|
aFuncs->writeready = NPAPIPluginParent::NPP_WriteReady;
|
|
|
|
aFuncs->write = NPAPIPluginParent::NPP_Write;
|
2009-07-02 09:54:22 -07:00
|
|
|
aFuncs->print = Shim::NPP_Print;
|
|
|
|
aFuncs->event = Shim::NPP_HandleEvent;
|
|
|
|
aFuncs->urlnotify = Shim::NPP_URLNotify;
|
|
|
|
aFuncs->getvalue = Shim::NPP_GetValue;
|
|
|
|
aFuncs->setvalue = Shim::NPP_SetValue;
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
#ifdef OS_LINUX
|
2009-06-30 11:51:05 -07:00
|
|
|
NPError
|
|
|
|
NPAPIPluginParent::NP_Initialize(const NPNetscapeFuncs* npnIface,
|
|
|
|
NPPluginFuncs* nppIface)
|
|
|
|
{
|
|
|
|
_MOZ_LOG(__FUNCTION__);
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
NPError prv;
|
|
|
|
nsresult rv = CallNP_Initialize(&prv);
|
|
|
|
if (NS_OK != rv)
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
else if (NPERR_NO_ERROR != prv)
|
|
|
|
return prv;
|
|
|
|
|
|
|
|
SetPluginFuncs(nppIface);
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
NPError
|
|
|
|
NPAPIPluginParent::NP_Initialize(const NPNetscapeFuncs* npnIface)
|
|
|
|
{
|
|
|
|
_MOZ_LOG(__FUNCTION__);
|
|
|
|
|
|
|
|
NPError prv;
|
|
|
|
nsresult rv = CallNP_Initialize(&prv);
|
2009-07-02 13:48:33 -07:00
|
|
|
if (NS_FAILED(rv))
|
2009-06-30 11:51:05 -07:00
|
|
|
return rv;
|
2009-07-02 13:48:33 -07:00
|
|
|
return prv;
|
2009-07-02 09:54:22 -07:00
|
|
|
}
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
NPError
|
|
|
|
NPAPIPluginParent::NP_GetEntryPoints(NPPluginFuncs* nppIface)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(nppIface, "Null pointer!");
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
SetPluginFuncs(nppIface);
|
2009-06-30 11:51:05 -07:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2009-07-02 09:54:22 -07:00
|
|
|
#endif
|
2009-06-30 11:51:05 -07:00
|
|
|
|
|
|
|
NPError
|
2009-07-29 14:12:15 -07:00
|
|
|
NPAPIPluginParent::NPP_New(NPMIMEType pluginType,
|
|
|
|
NPP instance,
|
|
|
|
uint16_t mode,
|
|
|
|
int16_t argc,
|
|
|
|
char* argn[],
|
|
|
|
char* argv[],
|
2009-06-30 11:51:05 -07:00
|
|
|
NPSavedData* saved)
|
|
|
|
{
|
|
|
|
_MOZ_LOG(__FUNCTION__);
|
|
|
|
|
|
|
|
// create the instance on the other side
|
2009-07-29 14:12:15 -07:00
|
|
|
nsTArray<nsCString> names;
|
|
|
|
nsTArray<nsCString> values;
|
2009-06-30 11:51:05 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
2009-07-29 14:12:15 -07:00
|
|
|
names.AppendElement(nsDependentCString(argn[i]));
|
|
|
|
values.AppendElement(nsDependentCString(argv[i]));
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
2009-08-07 16:13:20 -07:00
|
|
|
NPError prv = NPERR_GENERIC_ERROR;
|
2009-07-01 14:19:32 -07:00
|
|
|
nsAutoPtr<NPPInstanceParent> parentInstance(
|
2009-07-29 14:12:15 -07:00
|
|
|
static_cast<NPPInstanceParent*>(
|
2009-08-18 13:20:03 -07:00
|
|
|
CallNPPConstructor(new NPPInstanceParent(instance, mNPNIface),
|
|
|
|
nsDependentCString(pluginType), mode, names,
|
2009-07-29 14:12:15 -07:00
|
|
|
values, &prv)));
|
2009-06-30 11:51:05 -07:00
|
|
|
printf ("[NPAPIPluginParent] %s: got return value %hd\n", __FUNCTION__,
|
2009-07-02 09:54:22 -07:00
|
|
|
prv);
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
if (NPERR_NO_ERROR != prv)
|
|
|
|
return prv;
|
|
|
|
NS_ASSERTION(parentInstance,
|
|
|
|
"if there's no parentInstance, there should be an error");
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-07-01 14:19:32 -07:00
|
|
|
instance->pdata = (void*) parentInstance.forget();
|
|
|
|
return prv;
|
|
|
|
}
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-07-01 14:19:32 -07:00
|
|
|
NPError
|
|
|
|
NPAPIPluginParent::NPP_Destroy(NPP instance,
|
|
|
|
NPSavedData** save)
|
|
|
|
{
|
|
|
|
// FIXME/cjones:
|
|
|
|
// (1) send a "destroy" message to the child
|
|
|
|
// (2) the child shuts down its instance
|
|
|
|
// (3) remove both parent and child IDs from map
|
|
|
|
// (4) free parent
|
|
|
|
|
|
|
|
_MOZ_LOG(__FUNCTION__);
|
|
|
|
|
|
|
|
NPPInstanceParent* parentInstance =
|
|
|
|
static_cast<NPPInstanceParent*>(instance->pdata);
|
|
|
|
|
|
|
|
NPError prv;
|
|
|
|
if (CallNPPDestructor(parentInstance, &prv)) {
|
|
|
|
prv = NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
instance->pdata = nsnull;
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
return prv;
|
2009-07-01 14:19:32 -07:00
|
|
|
}
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
nsresult
|
|
|
|
NPAPIPluginParent::RecvNPN_GetStringIdentifier(const nsCString& aString,
|
|
|
|
NPRemoteIdentifier* aId)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NPAPIPluginParent::RecvNPN_GetIntIdentifier(const int32_t& aInt,
|
|
|
|
NPRemoteIdentifier* aId)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NPAPIPluginParent::RecvNPN_UTF8FromIdentifier(const NPRemoteIdentifier& aId,
|
|
|
|
nsCString* aString)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
nsresult
|
|
|
|
NPAPIPluginParent::RecvNPN_IntFromIdentifier(const NPRemoteIdentifier& aId,
|
|
|
|
int32_t* aInt)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
nsresult
|
|
|
|
NPAPIPluginParent::RecvNPN_IdentifierIsString(const NPRemoteIdentifier& aId,
|
|
|
|
bool* aIsString)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
nsresult
|
|
|
|
NPAPIPluginParent::RecvNPN_GetStringIdentifiers(nsTArray<nsCString>* aNames,
|
|
|
|
nsTArray<NPRemoteIdentifier>* aIds)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2009-08-18 13:20:03 -07:00
|
|
|
|
|
|
|
NPPInstanceParent*
|
|
|
|
NPAPIPluginParent::InstCast(NPP instance)
|
|
|
|
{
|
|
|
|
NPPInstanceParent* ip =
|
|
|
|
static_cast<NPPInstanceParent*>(instance->pdata);
|
|
|
|
if (instance != ip->mNPP)
|
|
|
|
NS_RUNTIMEABORT("Corrupted plugin data.");
|
|
|
|
return ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPBrowserStreamParent*
|
|
|
|
NPAPIPluginParent::StreamCast(NPP instance, NPStream* s)
|
|
|
|
{
|
|
|
|
NPPInstanceParent* ip = InstCast(instance);
|
|
|
|
NPBrowserStreamParent* sp =
|
|
|
|
static_cast<NPBrowserStreamParent*>(s->pdata);
|
|
|
|
if (sp->mNPP != ip || s != sp->mStream)
|
|
|
|
NS_RUNTIMEABORT("Corrupted plugin stream data.");
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPError
|
|
|
|
NPAPIPluginParent::NPP_DestroyStream(NPP instance,
|
|
|
|
NPStream* stream, NPReason reason)
|
|
|
|
{
|
|
|
|
return InstCast(instance)->NPP_DestroyStream(stream, reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
NPAPIPluginParent::NPP_WriteReady(NPP instance, NPStream* stream)
|
|
|
|
{
|
|
|
|
return StreamCast(instance, stream)->WriteReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
NPAPIPluginParent::NPP_Write(NPP instance, NPStream* stream,
|
|
|
|
int32_t offset, int32_t len, void* buffer)
|
|
|
|
{
|
|
|
|
return StreamCast(instance, stream)->Write(offset, len, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NPAPIPluginParent::NPP_StreamAsFile(NPP instance,
|
|
|
|
NPStream* stream, const char* fname)
|
|
|
|
{
|
|
|
|
StreamCast(instance, stream)->StreamAsFile(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace plugins
|
|
|
|
} // namespace mozilla
|