summaryrefslogtreecommitdiffstats
path: root/Source/WebKit2/WebProcess/Plugins/Netscape
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/WebProcess/Plugins/Netscape')
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.cpp2
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.h4
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp2
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.h4
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp41
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp39
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h10
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp6
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h2
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/gtk/NetscapePluginGtk.cpp105
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm19
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/qt/NetscapePluginQt.cpp125
-rw-r--r--Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp425
13 files changed, 529 insertions, 255 deletions
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.cpp
index fc73519..8b36d1d 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.cpp
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.cpp
@@ -42,7 +42,7 @@ namespace WebKit {
const ClassInfo JSNPMethod::s_info = { "NPMethod", &InternalFunction::s_info, 0, 0 };
JSNPMethod::JSNPMethod(ExecState* exec, JSGlobalObject* globalObject, const Identifier& name, NPIdentifier npIdentifier)
- : InternalFunction(&exec->globalData(), globalObject, createStructure(globalObject->functionPrototype()), name)
+ : InternalFunction(&exec->globalData(), globalObject, createStructure(exec->globalData(), globalObject->functionPrototype()), name)
, m_npIdentifier(npIdentifier)
{
ASSERT(inherits(&s_info));
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.h b/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.h
index a913a99..f0c2424 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.h
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPMethod.h
@@ -42,9 +42,9 @@ public:
NPIdentifier npIdentifier() const { return m_npIdentifier; }
private:
- static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
+ static PassRefPtr<JSC::Structure> createStructure(JSC::JSGlobalData& globalData, JSC::JSValue prototype)
{
- return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
+ return JSC::Structure::create(globalData, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
}
virtual JSC::CallType getCallData(JSC::CallData&);
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp
index 2724f0d..93f9fc5 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp
@@ -50,7 +50,7 @@ static NPIdentifier npIdentifierFromIdentifier(const Identifier& identifier)
const ClassInfo JSNPObject::s_info = { "NPObject", &JSObjectWithGlobalObject::s_info, 0, 0 };
JSNPObject::JSNPObject(JSGlobalObject* globalObject, NPRuntimeObjectMap* objectMap, NPObject* npObject)
- : JSObjectWithGlobalObject(globalObject, createStructure(globalObject->objectPrototype()))
+ : JSObjectWithGlobalObject(globalObject, createStructure(globalObject->globalData(), globalObject->objectPrototype()))
, m_objectMap(objectMap)
, m_npObject(npObject)
{
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.h b/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.h
index adaffa7..e8a08da 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.h
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.h
@@ -55,9 +55,9 @@ public:
private:
static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::OverridesGetPropertyNames | JSObject::StructureFlags;
- static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
+ static PassRefPtr<JSC::Structure> createStructure(JSC::JSGlobalData& globalData, JSC::JSValue prototype)
{
- return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
+ return JSC::Structure::create(globalData, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
}
virtual JSC::CallType getCallData(JSC::CallData&);
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
index 679de6f..a548fd6 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
@@ -35,6 +35,12 @@
#include <WebCore/SharedBuffer.h>
#include <utility>
+#if PLATFORM(QT)
+#include <QX11Info>
+#elif PLATFORM(GTK)
+#include <gdk/gdkx.h>
+#endif
+
using namespace WebCore;
using namespace std;
@@ -484,17 +490,33 @@ static NPError NPN_GetValue(NPP npp, NPNVariable variable, void *value)
*(NPBool*)value = true;
break;
#elif PLUGIN_ARCHITECTURE(X11)
+ case NPNVxDisplay:
+#if PLATFORM(QT)
+ *reinterpret_cast<Display**>(value) = QX11Info::display();
+ break;
+#elif PLATFORM(GTK)
+ *reinterpret_cast<Display**>(value) = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
+ break;
+#else
+ goto default;
+#endif
+ case NPNVSupportsXEmbedBool:
+ *static_cast<NPBool*>(value) = true;
+ break;
+ case NPNVSupportsWindowless:
+ *static_cast<NPBool*>(value) = true;
+ break;
+
case NPNVToolkit: {
const uint32_t expectedGTKToolKitVersion = 2;
RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
- if (plugin->quirks().contains(PluginQuirks::RequiresGTKToolKit)) {
- *reinterpret_cast<uint32_t*>(value) = expectedGTKToolKitVersion;
- break;
- }
-
- return NPERR_GENERIC_ERROR;
+ *reinterpret_cast<uint32_t*>(value) = plugin->quirks().contains(PluginQuirks::RequiresGTKToolKit) ?
+ expectedGTKToolKitVersion : 0;
+ break;
}
+
+ // TODO: implement NPNVnetscapeWindow once we want to support windowed plugins.
#endif
default:
notImplemented();
@@ -529,7 +551,12 @@ static NPError NPN_SetValue(NPP npp, NPPVariable variable, void *value)
return NPERR_NO_ERROR;
}
- case NPPVpluginTransparentBool:
+ case NPPVpluginTransparentBool: {
+ RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
+ plugin->setIsTransparent(value);
+ return NPERR_NO_ERROR;
+ }
+
default:
notImplemented();
return NPERR_GENERIC_ERROR;
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
index 7e9b059..7d00219 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
@@ -64,6 +64,7 @@ NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
#else
, m_isWindowed(true)
#endif
+ , m_isTransparent(false)
, m_inNPPNew(false)
, m_loadManually(false)
#if PLATFORM(MAC)
@@ -75,20 +76,23 @@ NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
#ifndef NP_NO_CARBON
, m_nullEventTimer(RunLoop::main(), this, &NetscapePlugin::nullEventTimerFired)
, m_npCGContext()
-#endif
+#endif
+#elif PLUGIN_ARCHITECTURE(X11)
+ , m_drawable(0)
+ , m_pluginDisplay(0)
#endif
{
m_npp.ndata = this;
m_npp.pdata = 0;
- m_pluginModule->pluginCreated();
+ m_pluginModule->incrementLoadCount();
}
NetscapePlugin::~NetscapePlugin()
{
ASSERT(!m_isStarted);
- m_pluginModule->pluginDestroyed();
+ m_pluginModule->decrementLoadCount();
}
PassRefPtr<NetscapePlugin> NetscapePlugin::fromNPP(NPP npp)
@@ -189,6 +193,11 @@ void NetscapePlugin::setIsWindowed(bool isWindowed)
m_isWindowed = isWindowed;
}
+void NetscapePlugin::setIsTransparent(bool isTransparent)
+{
+ m_isTransparent = isTransparent;
+}
+
void NetscapePlugin::setStatusbarText(const String& statusbarText)
{
m_pluginController->setStatusbarText(statusbarText);
@@ -347,8 +356,14 @@ NPError NetscapePlugin::NPP_SetValue(NPNVariable variable, void *value)
void NetscapePlugin::callSetWindow()
{
+#if PLUGIN_ARCHITECTURE(X11)
+ // We use a backing store as the painting area for the plugin.
+ m_npWindow.x = 0;
+ m_npWindow.y = 0;
+#else
m_npWindow.x = m_frameRect.x();
m_npWindow.y = m_frameRect.y();
+#endif
m_npWindow.width = m_frameRect.width();
m_npWindow.height = m_frameRect.height();
m_npWindow.clipRect.top = m_clipRect.y();
@@ -427,6 +442,17 @@ bool NetscapePlugin::initialize(PluginController* pluginController, const Parame
values.append(paramValues[i].data());
}
+#if PLATFORM(MAC)
+ if (m_pluginModule->pluginQuirks().contains(PluginQuirks::MakeTransparentIfBackgroundAttributeExists)) {
+ for (size_t i = 0; i < parameters.names.size(); ++i) {
+ if (equalIgnoringCase(parameters.names[i], "background")) {
+ setIsTransparent(true);
+ break;
+ }
+ }
+ }
+#endif
+
NetscapePlugin* previousNPPNewPlugin = currentNPPNewPlugin;
m_inNPPNew = true;
@@ -487,7 +513,7 @@ PassRefPtr<ShareableBitmap> NetscapePlugin::snapshot()
ASSERT(m_isStarted);
- RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(m_frameRect.size());
+ RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(m_frameRect.size(), ShareableBitmap::SupportsAlpha);
OwnPtr<GraphicsContext> context = bitmap->createGraphicsContext();
context->translate(-m_frameRect.x(), -m_frameRect.y());
@@ -497,6 +523,11 @@ PassRefPtr<ShareableBitmap> NetscapePlugin::snapshot()
return bitmap.release();
}
+bool NetscapePlugin::isTransparent()
+{
+ return m_isTransparent;
+}
+
void NetscapePlugin::geometryDidChange(const IntRect& frameRect, const IntRect& clipRect)
{
ASSERT(m_isStarted);
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
index e865d93..7cf9ead 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
@@ -78,6 +78,7 @@ public:
const Vector<uint8_t>& httpBody, bool sendNotification, void* notificationData);
NPError destroyStream(NPStream*, NPReason);
void setIsWindowed(bool);
+ void setIsTransparent(bool);
void setStatusbarText(const String&);
static void setException(const String&);
bool evaluate(NPObject*, const String&scriptString, NPVariant* result);
@@ -145,6 +146,7 @@ private:
#if PLATFORM(MAC)
virtual PlatformLayer* pluginLayer();
#endif
+ virtual bool isTransparent();
virtual void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect);
virtual void frameDidFinishLoading(uint64_t requestID);
virtual void frameDidFail(uint64_t requestID, bool wasCancelled);
@@ -203,12 +205,13 @@ private:
bool m_isStarted;
bool m_isWindowed;
+ bool m_isTransparent;
bool m_inNPPNew;
bool m_loadManually;
RefPtr<NetscapePluginStream> m_manualStream;
Vector<bool, 8> m_popupEnabledStates;
-#if PLATFORM(MAC)
+#if PLUGIN_ARCHITECTURE(MAC)
NPDrawingModel m_drawingModel;
NPEventModel m_eventModel;
RetainPtr<PlatformLayer> m_pluginLayer;
@@ -229,8 +232,11 @@ private:
RunLoop::Timer<NetscapePlugin> m_nullEventTimer;
NP_CGContext m_npCGContext;
#endif
-#elif PLATFORM(WIN)
+#elif PLUGIN_ARCHITECTURE(WIN)
HWND m_window;
+#elif PLUGIN_ARCHITECTURE(X11)
+ Pixmap m_drawable;
+ Display* m_pluginDisplay;
#endif
};
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp
index 9450317..cf5affc 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp
@@ -304,7 +304,7 @@ void NetscapePluginStream::stop(NPReason reason)
ASSERT(!m_filePath.isNull());
- m_plugin->NPP_StreamAsFile(&m_npStream, m_filePath.data());
+ m_plugin->NPP_StreamAsFile(&m_npStream, m_filePath.utf8().data());
} else {
// Just close the file.
if (m_fileHandle != invalidPlatformFileHandle)
@@ -315,8 +315,8 @@ void NetscapePluginStream::stop(NPReason reason)
// to delete the file here -- NPP_StreamAsFile() is always called immediately before NPP_DestroyStream()
// (the stream destruction function), so there can be no expectation that a plugin will read the stream
// file asynchronously after NPP_StreamAsFile() is called.
- deleteFile(String::fromUTF8(m_filePath.data()));
- m_filePath = CString();
+ deleteFile(m_filePath);
+ m_filePath = String();
// NPP_StreamAsFile could call NPN_DestroyStream and destroy the stream.
if (!m_isStarted)
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h
index 7757001..f22ab61 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h
@@ -88,7 +88,7 @@ private:
uint16_t m_transferMode;
int32_t m_offset;
- CString m_filePath;
+ String m_filePath;
WebCore::PlatformFileHandle m_fileHandle;
// Whether NPP_NewStream has successfully been called.
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/gtk/NetscapePluginGtk.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/gtk/NetscapePluginGtk.cpp
deleted file mode 100644
index f7c9440..0000000
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/gtk/NetscapePluginGtk.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "NetscapePlugin.h"
-
-#include <WebCore/NotImplemented.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-
-bool NetscapePlugin::platformPostInitialize()
-{
- notImplemented();
- return true;
-}
-
-void NetscapePlugin::platformDestroy()
-{
- notImplemented();
-}
-
-bool NetscapePlugin::platformInvalidate(const IntRect&)
-{
- notImplemented();
- return false;
-}
-
-void NetscapePlugin::platformGeometryDidChange()
-{
- notImplemented();
-}
-
-void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect, bool)
-{
- notImplemented();
-}
-
-NPEvent toNP(const WebMouseEvent& event)
-{
- NPEvent npEvent = NPEvent();
- notImplemented();
- return npEvent;
-}
-
-bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent& event)
-{
- notImplemented();
- return true;
-}
-
-bool NetscapePlugin::platformHandleWheelEvent(const WebWheelEvent&)
-{
- notImplemented();
- return false;
-}
-
-void NetscapePlugin::platformSetFocus(bool)
-{
- notImplemented();
-}
-
-bool NetscapePlugin::platformHandleMouseEnterEvent(const WebMouseEvent& event)
-{
- notImplemented();
- return true;
-}
-
-bool NetscapePlugin::platformHandleMouseLeaveEvent(const WebMouseEvent& event)
-{
- notImplemented();
- return true;
-}
-
-bool NetscapePlugin::platformHandleKeyboardEvent(const WebKeyboardEvent&)
-{
- notImplemented();
- return false;
-}
-
-} // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm b/Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm
index 2a33008..14ac070 100644
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm
@@ -221,7 +221,8 @@ bool NetscapePlugin::platformPostInitialize()
#ifndef NP_NO_QUICKDRAW
// Right now we don't support the QuickDraw drawing model at all
- if (m_drawingModel == NPDrawingModelQuickDraw)
+ if (m_drawingModel == NPDrawingModelQuickDraw &&
+ !m_pluginModule->pluginQuirks().contains(PluginQuirks::AllowHalfBakedQuickDrawSupport))
return false;
#endif
@@ -230,7 +231,17 @@ bool NetscapePlugin::platformPostInitialize()
// Get the Core Animation layer.
if (NPP_GetValue(NPPVpluginCoreAnimationLayer, &value) == NPERR_NO_ERROR && value) {
ASSERT(!m_pluginLayer);
- m_pluginLayer = reinterpret_cast<CALayer *>(value);
+
+ CALayer *realPluginLayer = reinterpret_cast<CALayer *>(value);
+
+ // Create a layer with flipped geometry and add the real plug-in layer as a sublayer
+ // so the coordinate system will match the event coordinate system.
+ m_pluginLayer.adoptNS([[CALayer alloc] init]);
+ [m_pluginLayer.get() setBounds:[realPluginLayer bounds]];
+ [m_pluginLayer.get() setGeometryFlipped:YES];
+
+ [realPluginLayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
+ [m_pluginLayer.get() addSublayer:realPluginLayer];
}
}
@@ -277,6 +288,10 @@ void NetscapePlugin::platformDestroy()
bool NetscapePlugin::platformInvalidate(const IntRect&)
{
+ // NPN_InvalidateRect is just a no-op in the Core Animation drawing model.
+ if (m_drawingModel == NPDrawingModelCoreAnimation)
+ return true;
+
return false;
}
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/qt/NetscapePluginQt.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/qt/NetscapePluginQt.cpp
deleted file mode 100644
index 581dcf3..0000000
--- a/Source/WebKit2/WebProcess/Plugins/Netscape/qt/NetscapePluginQt.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Copyright (C) 2010 University of Szeged
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "NetscapePlugin.h"
-
-#include "WebEvent.h"
-#include <WebCore/GraphicsContext.h>
-#include <WebCore/NotImplemented.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-
-bool NetscapePlugin::platformPostInitialize()
-{
- notImplemented();
- return true;
-}
-
-void NetscapePlugin::platformDestroy()
-{
- notImplemented();
-}
-
-bool NetscapePlugin::platformInvalidate(const IntRect&)
-{
- notImplemented();
- return false;
-}
-
-void NetscapePlugin::platformGeometryDidChange()
-{
- notImplemented();
-}
-
-void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect, bool)
-{
- notImplemented();
-}
-
-NPEvent toNP(const WebMouseEvent& event)
-{
-#if OS(SYMBIAN)
- NPEvent npEvent = QEvent(QEvent::None);
-#else
- NPEvent npEvent = NPEvent();
-#endif
-
- notImplemented();
-
- return npEvent;
-}
-
-bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent& event)
-{
- if (m_isWindowed)
- return false;
-
- NPEvent npEvent = toNP(event);
- NPP_HandleEvent(&npEvent);
- return true;
-}
-
-bool NetscapePlugin::platformHandleWheelEvent(const WebWheelEvent&)
-{
- notImplemented();
- return false;
-}
-
-void NetscapePlugin::platformSetFocus(bool)
-{
- notImplemented();
-}
-
-bool NetscapePlugin::platformHandleMouseEnterEvent(const WebMouseEvent& event)
-{
- if (m_isWindowed)
- return false;
-
- NPEvent npEvent = toNP(event);
- NPP_HandleEvent(&npEvent);
- return true;
-}
-
-bool NetscapePlugin::platformHandleMouseLeaveEvent(const WebMouseEvent& event)
-{
- if (m_isWindowed)
- return false;
-
- NPEvent npEvent = toNP(event);
- NPP_HandleEvent(&npEvent);
- return true;
-}
-
-bool NetscapePlugin::platformHandleKeyboardEvent(const WebKeyboardEvent&)
-{
- notImplemented();
- return false;
-}
-
-} // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
new file mode 100644
index 0000000..27e694b
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
@@ -0,0 +1,425 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 University of Szeged
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "NetscapePlugin.h"
+
+#include "WebEvent.h"
+#include <WebCore/GraphicsContext.h>
+#include <WebCore/NotImplemented.h>
+
+#if PLATFORM(QT)
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QPixmap>
+#include <QX11Info>
+#elif PLATFORM(GTK)
+#include <gdk/gdkx.h>
+#endif
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static Display *getPluginDisplay()
+{
+#if PLATFORM(QT)
+ // At the moment, we only support gdk based plugins (like Flash) that use a different X connection.
+ // The code below has the same effect as this one:
+ // Display *gdkDisplay = gdk_x11_display_get_xdisplay(gdk_display_get_default());
+
+ QLibrary library(QLatin1String("libgdk-x11-2.0"), 0);
+ if (!library.load())
+ return 0;
+
+ typedef void *(*gdk_display_get_default_ptr)();
+ gdk_display_get_default_ptr gdk_display_get_default = (gdk_display_get_default_ptr)library.resolve("gdk_display_get_default");
+ if (!gdk_display_get_default)
+ return 0;
+
+ typedef void *(*gdk_x11_display_get_xdisplay_ptr)(void *);
+ gdk_x11_display_get_xdisplay_ptr gdk_x11_display_get_xdisplay = (gdk_x11_display_get_xdisplay_ptr)library.resolve("gdk_x11_display_get_xdisplay");
+ if (!gdk_x11_display_get_xdisplay)
+ return 0;
+
+ return (Display*)gdk_x11_display_get_xdisplay(gdk_display_get_default());
+#elif PLATFORM(GTK)
+ // Since we're a gdk/gtk app, we'll (probably?) have the same X connection as any gdk-based
+ // plugins, so we can return that. We might want to add other implementations here later.
+ return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
+#else
+ return 0;
+#endif
+}
+
+static inline Display* x11Display()
+{
+#if PLATFORM(QT)
+ return QX11Info::display();
+#elif PLATFORM(GTK)
+ return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
+#else
+ return 0;
+#endif
+}
+
+static inline int displayDepth()
+{
+#if PLATFORM(QT)
+ return QApplication::desktop()->x11Info().depth();
+#elif PLATFORM(GTK)
+ return gdk_visual_get_depth(gdk_screen_get_system_visual(gdk_screen_get_default()));
+#else
+ return 0;
+#endif
+}
+
+static inline unsigned long rootWindowID()
+{
+#if PLATFORM(QT)
+ return QX11Info::appRootWindow();
+#elif PLATFORM(GTK)
+ return GDK_ROOT_WINDOW();
+#else
+ return 0;
+#endif
+}
+
+static inline int x11Screen()
+{
+#if PLATFORM(QT)
+ return QX11Info::appScreen();
+#elif PLATFORM(GTK)
+ return gdk_screen_get_number(gdk_screen_get_default());
+#else
+ return 0;
+#endif
+}
+
+bool NetscapePlugin::platformPostInitialize()
+{
+ if (m_isWindowed)
+ return false;
+
+ if (!(m_pluginDisplay = getPluginDisplay()))
+ return false;
+
+ NPSetWindowCallbackStruct* callbackStruct = new NPSetWindowCallbackStruct;
+ callbackStruct->type = 0;
+ Display* display = x11Display();
+ int depth = displayDepth();
+ callbackStruct->display = display;
+ callbackStruct->depth = depth;
+
+ XVisualInfo visualTemplate;
+ visualTemplate.screen = x11Screen();
+ visualTemplate.depth = depth;
+ visualTemplate.c_class = TrueColor;
+ int numMatching;
+ XVisualInfo* visualInfo = XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask,
+ &visualTemplate, &numMatching);
+ ASSERT(visualInfo);
+ Visual* visual = visualInfo[0].visual;
+ ASSERT(visual);
+ XFree(visualInfo);
+
+ callbackStruct->visual = visual;
+ callbackStruct->colormap = XCreateColormap(display, rootWindowID(), visual, AllocNone);
+
+ m_npWindow.type = NPWindowTypeDrawable;
+ m_npWindow.window = 0;
+ m_npWindow.ws_info = callbackStruct;
+
+ callSetWindow();
+
+ return true;
+}
+
+void NetscapePlugin::platformDestroy()
+{
+ delete static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info);
+
+ if (m_drawable) {
+ XFreePixmap(x11Display(), m_drawable);
+ m_drawable = 0;
+ }
+}
+
+bool NetscapePlugin::platformInvalidate(const IntRect&)
+{
+ notImplemented();
+ return false;
+}
+
+void NetscapePlugin::platformGeometryDidChange()
+{
+ if (m_isWindowed) {
+ notImplemented();
+ return;
+ }
+
+ Display* display = x11Display();
+ if (m_drawable)
+ XFreePixmap(display, m_drawable);
+
+ m_drawable = XCreatePixmap(display, rootWindowID(), m_frameRect.width(), m_frameRect.height(), displayDepth());
+
+ XSync(display, false); // Make sure that the server knows about the Drawable.
+}
+
+void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect, bool /*isSnapshot*/)
+{
+ if (m_isWindowed) {
+ notImplemented();
+ return;
+ }
+
+ if (!m_isStarted) {
+ // FIXME: we should paint a missing plugin icon.
+ return;
+ }
+
+ if (context->paintingDisabled())
+ return;
+
+ ASSERT(m_drawable);
+
+#if PLATFORM(QT)
+ QPainter* painter = context->platformContext();
+ painter->translate(m_frameRect.x(), m_frameRect.y());
+#else
+ notImplemented();
+ return;
+#endif
+
+ XEvent xevent;
+ memset(&xevent, 0, sizeof(XEvent));
+ XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose;
+ exposeEvent.type = GraphicsExpose;
+ exposeEvent.display = x11Display();
+ exposeEvent.drawable = m_drawable;
+
+ IntRect exposedRect(dirtyRect);
+ exposedRect.intersect(m_frameRect);
+ exposedRect.move(-m_frameRect.x(), -m_frameRect.y());
+ exposeEvent.x = exposedRect.x();
+ exposeEvent.y = exposedRect.y();
+
+ // Note: in transparent mode Flash thinks width is the right and height is the bottom.
+ // We should take it into account if we want to support transparency.
+ exposeEvent.width = exposedRect.width();
+ exposeEvent.height = exposedRect.height();
+
+ NPP_HandleEvent(&xevent);
+
+ if (m_pluginDisplay != x11Display())
+ XSync(m_pluginDisplay, false);
+
+#if PLATFORM(QT)
+ QPixmap qtDrawable = QPixmap::fromX11Pixmap(m_drawable, QPixmap::ExplicitlyShared);
+ ASSERT(qtDrawable.depth() == static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info)->depth);
+ painter->drawPixmap(QPoint(exposedRect.x(), exposedRect.y()), qtDrawable, exposedRect);
+
+ painter->translate(-m_frameRect.x(), -m_frameRect.y());
+#endif
+}
+
+static inline void initializeXEvent(XEvent& event)
+{
+ memset(&event, 0, sizeof(XEvent));
+ event.xany.serial = 0;
+ event.xany.send_event = false;
+ event.xany.display = x11Display();
+ event.xany.window = 0;
+}
+
+static inline uint64_t xTimeStamp(double timestampInSeconds)
+{
+ return timestampInSeconds * 1000;
+}
+
+static inline unsigned xKeyModifiers(const WebEvent& event)
+{
+ unsigned xModifiers = 0;
+ if (event.controlKey())
+ xModifiers |= ControlMask;
+ if (event.shiftKey())
+ xModifiers |= ShiftMask;
+ if (event.altKey())
+ xModifiers |= Mod1Mask;
+ if (event.metaKey())
+ xModifiers |= Mod4Mask;
+
+ return xModifiers;
+}
+
+template <typename XEventType>
+static inline void setCommonMouseEventFields(XEventType& xEvent, const WebMouseEvent& webEvent, const WebCore::IntPoint& pluginLocation)
+{
+ xEvent.root = rootWindowID();
+ xEvent.subwindow = 0;
+ xEvent.time = xTimeStamp(webEvent.timestamp());
+ xEvent.x = webEvent.position().x() - pluginLocation.x();
+ xEvent.y = webEvent.position().y() - pluginLocation.y();
+ xEvent.x_root = webEvent.globalPosition().x();
+ xEvent.y_root = webEvent.globalPosition().y();
+ xEvent.state = xKeyModifiers(webEvent);
+ xEvent.same_screen = true;
+}
+
+static inline void setXMotionEventFields(XEvent& xEvent, const WebMouseEvent& webEvent, const WebCore::IntPoint& pluginLocation)
+{
+ XMotionEvent& xMotion = xEvent.xmotion;
+ setCommonMouseEventFields(xMotion, webEvent, pluginLocation);
+ xMotion.type = MotionNotify;
+}
+
+static inline void setXButtonEventFields(XEvent& xEvent, const WebMouseEvent& webEvent, const WebCore::IntPoint& pluginLocation)
+{
+ XButtonEvent& xButton = xEvent.xbutton;
+ setCommonMouseEventFields(xButton, webEvent, pluginLocation);
+
+ xButton.type = (webEvent.type() == WebEvent::MouseDown) ? ButtonPress : ButtonRelease;
+ switch (webEvent.button()) {
+ case WebMouseEvent::LeftButton:
+ xButton.button = Button1;
+ break;
+ case WebMouseEvent::MiddleButton:
+ xButton.button = Button2;
+ break;
+ case WebMouseEvent::RightButton:
+ xButton.button = Button3;
+ break;
+ }
+}
+
+static inline void setXCrossingEventFields(XEvent& xEvent, const WebMouseEvent& webEvent, const WebCore::IntPoint& pluginLocation, int type)
+{
+ XCrossingEvent& xCrossing = xEvent.xcrossing;
+ setCommonMouseEventFields(xCrossing, webEvent, pluginLocation);
+
+ xCrossing.type = type;
+ xCrossing.mode = NotifyNormal;
+ xCrossing.detail = NotifyDetailNone;
+ xCrossing.focus = false;
+}
+
+bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent& event)
+{
+ if (m_isWindowed)
+ return false;
+
+ XEvent xEvent;
+ initializeXEvent(xEvent);
+
+ switch (event.type()) {
+ case WebEvent::MouseDown:
+ case WebEvent::MouseUp:
+ setXButtonEventFields(xEvent, event, m_frameRect.location());
+ break;
+ case WebEvent::MouseMove:
+ setXMotionEventFields(xEvent, event, m_frameRect.location());
+ break;
+ }
+
+ return NPP_HandleEvent(&xEvent);
+}
+
+// We undefine these constants in npruntime_internal.h to avoid collision
+// with WebKit and platform headers. Values are defined in X.h.
+const int kKeyPressType = 2;
+const int kKeyReleaseType = 3;
+const int kFocusInType = 9;
+const int kFocusOutType = 10;
+
+bool NetscapePlugin::platformHandleWheelEvent(const WebWheelEvent&)
+{
+ notImplemented();
+ return false;
+}
+
+void NetscapePlugin::platformSetFocus(bool)
+{
+ notImplemented();
+}
+
+bool NetscapePlugin::platformHandleMouseEnterEvent(const WebMouseEvent& event)
+{
+ if (m_isWindowed)
+ return false;
+
+ XEvent xEvent;
+ initializeXEvent(xEvent);
+ setXCrossingEventFields(xEvent, event, m_frameRect.location(), EnterNotify);
+
+ return NPP_HandleEvent(&xEvent);
+}
+
+bool NetscapePlugin::platformHandleMouseLeaveEvent(const WebMouseEvent& event)
+{
+ if (m_isWindowed)
+ return false;
+
+ XEvent xEvent;
+ initializeXEvent(xEvent);
+ setXCrossingEventFields(xEvent, event, m_frameRect.location(), LeaveNotify);
+
+ return NPP_HandleEvent(&xEvent);
+}
+
+static inline void setXKeyEventFields(XEvent& xEvent, const WebKeyboardEvent& webEvent)
+{
+ xEvent.xany.type = (webEvent.type() == WebEvent::KeyDown) ? kKeyPressType : kKeyReleaseType;
+ XKeyEvent& xKey = xEvent.xkey;
+ xKey.root = rootWindowID();
+ xKey.subwindow = 0;
+ xKey.time = xTimeStamp(webEvent.timestamp());
+ xKey.state = xKeyModifiers(webEvent);
+ xKey.keycode = webEvent.nativeVirtualKeyCode();
+
+ xKey.same_screen = true;
+
+ // Key events propagated to the plugin does not need to have position.
+ // source: https://developer.mozilla.org/en/NPEvent
+ xKey.x = 0;
+ xKey.y = 0;
+ xKey.x_root = 0;
+ xKey.y_root = 0;
+}
+
+bool NetscapePlugin::platformHandleKeyboardEvent(const WebKeyboardEvent& event)
+{
+ // We don't generate other types of keyboard events via WebEventFactory.
+ ASSERT(event.type() == WebEvent::KeyDown || event.type() == WebEvent::KeyUp);
+
+ XEvent xEvent;
+ initializeXEvent(xEvent);
+ setXKeyEventFields(xEvent, event);
+
+ return NPP_HandleEvent(&xEvent);
+}
+
+} // namespace WebKit