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