fix more bustage related to nsresult-to-bool switch. committing initial (untested!) NPEvent forwarding caught in the crossfire

This commit is contained in:
Chris Jones 2009-09-18 20:19:11 -05:00
parent 90a2666dff
commit fcd45719e6
11 changed files with 336 additions and 20 deletions

View File

@ -58,19 +58,22 @@ ifdef MOZ_IPC
EXPORTS_NAMESPACES = mozilla mozilla/plugins
EXPORTS_mozilla/plugins = \
PluginModuleChild.h \
PluginModuleParent.h \
PluginScriptableObjectChild.h \
PluginScriptableObjectParent.h \
PluginInstanceChild.h \
PluginInstanceParent.h \
BrowserStreamChild.h \
BrowserStreamParent.h \
NPEventOSX.h \
NPEventWindows.h \
NPEventX11.h \
PluginInstanceChild.h \
PluginInstanceParent.h \
PluginMessageUtils.h \
PluginModuleChild.h \
PluginModuleParent.h \
PluginProcessParent.h \
PluginScriptableObjectChild.h \
PluginScriptableObjectParent.h \
PluginThreadChild.h \
StreamNotifyParent.h \
StreamNotifyChild.h \
StreamNotifyParent.h \
$(NULL)
MODULE = dom

67
dom/plugins/NPEventOSX.h Normal file
View File

@ -0,0 +1,67 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* ***** 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
* The Mozilla Foundation.
* 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 ***** */
#ifndef mozilla_dom_plugins_NPEventOSX_h
#define mozilla_dom_plugins_NPEventOSX_h 1
#include "npapi.h"
#warning This is only a stub implementation IMPLEMENT ME
template <>
struct ParamTraits<NPEvent>
{
typedef NPEvent paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
return true;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
}
};
#endif // ifndef mozilla_dom_plugins_NPEventOSX_h

View File

@ -0,0 +1,67 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* ***** 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
* The Mozilla Foundation.
* 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 ***** */
#ifndef mozilla_dom_plugins_NPEventWindows_h
#define mozilla_dom_plugins_NPEventWindows_h 1
#include "npapi.h"
#warning This is only a stub implementation IMPLEMENT ME
template <>
struct ParamTraits<NPEvent>
{
typedef NPEvent paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
return true;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
}
};
#endif // ifndef mozilla_dom_plugins_NPEventWindows_h

134
dom/plugins/NPEventX11.h Normal file
View File

@ -0,0 +1,134 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* ***** 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
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* 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 ***** */
#ifndef mozilla_dom_plugins_NPEventX11_h
#define mozilla_dom_plugins_NPEventX11_h 1
#if defined(MOZ_WIDGET_GTK2)
# include <gdk/gdkx.h>
#else
# error Implement me for your toolkit
#endif
#include "npapi.h"
//
// XEvent is defined as a union of all more specific X*Events.
// Luckily, as of xorg 1.6.0 / X protocol 11 rev 0, the only pointer
// field contained in any of these specific X*Event structs is a
// |Display*|. So to simplify serializing these XEvents, we make the
//
// ********** XXX ASSUMPTION XXX **********
//
// that the process to which the event is forwarded shares the same
// display as the process on which the event originated.
//
// With this simplification, serialization becomes a simple memcpy to
// the output stream. Deserialization starts as just a memcpy from
// the input stream, BUT we then have to write the correct |Display*|
// into the right field of each X*Event that contains one.
//
namespace IPC {
template <>
struct ParamTraits<NPEvent> // synonym for XEvent
{
typedef NPEvent paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
aMsg->WriteBytes(&aParam, sizeof(paramType));
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
const char* bytes = 0;
if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) {
return false;
}
memcpy(aResult, bytes, sizeof(paramType));
SetXDisplay(*aResult);
return true;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
// TODO
aLog->append(L"(XEvent)");
}
private:
static Display* GetXDisplay(const XAnyEvent& ev)
{
// TODO: get Display* from Window in |ev|
// FIXME: do this using Xlib, don't use Gdk
return GDK_DISPLAY();
}
static Display* GetXDisplay(const XErrorEvent& ev)
{
// TODO: get Display* from Window in |ev|
// FIXME: do this using Xlib, don't use Gdk
return GDK_DISPLAY();
}
static void SetXDisplay(XEvent& ev)
{
if (ev.type >= KeyPress) {
ev.xany.display = GetXDisplay(ev.xany);
}
else {
// XXX assuming that this is an error event
// (type == 0? not clear from Xlib.h)
ev.xerror.display = GetXDisplay(ev.xerror);
}
}
};
} // namespace IPC
#endif // ifndef mozilla_dom_plugins_NPEventX11_h

View File

@ -45,6 +45,7 @@ include protocol "PStreamNotify.ipdl";
include "mozilla/plugins/PluginMessageUtils.h";
using NPError;
using NPEvent;
using NPWindow;
using NPReason;
@ -77,6 +78,9 @@ child:
rpc NPP_GetValue_NPPVpluginScriptableNPObject()
returns (PPluginScriptableObject value, NPError result);
rpc NPP_HandleEvent(NPEvent event)
returns (int16_t handled);
parent:
rpc NPN_GetValue_NPNVjavascriptEnabledBool()
returns (bool value, NPError result);

View File

@ -183,6 +183,16 @@ PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginScriptableNPObject(
return true;
}
bool
PluginInstanceChild::AnswerNPP_HandleEvent(const NPEvent& event,
int16_t* handled)
{
// plugins might be fooling with these, make a copy
NPEvent evcopy = event;
*handled = mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy));
return true;
}
bool
PluginInstanceChild::AnswerNPP_SetWindow(const NPWindow& aWindow,
NPError* rv)

View File

@ -73,6 +73,9 @@ protected:
AnswerNPP_GetValue_NPPVpluginScriptableNPObject(PPluginScriptableObjectChild** value,
NPError* result);
virtual bool
AnswerNPP_HandleEvent(const NPEvent& event, int16_t* handled);
virtual PPluginScriptableObjectChild*
PPluginScriptableObjectConstructor();

View File

@ -190,8 +190,7 @@ PluginInstanceParent::NPP_SetWindow(NPWindow* aWindow)
NS_ENSURE_TRUE(aWindow, NPERR_GENERIC_ERROR);
NPError prv;
nsresult rv = CallNPP_SetWindow(*aWindow, &prv);
if (NS_OK != rv)
if (!CallNPP_SetWindow(*aWindow, &prv))
return NPERR_GENERIC_ERROR;
return prv;
}
@ -224,6 +223,20 @@ PluginInstanceParent::NPP_GetValue(NPPVariable variable, void *ret_value)
return NPERR_GENERIC_ERROR;
}
int16_t
PluginInstanceParent::NPP_HandleEvent(void* event)
{
_MOZ_LOG(__FUNCTION__);
int16_t handled;
if (!CallNPP_HandleEvent(*reinterpret_cast<NPEvent*>(event),
&handled)) {
return 0; // no good way to handle errors here...
}
return handled;
}
NPError
PluginInstanceParent::NPP_NewStream(NPMIMEType type, NPStream* stream,
NPBool seekable, uint16_t* stype)

View File

@ -149,11 +149,7 @@ public:
_MOZ_LOG(__FUNCTION__);
}
int16_t NPP_HandleEvent(void* event)
{
_MOZ_LOG(__FUNCTION__);
return 0;
}
int16_t NPP_HandleEvent(void* event);
void NPP_URLNotify(const char* url, NPReason reason, void* notifyData)
{

View File

@ -425,6 +425,27 @@ struct ParamTraits<mozilla::plugins::IPCByteRange>
}
};
} /* namespace IPC */
// Serializing NPEvents is completely platform-specific and can be rather
// intricate depending on the platform. So for readability we split it
// into separate files and have the only macro crud live here.
//
// NB: these guards are based on those where struct NPEvent is defined
// in npapi.h. They should be kept in sync.
#if defined(XP_MACOSX)
# include "mozilla/plugins/NPEventOSX.h"
#elif defined(XP_WIN)
# include "mozilla/plugins/NPEventWindows.h"
#elif defined(XP_OS2)
# error Sorry, OS/2 is not supported
#elif defined(XP_UNIX) && defined(MOZ_X11)
# include "mozilla/plugins/NPEventX11.h"
#else
# error Unsupported platform
#endif
#endif /* DOM_PLUGINS_PLUGINMESSAGEUTILS_H */

View File

@ -136,8 +136,7 @@ PluginModuleParent::NP_Initialize(const NPNetscapeFuncs* npnIface,
_MOZ_LOG(__FUNCTION__);
NPError prv;
nsresult rv = CallNP_Initialize(&prv);
if (NS_OK != rv)
if (!CallNP_Initialize(&prv))
return NPERR_GENERIC_ERROR;
else if (NPERR_NO_ERROR != prv)
return prv;
@ -152,9 +151,8 @@ PluginModuleParent::NP_Initialize(const NPNetscapeFuncs* npnIface)
_MOZ_LOG(__FUNCTION__);
NPError prv;
nsresult rv = CallNP_Initialize(&prv);
if (NS_FAILED(rv))
return rv;
if (!CallNP_Initialize(&prv))
return NP_ERR_GENERIC_ERROR;
return prv;
}
@ -223,7 +221,7 @@ PluginModuleParent::NPP_Destroy(NPP instance,
static_cast<PluginInstanceParent*>(instance->pdata);
NPError prv;
if (Shim::HACK_target->CallPPluginInstanceDestructor(parentInstance, &prv)) {
if (!Shim::HACK_target->CallPPluginInstanceDestructor(parentInstance, &prv)) {
prv = NPERR_GENERIC_ERROR;
}
instance->pdata = nsnull;