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(PLUGIN_PROCESS)
30
31#include "Connection.h"
32#include "Plugin.h"
33#include "PluginController.h"
34#include "PluginControllerProxyMessages.h"
35#include "RunLoop.h"
36#include "ShareableBitmap.h"
37#include <wtf/Noncopyable.h>
38
39#if PLATFORM(MAC)
40#include <wtf/RetainPtr.h>
41
42typedef struct __WKCARemoteLayerClientRef *WKCARemoteLayerClientRef;
43#endif
44
45namespace CoreIPC {
46    class DataReference;
47}
48
49namespace WebKit {
50
51class ShareableBitmap;
52class WebProcessConnection;
53
54class PluginControllerProxy : PluginController {
55    WTF_MAKE_NONCOPYABLE(PluginControllerProxy);
56
57public:
58    static PassOwnPtr<PluginControllerProxy> create(WebProcessConnection* connection, uint64_t pluginInstanceID, const String& userAgent, bool isPrivateBrowsingEnabled, bool isAcceleratedCompositingEnabled);
59    ~PluginControllerProxy();
60
61    uint64_t pluginInstanceID() const { return m_pluginInstanceID; }
62
63    bool initialize(const Plugin::Parameters&);
64    void destroy();
65
66    void didReceivePluginControllerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
67    CoreIPC::SyncReplyMode didReceiveSyncPluginControllerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
68
69#if PLATFORM(MAC)
70    uint32_t remoteLayerClientID() const;
71#endif
72
73    PluginController* asPluginController() { return this; }
74
75private:
76    PluginControllerProxy(WebProcessConnection* connection, uint64_t pluginInstanceID, const String& userAgent, bool isPrivateBrowsingEnabled, bool isAcceleratedCompositingEnabled);
77
78    void startPaintTimer();
79    void paint();
80
81    // PluginController
82    virtual void invalidate(const WebCore::IntRect&);
83    virtual String userAgent();
84    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);
85    virtual void cancelStreamLoad(uint64_t streamID);
86    virtual void cancelManualStreamLoad();
87    virtual NPObject* windowScriptNPObject();
88    virtual NPObject* pluginElementNPObject();
89    virtual bool evaluate(NPObject*, const String& scriptString, NPVariant* result, bool allowPopups);
90    virtual void setStatusbarText(const String&);
91    virtual bool isAcceleratedCompositingEnabled();
92    virtual void pluginProcessCrashed();
93
94#if PLATFORM(MAC)
95    virtual void setComplexTextInputEnabled(bool);
96    virtual mach_port_t compositingRenderServerPort();
97#endif
98
99    virtual String proxiesForURL(const String&);
100    virtual String cookiesForURL(const String&);
101    virtual void setCookiesForURL(const String& urlString, const String& cookieString);
102    virtual bool isPrivateBrowsingEnabled();
103    virtual void protectPluginFromDestruction();
104    virtual void unprotectPluginFromDestruction();
105
106    // Message handlers.
107    void frameDidFinishLoading(uint64_t requestID);
108    void frameDidFail(uint64_t requestID, bool wasCancelled);
109    void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, const ShareableBitmap::Handle& backingStoreHandle);
110    void didEvaluateJavaScript(uint64_t requestID, const String& requestURLString, const String& result);
111    void streamDidReceiveResponse(uint64_t streamID, const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers);
112    void streamDidReceiveData(uint64_t streamID, const CoreIPC::DataReference& data);
113    void streamDidFinishLoading(uint64_t streamID);
114    void streamDidFail(uint64_t streamID, bool wasCancelled);
115    void manualStreamDidReceiveResponse(const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers);
116    void manualStreamDidReceiveData(const CoreIPC::DataReference& data);
117    void manualStreamDidFinishLoading();
118    void manualStreamDidFail(bool wasCancelled);
119    void handleMouseEvent(const WebMouseEvent&, PassRefPtr<Messages::PluginControllerProxy::HandleMouseEvent::DelayedReply>);
120    void handleWheelEvent(const WebWheelEvent&, bool& handled);
121    void handleMouseEnterEvent(const WebMouseEvent&, bool& handled);
122    void handleMouseLeaveEvent(const WebMouseEvent&, bool& handled);
123    void handleKeyboardEvent(const WebKeyboardEvent&, bool& handled);
124    void paintEntirePlugin();
125    void snapshot(ShareableBitmap::Handle& backingStoreHandle);
126    void setFocus(bool);
127    void didUpdate();
128    void getPluginScriptableNPObject(uint64_t& pluginScriptableNPObjectID);
129
130#if PLATFORM(MAC)
131    void windowFocusChanged(bool);
132    void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
133    void windowVisibilityChanged(bool);
134    void sendComplexTextInput(const String& textInput);
135#endif
136
137    void privateBrowsingStateChanged(bool);
138
139    void platformInitialize();
140    void platformDestroy();
141    void platformGeometryDidChange();
142
143    WebProcessConnection* m_connection;
144    uint64_t m_pluginInstanceID;
145
146    String m_userAgent;
147    bool m_isPrivateBrowsingEnabled;
148    bool m_isAcceleratedCompositingEnabled;
149
150    RefPtr<Plugin> m_plugin;
151
152    // The plug-in rect and clip rect in window coordinates.
153    WebCore::IntRect m_frameRect;
154    WebCore::IntRect m_clipRect;
155
156    // The dirty rect in plug-in coordinates.
157    WebCore::IntRect m_dirtyRect;
158
159    // The paint timer, used for coalescing painting.
160    RunLoop::Timer<PluginControllerProxy> m_paintTimer;
161
162    // A counter used to prevent the plug-in from being destroyed.
163    unsigned m_pluginDestructionProtectCount;
164
165    // A timer that we use to prevent destruction of the plug-in while plug-in
166    // code is on the stack.
167    RunLoop::Timer<PluginControllerProxy> m_pluginDestroyTimer;
168
169    // Whether we're waiting for the plug-in proxy in the web process to draw the contents of its
170    // backing store into the web process backing store.
171    bool m_waitingForDidUpdate;
172
173    // Whether the plug-in has canceled the manual stream load.
174    bool m_pluginCanceledManualStreamLoad;
175
176#if PLATFORM(MAC)
177    // Whether complex text input is enabled for this plug-in.
178    bool m_isComplexTextInputEnabled;
179
180    // For CA plug-ins, this holds the information needed to export the layer hierarchy to the UI process.
181    RetainPtr<WKCARemoteLayerClientRef> m_remoteLayerClient;
182#endif
183
184    // The backing store that this plug-in draws into.
185    RefPtr<ShareableBitmap> m_backingStore;
186
187    // The window NPObject.
188    NPObject* m_windowNPObject;
189
190    // The plug-in element NPObject.
191    NPObject* m_pluginElementNPObject;
192};
193
194} // namespace WebKit
195
196#endif // ENABLE(PLUGIN_PROCESS)
197
198#endif // PluginControllerProxy_h
199