Bug 672857 - Make IM work for IPC plugins in remote browser. r=karlt

This commit is contained in:
Oleg Romashin
2011-08-29 17:26:24 +01:00
parent bb4e4d681b
commit a64450a13a
16 changed files with 224 additions and 0 deletions

View File

@@ -246,6 +246,17 @@ PluginPRLibrary::AsyncSetWindow(NPP instance, NPWindow* window)
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
nsresult
PluginPRLibrary::HandleGUIEvent(NPP instance, const nsGUIEvent& anEvent,
bool* handled)
{
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif
nsresult nsresult
PluginPRLibrary::GetImage(NPP instance, ImageContainer* aContainer, Image** aImage) PluginPRLibrary::GetImage(NPP instance, ImageContainer* aContainer, Image** aImage)
{ {

View File

@@ -154,6 +154,10 @@ public:
NS_OVERRIDE NS_OVERRIDE
virtual nsresult EndUpdateBackground(NPP instance, virtual nsresult EndUpdateBackground(NPP instance,
gfxContext* aCtx, const nsIntRect&); gfxContext* aCtx, const nsIntRect&);
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
virtual nsresult HandleGUIEvent(NPP instance,
const nsGUIEvent& anEvent, bool* handled);
#endif
private: private:
NP_InitializeFunc mNP_Initialize; NP_InitializeFunc mNP_Initialize;

View File

@@ -842,6 +842,23 @@ nsNPAPIPluginInstance::AsyncSetWindow(NPWindow* window)
return library->AsyncSetWindow(&mNPP, window); return library->AsyncSetWindow(&mNPP, window);
} }
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
nsresult
nsNPAPIPluginInstance::HandleGUIEvent(const nsGUIEvent& anEvent, bool* handled)
{
if (RUNNING != mRunning) {
*handled = false;
return NS_OK;
}
AutoPluginLibraryCall library(this);
if (!library)
return NS_ERROR_FAILURE;
return library->HandleGUIEvent(&mNPP, anEvent, handled);
}
#endif
nsresult nsresult
nsNPAPIPluginInstance::GetImage(ImageContainer* aContainer, Image** aImage) nsNPAPIPluginInstance::GetImage(ImageContainer* aContainer, Image** aImage)
{ {

View File

@@ -114,6 +114,9 @@ public:
nsresult SetOwner(nsIPluginInstanceOwner *aOwner); nsresult SetOwner(nsIPluginInstanceOwner *aOwner);
nsresult ShowStatus(const char* message); nsresult ShowStatus(const char* message);
nsresult InvalidateOwner(); nsresult InvalidateOwner();
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
nsresult HandleGUIEvent(const nsGUIEvent& anEvent, bool* handled);
#endif
nsNPAPIPlugin* GetPlugin(); nsNPAPIPlugin* GetPlugin();

View File

@@ -1688,6 +1688,29 @@ nsresult nsPluginInstanceOwner::DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent)
return NS_OK; return NS_OK;
} }
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
nsresult nsPluginInstanceOwner::Text(nsIDOMEvent* aTextEvent)
{
if (mInstance) {
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aTextEvent));
if (privateEvent) {
nsEvent *event = privateEvent->GetInternalNSEvent();
if (event && event->eventStructType == NS_TEXT_EVENT) {
nsEventStatus rv = ProcessEvent(*static_cast<nsGUIEvent*>(event));
if (nsEventStatus_eConsumeNoDefault == rv) {
aTextEvent->PreventDefault();
aTextEvent->StopPropagation();
}
}
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchTextToPlugin failed, textEvent null");
}
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchTextToPlugin failed, privateEvent null");
}
return NS_OK;
}
#endif
nsresult nsPluginInstanceOwner::KeyPress(nsIDOMEvent* aKeyEvent) nsresult nsPluginInstanceOwner::KeyPress(nsIDOMEvent* aKeyEvent)
{ {
#ifdef XP_MACOSX #ifdef XP_MACOSX
@@ -1871,6 +1894,11 @@ nsPluginInstanceOwner::HandleEvent(nsIDOMEvent* aEvent)
if (eventType.EqualsLiteral("keypress")) { if (eventType.EqualsLiteral("keypress")) {
return KeyPress(aEvent); return KeyPress(aEvent);
} }
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
if (eventType.EqualsLiteral("text")) {
return Text(aEvent);
}
#endif
nsCOMPtr<nsIDOMDragEvent> dragEvent(do_QueryInterface(aEvent)); nsCOMPtr<nsIDOMDragEvent> dragEvent(do_QueryInterface(aEvent));
if (dragEvent && mInstance) { if (dragEvent && mInstance) {
@@ -2368,10 +2396,29 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const nsGUIEvent& anEvent)
// DOMKeyCodeToGdkKeyCode(keyEvent.keyCode) and // DOMKeyCodeToGdkKeyCode(keyEvent.keyCode) and
// gdk_keymap_get_entries_for_keyval will be useful, but the // gdk_keymap_get_entries_for_keyval will be useful, but the
// mappings will not be unique. // mappings will not be unique.
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
bool handled;
if (NS_SUCCEEDED(mInstance->HandleGUIEvent(anEvent, &handled)) &&
handled) {
rv = nsEventStatus_eConsumeNoDefault;
}
#else
NS_WARNING("Synthesized key event not sent to plugin"); NS_WARNING("Synthesized key event not sent to plugin");
#endif
} }
break; break;
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
case NS_TEXT_EVENT:
{
bool handled;
if (NS_SUCCEEDED(mInstance->HandleGUIEvent(anEvent, &handled)) &&
handled) {
rv = nsEventStatus_eConsumeNoDefault;
}
}
break;
#endif
default: default:
switch (anEvent.message) switch (anEvent.message)
{ {
@@ -2452,6 +2499,9 @@ nsPluginInstanceOwner::Destroy()
mContent->RemoveEventListener(NS_LITERAL_STRING("dragstart"), this, PR_TRUE); mContent->RemoveEventListener(NS_LITERAL_STRING("dragstart"), this, PR_TRUE);
mContent->RemoveEventListener(NS_LITERAL_STRING("draggesture"), this, PR_TRUE); mContent->RemoveEventListener(NS_LITERAL_STRING("draggesture"), this, PR_TRUE);
mContent->RemoveEventListener(NS_LITERAL_STRING("dragend"), this, PR_TRUE); mContent->RemoveEventListener(NS_LITERAL_STRING("dragend"), this, PR_TRUE);
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
mContent->RemoveEventListener(NS_LITERAL_STRING("text"), this, PR_TRUE);
#endif
if (mWidget) { if (mWidget) {
nsCOMPtr<nsIPluginWidget> pluginWidget = do_QueryInterface(mWidget); nsCOMPtr<nsIPluginWidget> pluginWidget = do_QueryInterface(mWidget);
@@ -2912,6 +2962,9 @@ nsresult nsPluginInstanceOwner::Init(nsPresContext* aPresContext,
mContent->AddEventListener(NS_LITERAL_STRING("dragstart"), this, PR_TRUE); mContent->AddEventListener(NS_LITERAL_STRING("dragstart"), this, PR_TRUE);
mContent->AddEventListener(NS_LITERAL_STRING("draggesture"), this, PR_TRUE); mContent->AddEventListener(NS_LITERAL_STRING("draggesture"), this, PR_TRUE);
mContent->AddEventListener(NS_LITERAL_STRING("dragend"), this, PR_TRUE); mContent->AddEventListener(NS_LITERAL_STRING("dragend"), this, PR_TRUE);
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
mContent->AddEventListener(NS_LITERAL_STRING("text"), this, PR_TRUE);
#endif
// Register scroll position listeners // Register scroll position listeners
// We need to register a scroll position listener on every scrollable // We need to register a scroll position listener on every scrollable

View File

@@ -130,6 +130,9 @@ public:
nsresult MouseDown(nsIDOMEvent* aKeyEvent); nsresult MouseDown(nsIDOMEvent* aKeyEvent);
nsresult KeyPress(nsIDOMEvent* aKeyEvent); nsresult KeyPress(nsIDOMEvent* aKeyEvent);
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
nsresult Text(nsIDOMEvent* aTextEvent);
#endif
nsresult Destroy(); nsresult Destroy();

View File

@@ -46,6 +46,7 @@ include protocol PStreamNotify;
include protocol PPluginSurface; include protocol PPluginSurface;
include "mozilla/plugins/PluginMessageUtils.h"; include "mozilla/plugins/PluginMessageUtils.h";
include "IPC/nsGUIEventIPC.h";
using NPError; using NPError;
using NPRemoteWindow; using NPRemoteWindow;
@@ -59,6 +60,8 @@ using gfxIntSize;
using mozilla::null_t; using mozilla::null_t;
using mozilla::plugins::WindowsSharedMemoryHandle; using mozilla::plugins::WindowsSharedMemoryHandle;
using nsIntRect; using nsIntRect;
using nsTextEvent;
using nsKeyEvent;
namespace mozilla { namespace mozilla {
namespace plugins { namespace plugins {
@@ -147,6 +150,11 @@ child:
// refer to the existing background or a fresh descriptor. // refer to the existing background or a fresh descriptor.
async UpdateBackground(SurfaceDescriptor background, nsIntRect rect); async UpdateBackground(SurfaceDescriptor background, nsIntRect rect);
rpc HandleTextEvent(nsTextEvent event)
returns (bool handled);
rpc HandleKeyEvent(nsKeyEvent event)
returns (bool handled);
rpc NPP_Destroy() rpc NPP_Destroy()
returns (NPError rv); returns (NPError rv);

View File

@@ -37,6 +37,14 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
#include <QEvent>
#include <QKeyEvent>
#include <QApplication>
#include <QInputMethodEvent>
#include "nsQtKeyUtils.h"
#endif
#include "PluginBackgroundDestroyer.h" #include "PluginBackgroundDestroyer.h"
#include "PluginInstanceChild.h" #include "PluginInstanceChild.h"
#include "PluginModuleChild.h" #include "PluginModuleChild.h"
@@ -74,6 +82,8 @@ using namespace mozilla::plugins;
#elif defined(MOZ_WIDGET_QT) #elif defined(MOZ_WIDGET_QT)
#include <QX11Info> #include <QX11Info>
#undef KeyPress
#undef KeyRelease
#elif defined(OS_WIN) #elif defined(OS_WIN)
#ifndef WM_MOUSEHWHEEL #ifndef WM_MOUSEHWHEEL
#define WM_MOUSEHWHEEL 0x020E #define WM_MOUSEHWHEEL 0x020E
@@ -2317,6 +2327,57 @@ PluginInstanceChild::RecvAsyncSetWindow(const gfxSurfaceType& aSurfaceType,
return true; return true;
} }
bool
PluginInstanceChild::AnswerHandleKeyEvent(const nsKeyEvent& aKeyEvent,
bool* handled)
{
AssertPluginThread();
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
Qt::KeyboardModifiers modifier;
if (aKeyEvent.isShift)
modifier |= Qt::ShiftModifier;
if (aKeyEvent.isControl)
modifier |= Qt::ControlModifier;
if (aKeyEvent.isAlt)
modifier |= Qt::AltModifier;
if (aKeyEvent.isMeta)
modifier |= Qt::MetaModifier;
QEvent::Type type;
if (aKeyEvent.message == NS_KEY_DOWN) {
type = QEvent::KeyPress;
} else if (aKeyEvent.message == NS_KEY_UP) {
type = QEvent::KeyRelease;
} else {
*handled = false;
return true;
}
QKeyEvent keyEv(type, DOMKeyCodeToQtKeyCode(aKeyEvent.keyCode), modifier);
*handled = QApplication::sendEvent(qApp, &keyEv);
#else
NS_ERROR("Not implemented");
#endif
return true;
}
bool
PluginInstanceChild::AnswerHandleTextEvent(const nsTextEvent& aEvent,
bool* handled)
{
AssertPluginThread();
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
QInputMethodEvent event;
event.setCommitString(QString((const QChar*)aEvent.theText.get(),
aEvent.theText.Length()));
*handled = QApplication::sendEvent(qApp, &event);
#else
NS_ERROR("Not implemented");
#endif
return true;
}
void void
PluginInstanceChild::DoAsyncSetWindow(const gfxSurfaceType& aSurfaceType, PluginInstanceChild::DoAsyncSetWindow(const gfxSurfaceType& aSurfaceType,
const NPRemoteWindow& aWindow, const NPRemoteWindow& aWindow,

View File

@@ -120,6 +120,11 @@ protected:
const NPRemoteWindow& aWindow, const NPRemoteWindow& aWindow,
bool aIsAsync); bool aIsAsync);
virtual bool
AnswerHandleKeyEvent(const nsKeyEvent& aEvent, bool* handled);
virtual bool
AnswerHandleTextEvent(const nsTextEvent& aEvent, bool* handled);
virtual PPluginSurfaceChild* AllocPPluginSurface(const WindowsSharedMemoryHandle&, virtual PPluginSurfaceChild* AllocPPluginSurface(const WindowsSharedMemoryHandle&,
const gfxIntSize&, const bool&) { const gfxIntSize&, const bool&) {
return new PPluginSurfaceChild(); return new PPluginSurfaceChild();

View File

@@ -618,6 +618,31 @@ PluginInstanceParent::AsyncSetWindow(NPWindow* aWindow)
return NS_OK; return NS_OK;
} }
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
nsresult
PluginInstanceParent::HandleGUIEvent(const nsGUIEvent& anEvent, bool* handled)
{
switch (anEvent.eventStructType) {
case NS_KEY_EVENT:
if (!CallHandleKeyEvent(static_cast<const nsKeyEvent&>(anEvent),
handled)) {
return NS_ERROR_FAILURE;
}
break;
case NS_TEXT_EVENT:
if (!CallHandleTextEvent(static_cast<const nsTextEvent&>(anEvent),
handled)) {
return NS_ERROR_FAILURE;
}
break;
default:
NS_ERROR("Not implemented for this event type");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
#endif
nsresult nsresult
PluginInstanceParent::GetImage(ImageContainer* aContainer, Image** aImage) PluginInstanceParent::GetImage(ImageContainer* aContainer, Image** aImage)
{ {

View File

@@ -57,6 +57,7 @@
#ifdef MOZ_X11 #ifdef MOZ_X11
class gfxXlibSurface; class gfxXlibSurface;
#endif #endif
#include "nsGUIEvent.h"
namespace mozilla { namespace mozilla {
namespace plugins { namespace plugins {
@@ -290,6 +291,9 @@ public:
gfxContext** aCtx); gfxContext** aCtx);
nsresult EndUpdateBackground(gfxContext* aCtx, nsresult EndUpdateBackground(gfxContext* aCtx,
const nsIntRect& aRect); const nsIntRect& aRect);
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
nsresult HandleGUIEvent(const nsGUIEvent& anEvent, bool* handled);
#endif
private: private:
// Create an appropriate platform surface for a background of size // Create an appropriate platform surface for a background of size

View File

@@ -52,6 +52,7 @@ class nsCString;
struct nsIntRect; struct nsIntRect;
struct nsIntSize; struct nsIntSize;
class nsNPAPIPlugin; class nsNPAPIPlugin;
class nsGUIEvent;
namespace mozilla { namespace mozilla {
namespace layers { namespace layers {
@@ -116,6 +117,9 @@ public:
const nsIntRect&, gfxContext**) = 0; const nsIntRect&, gfxContext**) = 0;
virtual nsresult EndUpdateBackground(NPP instance, virtual nsresult EndUpdateBackground(NPP instance,
gfxContext*, const nsIntRect&) = 0; gfxContext*, const nsIntRect&) = 0;
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
virtual nsresult HandleGUIEvent(NPP instance, const nsGUIEvent&, bool*) = 0;
#endif
}; };

View File

@@ -703,6 +703,20 @@ PluginModuleParent::AsyncSetWindow(NPP instance, NPWindow* window)
return i->AsyncSetWindow(window); return i->AsyncSetWindow(window);
} }
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
nsresult
PluginModuleParent::HandleGUIEvent(NPP instance,
const nsGUIEvent& anEvent,
bool* handled)
{
PluginInstanceParent* i = InstCast(instance);
if (!i)
return NS_ERROR_FAILURE;
return i->HandleGUIEvent(anEvent, handled);
}
#endif
nsresult nsresult
PluginModuleParent::GetImage(NPP instance, PluginModuleParent::GetImage(NPP instance,
mozilla::layers::ImageContainer* aContainer, mozilla::layers::ImageContainer* aContainer,

View File

@@ -296,6 +296,10 @@ private:
#if defined(XP_MACOSX) #if defined(XP_MACOSX)
virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing); virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing);
#endif #endif
#if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
virtual nsresult HandleGUIEvent(NPP instance, const nsGUIEvent& anEvent,
bool* handled);
#endif
private: private:
void WritePluginExtraDataForMinidump(const nsAString& id); void WritePluginExtraDataForMinidump(const nsAString& id);

View File

@@ -66,6 +66,9 @@ namespace dom {
class PBrowserParent; class PBrowserParent;
class PBrowserChild; class PBrowserChild;
} }
namespace plugins {
class PPluginInstanceChild;
}
} }
#ifdef ACCESSIBILITY #ifdef ACCESSIBILITY
@@ -1122,6 +1125,7 @@ class nsTextEvent : public nsInputEvent
private: private:
friend class mozilla::dom::PBrowserParent; friend class mozilla::dom::PBrowserParent;
friend class mozilla::dom::PBrowserChild; friend class mozilla::dom::PBrowserChild;
friend class mozilla::plugins::PPluginInstanceChild;
nsTextEvent() nsTextEvent()
{ {

View File

@@ -82,6 +82,10 @@ CPPSRCS = \
nsDeviceContextSpecQt.cpp \ nsDeviceContextSpecQt.cpp \
$(NULL) $(NULL)
EXPORTS = \
nsQtKeyUtils.h \
$(NULL)
ifdef MOZ_ENABLE_QTMOBILITY ifdef MOZ_ENABLE_QTMOBILITY
MOCSRCS += moc_mozqorientationsensorfilter.cpp MOCSRCS += moc_mozqorientationsensorfilter.cpp
CPPSRCS += mozqorientationsensorfilter.cpp CPPSRCS += mozqorientationsensorfilter.cpp