Changeset 196053 in webkit


Ignore:
Timestamp:
Feb 3, 2016 12:18:23 AM (8 years ago)
Author:
Carlos Garcia Campos
Message:

[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.
Location:
trunk/Source/WebKit2
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r196046 r196053  
     12016-02-02  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [UNIX] Add support for windowless NPAPI plugins with no UI in non X11 platforms
     4        https://bugs.webkit.org/show_bug.cgi?id=151992
     5
     6        Reviewed by Darin Adler.
     7
     8        We are currently disabling all plugins when running under wayland,
     9        for example. There are some plugins, like the one used by
     10        extensions.gnome.org, that don't do any rendering, so there's not
     11        reason not to support those plugins under wayland or any other
     12        unix non-x11 platform.
     13        X11 specific code has been moved to a new class NetscapePluginX11,
     14        only used under X11. The common code is in NetscapePluginUnix.cpp
     15        that will use the X11 implementatin only when needed and
     16        available. For windowed plugins we will fail the initialization
     17        under non-X11 plaforms, while for windowless plugins we will just
     18        return early from paint method.
     19
     20        * PlatformEfl.cmake: Add new files to compilation.
     21        * PlatformGTK.cmake: Ditto.
     22        * UIProcess/API/gtk/WebKitSettings.cpp:
     23        (webkit_settings_set_enable_plugins): Do not disable plugins in wayland.
     24        * UIProcess/gtk/WebPreferencesGtk.cpp:
     25        (WebKit::WebPreferences::platformInitializeStore): Ditto.
     26        * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
     27        (WebKit::NPN_GetValue): Use PlatformDisplay instead of
     28        NetscapePlugin::x11HostDisplay() and don't claim to support X11
     29        specific features under non-x11 platforms.
     30        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
     31        (WebKit::NetscapePlugin::NetscapePlugin): Remove X11 and GTK
     32        specific memebers that are now moved to a dedicated class NetscapePluginX11.
     33        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
     34        (WebKit::NetscapePlugin::frameRectInWindowCoordinates): Make this public.
     35        (WebKit::NetscapePlugin::clipRect): Add getter.
     36        (WebKit::NetscapePlugin::size): Ditto.
     37        (WebKit::NetscapePlugin::isWindowed): Ditto.
     38        (WebKit::NetscapePlugin::isVisible): Ditto.
     39        * WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp: Added.
     40        (WebKit::NetscapePlugin::platformPreInitialize):
     41        (WebKit::NetscapePlugin::platformPostInitialize):
     42        (WebKit::NetscapePlugin::platformDestroy):
     43        (WebKit::NetscapePlugin::platformInvalidate):
     44        (WebKit::NetscapePlugin::platformGeometryDidChange):
     45        (WebKit::NetscapePlugin::platformVisibilityDidChange):
     46        (WebKit::NetscapePlugin::platformPaint):
     47        (WebKit::NetscapePlugin::platformHandleMouseEvent):
     48        (WebKit::NetscapePlugin::platformHandleWheelEvent):
     49        (WebKit::NetscapePlugin::platformSetFocus):
     50        (WebKit::NetscapePlugin::wantsPluginRelativeNPWindowCoordinates):
     51        (WebKit::NetscapePlugin::platformHandleMouseEnterEvent):
     52        (WebKit::NetscapePlugin::platformHandleMouseLeaveEvent):
     53        (WebKit::NetscapePlugin::platformHandleKeyboardEvent):
     54        * WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.h: Added.
     55        (WebKit::NetscapePluginUnix::~NetscapePluginUnix):
     56        * WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp:
     57        (WebKit::getPluginDisplay):
     58        (WebKit::displayDepth):
     59        (WebKit::x11HostDisplay):
     60        (WebKit::NetscapePluginX11::create):
     61        (WebKit::NetscapePluginX11::NetscapePluginX11):
     62        (WebKit::NetscapePluginX11::~NetscapePluginX11):
     63        (WebKit::NetscapePluginX11::windowType):
     64        (WebKit::NetscapePluginX11::window):
     65        (WebKit::NetscapePluginX11::geometryDidChange):
     66        (WebKit::NetscapePluginX11::visibilityDidChange):
     67        (WebKit::NetscapePluginX11::paint):
     68        (WebKit::initializeXEvent):
     69        (WebKit::NetscapePluginX11::handleMouseEvent):
     70        (WebKit::NetscapePluginX11::handleWheelEvent):
     71        (WebKit::NetscapePluginX11::setFocus):
     72        (WebKit::NetscapePluginX11::handleMouseEnterEvent):
     73        (WebKit::NetscapePluginX11::handleMouseLeaveEvent):
     74        (WebKit::NetscapePluginX11::handleKeyboardEvent):
     75        (WebKit::setCommonMouseEventFields): Deleted.
     76        (WebKit::setXKeyEventFields): Deleted.
     77        * WebProcess/Plugins/Netscape/x11/NetscapePluginX11.h: Added.
     78
    1792016-02-02  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
    280
  • trunk/Source/WebKit2/PlatformEfl.cmake

    r194637 r196053  
    201201    WebProcess/MediaCache/WebMediaKeyStorageManager.cpp
    202202
     203    WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp
    203204    WebProcess/Plugins/Netscape/unix/PluginProxyUnix.cpp
    204205
     
    274275    "${WEBKIT2_DIR}/WebProcess/unix"
    275276    "${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/efl"
     277    "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/unix"
     278    "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/x11"
    276279    "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/efl"
    277280    "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/soup"
  • trunk/Source/WebKit2/PlatformGTK.cmake

    r195902 r196053  
    339339    WebProcess/MediaCache/WebMediaKeyStorageManager.cpp
    340340
     341    WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp
    341342    WebProcess/Plugins/Netscape/unix/PluginProxyUnix.cpp
    342343
     
    525526    "${WEBKIT2_DIR}/UIProcess/soup"
    526527    "${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk"
     528    "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/unix"
     529    "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/x11"
    527530    "${WEBKIT2_DIR}/WebProcess/gtk"
    528531    "${WEBKIT2_DIR}/WebProcess/soup"
     
    794797        WebProcess/Plugins/Netscape/NetscapePluginStream.cpp
    795798
     799        WebProcess/Plugins/Netscape/unix/NetscapePluginUnix.cpp
    796800        WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
    797801
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp

    r187641 r196053  
    15951595    g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
    15961596
    1597 #if PLATFORM(WAYLAND)
    1598     // Do not allow to change this setting in Wayland, since plugins are not supported.
    1599     if (WebCore::PlatformDisplay::sharedDisplay().type() == WebCore::PlatformDisplay::Type::Wayland)
    1600         return;
    1601 #endif
    1602 
    16031597    WebKitSettingsPrivate* priv = settings->priv;
    16041598    bool currentValue = priv->preferences->pluginsEnabled();
  • trunk/Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp

    r193626 r196053  
    4040        // https://bugs.webkit.org/show_bug.cgi?id=115803
    4141        setAcceleratedCompositingEnabled(false);
    42 
    43         setPluginsEnabled(false);
    4442    }
    4543#endif
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp

    r194496 r196053  
    4646#endif
    4747
     48#if PLUGIN_ARCHITECTURE(X11)
     49#include <WebCore/PlatformDisplayX11.h>
     50#endif
     51
    4852using namespace WebCore;
    4953
     
    525529#endif
    526530#elif PLUGIN_ARCHITECTURE(X11)
    527        case NPNVxDisplay: {
    528            if (!npp)
    529                return NPERR_GENERIC_ERROR;
    530            *reinterpret_cast<Display**>(value) = NetscapePlugin::x11HostDisplay();
    531            break;
    532        }
    533        case NPNVSupportsXEmbedBool:
    534            *static_cast<NPBool*>(value) = true;
    535            break;
    536        case NPNVSupportsWindowless:
    537            *static_cast<NPBool*>(value) = true;
    538            break;
     531        case NPNVxDisplay: {
     532            if (!npp)
     533                return NPERR_GENERIC_ERROR;
     534            auto& display = PlatformDisplay::sharedDisplay();
     535            if (display.type() != PlatformDisplay::Type::X11)
     536                return NPERR_GENERIC_ERROR;
     537            *reinterpret_cast<Display**>(value) = downcast<PlatformDisplayX11>(display).native();
     538            break;
     539        }
     540        case NPNVSupportsXEmbedBool:
     541            *static_cast<NPBool*>(value) = PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11;
     542            break;
     543        case NPNVSupportsWindowless:
     544            *static_cast<NPBool*>(value) = true;
     545            break;
    539546
    540547       case NPNVToolkit: {
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp

    r195452 r196053  
    4343#include <wtf/text/CString.h>
    4444
     45#if PLUGIN_ARCHITECTURE(X11)
     46#include "NetscapePluginUnix.h"
     47#endif
     48
    4549using namespace WebCore;
    4650
     
    9195    , m_npCGContext()
    9296#endif
    93 #elif PLUGIN_ARCHITECTURE(X11)
    94     , m_drawable(0)
    95     , m_pluginDisplay(0)
    96 #if PLATFORM(GTK)
    97     , m_platformPluginWidget(0)
    98 #endif
    9997#endif
    10098{
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h

    r191922 r196053  
    3939#include <wtf/text/StringHash.h>
    4040
    41 #if PLUGIN_ARCHITECTURE(X11)
    42 #include <WebCore/XUniqueResource.h>
    43 #endif
    44 
    4541namespace WebCore {
    4642class MachSendRight;
     
    5551
    5652class NetscapePluginStream;
    57    
     53class NetscapePluginUnix;
     54
    5855class NetscapePlugin : public Plugin {
    5956public:
     
    9592
    9693#endif
     94
     95#if PLUGIN_ARCHITECTURE(X11)
     96    const WebCore::IntRect& frameRectInWindowCoordinates() const { return m_frameRectInWindowCoordinates; }
     97#endif
     98    const WebCore::IntRect& clipRect() const { return m_clipRect; }
     99    const WebCore::IntSize& size() const { return m_pluginSize; }
    97100
    98101    PluginQuirks quirks() const { return m_pluginModule->pluginQuirks(); }
     
    110113    bool isPrivateBrowsingEnabled();
    111114    bool isMuted() const;
     115    bool isWindowed() const { return m_isWindowed; }
     116    bool isVisible() const { return m_isVisible; }
    112117
    113118    static void setSetExceptionFunction(void (*)(const String&));
     
    155160    NPError NPP_GetValue(NPPVariable, void *value);
    156161    NPError NPP_SetValue(NPNVariable, void *value);
     162
     163    // Convert the given point from plug-in coordinates to root view coordinates.
     164    virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const override;
    157165
    158166private:
     
    259267    virtual bool supportsSnapshotting() const override;
    260268
    261     // Convert the given point from plug-in coordinates to root view coordinates.
    262     virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const override;
    263 
    264269    // Convert the given point from root view coordinates to plug-in coordinates. Returns false if the point can't be
    265270    // converted (if the transformation matrix isn't invertible).
     
    277282
    278283    void updateNPNPrivateMode();
    279 
    280 #if PLUGIN_ARCHITECTURE(X11)
    281     bool platformPostInitializeWindowed(bool needsXEmbed, uint64_t windowID);
    282     bool platformPostInitializeWindowless();
    283 #endif
    284284
    285285    uint64_t m_nextRequestID;
     
    395395#endif
    396396#elif PLUGIN_ARCHITECTURE(X11)
    397     WebCore::XUniquePixmap m_drawable;
    398     Display* m_pluginDisplay;
    399 #if PLATFORM(GTK)
    400     GtkWidget* m_platformPluginWidget;
    401 #endif
    402 
    403 public: // Need to call it in the NPN_GetValue browser callback.
    404     static Display* x11HostDisplay();
     397    std::unique_ptr<NetscapePluginUnix> m_impl;
    405398#endif
    406399};
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp

    r192311 r196053  
    2626
    2727#include "config.h"
     28#include "NetscapePluginX11.h"
     29
    2830#if PLUGIN_ARCHITECTURE(X11) && ENABLE(NETSCAPE_PLUGIN_API)
    2931
    3032#include "NetscapePlugin.h"
    31 
    3233#include "PluginController.h"
    3334#include "WebEvent.h"
     
    5859namespace WebKit {
    5960
     61static inline Display* x11HostDisplay()
     62{
     63    return downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
     64}
     65
    6066static Display* getPluginDisplay()
    6167{
     
    6773    return static_cast<Display*>(ecore_x_display_get());
    6874#else
    69     return 0;
     75    return nullptr;
    7076#endif
    7177}
     
    8793    return gdk_visual_get_depth(gdk_screen_get_system_visual(gdk_screen_get_default()));
    8894#elif PLATFORM(EFL) && defined(HAVE_ECORE_X)
    89     return ecore_x_default_depth_get(NetscapePlugin::x11HostDisplay(), ecore_x_default_screen_get());
     95    return ecore_x_default_depth_get(x11HostDisplay(), ecore_x_default_screen_get());
    9096#else
    9197    return 0;
     
    102108    return 0;
    103109#endif
    104 }
    105 
    106 Display* NetscapePlugin::x11HostDisplay()
    107 {
    108     return downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    109110}
    110111
     
    120121#endif
    121122
    122 bool NetscapePlugin::platformPostInitializeWindowed(bool needsXEmbed, uint64_t windowID)
    123 {
    124     m_npWindow.type = NPWindowTypeWindow;
    125     if (!needsXEmbed) {
     123std::unique_ptr<NetscapePluginX11> NetscapePluginX11::create(NetscapePlugin& plugin)
     124{
     125#if PLATFORM(GTK)
     126    uint64_t windowID = 0;
     127#endif
     128    if (plugin.isWindowed()) {
     129#if PLATFORM(GTK)
     130        // NPPVplugiNeedsXEmbed is a boolean value, but at least the
     131        // Flash player plugin is using an 'int' instead.
     132        int needsXEmbed = 0;
     133        plugin.NPP_GetValue(NPPVpluginNeedsXEmbed, &needsXEmbed);
     134        if (needsXEmbed) {
     135            windowID = plugin.controller()->createPluginContainer();
     136            if (!windowID)
     137                return nullptr;
     138        } else {
     139            notImplemented();
     140            return nullptr;
     141        }
     142#else
    126143        notImplemented();
    127         return false;
     144        return nullptr;
     145#endif
    128146    }
    129147
    130     Display* display = x11HostDisplay();
    131 
    132 #if PLATFORM(GTK)
     148    Display* display = getPluginDisplay();
     149    if (!display)
     150        return nullptr;
     151
     152#if PLATFORM(GTK)
     153    if (plugin.isWindowed())
     154        return std::make_unique<NetscapePluginX11>(plugin, display, windowID);
     155#endif
     156
     157    return std::make_unique<NetscapePluginX11>(plugin, display);
     158}
     159
     160NetscapePluginX11::NetscapePluginX11(NetscapePlugin& plugin, Display* display)
     161    : m_plugin(plugin)
     162    , m_pluginDisplay(display)
     163{
     164    Display* hostDisplay = x11HostDisplay();
     165    int depth = displayDepth();
     166    m_setWindowCallbackStruct.display = hostDisplay;
     167    m_setWindowCallbackStruct.depth = depth;
     168
     169    XVisualInfo visualTemplate;
     170    visualTemplate.screen = x11Screen();
     171    visualTemplate.depth = depth;
     172    visualTemplate.c_class = TrueColor;
     173    int numMatching;
     174    XUniquePtr<XVisualInfo> visualInfo(XGetVisualInfo(hostDisplay, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualTemplate, &numMatching));
     175    ASSERT(visualInfo);
     176    Visual* visual = visualInfo.get()[0].visual;
     177    ASSERT(visual);
     178
     179    m_setWindowCallbackStruct.visual = visual;
     180    m_setWindowCallbackStruct.colormap = XCreateColormap(hostDisplay, rootWindowID(), visual, AllocNone);
     181}
     182
     183#if PLATFORM(GTK)
     184NetscapePluginX11::NetscapePluginX11(NetscapePlugin& plugin, Display* display, uint64_t windowID)
     185    : m_plugin(plugin)
     186    , m_pluginDisplay(display)
     187    , m_windowID(windowID)
     188{
    133189    // It seems flash needs the socket to be in the same process,
    134190    // I guess it uses gdk_window_lookup(), so we create a new socket here
     
    147203    gtk_widget_show(socket);
    148204
    149     m_npWindow.window = GINT_TO_POINTER(gtk_socket_get_id(GTK_SOCKET(socket)));
     205    Display* hostDisplay = x11HostDisplay();
     206    m_npWindowID = gtk_socket_get_id(GTK_SOCKET(socket));
    150207    GdkWindow* window = gtk_widget_get_window(socket);
    151     NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info);
    152     callbackStruct->display = GDK_WINDOW_XDISPLAY(window);
    153     callbackStruct->visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window));
    154     callbackStruct->depth = gdk_visual_get_depth(gdk_window_get_visual(window));
    155     callbackStruct->colormap = XCreateColormap(display, GDK_ROOT_WINDOW(), callbackStruct->visual, AllocNone);
    156 #else
    157     UNUSED_PARAM(windowID);
    158 #endif
    159 
    160     XFlush(display);
    161 
    162     callSetWindow();
    163 
    164     return true;
    165 }
    166 
    167 bool NetscapePlugin::platformPostInitializeWindowless()
    168 {
    169     Display* display = x11HostDisplay();
    170     m_npWindow.type = NPWindowTypeDrawable;
    171     m_npWindow.window = 0;
    172 
    173     int depth = displayDepth();
    174 
    175     NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info);
    176     callbackStruct->display = display;
    177     callbackStruct->depth = depth;
    178 
    179     XVisualInfo visualTemplate;
    180     visualTemplate.screen = x11Screen();
    181     visualTemplate.depth = depth;
    182     visualTemplate.c_class = TrueColor;
    183     int numMatching;
    184     XUniquePtr<XVisualInfo> visualInfo(XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualTemplate, &numMatching));
    185     ASSERT(visualInfo);
    186     Visual* visual = visualInfo.get()[0].visual;
    187     ASSERT(visual);
    188 
    189     callbackStruct->visual = visual;
    190     callbackStruct->colormap = XCreateColormap(display, rootWindowID(), visual, AllocNone);
    191 
    192     callSetWindow();
    193 
    194     return true;
    195 }
    196 
    197 void NetscapePlugin::platformPreInitialize()
    198 {
    199 }
    200 
    201 bool NetscapePlugin::platformPostInitialize()
    202 {
    203     uint64_t windowID = 0;
    204     // NPPVpluginNeedsXEmbed is a boolean value, but at least the
    205     // Flash player plugin is using an 'int' instead.
    206     int needsXEmbed = 0;
    207     if (m_isWindowed) {
    208         NPP_GetValue(NPPVpluginNeedsXEmbed, &needsXEmbed);
    209         if (needsXEmbed) {
    210             windowID = controller()->createPluginContainer();
    211             if (!windowID)
    212                 return false;
    213         } else {
    214             notImplemented();
    215             return false;
    216         }
    217     }
    218 
    219     if (!(m_pluginDisplay = getPluginDisplay()))
    220         return false;
    221 
    222     NPSetWindowCallbackStruct* callbackStruct = new NPSetWindowCallbackStruct;
    223     callbackStruct->type = 0;
    224     m_npWindow.ws_info = callbackStruct;
    225 
    226     if (m_isWindowed)
    227         return platformPostInitializeWindowed(needsXEmbed, windowID);
    228 
    229     return platformPostInitializeWindowless();
    230 }
    231 
    232 void NetscapePlugin::platformDestroy()
    233 {
    234     NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info);
    235     Display* hostDisplay = x11HostDisplay();
    236     XFreeColormap(hostDisplay, callbackStruct->colormap);
    237     delete callbackStruct;
     208    m_setWindowCallbackStruct.display = GDK_WINDOW_XDISPLAY(window);
     209    m_setWindowCallbackStruct.visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window));
     210    m_setWindowCallbackStruct.depth = gdk_visual_get_depth(gdk_window_get_visual(window));
     211    m_setWindowCallbackStruct.colormap = XCreateColormap(hostDisplay, GDK_ROOT_WINDOW(), m_setWindowCallbackStruct.visual, AllocNone);
     212
     213    XFlush(hostDisplay);
     214}
     215#endif
     216
     217NetscapePluginX11::~NetscapePluginX11()
     218{
     219    XFreeColormap(x11HostDisplay(), m_setWindowCallbackStruct.colormap);
    238220
    239221    m_drawable.reset();
    240222
    241223#if PLATFORM(GTK)
    242     if (m_platformPluginWidget) {
     224    if (m_platformPluginWidget)
    243225        gtk_widget_destroy(m_platformPluginWidget);
    244         m_platformPluginWidget = 0;
    245     }
    246 #endif
    247 }
    248 
    249 bool NetscapePlugin::platformInvalidate(const IntRect&)
    250 {
    251     notImplemented();
    252     return false;
    253 }
    254 
    255 void NetscapePlugin::platformGeometryDidChange()
    256 {
    257     if (m_isWindowed) {
     226#endif
     227}
     228
     229NPWindowType NetscapePluginX11::windowType() const
     230{
     231    return m_plugin.isWindowed() ? NPWindowTypeWindow : NPWindowTypeDrawable;
     232}
     233
     234void* NetscapePluginX11::window() const
     235{
     236#if PLATFORM(GTK)
     237    return m_plugin.isWindowed() ? GINT_TO_POINTER(m_npWindowID) : nullptr;
     238#else
     239    return nullptr;
     240#endif
     241}
     242
     243void NetscapePluginX11::geometryDidChange()
     244{
     245    if (m_plugin.isWindowed()) {
    258246        uint64_t windowID = 0;
    259247#if PLATFORM(GTK)
    260248        windowID = static_cast<uint64_t>(GDK_WINDOW_XID(gtk_plug_get_socket_window(GTK_PLUG(m_platformPluginWidget))));
    261249#endif
    262         controller()->windowedPluginGeometryDidChange(m_frameRectInWindowCoordinates, m_clipRect, windowID);
     250        m_plugin.controller()->windowedPluginGeometryDidChange(m_plugin.frameRectInWindowCoordinates(), m_plugin.clipRect(), windowID);
    263251        return;
    264252    }
    265253
    266254    m_drawable.reset();
    267     if (m_pluginSize.isEmpty())
     255    if (m_plugin.size().isEmpty())
    268256        return;
    269257
    270     m_drawable = XCreatePixmap(x11HostDisplay(), rootWindowID(), m_pluginSize.width(), m_pluginSize.height(), displayDepth());
     258    m_drawable = XCreatePixmap(x11HostDisplay(), rootWindowID(), m_plugin.size().width(), m_plugin.size().height(), displayDepth());
    271259    XSync(x11HostDisplay(), false); // Make sure that the server knows about the Drawable.
    272260}
    273261
    274 void NetscapePlugin::platformVisibilityDidChange()
    275 {
    276     if (!m_isWindowed)
    277         return;
    278 
     262void NetscapePluginX11::visibilityDidChange()
     263{
     264    ASSERT(m_plugin.isWindowed());
    279265    uint64_t windowID = 0;
    280266#if PLATFORM(GTK)
    281267    windowID = static_cast<uint64_t>(GDK_WINDOW_XID(gtk_plug_get_socket_window(GTK_PLUG(m_platformPluginWidget))));
    282268#endif
    283     controller()->windowedPluginVisibilityDidChange(m_isVisible, windowID);
    284     controller()->windowedPluginGeometryDidChange(m_frameRectInWindowCoordinates, m_clipRect, windowID);
    285 }
    286 
    287 void NetscapePlugin::platformPaint(GraphicsContext& context, const IntRect& dirtyRect, bool /*isSnapshot*/)
    288 {
    289     if (m_isWindowed)
    290         return;
    291 
    292     if (!m_isStarted) {
    293         // FIXME: we should paint a missing plugin icon.
    294         return;
    295     }
     269    m_plugin.controller()->windowedPluginVisibilityDidChange(m_plugin.isVisible(), windowID);
     270    m_plugin.controller()->windowedPluginGeometryDidChange(m_plugin.frameRectInWindowCoordinates(), m_plugin.clipRect(), windowID);
     271}
     272
     273void NetscapePluginX11::paint(GraphicsContext& context, const IntRect& dirtyRect)
     274{
     275    ASSERT(m_plugin.isWindowed());
    296276
    297277    if (context.paintingDisabled() || !m_drawable)
     
    314294    exposeEvent.height = exposedRect.height();
    315295
    316     NPP_HandleEvent(&xevent);
     296    m_plugin.NPP_HandleEvent(&xevent);
    317297
    318298    if (m_pluginDisplay != x11HostDisplay())
     
    321301#if PLATFORM(GTK) || (PLATFORM(EFL) && USE(CAIRO))
    322302    RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(m_pluginDisplay, m_drawable.get(),
    323         static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info)->visual, m_pluginSize.width(), m_pluginSize.height()));
     303        m_setWindowCallbackStruct.visual, m_plugin.size().width(), m_plugin.size().height()));
    324304    cairo_t* cr = context.platformContext()->cr();
    325305    cairo_save(cr);
     
    343323    event.xany.serial = 0;
    344324    event.xany.send_event = false;
    345     event.xany.display = NetscapePlugin::x11HostDisplay();
     325    event.xany.display = x11HostDisplay();
    346326    event.xany.window = 0;
    347327}
     
    441421}
    442422
    443 bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent& event)
    444 {
    445     if (m_isWindowed)
    446         return false;
    447 
    448     if ((event.type() == WebEvent::MouseDown || event.type() == WebEvent::MouseUp)
    449          && event.button() == WebMouseEvent::RightButton
    450          && quirks().contains(PluginQuirks::IgnoreRightClickInWindowlessMode))
    451         return false;
     423bool NetscapePluginX11::handleMouseEvent(const WebMouseEvent& event)
     424{
     425    ASSERT(m_plugin.isWindowed());
    452426
    453427    XEvent xEvent;
     
    457431    case WebEvent::MouseDown:
    458432    case WebEvent::MouseUp:
    459         setXButtonEventFields(xEvent, event, convertToRootView(IntPoint()));
     433        setXButtonEventFields(xEvent, event, m_plugin.convertToRootView(IntPoint()));
    460434        break;
    461435    case WebEvent::MouseMove:
    462         setXMotionEventFields(xEvent, event, convertToRootView(IntPoint()));
     436        setXMotionEventFields(xEvent, event, m_plugin.convertToRootView(IntPoint()));
    463437        break;
    464438    case WebEvent::MouseForceChanged:
     
    480454    }
    481455
    482     return !NPP_HandleEvent(&xEvent);
     456    return !m_plugin.NPP_HandleEvent(&xEvent);
    483457}
    484458
     
    490464const int kFocusOutType = 10;
    491465
    492 bool NetscapePlugin::platformHandleWheelEvent(const WebWheelEvent& event)
    493 {
    494     if (m_isWindowed)
    495         return false;
     466bool NetscapePluginX11::handleWheelEvent(const WebWheelEvent& event)
     467{
     468    ASSERT(m_plugin.isWindowed());
    496469
    497470    XEvent xEvent;
    498471    initializeXEvent(xEvent);
    499     setXButtonEventFieldsByWebWheelEvent(xEvent, event, convertToRootView(IntPoint()));
    500 
    501     return !NPP_HandleEvent(&xEvent);
    502 }
    503 
    504 void NetscapePlugin::platformSetFocus(bool focusIn)
    505 {
    506     if (m_isWindowed)
    507         return;
     472    setXButtonEventFieldsByWebWheelEvent(xEvent, event, m_plugin.convertToRootView(IntPoint()));
     473
     474    return !m_plugin.NPP_HandleEvent(&xEvent);
     475}
     476
     477void NetscapePluginX11::setFocus(bool focusIn)
     478{
     479    ASSERT(m_plugin.isWindowed());
    508480
    509481    XEvent xEvent;
     
    514486    focusEvent.detail = NotifyDetailNone;
    515487
    516     NPP_HandleEvent(&xEvent);
    517 }
    518 
    519 bool NetscapePlugin::wantsPluginRelativeNPWindowCoordinates()
    520 {
    521     return true;
    522 }
    523 
    524 bool NetscapePlugin::platformHandleMouseEnterEvent(const WebMouseEvent& event)
    525 {
    526     if (m_isWindowed)
    527         return false;
     488    m_plugin.NPP_HandleEvent(&xEvent);
     489}
     490
     491bool NetscapePluginX11::handleMouseEnterEvent(const WebMouseEvent& event)
     492{
     493    ASSERT(m_plugin.isWindowed());
    528494
    529495    XEvent xEvent;
    530496    initializeXEvent(xEvent);
    531     setXCrossingEventFields(xEvent, event, convertToRootView(IntPoint()), EnterNotify);
    532 
    533     return !NPP_HandleEvent(&xEvent);
    534 }
    535 
    536 bool NetscapePlugin::platformHandleMouseLeaveEvent(const WebMouseEvent& event)
    537 {
    538     if (m_isWindowed)
    539         return false;
     497    setXCrossingEventFields(xEvent, event, m_plugin.convertToRootView(IntPoint()), EnterNotify);
     498
     499    return !m_plugin.NPP_HandleEvent(&xEvent);
     500}
     501
     502bool NetscapePluginX11::handleMouseLeaveEvent(const WebMouseEvent& event)
     503{
     504    ASSERT(m_plugin.isWindowed());
    540505
    541506    XEvent xEvent;
    542507    initializeXEvent(xEvent);
    543     setXCrossingEventFields(xEvent, event, convertToRootView(IntPoint()), LeaveNotify);
    544 
    545     return !NPP_HandleEvent(&xEvent);
     508    setXCrossingEventFields(xEvent, event, m_plugin.convertToRootView(IntPoint()), LeaveNotify);
     509
     510    return !m_plugin.NPP_HandleEvent(&xEvent);
    546511}
    547512
     
    566531}
    567532
    568 bool NetscapePlugin::platformHandleKeyboardEvent(const WebKeyboardEvent& event)
    569 {
     533bool NetscapePluginX11::handleKeyboardEvent(const WebKeyboardEvent& event)
     534{
     535    ASSERT(m_plugin.isWindowed());
    570536    // We don't generate other types of keyboard events via WebEventFactory.
    571537    ASSERT(event.type() == WebEvent::KeyDown || event.type() == WebEvent::KeyUp);
     
    575541    setXKeyEventFields(xEvent, event);
    576542
    577     return !NPP_HandleEvent(&xEvent);
     543    return !m_plugin.NPP_HandleEvent(&xEvent);
    578544}
    579545
Note: See TracChangeset for help on using the changeset viewer.