1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 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#ifndef PluginControllerProxy_h 27#define PluginControllerProxy_h 28 29#if ENABLE(NETSCAPE_PLUGIN_API) 30 31#include "Connection.h" 32#include "Plugin.h" 33#include "PluginController.h" 34#include "PluginControllerProxyMessages.h" 35#include "ShareableBitmap.h" 36#include "WebProcessConnectionMessages.h" 37#include <WebCore/SecurityOrigin.h> 38#include <wtf/Noncopyable.h> 39#include <wtf/RunLoop.h> 40 41namespace IPC { 42 class DataReference; 43} 44 45namespace WebKit { 46 47class LayerHostingContext; 48class ShareableBitmap; 49class WebProcessConnection; 50struct PluginCreationParameters; 51 52class PluginControllerProxy : PluginController { 53 WTF_MAKE_NONCOPYABLE(PluginControllerProxy); 54 55public: 56 PluginControllerProxy(WebProcessConnection*, const PluginCreationParameters&); 57 ~PluginControllerProxy(); 58 59 uint64_t pluginInstanceID() const { return m_pluginInstanceID; } 60 61 bool initialize(const PluginCreationParameters&); 62 void destroy(); 63 64 void didReceivePluginControllerProxyMessage(IPC::Connection*, IPC::MessageDecoder&); 65 void didReceiveSyncPluginControllerProxyMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&); 66 67 bool wantsWheelEvents() const; 68 69#if PLATFORM(COCOA) 70 uint32_t remoteLayerClientID() const; 71#endif 72 73 PluginController* asPluginController() { return this; } 74 75 bool isInitializing() const { return m_isInitializing; } 76 77 void setInitializationReply(PassRefPtr<Messages::WebProcessConnection::CreatePlugin::DelayedReply>); 78 PassRefPtr<Messages::WebProcessConnection::CreatePlugin::DelayedReply> takeInitializationReply(); 79 80private: 81 void startPaintTimer(); 82 void paint(); 83 84 // PluginController 85 virtual bool isPluginVisible() override; 86 virtual void invalidate(const WebCore::IntRect&) override; 87 virtual String userAgent() override; 88 virtual void loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target, const WebCore::HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups) override; 89 virtual void cancelStreamLoad(uint64_t streamID) override; 90 virtual void cancelManualStreamLoad() override; 91 virtual NPObject* windowScriptNPObject() override; 92 virtual NPObject* pluginElementNPObject() override; 93 virtual bool evaluate(NPObject*, const String& scriptString, NPVariant* result, bool allowPopups) override; 94 virtual void setStatusbarText(const String&) override; 95 virtual bool isAcceleratedCompositingEnabled() override; 96 virtual void pluginProcessCrashed() override; 97 virtual void willSendEventToPlugin() override; 98 virtual void didInitializePlugin() override; 99 virtual void didFailToInitializePlugin() override; 100 101#if PLATFORM(COCOA) 102 virtual void pluginFocusOrWindowFocusChanged(bool) override; 103 virtual void setComplexTextInputState(PluginComplexTextInputState) override; 104 virtual mach_port_t compositingRenderServerPort() override; 105 virtual void openPluginPreferencePane() override; 106#endif 107 108 virtual float contentsScaleFactor() override; 109 virtual String proxiesForURL(const String&) override; 110 virtual String cookiesForURL(const String&) override; 111 virtual void setCookiesForURL(const String& urlString, const String& cookieString) override; 112 virtual bool isPrivateBrowsingEnabled() override; 113 virtual bool getAuthenticationInfo(const WebCore::ProtectionSpace&, String& username, String& password) override; 114 virtual void protectPluginFromDestruction() override; 115 virtual void unprotectPluginFromDestruction() override; 116#if PLUGIN_ARCHITECTURE(X11) 117 virtual uint64_t createPluginContainer() override; 118 virtual void windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID) override; 119 virtual void windowedPluginVisibilityDidChange(bool isVisible, uint64_t windowID) override; 120#endif 121 122 // Message handlers. 123 void frameDidFinishLoading(uint64_t requestID); 124 void frameDidFail(uint64_t requestID, bool wasCancelled); 125 void geometryDidChange(const WebCore::IntSize& pluginSize, const WebCore::IntRect& clipRect, const WebCore::AffineTransform& pluginToRootViewTransform, float contentsScaleFactor, const ShareableBitmap::Handle& backingStoreHandle); 126 void visibilityDidChange(bool isVisible); 127 void didEvaluateJavaScript(uint64_t requestID, const String& result); 128 void streamDidReceiveResponse(uint64_t streamID, const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers); 129 void streamDidReceiveData(uint64_t streamID, const IPC::DataReference& data); 130 void streamDidFinishLoading(uint64_t streamID); 131 void streamDidFail(uint64_t streamID, bool wasCancelled); 132 void manualStreamDidReceiveResponse(const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers); 133 void manualStreamDidReceiveData(const IPC::DataReference& data); 134 void manualStreamDidFinishLoading(); 135 void manualStreamDidFail(bool wasCancelled); 136 void handleMouseEvent(const WebMouseEvent&, PassRefPtr<Messages::PluginControllerProxy::HandleMouseEvent::DelayedReply>); 137 void handleWheelEvent(const WebWheelEvent&, bool& handled); 138 void handleMouseEnterEvent(const WebMouseEvent&, bool& handled); 139 void handleMouseLeaveEvent(const WebMouseEvent&, bool& handled); 140 void handleKeyboardEvent(const WebKeyboardEvent&, bool& handled); 141 void handleEditingCommand(const String&, const String&, bool&); 142 void isEditingCommandEnabled(const String&, bool&); 143 void handlesPageScaleFactor(bool&); 144 void paintEntirePlugin(); 145 void supportsSnapshotting(bool&); 146 void snapshot(ShareableBitmap::Handle& backingStoreHandle); 147 void setFocus(bool); 148 void didUpdate(); 149 void getPluginScriptableNPObject(uint64_t& pluginScriptableNPObjectID); 150 151#if PLATFORM(COCOA) 152 void windowFocusChanged(bool); 153 void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates); 154 void windowVisibilityChanged(bool); 155 void sendComplexTextInput(const String& textInput); 156 void setLayerHostingMode(uint32_t); 157 158 void updateLayerHostingContext(LayerHostingMode); 159#endif 160 161 void storageBlockingStateChanged(bool); 162 void privateBrowsingStateChanged(bool); 163 void getFormValue(bool& returnValue, String& formValue); 164 165 void platformInitialize(const PluginCreationParameters&); 166 void platformDestroy(); 167 void platformGeometryDidChange(); 168 169 WebProcessConnection* m_connection; 170 uint64_t m_pluginInstanceID; 171 172 String m_userAgent; 173 bool m_storageBlockingEnabled; 174 bool m_isPrivateBrowsingEnabled; 175 bool m_isAcceleratedCompositingEnabled; 176 bool m_isInitializing; 177 178 RefPtr<Messages::WebProcessConnection::CreatePlugin::DelayedReply> m_initializationReply; 179 180 RefPtr<Plugin> m_plugin; 181 182 WebCore::IntSize m_pluginSize; 183 184 // The dirty rect in plug-in coordinates. 185 WebCore::IntRect m_dirtyRect; 186 187 // The paint timer, used for coalescing painting. 188 RunLoop::Timer<PluginControllerProxy> m_paintTimer; 189 190 // A counter used to prevent the plug-in from being destroyed. 191 unsigned m_pluginDestructionProtectCount; 192 193 // A timer that we use to prevent destruction of the plug-in while plug-in 194 // code is on the stack. 195 RunLoop::Timer<PluginControllerProxy> m_pluginDestroyTimer; 196 197 // Whether we're waiting for the plug-in proxy in the web process to draw the contents of its 198 // backing store into the web process backing store. 199 bool m_waitingForDidUpdate; 200 201 // Whether the plug-in has canceled the manual stream load. 202 bool m_pluginCanceledManualStreamLoad; 203 204#if PLATFORM(COCOA) 205 // Whether complex text input is enabled for this plug-in. 206 bool m_isComplexTextInputEnabled; 207 208 // For CA plug-ins, this holds the information needed to export the layer hierarchy to the UI process. 209 std::unique_ptr<LayerHostingContext> m_layerHostingContext; 210#endif 211 212 // The contents scale factor of this plug-in. 213 float m_contentsScaleFactor; 214 215 // The backing store that this plug-in draws into. 216 RefPtr<ShareableBitmap> m_backingStore; 217 218 // The window NPObject. 219 NPObject* m_windowNPObject; 220 221 // The plug-in element NPObject. 222 NPObject* m_pluginElementNPObject; 223}; 224 225} // namespace WebKit 226 227#endif // ENABLE(NETSCAPE_PLUGIN_API) 228 229#endif // PluginControllerProxy_h 230