Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(658)

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.h

Issue 19744007: Create a public API around webkit::ppapi::PluginInstance and use it in chrome. After this, webkit/p… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_ 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_
6 #define WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_ 6 #define WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_
7 7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h" 8 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 9 #include "base/process/process_handle.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/strings/string16.h"
18 #include "cc/layers/texture_layer_client.h"
19 #include "ppapi/c/dev/pp_cursor_type_dev.h"
20 #include "ppapi/c/dev/ppp_find_dev.h"
21 #include "ppapi/c/dev/ppp_printing_dev.h"
22 #include "ppapi/c/dev/ppp_selection_dev.h"
23 #include "ppapi/c/dev/ppp_text_input_dev.h"
24 #include "ppapi/c/dev/ppp_zoom_dev.h"
25 #include "ppapi/c/pp_completion_callback.h"
26 #include "ppapi/c/pp_instance.h"
27 #include "ppapi/c/pp_resource.h" 10 #include "ppapi/c/pp_resource.h"
28 #include "ppapi/c/pp_time.h" 11 #include "ppapi/c/private/ppb_instance_private.h"
29 #include "ppapi/c/pp_var.h"
30 #include "ppapi/c/ppb_audio_config.h"
31 #include "ppapi/c/ppb_gamepad.h"
32 #include "ppapi/c/ppb_input_event.h"
33 #include "ppapi/c/ppp_graphics_3d.h"
34 #include "ppapi/c/ppp_input_event.h"
35 #include "ppapi/c/ppp_messaging.h"
36 #include "ppapi/c/ppp_mouse_lock.h"
37 #include "ppapi/c/private/ppb_content_decryptor_private.h"
38 #include "ppapi/c/private/ppp_instance_private.h"
39 #include "ppapi/shared_impl/ppb_instance_shared.h"
40 #include "ppapi/shared_impl/ppb_view_shared.h"
41 #include "ppapi/shared_impl/singleton_resource_id.h"
42 #include "ppapi/shared_impl/tracked_callback.h"
43 #include "ppapi/thunk/ppb_gamepad_api.h"
44 #include "ppapi/thunk/resource_creation_api.h"
45 #include "skia/ext/refptr.h"
46 #include "third_party/WebKit/public/platform/WebCanvas.h"
47 #include "third_party/WebKit/public/platform/WebString.h"
48 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
49 #include "third_party/WebKit/public/platform/WebURLResponse.h"
50 #include "third_party/WebKit/public/web/WebPlugin.h"
51 #include "third_party/WebKit/public/web/WebUserGestureToken.h"
52 #include "ui/base/ime/text_input_type.h"
53 #include "ui/gfx/rect.h"
54 #include "url/gurl.h"
55 #include "webkit/plugins/ppapi/plugin_delegate.h"
56 #include "webkit/plugins/ppapi/ppp_pdf.h"
57 #include "webkit/plugins/webkit_plugins_export.h" 12 #include "webkit/plugins/webkit_plugins_export.h"
58 13
59 struct PP_Point; 14 class GURL;
60 struct _NPP;
61 15
62 class SkBitmap; 16 namespace base {
63 class TransportDIB; 17 class FilePath;
64
65 namespace IPC {
66 struct ChannelHandle;
67 }
68
69 namespace WebKit {
70 class WebInputEvent;
71 class WebLayer;
72 class WebMouseEvent;
73 class WebPluginContainer;
74 class WebURLLoader;
75 class WebURLResponse;
76 struct WebCompositionUnderline;
77 struct WebCursorInfo;
78 struct WebURLError;
79 struct WebPrintParams;
80 }
81
82 namespace cc {
83 class TextureLayer;
84 } 18 }
85 19
86 namespace content { 20 namespace content {
87 class RenderView; 21 class RenderView;
88 } 22 }
89 23
90 namespace gfx { 24 namespace gfx {
91 class ImageSkia; 25 class ImageSkia;
26 class Rect;
92 } 27 }
93 28
94 namespace ppapi { 29 namespace ppapi {
95 class PpapiPermissions; 30 class PpapiPermissions;
96 class Resource;
97 class VarTracker; 31 class VarTracker;
98 struct InputEventData;
99 struct PPP_Instance_Combined;
100 struct URLRequestInfoData; 32 struct URLRequestInfoData;
101 } 33 }
102 34
103 namespace ui { 35 namespace IPC {
104 class Range; 36 struct ChannelHandle;
105 } 37 }
106 38
107 namespace v8 { 39 namespace WebKit {
108 class Isolate; 40 class WebPluginContainer;
109 } 41 }
110 42
111 namespace webkit { 43 namespace webkit {
112 namespace ppapi { 44 namespace ppapi {
113 45
114 class ContentDecryptorDelegate; 46 class PluginInstance {
115 class FullscreenContainer; 47 public:
116 class MessageChannel; 48 static WEBKIT_PLUGINS_EXPORT PluginInstance* Get(PP_Instance instance_id);
117 class PluginDelegate;
118 class PluginModule;
119 class PluginObject;
120 class PPB_Graphics3D_Impl;
121 class PPB_ImageData_Impl;
122 class PPB_URLLoader_Impl;
123 49
124 // Represents one time a plugin appears on one web page. 50 virtual ~PluginInstance() {}
125 //
126 // Note: to get from a PP_Instance to a PluginInstance*, use the
127 // ResourceTracker.
128 class WEBKIT_PLUGINS_EXPORT PluginInstance :
129 public base::RefCounted<PluginInstance>,
130 public base::SupportsWeakPtr<PluginInstance>,
131 public ::ppapi::PPB_Instance_Shared {
132 public:
133 // Create and return a PluginInstance object which supports the most recent
134 // version of PPP_Instance possible by querying the given get_plugin_interface
135 // function. If the plugin does not support any valid PPP_Instance interface,
136 // returns NULL.
137 static PluginInstance* Create(PluginDelegate* delegate,
138 content::RenderView* render_view,
139 PluginModule* module,
140 WebKit::WebPluginContainer* container,
141 const GURL& plugin_url);
142 // Delete should be called by the WebPlugin before this destructor.
143 virtual ~PluginInstance();
144 51
145 PluginDelegate* delegate() const { return delegate_; } 52 virtual content::RenderView* GetRenderView() = 0;
146 content::RenderView* render_view() const {return render_view_; }
147 PluginModule* module() const { return module_.get(); }
148 MessageChannel& message_channel() { return *message_channel_; }
149 53
150 WebKit::WebPluginContainer* container() const { return container_; } 54 virtual WebKit::WebPluginContainer* GetContainer() = 0;
151 55
152 void set_always_on_top(bool on_top) { always_on_top_ = on_top; } 56 virtual ::ppapi::VarTracker* GetVarTracker() = 0;
153 57
154 // Returns the PP_Instance uniquely identifying this instance. Guaranteed 58 virtual const GURL& GetPluginURL() = 0;
155 // nonzero.
156 PP_Instance pp_instance() const { return pp_instance_; }
157 59
158 ::ppapi::PPP_Instance_Combined* instance_interface() const { 60 // Returns the location of this module.
159 return instance_interface_.get(); 61 virtual base::FilePath GetModulePath() = 0;
160 }
161 62
162 ::ppapi::thunk::ResourceCreationAPI& resource_creation() { 63 // Returns a reference to a file with the given path.
163 return *resource_creation_.get(); 64 // The returned object will have a refcount of 0 (just like "new").
164 } 65 virtual PP_Resource CreateExternalFileReference(
66 const base::FilePath& external_file_path) = 0;
165 67
166 // Does some pre-destructor cleanup on the instance. This is necessary 68 // Creates a PPB_ImageData given a Skia image.
167 // because some cleanup depends on the plugin instance still existing (like 69 virtual PP_Resource CreateImage(gfx::ImageSkia* source_image,
168 // calling the plugin's DidDestroy function). This function is called from 70 float scale) = 0;
169 // the WebPlugin implementation when WebKit is about to remove the plugin.
170 void Delete();
171 71
172 // Paints the current backing store to the web page. 72 // Switches this instance with one that uses the out of process IPC proxy.
173 void Paint(WebKit::WebCanvas* canvas, 73 virtual PP_ExternalPluginResult SwitchToOutOfProcessProxy(
174 const gfx::Rect& plugin_rect, 74 const base::FilePath& file_path,
175 const gfx::Rect& paint_rect); 75 ::ppapi::PpapiPermissions permissions,
76 const IPC::ChannelHandle& channel_handle,
77 base::ProcessId plugin_pid,
78 int plugin_child_id) = 0;
176 79
177 // Schedules a paint of the page for the given region. The coordinates are 80 // Set this to true if plugin thinks it will always be on top. This allows us
178 // relative to the top-left of the plugin. This does nothing if the plugin 81 // to use a more optimized painting path in some cases.
179 // has not yet been positioned. You can supply an empty gfx::Rect() to 82 virtual void SetAlwaysOnTop(bool on_top) = 0;
180 // invalidate the entire plugin.
181 void InvalidateRect(const gfx::Rect& rect);
182 83
183 // Schedules a scroll of the plugin. This uses optimized scrolling only for 84 // Returns true iff the plugin is a full-page plugin (i.e. not in an iframe
184 // full-frame plugins, as otherwise there could be other elements on top. The 85 // or embedded in a page).
185 // slow path can also be triggered if there is an overlapping frame. 86 virtual bool IsFullPagePlugin() = 0;
186 void ScrollRect(int dx, int dy, const gfx::Rect& rect);
187
188 // Commit the backing texture to the screen once the side effects some
189 // rendering up to an offscreen SwapBuffers are visible.
190 void CommitBackingTexture();
191
192 // Called when the out-of-process plugin implementing this instance crashed.
193 void InstanceCrashed();
194
195 // PPB_Instance and PPB_Instance_Private implementation.
196 const GURL& plugin_url() const { return plugin_url_; }
197 bool full_frame() const { return full_frame_; }
198 const ::ppapi::ViewData& view_data() const { return view_data_; }
199
200 // PPP_Instance and PPP_Instance_Private.
201 bool Initialize(const std::vector<std::string>& arg_names,
202 const std::vector<std::string>& arg_values,
203 bool full_frame);
204 bool HandleDocumentLoad(const WebKit::WebURLResponse& response);
205 bool HandleInputEvent(const WebKit::WebInputEvent& event,
206 WebKit::WebCursorInfo* cursor_info);
207 PP_Var GetInstanceObject();
208 void ViewChanged(const gfx::Rect& position, const gfx::Rect& clip,
209 const std::vector<gfx::Rect>& cut_outs_rects);
210
211 // Handlers for composition events.
212 bool HandleCompositionStart(const base::string16& text);
213 bool HandleCompositionUpdate(
214 const base::string16& text,
215 const std::vector<WebKit::WebCompositionUnderline>& underlines,
216 int selection_start,
217 int selection_end);
218 bool HandleCompositionEnd(const base::string16& text);
219 bool HandleTextInput(const base::string16& text);
220
221 // Gets the current text input status.
222 ui::TextInputType text_input_type() const { return text_input_type_; }
223 gfx::Rect GetCaretBounds() const;
224 bool IsPluginAcceptingCompositionEvents() const;
225 void GetSurroundingText(base::string16* text, ui::Range* range) const;
226
227 // Notifications about focus changes, see has_webkit_focus_ below.
228 void SetWebKitFocus(bool has_focus);
229 void SetContentAreaFocus(bool has_focus);
230
231 // Notification about page visibility. The default is "visible".
232 void PageVisibilityChanged(bool is_visible);
233
234 // Notifications that the view is about to paint, has started painting, and
235 // has flushed the painted content to the screen. These messages are used to
236 // send Flush callbacks to the plugin for DeviceContext2D/3D.
237 void ViewWillInitiatePaint();
238 void ViewInitiatedPaint();
239 void ViewFlushedPaint();
240
241 // If this plugin can be painted merely by copying the backing store to the
242 // screen, and the plugin bounds encloses the given paint bounds, returns
243 // true. In this case, the location, clipping, and ID of the backing store
244 // will be filled into the given output parameters.
245 bool GetBitmapForOptimizedPluginPaint(
246 const gfx::Rect& paint_bounds,
247 TransportDIB** dib,
248 gfx::Rect* dib_bounds,
249 gfx::Rect* clip,
250 float* scale_factor);
251
252 // Tracks all live PluginObjects.
253 void AddPluginObject(PluginObject* plugin_object);
254 void RemovePluginObject(PluginObject* plugin_object);
255
256 base::string16 GetSelectedText(bool html);
257 base::string16 GetLinkAtPosition(const gfx::Point& point);
258 void RequestSurroundingText(size_t desired_number_of_characters);
259 void Zoom(double factor, bool text_only);
260 bool StartFind(const base::string16& search_text,
261 bool case_sensitive,
262 int identifier);
263 void SelectFindResult(bool forward);
264 void StopFind();
265
266 bool SupportsPrintInterface();
267 bool IsPrintScalingDisabled();
268 int PrintBegin(const WebKit::WebPrintParams& print_params);
269 bool PrintPage(int page_number, WebKit::WebCanvas* canvas);
270 void PrintEnd();
271
272 bool CanRotateView();
273 void RotateView(WebKit::WebPlugin::RotationType type);
274
275 // Sets the bound_graphics_2d_platform_ for testing purposes. This is instead
276 // of calling BindGraphics and allows any PlatformGraphics implementation to
277 // be used, not just a resource one.
278 void SetBoundGraphics2DForTest(PluginDelegate::PlatformGraphics2D* graphics);
279
280 // There are 2 implementations of the fullscreen interface
281 // PPB_FlashFullscreen is used by Pepper Flash.
282 // PPB_Fullscreen is intended for other applications including NaCl.
283 // The two interface are mutually exclusive.
284
285 // Implementation of PPB_FlashFullscreen.
286
287 // Because going to fullscreen is asynchronous (but going out is not), there
288 // are 3 states:
289 // - normal : fullscreen_container_ == NULL
290 // flash_fullscreen_ == false
291 // - fullscreen pending: fullscreen_container_ != NULL
292 // flash_fullscreen_ == false
293 // - fullscreen : fullscreen_container_ != NULL
294 // flash_fullscreen_ == true
295 //
296 // In normal state, events come from webkit and painting goes back to it.
297 // In fullscreen state, events come from the fullscreen container, and
298 // painting goes back to it.
299 // In pending state, events from webkit are ignored, and as soon as we
300 // receive events from the fullscreen container, we go to the fullscreen
301 // state.
302 bool FlashIsFullscreenOrPending();
303 87
304 // Switches between fullscreen and normal mode. If |delay_report| is set to 88 // Switches between fullscreen and normal mode. If |delay_report| is set to
305 // false, it may report the new state through DidChangeView immediately. If 89 // false, it may report the new state through DidChangeView immediately. If
306 // true, it will delay it. When called from the plugin, delay_report should 90 // true, it will delay it. When called from the plugin, delay_report should
307 // be true to avoid re-entrancy. 91 // be true to avoid re-entrancy.
308 void FlashSetFullscreen(bool fullscreen, bool delay_report); 92 virtual void FlashSetFullscreen(bool fullscreen, bool delay_report) = 0;
309 93
310 // Updates |flash_fullscreen_| and sends focus change notification if 94 virtual bool IsRectTopmost(const gfx::Rect& rect) = 0;
311 // necessary.
312 void UpdateFlashFullscreenState(bool flash_fullscreen);
313 95
314 FullscreenContainer* fullscreen_container() const { 96 virtual int32_t Navigate(const ::ppapi::URLRequestInfoData& request,
315 return fullscreen_container_; 97 const char* target,
316 } 98 bool from_user_action) = 0;
317 99
318 // Implementation of PPB_Fullscreen.
319
320 // Because going to/from fullscreen is asynchronous, there are 4 states:
321 // - normal : desired_fullscreen_state_ == false
322 // view_data_.is_fullscreen == false
323 // - fullscreen pending: desired_fullscreen_state_ == true
324 // view_data_.is_fullscreen == false
325 // - fullscreen : desired_fullscreen_state_ == true
326 // view_data_.is_fullscreen == true
327 // - normal pending : desired_fullscreen_state_ = false
328 // view_data_.is_fullscreen = true
329 bool IsFullscreenOrPending();
330
331 bool flash_fullscreen() const { return flash_fullscreen_; }
332
333 // Switches between fullscreen and normal mode. The transition is
334 // asynchronous. WebKit will trigger corresponding VewChanged calls.
335 // Returns true on success, false on failure (e.g. trying to enter fullscreen
336 // when not processing a user gesture or trying to set fullscreen when
337 // already in fullscreen mode).
338 bool SetFullscreen(bool fullscreen);
339
340 // Implementation of PPB_Flash.
341 int32_t Navigate(const ::ppapi::URLRequestInfoData& request,
342 const char* target,
343 bool from_user_action);
344 bool IsRectTopmost(const gfx::Rect& rect);
345
346 // Implementation of PPP_Messaging.
347 void HandleMessage(PP_Var message);
348
349 PluginDelegate::PlatformContext3D* CreateContext3D();
350
351 // Returns true iff the plugin is a full-page plugin (i.e. not in an iframe
352 // or embedded in a page).
353 bool IsFullPagePlugin() const;
354
355 // Returns true if the plugin is processing a user gesture.
356 bool IsProcessingUserGesture();
357
358 // Returns the user gesture token to use for creating a WebScopedUserGesture,
359 // if IsProcessingUserGesture returned true.
360 WebKit::WebUserGestureToken CurrentUserGestureToken();
361
362 // A mouse lock request was pending and this reports success or failure.
363 void OnLockMouseACK(bool succeeded);
364 // A mouse lock was in place, but has been lost.
365 void OnMouseLockLost();
366 // A mouse lock is enabled and mouse events are being delivered.
367 void HandleMouseLockedInputEvent(const WebKit::WebMouseEvent& event);
368
369 // Simulates an input event to the plugin by passing it down to WebKit,
370 // which sends it back up to the plugin as if it came from the user.
371 void SimulateInputEvent(const ::ppapi::InputEventData& input_event);
372
373 // Simulates an IME event at the level of RenderView which sends it back up to
374 // the plugin as if it came from the user.
375 bool SimulateIMEEvent(const ::ppapi::InputEventData& input_event);
376 void SimulateImeSetCompositionEvent(
377 const ::ppapi::InputEventData& input_event);
378
379 // The document loader is valid when the plugin is "full-frame" and in this
380 // case is non-NULL as long as the corresponding loader resource is alive.
381 // This pointer is non-owning, so the loader must use set_document_loader to
382 // clear itself when it is destroyed.
383 WebKit::WebURLLoaderClient* document_loader() const {
384 return document_loader_;
385 }
386 void set_document_loader(WebKit::WebURLLoaderClient* loader) {
387 document_loader_ = loader;
388 }
389
390 ContentDecryptorDelegate* GetContentDecryptorDelegate();
391
392 // PPB_Instance_API implementation.
393 virtual PP_Bool BindGraphics(PP_Instance instance,
394 PP_Resource device) OVERRIDE;
395 virtual PP_Bool IsFullFrame(PP_Instance instance) OVERRIDE;
396 virtual const ::ppapi::ViewData* GetViewData(PP_Instance instance) OVERRIDE;
397 virtual PP_Bool FlashIsFullscreen(PP_Instance instance) OVERRIDE;
398 virtual PP_Var GetWindowObject(PP_Instance instance) OVERRIDE;
399 virtual PP_Var GetOwnerElementObject(PP_Instance instance) OVERRIDE;
400 virtual PP_Var ExecuteScript(PP_Instance instance,
401 PP_Var script,
402 PP_Var* exception) OVERRIDE;
403 virtual uint32_t GetAudioHardwareOutputSampleRate(PP_Instance instance)
404 OVERRIDE;
405 virtual uint32_t GetAudioHardwareOutputBufferSize(PP_Instance instance)
406 OVERRIDE;
407 virtual PP_Var GetDefaultCharSet(PP_Instance instance) OVERRIDE;
408 virtual void NumberOfFindResultsChanged(PP_Instance instance,
409 int32_t total,
410 PP_Bool final_result) OVERRIDE;
411 virtual void SelectedFindResultChanged(PP_Instance instance,
412 int32_t index) OVERRIDE;
413 virtual PP_Bool IsFullscreen(PP_Instance instance) OVERRIDE;
414 virtual PP_Bool SetFullscreen(PP_Instance instance,
415 PP_Bool fullscreen) OVERRIDE;
416 virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size)
417 OVERRIDE;
418 virtual ::ppapi::Resource* GetSingletonResource(PP_Instance instance,
419 ::ppapi::SingletonResourceID id) OVERRIDE;
420 virtual int32_t RequestInputEvents(PP_Instance instance,
421 uint32_t event_classes) OVERRIDE;
422 virtual int32_t RequestFilteringInputEvents(PP_Instance instance,
423 uint32_t event_classes) OVERRIDE;
424 virtual void ClearInputEventRequest(PP_Instance instance,
425 uint32_t event_classes) OVERRIDE;
426 virtual void ZoomChanged(PP_Instance instance, double factor) OVERRIDE;
427 virtual void ZoomLimitsChanged(PP_Instance instance,
428 double minimum_factor,
429 double maximium_factor) OVERRIDE;
430 virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE;
431 virtual PP_Bool SetCursor(PP_Instance instance,
432 PP_MouseCursor_Type type,
433 PP_Resource image,
434 const PP_Point* hot_spot) OVERRIDE;
435 virtual int32_t LockMouse(
436 PP_Instance instance,
437 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
438 virtual void UnlockMouse(PP_Instance instance) OVERRIDE;
439 virtual void SetTextInputType(PP_Instance instance,
440 PP_TextInput_Type type) OVERRIDE;
441 virtual void UpdateCaretPosition(PP_Instance instance,
442 const PP_Rect& caret,
443 const PP_Rect& bounding_box) OVERRIDE;
444 virtual void CancelCompositionText(PP_Instance instance) OVERRIDE;
445 virtual void SelectionChanged(PP_Instance instance) OVERRIDE;
446 virtual void UpdateSurroundingText(PP_Instance instance,
447 const char* text,
448 uint32_t caret,
449 uint32_t anchor) OVERRIDE;
450 virtual PP_Var ResolveRelativeToDocument(
451 PP_Instance instance,
452 PP_Var relative,
453 PP_URLComponents_Dev* components) OVERRIDE;
454 virtual PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) OVERRIDE;
455 virtual PP_Bool DocumentCanAccessDocument(PP_Instance instance,
456 PP_Instance target) OVERRIDE;
457 virtual PP_Var GetDocumentURL(PP_Instance instance,
458 PP_URLComponents_Dev* components) OVERRIDE;
459 virtual PP_Var GetPluginInstanceURL(
460 PP_Instance instance,
461 PP_URLComponents_Dev* components) OVERRIDE;
462
463 // PPB_ContentDecryptor_Private implementation.
464 virtual void NeedKey(PP_Instance instance,
465 PP_Var key_system,
466 PP_Var session_id,
467 PP_Var init_data) OVERRIDE;
468 virtual void KeyAdded(PP_Instance instance,
469 PP_Var key_system,
470 PP_Var session_id) OVERRIDE;
471 virtual void KeyMessage(PP_Instance instance,
472 PP_Var key_system,
473 PP_Var session_id,
474 PP_Var message,
475 PP_Var default_url) OVERRIDE;
476 virtual void KeyError(PP_Instance instance,
477 PP_Var key_system,
478 PP_Var session_id,
479 int32_t media_error,
480 int32_t system_code) OVERRIDE;
481 virtual void DeliverBlock(PP_Instance instance,
482 PP_Resource decrypted_block,
483 const PP_DecryptedBlockInfo* block_info) OVERRIDE;
484 virtual void DecoderInitializeDone(PP_Instance instance,
485 PP_DecryptorStreamType decoder_type,
486 uint32_t request_id,
487 PP_Bool success) OVERRIDE;
488 virtual void DecoderDeinitializeDone(PP_Instance instance,
489 PP_DecryptorStreamType decoder_type,
490 uint32_t request_id) OVERRIDE;
491 virtual void DecoderResetDone(PP_Instance instance,
492 PP_DecryptorStreamType decoder_type,
493 uint32_t request_id) OVERRIDE;
494 virtual void DeliverFrame(PP_Instance instance,
495 PP_Resource decrypted_frame,
496 const PP_DecryptedFrameInfo* frame_info) OVERRIDE;
497 virtual void DeliverSamples(PP_Instance instance,
498 PP_Resource audio_frames,
499 const PP_DecryptedBlockInfo* block_info) OVERRIDE;
500
501 // Reset this instance as proxied. Assigns the instance a new module, resets
502 // cached interfaces to point to the out-of-process proxy and re-sends
503 // DidCreate, DidChangeView, and HandleDocumentLoad (if necessary).
504 // This should be used only when switching an in-process instance to an
505 // external out-of-process instance.
506 PP_ExternalPluginResult ResetAsProxied(scoped_refptr<PluginModule> module);
507
508 // Checks whether this is a valid instance of the given module. After calling
509 // ResetAsProxied above, a NaCl plugin instance's module changes, so external
510 // hosts won't recognize it as a valid instance of the original module. This
511 // method fixes that be checking that either module_ or original_module_ match
512 // the given module.
513 bool IsValidInstanceOf(PluginModule* module);
514
515 // Returns the plugin NPP identifier that this plugin will use to identify
516 // itself when making NPObject scripting calls to WebBindings.
517 struct _NPP* instanceNPP();
518
519 // Returns the v8::Isolate that was current when this Instance was created.
520 // This is not inlined so as to avoid an unnecessary header include of v8.h.
521 v8::Isolate* GetIsolate() const;
522
523 static PluginInstance* Get(PP_Instance instance_id);
524
525 ::ppapi::VarTracker* GetVarTracker();
526
527 // Returns a reference to a file with the given path.
528 // The returned object will have a refcount of 0 (just like "new").
529 PP_Resource CreateExternalFileReference(
530 const base::FilePath& external_file_path);
531
532 // Creates a PPB_ImageData given a Skia image.
533 PP_Resource CreateImage(gfx::ImageSkia* source_image, float scale);
534
535 // Returns the location of this module.
536 base::FilePath GetModulePath();
537
538 // Switches this instance with one that uses the out of process IPC proxy.
539 PP_ExternalPluginResult SwitchToOutOfProcessProxy(
540 const base::FilePath& file_path,
541 ::ppapi::PpapiPermissions permissions,
542 const IPC::ChannelHandle& channel_handle,
543 base::ProcessId plugin_pid,
544 int plugin_child_id);
545
546 private:
547 friend class PpapiUnittest;
548
549 // Class to record document load notifications and play them back once the
550 // real document loader becomes available. Used only by NaCl instances.
551 class NaClDocumentLoader : public WebKit::WebURLLoaderClient {
552 public:
553 NaClDocumentLoader();
554 virtual ~NaClDocumentLoader();
555
556 void ReplayReceivedData(WebURLLoaderClient* document_loader);
557
558 // WebKit::WebURLLoaderClient implementation.
559 virtual void didReceiveData(WebKit::WebURLLoader* loader,
560 const char* data,
561 int data_length,
562 int encoded_data_length);
563 virtual void didFinishLoading(WebKit::WebURLLoader* loader,
564 double finish_time);
565 virtual void didFail(WebKit::WebURLLoader* loader,
566 const WebKit::WebURLError& error);
567
568 private:
569 std::list<std::string> data_;
570 bool finished_loading_;
571 scoped_ptr<WebKit::WebURLError> error_;
572 };
573
574 // Implements PPB_Gamepad_API. This is just to avoid having an excessive
575 // number of interfaces implemented by PluginInstance.
576 class GamepadImpl : public ::ppapi::thunk::PPB_Gamepad_API,
577 public ::ppapi::Resource {
578 public:
579 explicit GamepadImpl(PluginDelegate* delegate);
580 // Resource implementation.
581 virtual ::ppapi::thunk::PPB_Gamepad_API* AsPPB_Gamepad_API() OVERRIDE;
582 virtual void Sample(PP_Instance instance,
583 PP_GamepadsSampleData* data) OVERRIDE;
584 private:
585 PluginDelegate* delegate_;
586 };
587
588 // See the static Create functions above for creating PluginInstance objects.
589 // This constructor is private so that we can hide the PPP_Instance_Combined
590 // details while still having 1 constructor to maintain for member
591 // initialization.
592 PluginInstance(PluginDelegate* delegate,
593 content::RenderView* render_view,
594 PluginModule* module,
595 ::ppapi::PPP_Instance_Combined* instance_interface,
596 WebKit::WebPluginContainer* container,
597 const GURL& plugin_url);
598
599 bool LoadFindInterface();
600 bool LoadInputEventInterface();
601 bool LoadMessagingInterface();
602 bool LoadMouseLockInterface();
603 bool LoadPdfInterface();
604 bool LoadPrintInterface();
605 bool LoadPrivateInterface();
606 bool LoadSelectionInterface();
607 bool LoadTextInputInterface();
608 bool LoadZoomInterface();
609
610 // Determines if we think the plugin has focus, both content area and webkit
611 // (see has_webkit_focus_ below).
612 bool PluginHasFocus() const;
613 void SendFocusChangeNotification();
614
615 void UpdateTouchEventRequest();
616
617 // Returns true if the plugin has registered to accept wheel events.
618 bool IsAcceptingWheelEvents() const;
619
620 void ScheduleAsyncDidChangeView();
621 void SendAsyncDidChangeView();
622 void SendDidChangeView();
623
624 // Reports the current plugin geometry to the plugin by calling
625 // DidChangeView.
626 void ReportGeometry();
627
628 // Queries the plugin for supported print formats and sets |format| to the
629 // best format to use. Returns false if the plugin does not support any
630 // print format that we can handle (we can handle only PDF).
631 bool GetPreferredPrintOutputFormat(PP_PrintOutputFormat_Dev* format);
632 bool PrintPDFOutput(PP_Resource print_output, WebKit::WebCanvas* canvas);
633
634 // Get the bound graphics context as a concrete 2D graphics context or returns
635 // null if the context is not 2D.
636 PluginDelegate::PlatformGraphics2D* GetBoundGraphics2D() const;
637
638 // Updates the layer for compositing. This creates a layer and attaches to the
639 // container if:
640 // - we have a bound Graphics3D
641 // - the Graphics3D has a texture
642 // - we are not in Flash full-screen mode (or transitioning to it)
643 // Otherwise it destroys the layer.
644 // It does either operation lazily.
645 void UpdateLayer();
646
647 // Internal helper function for PrintPage().
648 bool PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges,
649 int num_ranges,
650 WebKit::WebCanvas* canvas);
651
652 void DoSetCursor(WebKit::WebCursorInfo* cursor);
653
654 // Internal helper functions for HandleCompositionXXX().
655 bool SendCompositionEventToPlugin(
656 PP_InputEvent_Type type,
657 const base::string16& text);
658 bool SendCompositionEventWithUnderlineInformationToPlugin(
659 PP_InputEvent_Type type,
660 const base::string16& text,
661 const std::vector<WebKit::WebCompositionUnderline>& underlines,
662 int selection_start,
663 int selection_end);
664
665 // Internal helper function for XXXInputEvents().
666 void RequestInputEventsHelper(uint32_t event_classes);
667
668 // Checks if the security origin of the document containing this instance can
669 // assess the security origin of the main frame document.
670 bool CanAccessMainFrame() const;
671
672 // Returns true if the WebView the plugin is in renders via the accelerated
673 // compositing path.
674 bool IsViewAccelerated();
675
676 // Track, set and reset size attributes to control the size of the plugin
677 // in and out of fullscreen mode.
678 void KeepSizeAttributesBeforeFullscreen();
679 void SetSizeAttributesForFullscreen();
680 void ResetSizeAttributesAfterFullscreen();
681
682 PluginDelegate* delegate_;
683 content::RenderView* render_view_;
684 scoped_refptr<PluginModule> module_;
685 scoped_ptr< ::ppapi::PPP_Instance_Combined> instance_interface_;
686 // If this is the NaCl plugin, we create a new module when we switch to the
687 // IPC-based PPAPI proxy. Store the original module and instance interface
688 // so we can shut down properly.
689 scoped_refptr<PluginModule> original_module_;
690 scoped_ptr< ::ppapi::PPP_Instance_Combined> original_instance_interface_;
691
692 PP_Instance pp_instance_;
693
694 // NULL until we have been initialized.
695 WebKit::WebPluginContainer* container_;
696 scoped_refptr<cc::TextureLayer> texture_layer_;
697 scoped_ptr<WebKit::WebLayer> web_layer_;
698 bool layer_bound_to_fullscreen_;
699
700 // Plugin URL.
701 GURL plugin_url_;
702
703 // Indicates whether this is a full frame instance, which means it represents
704 // an entire document rather than an embed tag.
705 bool full_frame_;
706
707 // Stores the current state of the plugin view.
708 ::ppapi::ViewData view_data_;
709 // The last state sent to the plugin. It is only valid after
710 // |sent_initial_did_change_view_| is set to true.
711 ::ppapi::ViewData last_sent_view_data_;
712
713 // Indicates if we've ever sent a didChangeView to the plugin. This ensures we
714 // always send an initial notification, even if the position and clip are the
715 // same as the default values.
716 bool sent_initial_did_change_view_;
717
718 // We use a weak ptr factory for scheduling DidChangeView events so that we
719 // can tell whether updates are pending and consolidate them. When there's
720 // already a weak ptr pending (HasWeakPtrs is true), code should update the
721 // view_data_ but not send updates. This also allows us to cancel scheduled
722 // view change events.
723 base::WeakPtrFactory<PluginInstance> view_change_weak_ptr_factory_;
724
725 // The current device context for painting in 2D and 3D.
726 scoped_refptr<PPB_Graphics3D_Impl> bound_graphics_3d_;
727 PluginDelegate::PlatformGraphics2D* bound_graphics_2d_platform_;
728
729 // We track two types of focus, one from WebKit, which is the focus among
730 // all elements of the page, one one from the browser, which is whether the
731 // tab/window has focus. We tell the plugin it has focus only when both of
732 // these values are set to true.
733 bool has_webkit_focus_;
734 bool has_content_area_focus_;
735
736 // The id of the current find operation, or -1 if none is in process.
737 int find_identifier_;
738
739 // Helper object that creates resources.
740 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> resource_creation_;
741
742 // The plugin-provided interfaces.
743 // When adding PPP interfaces, make sure to reset them in ResetAsProxied.
744 const PPP_Find_Dev* plugin_find_interface_;
745 const PPP_InputEvent* plugin_input_event_interface_;
746 const PPP_Messaging* plugin_messaging_interface_;
747 const PPP_MouseLock* plugin_mouse_lock_interface_;
748 const PPP_Pdf* plugin_pdf_interface_;
749 const PPP_Instance_Private* plugin_private_interface_;
750 const PPP_Selection_Dev* plugin_selection_interface_;
751 const PPP_TextInput_Dev* plugin_textinput_interface_;
752 const PPP_Zoom_Dev* plugin_zoom_interface_;
753
754 // Flags indicating whether we have asked this plugin instance for the
755 // corresponding interfaces, so that we can ask only once.
756 // When adding flags, make sure to reset them in ResetAsProxied.
757 bool checked_for_plugin_input_event_interface_;
758 bool checked_for_plugin_messaging_interface_;
759 bool checked_for_plugin_pdf_interface_;
760
761 // This is only valid between a successful PrintBegin call and a PrintEnd
762 // call.
763 PP_PrintSettings_Dev current_print_settings_;
764 #if defined(OS_MACOSX)
765 // On the Mac, when we draw the bitmap to the PDFContext, it seems necessary
766 // to keep the pixels valid until CGContextEndPage is called. We use this
767 // variable to hold on to the pixels.
768 scoped_refptr<PPB_ImageData_Impl> last_printed_page_;
769 #endif // defined(OS_MACOSX)
770 // Always when printing to PDF on Linux and when printing for preview on Mac
771 // and Win, the entire document goes into one metafile. However, when users
772 // print only a subset of all the pages, it is impossible to know if a call
773 // to PrintPage() is the last call. Thus in PrintPage(), just store the page
774 // number in |ranges_|. The hack is in PrintEnd(), where a valid |canvas_|
775 // is preserved in PrintWebViewHelper::PrintPages. This makes it possible
776 // to generate the entire PDF given the variables below:
777 //
778 // The most recently used WebCanvas, guaranteed to be valid.
779 skia::RefPtr<WebKit::WebCanvas> canvas_;
780 // An array of page ranges.
781 std::vector<PP_PrintPageNumberRange_Dev> ranges_;
782
783 scoped_refptr< ::ppapi::Resource> gamepad_impl_;
784
785 // The plugin print interface.
786 const PPP_Printing_Dev* plugin_print_interface_;
787
788 // The plugin 3D interface.
789 const PPP_Graphics3D* plugin_graphics_3d_interface_;
790
791 // Contains the cursor if it's set by the plugin.
792 scoped_ptr<WebKit::WebCursorInfo> cursor_;
793
794 // Set to true if this plugin thinks it will always be on top. This allows us
795 // to use a more optimized painting path in some cases.
796 bool always_on_top_;
797 // Even if |always_on_top_| is true, the plugin is not fully visible if there
798 // are some cut-out areas (occupied by iframes higher in the stacking order).
799 // This information is used in the optimized painting path.
800 std::vector<gfx::Rect> cut_outs_rects_;
801
802 // Implementation of PPB_FlashFullscreen.
803
804 // Plugin container for fullscreen mode. NULL if not in fullscreen mode. Note:
805 // there is a transition state where fullscreen_container_ is non-NULL but
806 // flash_fullscreen_ is false (see above).
807 FullscreenContainer* fullscreen_container_;
808
809 // True if we are in "flash" fullscreen mode. False if we are in normal mode
810 // or in transition to fullscreen. Normal fullscreen mode is indicated in
811 // the ViewData.
812 bool flash_fullscreen_;
813
814 // Implementation of PPB_Fullscreen.
815
816 // Since entering fullscreen mode is an asynchronous operation, we set this
817 // variable to the desired state at the time we issue the fullscreen change
818 // request. The plugin will receive a DidChangeView event when it goes
819 // fullscreen.
820 bool desired_fullscreen_state_;
821
822 // WebKit does not resize the plugin when going into fullscreen mode, so we do
823 // this here by modifying the various plugin attributes and then restoring
824 // them on exit.
825 WebKit::WebString width_before_fullscreen_;
826 WebKit::WebString height_before_fullscreen_;
827 WebKit::WebString border_before_fullscreen_;
828 WebKit::WebString style_before_fullscreen_;
829 gfx::Size screen_size_for_fullscreen_;
830
831 // The MessageChannel used to implement bidirectional postMessage for the
832 // instance.
833 scoped_ptr<MessageChannel> message_channel_;
834
835 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
836 SkBitmap* sad_plugin_;
837
838 typedef std::set<PluginObject*> PluginObjectSet;
839 PluginObjectSet live_plugin_objects_;
840
841 // Classes of events that the plugin has registered for, both for filtering
842 // and not. The bits are PP_INPUTEVENT_CLASS_*.
843 uint32_t input_event_mask_;
844 uint32_t filtered_input_event_mask_;
845
846 // Text composition status.
847 ui::TextInputType text_input_type_;
848 gfx::Rect text_input_caret_;
849 gfx::Rect text_input_caret_bounds_;
850 bool text_input_caret_set_;
851
852 // Text selection status.
853 std::string surrounding_text_;
854 size_t selection_caret_;
855 size_t selection_anchor_;
856
857 scoped_refptr< ::ppapi::TrackedCallback> lock_mouse_callback_;
858
859 // Track pending user gestures so out-of-process plugins can respond to
860 // a user gesture after it has been processed.
861 PP_TimeTicks pending_user_gesture_;
862 WebKit::WebUserGestureToken pending_user_gesture_token_;
863
864 // We store the arguments so we can re-send them if we are reset to talk to
865 // NaCl via the IPC NaCl proxy.
866 std::vector<std::string> argn_;
867 std::vector<std::string> argv_;
868
869 // Non-owning pointer to the document loader, if any.
870 WebKit::WebURLLoaderClient* document_loader_;
871 // State for deferring document loads. Used only by NaCl instances.
872 WebKit::WebURLResponse nacl_document_response_;
873 scoped_ptr<NaClDocumentLoader> nacl_document_loader_;
874 bool nacl_document_load_;
875
876 // The ContentDecryptorDelegate forwards PPP_ContentDecryptor_Private
877 // calls and handles PPB_ContentDecryptor_Private calls.
878 scoped_ptr<ContentDecryptorDelegate> content_decryptor_delegate_;
879
880 // Dummy NPP value used when calling in to WebBindings, to allow the bindings
881 // to correctly track NPObjects belonging to this plugin instance.
882 scoped_ptr<struct _NPP> npp_;
883
884 // We store the isolate at construction so that we can be sure to use the
885 // Isolate in which this Instance was created when interacting with v8.
886 v8::Isolate* isolate_;
887
888 friend class PpapiPluginInstanceTest;
889 DISALLOW_COPY_AND_ASSIGN(PluginInstance);
890 }; 100 };
891 101
892 } // namespace ppapi 102 } // namespace ppapi
893 } // namespace webkit 103 } // namespace webkit
894 104
895 #endif // WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_ 105 #endif // WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698