[UNIX] Add support for windowless NPAPI plugins with no UI in non X11 platforms
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Feb 2016 08:18:23 +0000 (08:18 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Feb 2016 08:18:23 +0000 (08:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151992

Reviewed by Darin Adler.

We are currently disabling all plugins when running under wayland,
for example. There are some plugins, like the one used by
extensions.gnome.org, that don't do any rendering, so there's not
reason not to support those plugins under wayland or any other
unix non-x11 platform.
X11 specific code has been moved to a new class NetscapePluginX11,
only used under X11. The common code is in NetscapePluginUnix.cpp
that will use the X11 implementatin only when needed and
available. For windowed plugins we will fail the initialization
under non-X11 plaforms, while for windowless plugins we will just
return early from paint method.

* PlatformEfl.cmake: Add new files to compilation.
* PlatformGTK.cmake: Ditto.
* UIProcess/API/gtk/WebKitSettings.cpp:
(webkit_settings_set_enable_plugins): Do not disable plugins in wayland.
* UIProcess/gtk/WebPreferencesGtk.cpp:
(WebKit::WebPreferences::platformInitializeStore): Ditto.
* WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
(WebKit::NPN_GetValue): Use PlatformDisplay instead of
NetscapePlugin::x11HostDisplay() and don't claim to support X11
specific features under non-x11 platforms.
* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::NetscapePlugin): Remove X11 and GTK
specific memebers that are now moved to a dedicated class NetscapePluginX11.
* WebProcess/Plugins/Netscape/NetscapePlugin.h:
(WebKit::NetscapePlugin::frameRectInWindowCoordinates): Make this public.
(WebKit::NetscapePlugin::clipRect): Add getter.
(WebKit::NetscapePlugin::size): Ditto.
(WebKit::NetscapePlugin::isWindowed): Ditto.
(WebKit::NetscapePlugin::isVisible): Ditto.
* WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp: Added.
(WebKit::NetscapePlugin::platformPreInitialize):
(WebKit::NetscapePlugin::platformPostInitialize):
(WebKit::NetscapePlugin::platformDestroy):
(WebKit::NetscapePlugin::platformInvalidate):
(WebKit::NetscapePlugin::platformGeometryDidChange):
(WebKit::NetscapePlugin::platformVisibilityDidChange):
(WebKit::NetscapePlugin::platformPaint):
(WebKit::NetscapePlugin::platformHandleMouseEvent):
(WebKit::NetscapePlugin::platformHandleWheelEvent):
(WebKit::NetscapePlugin::platformSetFocus):
(WebKit::NetscapePlugin::wantsPluginRelativeNPWindowCoordinates):
(WebKit::NetscapePlugin::platformHandleMouseEnterEvent):
(WebKit::NetscapePlugin::platformHandleMouseLeaveEvent):
(WebKit::NetscapePlugin::platformHandleKeyboardEvent):
* WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.h: Added.
(WebKit::NetscapePluginUnix::~NetscapePluginUnix):
* WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp:
(WebKit::getPluginDisplay):
(WebKit::displayDepth):
(WebKit::x11HostDisplay):
(WebKit::NetscapePluginX11::create):
(WebKit::NetscapePluginX11::NetscapePluginX11):
(WebKit::NetscapePluginX11::~NetscapePluginX11):
(WebKit::NetscapePluginX11::windowType):
(WebKit::NetscapePluginX11::window):
(WebKit::NetscapePluginX11::geometryDidChange):
(WebKit::NetscapePluginX11::visibilityDidChange):
(WebKit::NetscapePluginX11::paint):
(WebKit::initializeXEvent):
(WebKit::NetscapePluginX11::handleMouseEvent):
(WebKit::NetscapePluginX11::handleWheelEvent):
(WebKit::NetscapePluginX11::setFocus):
(WebKit::NetscapePluginX11::handleMouseEnterEvent):
(WebKit::NetscapePluginX11::handleMouseLeaveEvent):
(WebKit::NetscapePluginX11::handleKeyboardEvent):
(WebKit::setCommonMouseEventFields): Deleted.
(WebKit::setXKeyEventFields): Deleted.
* WebProcess/Plugins/Netscape/x11/NetscapePluginX11.h: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196053 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformEfl.cmake
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp
Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
Source/WebKit2/WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.h [new file with mode: 0644]
Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.h [new file with mode: 0644]

index e5985ad..f03f36e 100644 (file)
@@ -1,3 +1,81 @@
+2016-02-02  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [UNIX] Add support for windowless NPAPI plugins with no UI in non X11 platforms
+        https://bugs.webkit.org/show_bug.cgi?id=151992
+
+        Reviewed by Darin Adler.
+
+        We are currently disabling all plugins when running under wayland,
+        for example. There are some plugins, like the one used by
+        extensions.gnome.org, that don't do any rendering, so there's not
+        reason not to support those plugins under wayland or any other
+        unix non-x11 platform.
+        X11 specific code has been moved to a new class NetscapePluginX11,
+        only used under X11. The common code is in NetscapePluginUnix.cpp
+        that will use the X11 implementatin only when needed and
+        available. For windowed plugins we will fail the initialization
+        under non-X11 plaforms, while for windowless plugins we will just
+        return early from paint method.
+
+        * PlatformEfl.cmake: Add new files to compilation.
+        * PlatformGTK.cmake: Ditto.
+        * UIProcess/API/gtk/WebKitSettings.cpp:
+        (webkit_settings_set_enable_plugins): Do not disable plugins in wayland.
+        * UIProcess/gtk/WebPreferencesGtk.cpp:
+        (WebKit::WebPreferences::platformInitializeStore): Ditto.
+        * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
+        (WebKit::NPN_GetValue): Use PlatformDisplay instead of
+        NetscapePlugin::x11HostDisplay() and don't claim to support X11
+        specific features under non-x11 platforms.
+        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
+        (WebKit::NetscapePlugin::NetscapePlugin): Remove X11 and GTK
+        specific memebers that are now moved to a dedicated class NetscapePluginX11.
+        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
+        (WebKit::NetscapePlugin::frameRectInWindowCoordinates): Make this public.
+        (WebKit::NetscapePlugin::clipRect): Add getter.
+        (WebKit::NetscapePlugin::size): Ditto.
+        (WebKit::NetscapePlugin::isWindowed): Ditto.
+        (WebKit::NetscapePlugin::isVisible): Ditto.
+        * WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp: Added.
+        (WebKit::NetscapePlugin::platformPreInitialize):
+        (WebKit::NetscapePlugin::platformPostInitialize):
+        (WebKit::NetscapePlugin::platformDestroy):
+        (WebKit::NetscapePlugin::platformInvalidate):
+        (WebKit::NetscapePlugin::platformGeometryDidChange):
+        (WebKit::NetscapePlugin::platformVisibilityDidChange):
+        (WebKit::NetscapePlugin::platformPaint):
+        (WebKit::NetscapePlugin::platformHandleMouseEvent):
+        (WebKit::NetscapePlugin::platformHandleWheelEvent):
+        (WebKit::NetscapePlugin::platformSetFocus):
+        (WebKit::NetscapePlugin::wantsPluginRelativeNPWindowCoordinates):
+        (WebKit::NetscapePlugin::platformHandleMouseEnterEvent):
+        (WebKit::NetscapePlugin::platformHandleMouseLeaveEvent):
+        (WebKit::NetscapePlugin::platformHandleKeyboardEvent):
+        * WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.h: Added.
+        (WebKit::NetscapePluginUnix::~NetscapePluginUnix):
+        * WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp:
+        (WebKit::getPluginDisplay):
+        (WebKit::displayDepth):
+        (WebKit::x11HostDisplay):
+        (WebKit::NetscapePluginX11::create):
+        (WebKit::NetscapePluginX11::NetscapePluginX11):
+        (WebKit::NetscapePluginX11::~NetscapePluginX11):
+        (WebKit::NetscapePluginX11::windowType):
+        (WebKit::NetscapePluginX11::window):
+        (WebKit::NetscapePluginX11::geometryDidChange):
+        (WebKit::NetscapePluginX11::visibilityDidChange):
+        (WebKit::NetscapePluginX11::paint):
+        (WebKit::initializeXEvent):
+        (WebKit::NetscapePluginX11::handleMouseEvent):
+        (WebKit::NetscapePluginX11::handleWheelEvent):
+        (WebKit::NetscapePluginX11::setFocus):
+        (WebKit::NetscapePluginX11::handleMouseEnterEvent):
+        (WebKit::NetscapePluginX11::handleMouseLeaveEvent):
+        (WebKit::NetscapePluginX11::handleKeyboardEvent):
+        (WebKit::setCommonMouseEventFields): Deleted.
+        (WebKit::setXKeyEventFields): Deleted.
+        * WebProcess/Plugins/Netscape/x11/NetscapePluginX11.h: Added.
+
 2016-02-02  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
 
         Remove ENABLE(GLOBAL_FASTMALLOC_NEW) guard in WebMemorySamplerLinux.cpp
index 97f680b..9c0aa69 100644 (file)
@@ -200,6 +200,7 @@ list(APPEND WebKit2_SOURCES
 
     WebProcess/MediaCache/WebMediaKeyStorageManager.cpp
 
+    WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp
     WebProcess/Plugins/Netscape/unix/PluginProxyUnix.cpp
 
     WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
@@ -273,6 +274,8 @@ list(APPEND WebKit2_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/WebProcess/soup"
     "${WEBKIT2_DIR}/WebProcess/unix"
     "${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/efl"
+    "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/unix"
+    "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/x11"
     "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/efl"
     "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/soup"
     "${WEBKIT2_DIR}/WebProcess/WebPage/CoordinatedGraphics"
index f2a93a9..c010bfb 100644 (file)
@@ -338,6 +338,7 @@ list(APPEND WebKit2_SOURCES
 
     WebProcess/MediaCache/WebMediaKeyStorageManager.cpp
 
+    WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp
     WebProcess/Plugins/Netscape/unix/PluginProxyUnix.cpp
 
     WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
@@ -524,6 +525,8 @@ list(APPEND WebKit2_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/UIProcess/gtk"
     "${WEBKIT2_DIR}/UIProcess/soup"
     "${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk"
+    "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/unix"
+    "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/x11"
     "${WEBKIT2_DIR}/WebProcess/gtk"
     "${WEBKIT2_DIR}/WebProcess/soup"
     "${WEBKIT2_DIR}/WebProcess/unix"
@@ -793,6 +796,7 @@ if (ENABLE_PLUGIN_PROCESS_GTK2)
         WebProcess/Plugins/Netscape/NetscapePluginNone.cpp
         WebProcess/Plugins/Netscape/NetscapePluginStream.cpp
 
+        WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp
         WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
 
         ${DERIVED_SOURCES_WEBKIT2_DIR}/PluginControllerProxyMessageReceiver.cpp
index 3e0c488..9d2133f 100644 (file)
@@ -1594,12 +1594,6 @@ void webkit_settings_set_enable_plugins(WebKitSettings* settings, gboolean enabl
 {
     g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
 
-#if PLATFORM(WAYLAND)
-    // Do not allow to change this setting in Wayland, since plugins are not supported.
-    if (WebCore::PlatformDisplay::sharedDisplay().type() == WebCore::PlatformDisplay::Type::Wayland)
-        return;
-#endif
-
     WebKitSettingsPrivate* priv = settings->priv;
     bool currentValue = priv->preferences->pluginsEnabled();
     if (currentValue == enabled)
index e4a0b7a..c7242c4 100644 (file)
@@ -39,8 +39,6 @@ void WebPreferences::platformInitializeStore()
         // FIXME: Accelerated compositing under Wayland is not yet supported.
         // https://bugs.webkit.org/show_bug.cgi?id=115803
         setAcceleratedCompositingEnabled(false);
-
-        setPluginsEnabled(false);
     }
 #endif
 #if !ENABLE(OPENGL)
index 393733b..d085762 100644 (file)
 #include <WebCore/MachSendRight.h>
 #endif
 
+#if PLUGIN_ARCHITECTURE(X11)
+#include <WebCore/PlatformDisplayX11.h>
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -524,18 +528,21 @@ static NPError NPN_GetValue(NPP npp, NPNVariable variable, void *value)
             break;
 #endif
 #elif PLUGIN_ARCHITECTURE(X11)
-       case NPNVxDisplay: {
-           if (!npp)
-               return NPERR_GENERIC_ERROR;
-           *reinterpret_cast<Display**>(value) = NetscapePlugin::x11HostDisplay();
-           break;
-       }
-       case NPNVSupportsXEmbedBool:
-           *static_cast<NPBool*>(value) = true;
-           break;
-       case NPNVSupportsWindowless:
-           *static_cast<NPBool*>(value) = true;
-           break;
+        case NPNVxDisplay: {
+            if (!npp)
+                return NPERR_GENERIC_ERROR;
+            auto& display = PlatformDisplay::sharedDisplay();
+            if (display.type() != PlatformDisplay::Type::X11)
+                return NPERR_GENERIC_ERROR;
+            *reinterpret_cast<Display**>(value) = downcast<PlatformDisplayX11>(display).native();
+            break;
+        }
+        case NPNVSupportsXEmbedBool:
+            *static_cast<NPBool*>(value) = PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11;
+            break;
+        case NPNVSupportsWindowless:
+            *static_cast<NPBool*>(value) = true;
+            break;
 
        case NPNVToolkit: {
            // Gtk based plugins need to be assured about the toolkit version.
index 1127d12..2483983 100644 (file)
 #include <utility>
 #include <wtf/text/CString.h>
 
+#if PLUGIN_ARCHITECTURE(X11)
+#include "NetscapePluginUnix.h"
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -90,12 +94,6 @@ NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
     , m_nullEventTimer(RunLoop::main(), this, &NetscapePlugin::nullEventTimerFired)
     , m_npCGContext()
 #endif
-#elif PLUGIN_ARCHITECTURE(X11)
-    , m_drawable(0)
-    , m_pluginDisplay(0)
-#if PLATFORM(GTK)
-    , m_platformPluginWidget(0)
-#endif
 #endif
 {
     m_npp.ndata = this;
index 4f92d8f..77c5cad 100644 (file)
 #include <wtf/text/CString.h>
 #include <wtf/text/StringHash.h>
 
-#if PLUGIN_ARCHITECTURE(X11)
-#include <WebCore/XUniqueResource.h>
-#endif
-
 namespace WebCore {
 class MachSendRight;
 class HTTPHeaderMap;
@@ -54,7 +50,8 @@ OBJC_CLASS WKNPAPIPlugInContainer;
 namespace WebKit {
 
 class NetscapePluginStream;
-    
+class NetscapePluginUnix;
+
 class NetscapePlugin : public Plugin {
 public:
     static RefPtr<NetscapePlugin> create(PassRefPtr<NetscapePluginModule>);
@@ -95,6 +92,12 @@ public:
 
 #endif
 
+#if PLUGIN_ARCHITECTURE(X11)
+    const WebCore::IntRect& frameRectInWindowCoordinates() const { return m_frameRectInWindowCoordinates; }
+#endif
+    const WebCore::IntRect& clipRect() const { return m_clipRect; }
+    const WebCore::IntSize& size() const { return m_pluginSize; }
+
     PluginQuirks quirks() const { return m_pluginModule->pluginQuirks(); }
 
     void invalidate(const NPRect*);
@@ -109,6 +112,8 @@ public:
     bool evaluate(NPObject*, const String&scriptString, NPVariant* result);
     bool isPrivateBrowsingEnabled();
     bool isMuted() const;
+    bool isWindowed() const { return m_isWindowed; }
+    bool isVisible() const { return m_isVisible; }
 
     static void setSetExceptionFunction(void (*)(const String&));
 
@@ -155,6 +160,9 @@ public:
     NPError NPP_GetValue(NPPVariable, void *value);
     NPError NPP_SetValue(NPNVariable, void *value);
 
+    // Convert the given point from plug-in coordinates to root view coordinates.
+    virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const override;
+
 private:
     NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule);
 
@@ -258,9 +266,6 @@ private:
 
     virtual bool supportsSnapshotting() const override;
 
-    // Convert the given point from plug-in coordinates to root view coordinates.
-    virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const override;
-
     // Convert the given point from root view coordinates to plug-in coordinates. Returns false if the point can't be
     // converted (if the transformation matrix isn't invertible).
     bool convertFromRootView(const WebCore::IntPoint& pointInRootViewCoordinates, WebCore::IntPoint& pointInPluginCoordinates);
@@ -277,11 +282,6 @@ private:
 
     void updateNPNPrivateMode();
 
-#if PLUGIN_ARCHITECTURE(X11)
-    bool platformPostInitializeWindowed(bool needsXEmbed, uint64_t windowID);
-    bool platformPostInitializeWindowless();
-#endif
-
     uint64_t m_nextRequestID;
 
     typedef HashMap<uint64_t, std::pair<String, void*>> PendingURLNotifyMap;
@@ -394,14 +394,7 @@ private:
     NP_CGContext m_npCGContext;
 #endif
 #elif PLUGIN_ARCHITECTURE(X11)
-    WebCore::XUniquePixmap m_drawable;
-    Display* m_pluginDisplay;
-#if PLATFORM(GTK)
-    GtkWidget* m_platformPluginWidget;
-#endif
-
-public: // Need to call it in the NPN_GetValue browser callback.
-    static Display* x11HostDisplay();
+    std::unique_ptr<NetscapePluginUnix> m_impl;
 #endif
 };
 
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp
new file mode 100644 (file)
index 0000000..b396b0b
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * 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"
+
+#if PLUGIN_ARCHITECTURE(X11) && ENABLE(NETSCAPE_PLUGIN_API)
+
+#include "NetscapePluginX11.h"
+#include "WebEvent.h"
+#include <WebCore/NotImplemented.h>
+#include <WebCore/PlatformDisplay.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void NetscapePlugin::platformPreInitialize()
+{
+}
+
+bool NetscapePlugin::platformPostInitialize()
+{
+#if PLATFORM(X11)
+    if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11) {
+        m_impl = NetscapePluginX11::create(*this);
+        if (!m_impl)
+            return false;
+    }
+#endif
+
+    if (m_impl) {
+        m_npWindow.type = m_impl->windowType();
+        m_npWindow.window = m_impl->window();
+        m_npWindow.ws_info = m_impl->windowSystemInfo();
+        callSetWindow();
+    }
+
+    return true;
+}
+
+void NetscapePlugin::platformDestroy()
+{
+    m_impl = nullptr;
+}
+
+bool NetscapePlugin::platformInvalidate(const IntRect&)
+{
+    notImplemented();
+    return false;
+}
+
+void NetscapePlugin::platformGeometryDidChange()
+{
+    if (!m_impl)
+        return;
+    m_impl->geometryDidChange();
+}
+
+void NetscapePlugin::platformVisibilityDidChange()
+{
+    if (!m_isWindowed || !m_impl)
+        return;
+
+    m_impl->visibilityDidChange();
+}
+
+void NetscapePlugin::platformPaint(GraphicsContext& context, const IntRect& dirtyRect, bool /*isSnapshot*/)
+{
+    if (m_isWindowed || !m_impl)
+        return;
+
+    if (!m_isStarted) {
+        // FIXME: we should paint a missing plugin icon.
+        return;
+    }
+
+    m_impl->paint(context, dirtyRect);
+}
+
+bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent& event)
+{
+    if (m_isWindowed || !m_impl)
+        return false;
+
+    if ((event.type() == WebEvent::MouseDown || event.type() == WebEvent::MouseUp)
+        && event.button() == WebMouseEvent::RightButton
+        && quirks().contains(PluginQuirks::IgnoreRightClickInWindowlessMode))
+        return false;
+
+    return m_impl->handleMouseEvent(event);
+}
+
+bool NetscapePlugin::platformHandleWheelEvent(const WebWheelEvent& event)
+{
+    if (m_isWindowed || !m_impl)
+        return false;
+
+    return m_impl->handleWheelEvent(event);
+}
+
+void NetscapePlugin::platformSetFocus(bool focusIn)
+{
+    if (m_isWindowed || !m_impl)
+        return;
+
+    m_impl->setFocus(focusIn);
+}
+
+bool NetscapePlugin::wantsPluginRelativeNPWindowCoordinates()
+{
+    return true;
+}
+
+bool NetscapePlugin::platformHandleMouseEnterEvent(const WebMouseEvent& event)
+{
+    if (m_isWindowed || !m_impl)
+        return false;
+
+    return m_impl->handleMouseEnterEvent(event);
+}
+
+bool NetscapePlugin::platformHandleMouseLeaveEvent(const WebMouseEvent& event)
+{
+    if (m_isWindowed || !m_impl)
+        return false;
+
+    return m_impl->handleMouseLeaveEvent(event);
+}
+
+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);
+
+    if (m_isWindowed || !m_impl)
+        return false;
+
+    return m_impl->handleKeyboardEvent(event);
+}
+
+} // namespace WebKit
+
+#endif // PLUGIN_ARCHITECTURE(X11) && ENABLE(NETSCAPE_PLUGIN_API)
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.h b/Source/WebKit2/WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.h
new file mode 100644 (file)
index 0000000..efa6cd0
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * 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.
+ */
+
+#ifndef NetscapePluginUnix_h
+#define NetscapePluginUnix_h
+
+#if PLUGIN_ARCHITECTURE(X11) && ENABLE(NETSCAPE_PLUGIN_API)
+
+#include <WebCore/npruntime_internal.h>
+
+namespace WebCore {
+class GraphicsContext;
+class IntRect;
+}
+
+namespace WebKit {
+
+class WebKeyboardEvent;
+class WebMouseEvent;
+class WebWheelEvent;
+
+class NetscapePluginUnix {
+public:
+    virtual ~NetscapePluginUnix() { }
+    virtual NPWindowType windowType() const = 0;
+    virtual void* window() const = 0;
+    virtual NPSetWindowCallbackStruct* windowSystemInfo() = 0;
+    virtual void geometryDidChange() = 0;
+    virtual void visibilityDidChange() = 0;
+    virtual void paint(WebCore::GraphicsContext&, const WebCore::IntRect&) = 0;
+    virtual bool handleMouseEvent(const WebMouseEvent&) = 0;
+    virtual bool handleWheelEvent(const WebWheelEvent&) = 0;
+    virtual bool handleMouseEnterEvent(const WebMouseEvent&) = 0;
+    virtual bool handleMouseLeaveEvent(const WebMouseEvent&) = 0;
+    virtual bool handleKeyboardEvent(const WebKeyboardEvent&) = 0;
+    virtual void setFocus(bool) = 0;
+};
+
+} // namespace WebKit
+
+#endif // PLUGIN_ARCHITECTURE(X11) && ENABLE(NETSCAPE_PLUGIN_API)
+
+#endif // NetscapePluginUnix_h
index 3802897..b5b5484 100644 (file)
  */
 
 #include "config.h"
+#include "NetscapePluginX11.h"
+
 #if PLUGIN_ARCHITECTURE(X11) && ENABLE(NETSCAPE_PLUGIN_API)
 
 #include "NetscapePlugin.h"
-
 #include "PluginController.h"
 #include "WebEvent.h"
 #include <WebCore/GraphicsContext.h>
@@ -57,6 +58,11 @@ using namespace WebCore;
 
 namespace WebKit {
 
+static inline Display* x11HostDisplay()
+{
+    return downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
+}
+
 static Display* getPluginDisplay()
 {
 #if PLATFORM(GTK)
@@ -66,7 +72,7 @@ static Display* getPluginDisplay()
 #elif PLATFORM(EFL) && defined(HAVE_ECORE_X)
     return static_cast<Display*>(ecore_x_display_get());
 #else
-    return 0;
+    return nullptr;
 #endif
 }
 
@@ -86,7 +92,7 @@ static inline int displayDepth()
 #if PLATFORM(GTK)
     return gdk_visual_get_depth(gdk_screen_get_system_visual(gdk_screen_get_default()));
 #elif PLATFORM(EFL) && defined(HAVE_ECORE_X)
-    return ecore_x_default_depth_get(NetscapePlugin::x11HostDisplay(), ecore_x_default_screen_get());
+    return ecore_x_default_depth_get(x11HostDisplay(), ecore_x_default_screen_get());
 #else
     return 0;
 #endif
@@ -103,11 +109,6 @@ static inline unsigned long rootWindowID()
 #endif
 }
 
-Display* NetscapePlugin::x11HostDisplay()
-{
-    return downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
-}
-
 #if PLATFORM(GTK)
 static gboolean socketPlugRemovedCallback(GtkSocket*)
 {
@@ -119,180 +120,159 @@ static gboolean socketPlugRemovedCallback(GtkSocket*)
 }
 #endif
 
-bool NetscapePlugin::platformPostInitializeWindowed(bool needsXEmbed, uint64_t windowID)
+std::unique_ptr<NetscapePluginX11> NetscapePluginX11::create(NetscapePlugin& plugin)
 {
-    m_npWindow.type = NPWindowTypeWindow;
-    if (!needsXEmbed) {
+#if PLATFORM(GTK)
+    uint64_t windowID = 0;
+#endif
+    if (plugin.isWindowed()) {
+#if PLATFORM(GTK)
+        // NPPVplugiNeedsXEmbed is a boolean value, but at least the
+        // Flash player plugin is using an 'int' instead.
+        int needsXEmbed = 0;
+        plugin.NPP_GetValue(NPPVpluginNeedsXEmbed, &needsXEmbed);
+        if (needsXEmbed) {
+            windowID = plugin.controller()->createPluginContainer();
+            if (!windowID)
+                return nullptr;
+        } else {
+            notImplemented();
+            return nullptr;
+        }
+#else
         notImplemented();
-        return false;
+        return nullptr;
+#endif
     }
 
-    Display* display = x11HostDisplay();
+    Display* display = getPluginDisplay();
+    if (!display)
+        return nullptr;
 
 #if PLATFORM(GTK)
-    // It seems flash needs the socket to be in the same process,
-    // I guess it uses gdk_window_lookup(), so we create a new socket here
-    // containing a plug with the UI process socket embedded.
-    m_platformPluginWidget = gtk_plug_new(static_cast<Window>(windowID));
-
-    // Hide the GtkPlug on delete-event since we assume the widget is valid while the plugin is active.
-    // platformDestroy() will be called anyway right after the delete-event.
-    g_signal_connect(m_platformPluginWidget, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), nullptr);
-
-    GtkWidget* socket = gtk_socket_new();
-    // Do not show the plug widget until the socket is connected.
-    g_signal_connect_swapped(socket, "plug-added", G_CALLBACK(gtk_widget_show), m_platformPluginWidget);
-    g_signal_connect(socket, "plug-removed", G_CALLBACK(socketPlugRemovedCallback), nullptr);
-    gtk_container_add(GTK_CONTAINER(m_platformPluginWidget), socket);
-    gtk_widget_show(socket);
-
-    m_npWindow.window = GINT_TO_POINTER(gtk_socket_get_id(GTK_SOCKET(socket)));
-    GdkWindow* window = gtk_widget_get_window(socket);
-    NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info);
-    callbackStruct->display = GDK_WINDOW_XDISPLAY(window);
-    callbackStruct->visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window));
-    callbackStruct->depth = gdk_visual_get_depth(gdk_window_get_visual(window));
-    callbackStruct->colormap = XCreateColormap(display, GDK_ROOT_WINDOW(), callbackStruct->visual, AllocNone);
-#else
-    UNUSED_PARAM(windowID);
+    if (plugin.isWindowed())
+        return std::make_unique<NetscapePluginX11>(plugin, display, windowID);
 #endif
 
-    XFlush(display);
-
-    callSetWindow();
-
-    return true;
+    return std::make_unique<NetscapePluginX11>(plugin, display);
 }
 
-bool NetscapePlugin::platformPostInitializeWindowless()
+NetscapePluginX11::NetscapePluginX11(NetscapePlugin& plugin, Display* display)
+    : m_plugin(plugin)
+    , m_pluginDisplay(display)
 {
-    Display* display = x11HostDisplay();
-    m_npWindow.type = NPWindowTypeDrawable;
-    m_npWindow.window = 0;
-
+    Display* hostDisplay = x11HostDisplay();
     int depth = displayDepth();
-
-    NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info);
-    callbackStruct->display = display;
-    callbackStruct->depth = depth;
+    m_setWindowCallbackStruct.display = hostDisplay;
+    m_setWindowCallbackStruct.depth = depth;
 
     XVisualInfo visualTemplate;
     visualTemplate.screen = x11Screen();
     visualTemplate.depth = depth;
     visualTemplate.c_class = TrueColor;
     int numMatching;
-    XUniquePtr<XVisualInfo> visualInfo(XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualTemplate, &numMatching));
+    XUniquePtr<XVisualInfo> visualInfo(XGetVisualInfo(hostDisplay, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualTemplate, &numMatching));
     ASSERT(visualInfo);
     Visual* visual = visualInfo.get()[0].visual;
     ASSERT(visual);
 
-    callbackStruct->visual = visual;
-    callbackStruct->colormap = XCreateColormap(display, rootWindowID(), visual, AllocNone);
-
-    callSetWindow();
-
-    return true;
-}
-
-void NetscapePlugin::platformPreInitialize()
-{
+    m_setWindowCallbackStruct.visual = visual;
+    m_setWindowCallbackStruct.colormap = XCreateColormap(hostDisplay, rootWindowID(), visual, AllocNone);
 }
 
-bool NetscapePlugin::platformPostInitialize()
+#if PLATFORM(GTK)
+NetscapePluginX11::NetscapePluginX11(NetscapePlugin& plugin, Display* display, uint64_t windowID)
+    : m_plugin(plugin)
+    , m_pluginDisplay(display)
+    , m_windowID(windowID)
 {
-    uint64_t windowID = 0;
-    // NPPVpluginNeedsXEmbed is a boolean value, but at least the
-    // Flash player plugin is using an 'int' instead.
-    int needsXEmbed = 0;
-    if (m_isWindowed) {
-        NPP_GetValue(NPPVpluginNeedsXEmbed, &needsXEmbed);
-        if (needsXEmbed) {
-            windowID = controller()->createPluginContainer();
-            if (!windowID)
-                return false;
-        } else {
-            notImplemented();
-            return false;
-        }
-    }
+    // It seems flash needs the socket to be in the same process,
+    // I guess it uses gdk_window_lookup(), so we create a new socket here
+    // containing a plug with the UI process socket embedded.
+    m_platformPluginWidget = gtk_plug_new(static_cast<Window>(windowID));
 
-    if (!(m_pluginDisplay = getPluginDisplay()))
-        return false;
+    // Hide the GtkPlug on delete-event since we assume the widget is valid while the plugin is active.
+    // platformDestroy() will be called anyway right after the delete-event.
+    g_signal_connect(m_platformPluginWidget, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), nullptr);
 
-    NPSetWindowCallbackStruct* callbackStruct = new NPSetWindowCallbackStruct;
-    callbackStruct->type = 0;
-    m_npWindow.ws_info = callbackStruct;
+    GtkWidget* socket = gtk_socket_new();
+    // Do not show the plug widget until the socket is connected.
+    g_signal_connect_swapped(socket, "plug-added", G_CALLBACK(gtk_widget_show), m_platformPluginWidget);
+    g_signal_connect(socket, "plug-removed", G_CALLBACK(socketPlugRemovedCallback), nullptr);
+    gtk_container_add(GTK_CONTAINER(m_platformPluginWidget), socket);
+    gtk_widget_show(socket);
 
-    if (m_isWindowed)
-        return platformPostInitializeWindowed(needsXEmbed, windowID);
+    Display* hostDisplay = x11HostDisplay();
+    m_npWindowID = gtk_socket_get_id(GTK_SOCKET(socket));
+    GdkWindow* window = gtk_widget_get_window(socket);
+    m_setWindowCallbackStruct.display = GDK_WINDOW_XDISPLAY(window);
+    m_setWindowCallbackStruct.visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window));
+    m_setWindowCallbackStruct.depth = gdk_visual_get_depth(gdk_window_get_visual(window));
+    m_setWindowCallbackStruct.colormap = XCreateColormap(hostDisplay, GDK_ROOT_WINDOW(), m_setWindowCallbackStruct.visual, AllocNone);
 
-    return platformPostInitializeWindowless();
+    XFlush(hostDisplay);
 }
+#endif
 
-void NetscapePlugin::platformDestroy()
+NetscapePluginX11::~NetscapePluginX11()
 {
-    NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info);
-    Display* hostDisplay = x11HostDisplay();
-    XFreeColormap(hostDisplay, callbackStruct->colormap);
-    delete callbackStruct;
+    XFreeColormap(x11HostDisplay(), m_setWindowCallbackStruct.colormap);
 
     m_drawable.reset();
 
 #if PLATFORM(GTK)
-    if (m_platformPluginWidget) {
+    if (m_platformPluginWidget)
         gtk_widget_destroy(m_platformPluginWidget);
-        m_platformPluginWidget = 0;
-    }
 #endif
 }
 
-bool NetscapePlugin::platformInvalidate(const IntRect&)
+NPWindowType NetscapePluginX11::windowType() const
 {
-    notImplemented();
-    return false;
+    return m_plugin.isWindowed() ? NPWindowTypeWindow : NPWindowTypeDrawable;
 }
 
-void NetscapePlugin::platformGeometryDidChange()
+void* NetscapePluginX11::window() const
 {
-    if (m_isWindowed) {
+#if PLATFORM(GTK)
+    return m_plugin.isWindowed() ? GINT_TO_POINTER(m_npWindowID) : nullptr;
+#else
+    return nullptr;
+#endif
+}
+
+void NetscapePluginX11::geometryDidChange()
+{
+    if (m_plugin.isWindowed()) {
         uint64_t windowID = 0;
 #if PLATFORM(GTK)
         windowID = static_cast<uint64_t>(GDK_WINDOW_XID(gtk_plug_get_socket_window(GTK_PLUG(m_platformPluginWidget))));
 #endif
-        controller()->windowedPluginGeometryDidChange(m_frameRectInWindowCoordinates, m_clipRect, windowID);
+        m_plugin.controller()->windowedPluginGeometryDidChange(m_plugin.frameRectInWindowCoordinates(), m_plugin.clipRect(), windowID);
         return;
     }
 
     m_drawable.reset();
-    if (m_pluginSize.isEmpty())
+    if (m_plugin.size().isEmpty())
         return;
 
-    m_drawable = XCreatePixmap(x11HostDisplay(), rootWindowID(), m_pluginSize.width(), m_pluginSize.height(), displayDepth());
+    m_drawable = XCreatePixmap(x11HostDisplay(), rootWindowID(), m_plugin.size().width(), m_plugin.size().height(), displayDepth());
     XSync(x11HostDisplay(), false); // Make sure that the server knows about the Drawable.
 }
 
-void NetscapePlugin::platformVisibilityDidChange()
+void NetscapePluginX11::visibilityDidChange()
 {
-    if (!m_isWindowed)
-        return;
-
+    ASSERT(m_plugin.isWindowed());
     uint64_t windowID = 0;
 #if PLATFORM(GTK)
     windowID = static_cast<uint64_t>(GDK_WINDOW_XID(gtk_plug_get_socket_window(GTK_PLUG(m_platformPluginWidget))));
 #endif
-    controller()->windowedPluginVisibilityDidChange(m_isVisible, windowID);
-    controller()->windowedPluginGeometryDidChange(m_frameRectInWindowCoordinates, m_clipRect, windowID);
+    m_plugin.controller()->windowedPluginVisibilityDidChange(m_plugin.isVisible(), windowID);
+    m_plugin.controller()->windowedPluginGeometryDidChange(m_plugin.frameRectInWindowCoordinates(), m_plugin.clipRect(), windowID);
 }
 
-void NetscapePlugin::platformPaint(GraphicsContext& context, const IntRect& dirtyRect, bool /*isSnapshot*/)
+void NetscapePluginX11::paint(GraphicsContext& context, const IntRect& dirtyRect)
 {
-    if (m_isWindowed)
-        return;
-
-    if (!m_isStarted) {
-        // FIXME: we should paint a missing plugin icon.
-        return;
-    }
+    ASSERT(m_plugin.isWindowed());
 
     if (context.paintingDisabled() || !m_drawable)
         return;
@@ -313,14 +293,14 @@ void NetscapePlugin::platformPaint(GraphicsContext& context, const IntRect& dirt
     exposeEvent.width = exposedRect.width();
     exposeEvent.height = exposedRect.height();
 
-    NPP_HandleEvent(&xevent);
+    m_plugin.NPP_HandleEvent(&xevent);
 
     if (m_pluginDisplay != x11HostDisplay())
         XSync(m_pluginDisplay, false);
 
 #if PLATFORM(GTK) || (PLATFORM(EFL) && USE(CAIRO))
     RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(m_pluginDisplay, m_drawable.get(),
-        static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info)->visual, m_pluginSize.width(), m_pluginSize.height()));
+        m_setWindowCallbackStruct.visual, m_plugin.size().width(), m_plugin.size().height()));
     cairo_t* cr = context.platformContext()->cr();
     cairo_save(cr);
 
@@ -342,7 +322,7 @@ static inline void initializeXEvent(XEvent& event)
     memset(&event, 0, sizeof(XEvent));
     event.xany.serial = 0;
     event.xany.send_event = false;
-    event.xany.display = NetscapePlugin::x11HostDisplay();
+    event.xany.display = x11HostDisplay();
     event.xany.window = 0;
 }
 
@@ -440,15 +420,9 @@ static inline void setXCrossingEventFields(XEvent& xEvent, const WebMouseEvent&
     xCrossing.focus = false;
 }
 
-bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent& event)
+bool NetscapePluginX11::handleMouseEvent(const WebMouseEvent& event)
 {
-    if (m_isWindowed)
-        return false;
-
-    if ((event.type() == WebEvent::MouseDown || event.type() == WebEvent::MouseUp)
-         && event.button() == WebMouseEvent::RightButton
-         && quirks().contains(PluginQuirks::IgnoreRightClickInWindowlessMode))
-        return false;
+    ASSERT(m_plugin.isWindowed());
 
     XEvent xEvent;
     initializeXEvent(xEvent);
@@ -456,10 +430,10 @@ bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent& event)
     switch (event.type()) {
     case WebEvent::MouseDown:
     case WebEvent::MouseUp:
-        setXButtonEventFields(xEvent, event, convertToRootView(IntPoint()));
+        setXButtonEventFields(xEvent, event, m_plugin.convertToRootView(IntPoint()));
         break;
     case WebEvent::MouseMove:
-        setXMotionEventFields(xEvent, event, convertToRootView(IntPoint()));
+        setXMotionEventFields(xEvent, event, m_plugin.convertToRootView(IntPoint()));
         break;
     case WebEvent::MouseForceChanged:
     case WebEvent::MouseForceDown:
@@ -479,7 +453,7 @@ bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent& event)
         return false;
     }
 
-    return !NPP_HandleEvent(&xEvent);
+    return !m_plugin.NPP_HandleEvent(&xEvent);
 }
 
 // We undefine these constants in npruntime_internal.h to avoid collision
@@ -489,22 +463,20 @@ const int kKeyReleaseType = 3;
 const int kFocusInType = 9;
 const int kFocusOutType = 10;
 
-bool NetscapePlugin::platformHandleWheelEvent(const WebWheelEvent& event)
+bool NetscapePluginX11::handleWheelEvent(const WebWheelEvent& event)
 {
-    if (m_isWindowed)
-        return false;
+    ASSERT(m_plugin.isWindowed());
 
     XEvent xEvent;
     initializeXEvent(xEvent);
-    setXButtonEventFieldsByWebWheelEvent(xEvent, event, convertToRootView(IntPoint()));
+    setXButtonEventFieldsByWebWheelEvent(xEvent, event, m_plugin.convertToRootView(IntPoint()));
 
-    return !NPP_HandleEvent(&xEvent);
+    return !m_plugin.NPP_HandleEvent(&xEvent);
 }
 
-void NetscapePlugin::platformSetFocus(bool focusIn)
+void NetscapePluginX11::setFocus(bool focusIn)
 {
-    if (m_isWindowed)
-        return;
+    ASSERT(m_plugin.isWindowed());
 
     XEvent xEvent;
     initializeXEvent(xEvent);
@@ -513,36 +485,29 @@ void NetscapePlugin::platformSetFocus(bool focusIn)
     focusEvent.mode = NotifyNormal;
     focusEvent.detail = NotifyDetailNone;
 
-    NPP_HandleEvent(&xEvent);
-}
-
-bool NetscapePlugin::wantsPluginRelativeNPWindowCoordinates()
-{
-    return true;
+    m_plugin.NPP_HandleEvent(&xEvent);
 }
 
-bool NetscapePlugin::platformHandleMouseEnterEvent(const WebMouseEvent& event)
+bool NetscapePluginX11::handleMouseEnterEvent(const WebMouseEvent& event)
 {
-    if (m_isWindowed)
-        return false;
+    ASSERT(m_plugin.isWindowed());
 
     XEvent xEvent;
     initializeXEvent(xEvent);
-    setXCrossingEventFields(xEvent, event, convertToRootView(IntPoint()), EnterNotify);
+    setXCrossingEventFields(xEvent, event, m_plugin.convertToRootView(IntPoint()), EnterNotify);
 
-    return !NPP_HandleEvent(&xEvent);
+    return !m_plugin.NPP_HandleEvent(&xEvent);
 }
 
-bool NetscapePlugin::platformHandleMouseLeaveEvent(const WebMouseEvent& event)
+bool NetscapePluginX11::handleMouseLeaveEvent(const WebMouseEvent& event)
 {
-    if (m_isWindowed)
-        return false;
+    ASSERT(m_plugin.isWindowed());
 
     XEvent xEvent;
     initializeXEvent(xEvent);
-    setXCrossingEventFields(xEvent, event, convertToRootView(IntPoint()), LeaveNotify);
+    setXCrossingEventFields(xEvent, event, m_plugin.convertToRootView(IntPoint()), LeaveNotify);
 
-    return !NPP_HandleEvent(&xEvent);
+    return !m_plugin.NPP_HandleEvent(&xEvent);
 }
 
 static inline void setXKeyEventFields(XEvent& xEvent, const WebKeyboardEvent& webEvent)
@@ -565,8 +530,9 @@ static inline void setXKeyEventFields(XEvent& xEvent, const WebKeyboardEvent& we
     xKey.y_root = 0;
 }
 
-bool NetscapePlugin::platformHandleKeyboardEvent(const WebKeyboardEvent& event)
+bool NetscapePluginX11::handleKeyboardEvent(const WebKeyboardEvent& event)
 {
+    ASSERT(m_plugin.isWindowed());
     // We don't generate other types of keyboard events via WebEventFactory.
     ASSERT(event.type() == WebEvent::KeyDown || event.type() == WebEvent::KeyUp);
 
@@ -574,7 +540,7 @@ bool NetscapePlugin::platformHandleKeyboardEvent(const WebKeyboardEvent& event)
     initializeXEvent(xEvent);
     setXKeyEventFields(xEvent, event);
 
-    return !NPP_HandleEvent(&xEvent);
+    return !m_plugin.NPP_HandleEvent(&xEvent);
 }
 
 } // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.h b/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.h
new file mode 100644 (file)
index 0000000..a609038
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+#ifndef NetscapePluginX11_h
+#define NetscapePluginX11_h
+
+#if PLUGIN_ARCHITECTURE(X11)
+
+#include "NetscapePluginUnix.h"
+#include <WebCore/XUniqueResource.h>
+
+namespace WebKit {
+
+class NetscapePlugin;
+
+class NetscapePluginX11 final : public NetscapePluginUnix {
+public:
+    static std::unique_ptr<NetscapePluginX11> create(NetscapePlugin&);
+    NetscapePluginX11(NetscapePlugin&, Display*);
+#if PLATFORM(GTK)
+    NetscapePluginX11(NetscapePlugin&, Display*, uint64_t windowID);
+#endif
+    virtual ~NetscapePluginX11();
+
+private:
+    virtual NPWindowType windowType() const override;
+    virtual void* window() const override;
+    virtual NPSetWindowCallbackStruct* windowSystemInfo() override { return &m_setWindowCallbackStruct; }
+    virtual void geometryDidChange() override;
+    virtual void visibilityDidChange() override;
+    virtual void paint(WebCore::GraphicsContext&, const WebCore::IntRect&) override;
+    virtual bool handleMouseEvent(const WebMouseEvent&) override;
+    virtual bool handleWheelEvent(const WebWheelEvent&) override;
+    virtual bool handleMouseEnterEvent(const WebMouseEvent&) override;
+    virtual bool handleMouseLeaveEvent(const WebMouseEvent&) override;
+    virtual bool handleKeyboardEvent(const WebKeyboardEvent&) override;
+    virtual void setFocus(bool) override;
+
+    NetscapePlugin& m_plugin;
+    Display* m_pluginDisplay { nullptr };
+    WebCore::XUniquePixmap m_drawable;
+    NPSetWindowCallbackStruct m_setWindowCallbackStruct;
+#if PLATFORM(GTK)
+    uint64_t m_windowID { 0 };
+    unsigned long m_npWindowID { 0 };
+    GtkWidget* m_platformPluginWidget { nullptr };
+#endif
+};
+} // namespace WebKit
+
+#endif // PLUGIN_ARCHITECTURE(X11)
+
+#endif // NetscapePluginX11_h