| 1 | /* |
| 2 | * Copyright (C) 2015 Igalia S.L. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "NetscapePluginUnix.h" |
| 28 | |
| 29 | #if PLUGIN_ARCHITECTURE(UNIX) && ENABLE(NETSCAPE_PLUGIN_API) |
| 30 | |
| 31 | #include "NetscapePlugin.h" |
| 32 | #include "WebEvent.h" |
| 33 | #include <WebCore/NotImplemented.h> |
| 34 | #include <WebCore/PlatformDisplay.h> |
| 35 | |
| 36 | #if PLATFORM(X11) |
| 37 | #include "NetscapePluginX11.h" |
| 38 | #endif |
| 39 | |
| 40 | namespace WebKit { |
| 41 | using namespace WebCore; |
| 42 | |
| 43 | void NetscapePlugin::platformPreInitialize() |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | bool NetscapePlugin::platformPostInitialize() |
| 48 | { |
| 49 | #if PLATFORM(X11) |
| 50 | if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11) { |
| 51 | m_impl = NetscapePluginX11::create(*this); |
| 52 | if (!m_impl) |
| 53 | return false; |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | // Windowed plugins need a platform implementation. |
| 58 | if (!m_impl) |
| 59 | return !m_isWindowed; |
| 60 | |
| 61 | m_npWindow.type = m_impl->windowType(); |
| 62 | m_npWindow.window = m_impl->window(); |
| 63 | m_npWindow.ws_info = m_impl->windowSystemInfo(); |
| 64 | callSetWindow(); |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | void NetscapePlugin::platformDestroy() |
| 69 | { |
| 70 | m_impl = nullptr; |
| 71 | } |
| 72 | |
| 73 | bool NetscapePlugin::platformInvalidate(const IntRect&) |
| 74 | { |
| 75 | notImplemented(); |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | void NetscapePlugin::platformGeometryDidChange() |
| 80 | { |
| 81 | if (!m_impl) |
| 82 | return; |
| 83 | m_impl->geometryDidChange(); |
| 84 | } |
| 85 | |
| 86 | void NetscapePlugin::platformVisibilityDidChange() |
| 87 | { |
| 88 | if (!m_isWindowed || !m_impl) |
| 89 | return; |
| 90 | |
| 91 | m_impl->visibilityDidChange(); |
| 92 | } |
| 93 | |
| 94 | void NetscapePlugin::platformPaint(GraphicsContext& context, const IntRect& dirtyRect, bool /*isSnapshot*/) |
| 95 | { |
| 96 | if (m_isWindowed || !m_impl) |
| 97 | return; |
| 98 | |
| 99 | if (!m_isStarted) { |
| 100 | // FIXME: we should paint a missing plugin icon. |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | m_impl->paint(context, dirtyRect); |
| 105 | } |
| 106 | |
| 107 | bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent& event) |
| 108 | { |
| 109 | if (m_isWindowed || !m_impl) |
| 110 | return false; |
| 111 | |
| 112 | #if PLATFORM(X11) |
| 113 | if ((event.type() == WebEvent::MouseDown || event.type() == WebEvent::MouseUp) |
| 114 | && event.button() == WebMouseEvent::RightButton |
| 115 | && quirks().contains(PluginQuirks::IgnoreRightClickInWindowlessMode)) |
| 116 | return false; |
| 117 | #endif |
| 118 | |
| 119 | return m_impl->handleMouseEvent(event); |
| 120 | } |
| 121 | |
| 122 | bool NetscapePlugin::platformHandleWheelEvent(const WebWheelEvent& event) |
| 123 | { |
| 124 | if (m_isWindowed || !m_impl) |
| 125 | return false; |
| 126 | |
| 127 | return m_impl->handleWheelEvent(event); |
| 128 | } |
| 129 | |
| 130 | void NetscapePlugin::platformSetFocus(bool focusIn) |
| 131 | { |
| 132 | if (m_isWindowed || !m_impl) |
| 133 | return; |
| 134 | |
| 135 | m_impl->setFocus(focusIn); |
| 136 | } |
| 137 | |
| 138 | bool NetscapePlugin::wantsPluginRelativeNPWindowCoordinates() |
| 139 | { |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | bool NetscapePlugin::platformHandleMouseEnterEvent(const WebMouseEvent& event) |
| 144 | { |
| 145 | if (m_isWindowed || !m_impl) |
| 146 | return false; |
| 147 | |
| 148 | return m_impl->handleMouseEnterEvent(event); |
| 149 | } |
| 150 | |
| 151 | bool NetscapePlugin::platformHandleMouseLeaveEvent(const WebMouseEvent& event) |
| 152 | { |
| 153 | if (m_isWindowed || !m_impl) |
| 154 | return false; |
| 155 | |
| 156 | return m_impl->handleMouseLeaveEvent(event); |
| 157 | } |
| 158 | |
| 159 | bool NetscapePlugin::platformHandleKeyboardEvent(const WebKeyboardEvent& event) |
| 160 | { |
| 161 | // We don't generate other types of keyboard events via WebEventFactory. |
| 162 | ASSERT(event.type() == WebEvent::KeyDown || event.type() == WebEvent::KeyUp); |
| 163 | |
| 164 | if (m_isWindowed || !m_impl) |
| 165 | return false; |
| 166 | |
| 167 | return m_impl->handleKeyboardEvent(event); |
| 168 | } |
| 169 | |
| 170 | } // namespace WebKit |
| 171 | |
| 172 | #endif // PLUGIN_ARCHITECTURE(UNIX) && ENABLE(NETSCAPE_PLUGIN_API) |
| 173 | |