1/*
2 * Copyright (C) 2010-2018 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#pragma once
27
28#if ENABLE(NETSCAPE_PLUGIN_API)
29
30#include "Connection.h"
31#include "Plugin.h"
32#include "PluginController.h"
33#include "PluginControllerProxyMessages.h"
34#include "ShareableBitmap.h"
35#include "WebProcessConnectionMessages.h"
36#include <WebCore/SecurityOrigin.h>
37#include <WebCore/UserActivity.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::Decoder&);
65 void didReceiveSyncPluginControllerProxyMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
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(Messages::WebProcessConnection::CreatePlugin::DelayedReply&&);
78 Messages::WebProcessConnection::CreatePlugin::DelayedReply takeInitializationReply();
79
80private:
81 void startPaintTimer();
82 void paint();
83
84 // PluginController
85 void invalidate(const WebCore::IntRect&) override;
86 String userAgent() override;
87 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;
88 void continueStreamLoad(uint64_t streamID) override;
89 void cancelStreamLoad(uint64_t streamID) override;
90 void cancelManualStreamLoad() override;
91 NPObject* windowScriptNPObject() override;
92 NPObject* pluginElementNPObject() override;
93 bool evaluate(NPObject*, const String& scriptString, NPVariant* result, bool allowPopups) override;
94 void setPluginIsPlayingAudio(bool) override;
95 void setStatusbarText(const String&) override;
96 bool isAcceleratedCompositingEnabled() override;
97 void pluginProcessCrashed() override;
98 void didInitializePlugin() override;
99 void didFailToInitializePlugin() override;
100
101#if PLATFORM(COCOA)
102 void pluginFocusOrWindowFocusChanged(bool) override;
103 void setComplexTextInputState(PluginComplexTextInputState) override;
104 const WTF::MachSendRight& compositingRenderServerPort() override;
105#endif
106
107 float contentsScaleFactor() override;
108 String proxiesForURL(const String&) override;
109 String cookiesForURL(const String&) override;
110 void setCookiesForURL(const String& urlString, const String& cookieString) override;
111 bool isPrivateBrowsingEnabled() override;
112 bool isMuted() const override { return m_isMuted; }
113 bool getAuthenticationInfo(const WebCore::ProtectionSpace&, String& username, String& password) override;
114 void protectPluginFromDestruction() override;
115 void unprotectPluginFromDestruction() override;
116#if PLATFORM(X11)
117 uint64_t createPluginContainer() override;
118 void windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID) override;
119 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 streamWillSendRequest(uint64_t streamID, const String& requestURLString, const String& redirectResponseURLString, uint32_t redirectResponseStatusCode);
129 void streamDidReceiveResponse(uint64_t streamID, const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers);
130 void streamDidReceiveData(uint64_t streamID, const IPC::DataReference& data);
131 void streamDidFinishLoading(uint64_t streamID);
132 void streamDidFail(uint64_t streamID, bool wasCancelled);
133 void manualStreamDidReceiveResponse(const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers);
134 void manualStreamDidReceiveData(const IPC::DataReference& data);
135 void manualStreamDidFinishLoading();
136 void manualStreamDidFail(bool wasCancelled);
137 void handleMouseEvent(const WebMouseEvent&);
138 void handleWheelEvent(const WebWheelEvent&, CompletionHandler<void(bool handled)>&&);
139 void handleMouseEnterEvent(const WebMouseEvent&, CompletionHandler<void(bool handled)>&&);
140 void handleMouseLeaveEvent(const WebMouseEvent&, CompletionHandler<void(bool handled)>&&);
141 void handleKeyboardEvent(const WebKeyboardEvent&, CompletionHandler<void(bool handled)>&&);
142 void handleEditingCommand(const String&, const String&, CompletionHandler<void(bool handled)>&&);
143 void isEditingCommandEnabled(const String&, CompletionHandler<void(bool)>&&);
144 void handlesPageScaleFactor(CompletionHandler<void(bool)>&&);
145 void requiresUnifiedScaleFactor(CompletionHandler<void(bool)>&&);
146 void paintEntirePlugin(CompletionHandler<void()>&&);
147 void supportsSnapshotting(CompletionHandler<void(bool)>&&);
148 void snapshot(CompletionHandler<void(ShareableBitmap::Handle&&)>);
149 void setFocus(bool);
150 void didUpdate();
151 void getPluginScriptableNPObject(CompletionHandler<void(uint64_t pluginScriptableNPObjectID)>&&);
152
153 void windowFocusChanged(bool);
154 void windowVisibilityChanged(bool);
155 void updateVisibilityActivity();
156
157#if PLATFORM(COCOA)
158 void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
159 void sendComplexTextInput(const String& textInput);
160 void setLayerHostingMode(uint32_t);
161
162 void updateLayerHostingContext(LayerHostingMode);
163#endif
164
165 void storageBlockingStateChanged(bool);
166 void privateBrowsingStateChanged(bool);
167 void mutedStateChanged(bool);
168 void getFormValue(CompletionHandler<void(bool returnValue, String&& formValue)>&&);
169
170 void platformInitialize(const PluginCreationParameters&);
171 void platformDestroy();
172 void platformGeometryDidChange();
173
174 WebProcessConnection* m_connection;
175 uint64_t m_pluginInstanceID;
176
177 String m_userAgent;
178 bool m_storageBlockingEnabled;
179 bool m_isPrivateBrowsingEnabled;
180 bool m_isMuted;
181 bool m_isAcceleratedCompositingEnabled;
182 bool m_isInitializing;
183 bool m_isVisible;
184 bool m_isWindowVisible;
185
186 Messages::WebProcessConnection::CreatePlugin::DelayedReply m_initializationReply;
187
188 RefPtr<Plugin> m_plugin;
189
190 WebCore::IntSize m_pluginSize;
191
192 // The dirty rect in plug-in coordinates.
193 WebCore::IntRect m_dirtyRect;
194
195 // The paint timer, used for coalescing painting.
196 RunLoop::Timer<PluginControllerProxy> m_paintTimer;
197
198 // A counter used to prevent the plug-in from being destroyed.
199 unsigned m_pluginDestructionProtectCount;
200
201 // A timer that we use to prevent destruction of the plug-in while plug-in
202 // code is on the stack.
203 RunLoop::Timer<PluginControllerProxy> m_pluginDestroyTimer;
204
205 // Whether we're waiting for the plug-in proxy in the web process to draw the contents of its
206 // backing store into the web process backing store.
207 bool m_waitingForDidUpdate;
208
209 // Whether the plug-in has canceled the manual stream load.
210 bool m_pluginCanceledManualStreamLoad;
211
212#if PLATFORM(COCOA)
213 // Whether complex text input is enabled for this plug-in.
214 bool m_isComplexTextInputEnabled;
215
216 // For CA plug-ins, this holds the information needed to export the layer hierarchy to the UI process.
217 std::unique_ptr<LayerHostingContext> m_layerHostingContext;
218#endif
219
220 // The contents scale factor of this plug-in.
221 float m_contentsScaleFactor;
222
223 // The backing store that this plug-in draws into.
224 RefPtr<ShareableBitmap> m_backingStore;
225
226 // The window NPObject.
227 NPObject* m_windowNPObject;
228
229 // The plug-in element NPObject.
230 NPObject* m_pluginElementNPObject;
231
232 // Hold an activity when the plugin is visible to prevent throttling.
233 UserActivity m_visiblityActivity;
234};
235
236} // namespace WebKit
237
238#endif // ENABLE(NETSCAPE_PLUGIN_API)
239