1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_DELEGATE_IMPL_H_
#define CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_DELEGATE_IMPL_H_
#include <map>
#include <set>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/id_map.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "content/public/renderer/render_view_observer.h"
#include "content/renderer/mouse_lock_dispatcher.h"
#include "content/renderer/pepper/pepper_parent_context_provider.h"
#include "content/renderer/render_view_pepper_helper.h"
#include "ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h"
#include "ppapi/shared_impl/private/tcp_socket_private_impl.h"
#include "ui/base/ime/text_input_type.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
namespace base {
class FilePath;
}
namespace IPC {
struct ChannelHandle;
}
namespace ppapi {
class PepperFilePath;
class PPB_X509Certificate_Fields;
class PpapiPermissions;
}
namespace webkit {
struct WebPluginInfo;
namespace ppapi {
class PluginInstance;
class PluginModule;
}
}
namespace WebKit {
class WebGamepads;
struct WebCompositionUnderline;
}
namespace content {
class ContextProviderCommandBuffer;
class GamepadSharedMemoryReader;
class PepperBrokerImpl;
class PepperDeviceEnumerationEventHandler;
class RenderViewImpl;
class PepperPluginDelegateImpl
: public webkit::ppapi::PluginDelegate,
public RenderViewPepperHelper,
public base::SupportsWeakPtr<PepperPluginDelegateImpl>,
public PepperParentContextProvider,
public RenderViewObserver {
public:
explicit PepperPluginDelegateImpl(RenderViewImpl* render_view);
virtual ~PepperPluginDelegateImpl();
RenderViewImpl* render_view() { return render_view_; }
// Sets up the renderer host and out-of-process proxy for an external plugin
// module. Returns the renderer host, or NULL if it couldn't be created.
RendererPpapiHost* CreateExternalPluginModule(
scoped_refptr<webkit::ppapi::PluginModule> module,
const base::FilePath& path,
ppapi::PpapiPermissions permissions,
const IPC::ChannelHandle& channel_handle,
base::ProcessId plugin_pid,
int plugin_child_id);
// Removes broker from pending_connect_broker_ if present. Returns true if so.
bool StopWaitingForBrokerConnection(PepperBrokerImpl* broker);
CONTENT_EXPORT int GetRoutingID() const;
typedef base::Callback<void (int /* request_id */,
bool /* succeeded */,
const std::string& /* label */)>
OpenDeviceCallback;
// Opens the specified device. The request ID passed into the callback will be
// the same as the return value. If successful, the label passed into the
// callback identifies a audio/video steam, which can be used to call
// CloseDevice() and GetSesssionID().
int OpenDevice(PP_DeviceType_Dev type,
const std::string& device_id,
const OpenDeviceCallback& callback);
void CloseDevice(const std::string& label);
// Gets audio/video session ID given a label.
int GetSessionID(PP_DeviceType_Dev type, const std::string& label);
private:
// RenderViewPepperHelper implementation.
virtual WebKit::WebPlugin* CreatePepperWebPlugin(
const webkit::WebPluginInfo& webplugin_info,
const WebKit::WebPluginParams& params) OVERRIDE;
virtual void ViewWillInitiatePaint() OVERRIDE;
virtual void ViewInitiatedPaint() OVERRIDE;
virtual void ViewFlushedPaint() OVERRIDE;
virtual webkit::ppapi::PluginInstance* GetBitmapForOptimizedPluginPaint(
const gfx::Rect& paint_bounds,
TransportDIB** dib,
gfx::Rect* location,
gfx::Rect* clip,
float* scale_factor) OVERRIDE;
virtual void OnAsyncFileOpened(base::PlatformFileError error_code,
base::PlatformFile file,
int message_id) OVERRIDE;
virtual void OnPpapiBrokerChannelCreated(
int request_id,
base::ProcessId broker_pid,
const IPC::ChannelHandle& handle) OVERRIDE;
virtual void OnPpapiBrokerPermissionResult(int request_id,
bool result) OVERRIDE;
virtual void OnSetFocus(bool has_focus) OVERRIDE;
virtual void PageVisibilityChanged(bool is_visible) OVERRIDE;
virtual bool IsPluginFocused() const OVERRIDE;
virtual gfx::Rect GetCaretBounds() const OVERRIDE;
virtual ui::TextInputType GetTextInputType() const OVERRIDE;
virtual bool IsPluginAcceptingCompositionEvents() const OVERRIDE;
virtual bool CanComposeInline() const OVERRIDE;
virtual void GetSurroundingText(string16* text,
ui::Range* range) const OVERRIDE;
virtual void OnImeSetComposition(
const string16& text,
const std::vector<WebKit::WebCompositionUnderline>& underlines,
int selection_start,
int selection_end) OVERRIDE;
virtual void OnImeConfirmComposition(const string16& text) OVERRIDE;
virtual void WillHandleMouseEvent() OVERRIDE;
// PluginDelegate implementation.
virtual void PluginFocusChanged(webkit::ppapi::PluginInstance* instance,
bool focused) OVERRIDE;
virtual void PluginTextInputTypeChanged(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual void PluginCaretPositionChanged(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual void PluginRequestedCancelComposition(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual void PluginSelectionChanged(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual void SimulateImeSetComposition(
const string16& text,
const std::vector<WebKit::WebCompositionUnderline>& underlines,
int selection_start,
int selection_end) OVERRIDE;
virtual void SimulateImeConfirmComposition(const string16& text) OVERRIDE;
virtual void PluginCrashed(webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual void InstanceCreated(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual void InstanceDeleted(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>
CreateResourceCreationAPI(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual SkBitmap* GetSadPluginBitmap() OVERRIDE;
virtual WebKit::WebPlugin* CreatePluginReplacement(
const base::FilePath& file_path) OVERRIDE;
virtual uint32_t GetAudioHardwareOutputSampleRate() OVERRIDE;
virtual uint32_t GetAudioHardwareOutputBufferSize() OVERRIDE;
virtual PlatformAudioOutput* CreateAudioOutput(
uint32_t sample_rate,
uint32_t sample_count,
PlatformAudioOutputClient* client) OVERRIDE;
virtual PlatformAudioInput* CreateAudioInput(
const std::string& device_id,
uint32_t sample_rate,
uint32_t sample_count,
PlatformAudioInputClient* client) OVERRIDE;
virtual PlatformImage2D* CreateImage2D(int width, int height) OVERRIDE;
virtual PlatformGraphics2D* GetGraphics2D(
webkit::ppapi::PluginInstance* instance,
PP_Resource resource) OVERRIDE;
virtual PlatformContext3D* CreateContext3D() OVERRIDE;
virtual void ReparentContext(PlatformContext3D*) OVERRIDE;
virtual PlatformVideoCapture* CreateVideoCapture(
const std::string& device_id,
PlatformVideoCaptureEventHandler* handler) OVERRIDE;
virtual PlatformVideoDecoder* CreateVideoDecoder(
media::VideoDecodeAccelerator::Client* client,
int32 command_buffer_route_id) OVERRIDE;
virtual Broker* ConnectToBroker(
webkit::ppapi::PPB_Broker_Impl* client) OVERRIDE;
virtual void NumberOfFindResultsChanged(int identifier,
int total,
bool final_result) OVERRIDE;
virtual void SelectedFindResultChanged(int identifier, int index) OVERRIDE;
virtual bool AsyncOpenFile(const base::FilePath& path,
int flags,
const AsyncOpenFileCallback& callback) OVERRIDE;
virtual bool AsyncOpenFileSystemURL(
const GURL& path,
int flags,
const AsyncOpenFileSystemURLCallback& callback) OVERRIDE;
virtual bool OpenFileSystem(
const GURL& origin_url,
fileapi::FileSystemType type,
long long size,
fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
virtual bool MakeDirectory(
const GURL& path,
bool recursive,
fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
virtual bool Query(
const GURL& path,
fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
virtual bool Touch(
const GURL& path,
const base::Time& last_access_time,
const base::Time& last_modified_time,
fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
virtual bool SetLength(
const GURL& path,
int64_t length,
fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
virtual bool Delete(
const GURL& path,
fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
virtual bool Rename(
const GURL& file_path,
const GURL& new_file_path,
fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
virtual bool ReadDirectory(
const GURL& directory_path,
fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
virtual void QueryAvailableSpace(
const GURL& origin,
quota::StorageType type,
const AvailableSpaceCallback& callback) OVERRIDE;
virtual void WillUpdateFile(const GURL& file_path) OVERRIDE;
virtual void DidUpdateFile(const GURL& file_path, int64_t delta) OVERRIDE;
virtual void SyncGetFileSystemPlatformPath(
const GURL& url,
base::FilePath* platform_path) OVERRIDE;
virtual scoped_refptr<base::MessageLoopProxy>
GetFileThreadMessageLoopProxy() OVERRIDE;
virtual uint32 TCPSocketCreate() OVERRIDE;
virtual void TCPSocketConnect(
webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
uint32 socket_id,
const std::string& host,
uint16_t port) OVERRIDE;
virtual void TCPSocketConnectWithNetAddress(
webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
uint32 socket_id,
const PP_NetAddress_Private& addr) OVERRIDE;
virtual void TCPSocketSSLHandshake(
uint32 socket_id,
const std::string& server_name,
uint16_t server_port,
const std::vector<std::vector<char> >& trusted_certs,
const std::vector<std::vector<char> >& untrusted_certs) OVERRIDE;
virtual void TCPSocketRead(uint32 socket_id, int32_t bytes_to_read) OVERRIDE;
virtual void TCPSocketWrite(uint32 socket_id,
const std::string& buffer) OVERRIDE;
virtual void TCPSocketDisconnect(uint32 socket_id) OVERRIDE;
virtual void TCPSocketSetBoolOption(uint32 socket_id,
PP_TCPSocketOption_Private name,
bool value) OVERRIDE;
virtual void RegisterTCPSocket(
webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
uint32 socket_id) OVERRIDE;
virtual void TCPServerSocketListen(
PP_Resource socket_resource,
const PP_NetAddress_Private& addr,
int32_t backlog) OVERRIDE;
virtual void TCPServerSocketAccept(uint32 server_socket_id) OVERRIDE;
virtual void TCPServerSocketStopListening(
PP_Resource socket_resource,
uint32 socket_id) OVERRIDE;
virtual bool AddNetworkListObserver(
webkit_glue::NetworkListObserver* observer) OVERRIDE;
virtual void RemoveNetworkListObserver(
webkit_glue::NetworkListObserver* observer) OVERRIDE;
virtual bool X509CertificateParseDER(
const std::vector<char>& der,
ppapi::PPB_X509Certificate_Fields* fields) OVERRIDE;
virtual webkit::ppapi::FullscreenContainer*
CreateFullscreenContainer(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual gfx::Size GetScreenSize() OVERRIDE;
virtual std::string GetDefaultEncoding() OVERRIDE;
virtual void ZoomLimitsChanged(double minimum_factor, double maximum_factor)
OVERRIDE;
virtual void DidStartLoading() OVERRIDE;
virtual void DidStopLoading() OVERRIDE;
virtual void SetContentRestriction(int restrictions) OVERRIDE;
virtual void SaveURLAs(const GURL& url) OVERRIDE;
virtual base::SharedMemory* CreateAnonymousSharedMemory(size_t size)
OVERRIDE;
virtual ::ppapi::Preferences GetPreferences() OVERRIDE;
virtual bool LockMouse(webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual void UnlockMouse(webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual bool IsMouseLocked(webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual void DidChangeCursor(webkit::ppapi::PluginInstance* instance,
const WebKit::WebCursorInfo& cursor) OVERRIDE;
virtual void DidReceiveMouseEvent(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual bool IsInFullscreenMode() OVERRIDE;
virtual void SampleGamepads(WebKit::WebGamepads* data) OVERRIDE;
virtual bool IsPageVisible() const OVERRIDE;
virtual int EnumerateDevices(
PP_DeviceType_Dev type,
const EnumerateDevicesCallback& callback) OVERRIDE;
virtual void StopEnumerateDevices(int request_id) OVERRIDE;
// RenderViewObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnDestruct() OVERRIDE;
void OnTCPSocketConnectACK(uint32 plugin_dispatcher_id,
uint32 socket_id,
bool succeeded,
const PP_NetAddress_Private& local_addr,
const PP_NetAddress_Private& remote_addr);
void OnTCPSocketSSLHandshakeACK(
uint32 plugin_dispatcher_id,
uint32 socket_id,
bool succeeded,
const ppapi::PPB_X509Certificate_Fields& certificate_fields);
void OnTCPSocketReadACK(uint32 plugin_dispatcher_id,
uint32 socket_id,
bool succeeded,
const std::string& data);
void OnTCPSocketWriteACK(uint32 plugin_dispatcher_id,
uint32 socket_id,
bool succeeded,
int32_t bytes_written);
void OnTCPSocketSetBoolOptionACK(uint32 plugin_dispatcher_id,
uint32 socket_id,
bool succeeded);
void OnTCPServerSocketListenACK(uint32 plugin_dispatcher_id,
PP_Resource socket_resource,
uint32 socket_id,
int32_t status);
void OnTCPServerSocketAcceptACK(uint32 plugin_dispatcher_id,
uint32 socket_id,
uint32 accepted_socket_id,
const PP_NetAddress_Private& local_addr,
const PP_NetAddress_Private& remote_addr);
// Attempts to create a PPAPI plugin for the given filepath. On success, it
// will return the newly-created module.
//
// There are two reasons for failure. The first is that the plugin isn't
// a PPAPI plugin. In this case, |*pepper_plugin_was_registered| will be set
// to false and the caller may want to fall back on creating an NPAPI plugin.
// the second is that the plugin failed to initialize. In this case,
// |*pepper_plugin_was_registered| will be set to true and the caller should
// not fall back on any other plugin types.
scoped_refptr<webkit::ppapi::PluginModule>
CreatePepperPluginModule(
const webkit::WebPluginInfo& webplugin_info,
bool* pepper_plugin_was_registered);
// Asynchronously attempts to create a PPAPI broker for the given plugin.
scoped_refptr<PepperBrokerImpl> CreateBroker(
webkit::ppapi::PluginModule* plugin_module);
// Create a new HostDispatcher for proxying, hook it to the PluginModule,
// and perform other common initialization.
RendererPpapiHost* CreateOutOfProcessModule(
webkit::ppapi::PluginModule* module,
const base::FilePath& path,
ppapi::PpapiPermissions permissions,
const IPC::ChannelHandle& channel_handle,
base::ProcessId plugin_pid,
int plugin_child_id,
bool is_external);
// Implementation of PepperParentContextProvider.
virtual WebGraphicsContext3DCommandBufferImpl*
GetParentContextForPlatformContext3D() OVERRIDE;
MouseLockDispatcher::LockTarget* GetOrCreateLockTargetAdapter(
webkit::ppapi::PluginInstance* instance);
void UnSetAndDeleteLockTargetAdapter(webkit::ppapi::PluginInstance* instance);
MouseLockDispatcher* GetMouseLockDispatcher(
webkit::ppapi::PluginInstance* instance);
// Pointer to the RenderView that owns us.
RenderViewImpl* render_view_;
std::set<webkit::ppapi::PluginInstance*> active_instances_;
typedef std::map<webkit::ppapi::PluginInstance*,
MouseLockDispatcher::LockTarget*> LockTargetMap;
LockTargetMap mouse_lock_instances_;
IDMap<AsyncOpenFileCallback> pending_async_open_files_;
IDMap<webkit::ppapi::PPB_TCPSocket_Private_Impl> tcp_sockets_;
IDMap<ppapi::PPB_TCPServerSocket_Shared> tcp_server_sockets_;
typedef IDMap<scoped_refptr<PepperBrokerImpl>, IDMapOwnPointer> BrokerMap;
BrokerMap pending_connect_broker_;
typedef IDMap<base::WeakPtr<webkit::ppapi::PPB_Broker_Impl> >
PermissionRequestMap;
PermissionRequestMap pending_permission_requests_;
// Whether or not the focus is on a PPAPI plugin
webkit::ppapi::PluginInstance* focused_plugin_;
// Current text input composition text. Empty if no composition is in
// progress.
string16 composition_text_;
// The plugin instance that received the last mouse event. It is set to NULL
// if the last mouse event went to elements other than Pepper plugins.
// |last_mouse_event_target_| is not owned by this class. We can know about
// when it is destroyed via InstanceDeleted().
webkit::ppapi::PluginInstance* last_mouse_event_target_;
scoped_ptr<GamepadSharedMemoryReader> gamepad_shared_memory_reader_;
scoped_ptr<PepperDeviceEnumerationEventHandler>
device_enumeration_event_handler_;
scoped_refptr<ContextProviderCommandBuffer> offscreen_context3d_;
DISALLOW_COPY_AND_ASSIGN(PepperPluginDelegateImpl);
};
} // namespace content
#endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_DELEGATE_IMPL_H_
|