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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_IMPL_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_IMPL_H_
13 #include "base/callback.h"
14 #include "base/compiler_specific.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/strings/string16.h"
19 #include "cc/layers/content_layer_client.h"
20 #include "cc/layers/layer.h"
21 #include "cc/layers/texture_layer_client.h"
22 #include "content/common/content_export.h"
23 #include "content/public/renderer/pepper_plugin_instance.h"
24 #include "content/public/renderer/render_frame_observer.h"
25 #include "content/renderer/mouse_lock_dispatcher.h"
26 #include "gin/handle.h"
27 #include "ppapi/c/dev/pp_cursor_type_dev.h"
28 #include "ppapi/c/dev/ppp_printing_dev.h"
29 #include "ppapi/c/dev/ppp_selection_dev.h"
30 #include "ppapi/c/dev/ppp_text_input_dev.h"
31 #include "ppapi/c/dev/ppp_zoom_dev.h"
32 #include "ppapi/c/pp_completion_callback.h"
33 #include "ppapi/c/pp_instance.h"
34 #include "ppapi/c/pp_time.h"
35 #include "ppapi/c/pp_var.h"
36 #include "ppapi/c/ppb_audio_config.h"
37 #include "ppapi/c/ppb_gamepad.h"
38 #include "ppapi/c/ppb_input_event.h"
39 #include "ppapi/c/ppp_graphics_3d.h"
40 #include "ppapi/c/ppp_input_event.h"
41 #include "ppapi/c/ppp_mouse_lock.h"
42 #include "ppapi/c/private/ppb_content_decryptor_private.h"
43 #include "ppapi/c/private/ppp_find_private.h"
44 #include "ppapi/c/private/ppp_instance_private.h"
45 #include "ppapi/c/private/ppp_pdf.h"
46 #include "ppapi/shared_impl/ppb_instance_shared.h"
47 #include "ppapi/shared_impl/ppb_view_shared.h"
48 #include "ppapi/shared_impl/singleton_resource_id.h"
49 #include "ppapi/shared_impl/tracked_callback.h"
50 #include "ppapi/thunk/ppb_gamepad_api.h"
51 #include "ppapi/thunk/resource_creation_api.h"
52 #include "skia/ext/refptr.h"
53 #include "third_party/WebKit/public/platform/WebCanvas.h"
54 #include "third_party/WebKit/public/platform/WebString.h"
55 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
56 #include "third_party/WebKit/public/platform/WebURLResponse.h"
57 #include "third_party/WebKit/public/web/WebPlugin.h"
58 #include "third_party/WebKit/public/web/WebUserGestureToken.h"
59 #include "ui/base/ime/text_input_type.h"
60 #include "ui/events/latency_info.h"
61 #include "ui/gfx/rect.h"
63 #include "v8/include/v8.h"
75 class WebPluginContainer
;
78 struct WebCompositionUnderline
;
81 struct WebPrintParams
;
94 struct InputEventData
;
95 struct PPP_Instance_Combined
;
101 class ContentDecryptorDelegate
;
102 class FullscreenContainer
;
103 class MessageChannel
;
104 class PepperCompositorHost
;
105 class PepperGraphics2DHost
;
106 class PepperPluginInstanceThrottler
;
109 class PPB_Graphics3D_Impl
;
110 class PPB_ImageData_Impl
;
111 class PPB_URLLoader_Impl
;
112 class RenderFrameImpl
;
113 class RenderViewImpl
;
115 // Represents one time a plugin appears on one web page.
117 // Note: to get from a PP_Instance to a PepperPluginInstance*, use the
119 class CONTENT_EXPORT PepperPluginInstanceImpl
120 : public base::RefCounted
<PepperPluginInstanceImpl
>,
121 public NON_EXPORTED_BASE(PepperPluginInstance
),
122 public ppapi::PPB_Instance_Shared
,
123 public NON_EXPORTED_BASE(cc::TextureLayerClient
),
124 public RenderFrameObserver
{
126 // Create and return a PepperPluginInstanceImpl object which supports the most
127 // recent version of PPP_Instance possible by querying the given
128 // get_plugin_interface function. If the plugin does not support any valid
129 // PPP_Instance interface, returns NULL.
130 static PepperPluginInstanceImpl
* Create(RenderFrameImpl
* render_frame
,
131 PluginModule
* module
,
132 blink::WebPluginContainer
* container
,
133 const GURL
& plugin_url
);
134 RenderFrameImpl
* render_frame() const { return render_frame_
; }
135 PluginModule
* module() const { return module_
.get(); }
137 blink::WebPluginContainer
* container() const { return container_
; }
139 // Returns the PP_Instance uniquely identifying this instance. Guaranteed
141 PP_Instance
pp_instance() const { return pp_instance_
; }
143 ppapi::thunk::ResourceCreationAPI
& resource_creation() {
144 return *resource_creation_
.get();
147 MessageChannel
* message_channel() { return message_channel_
; }
148 v8::Local
<v8::Object
> GetMessageChannelObject();
149 // Called when |message_channel_| is destroyed as it may be destroyed prior to
150 // the plugin being destroyed.
151 void MessageChannelDestroyed();
153 // Return the v8 context for the frame that the plugin is contained in. Care
154 // should be taken to use the correct context for plugin<->JS interactions.
155 // In cases where JS calls into the plugin, the caller's context should
156 // typically be used. When calling from the plugin into JS, this context
157 // should typically used.
158 v8::Local
<v8::Context
> GetMainWorldContext();
160 // Does some pre-destructor cleanup on the instance. This is necessary
161 // because some cleanup depends on the plugin instance still existing (like
162 // calling the plugin's DidDestroy function). This function is called from
163 // the WebPlugin implementation when WebKit is about to remove the plugin.
166 // Returns true if Delete() has been called on this object.
167 bool is_deleted() const;
169 // Paints the current backing store to the web page.
170 void Paint(blink::WebCanvas
* canvas
,
171 const gfx::Rect
& plugin_rect
,
172 const gfx::Rect
& paint_rect
);
174 // Schedules a paint of the page for the given region. The coordinates are
175 // relative to the top-left of the plugin. This does nothing if the plugin
176 // has not yet been positioned. You can supply an empty gfx::Rect() to
177 // invalidate the entire plugin.
178 void InvalidateRect(const gfx::Rect
& rect
);
180 // Schedules a scroll of the plugin. This uses optimized scrolling only for
181 // full-frame plugins, as otherwise there could be other elements on top. The
182 // slow path can also be triggered if there is an overlapping frame.
183 void ScrollRect(int dx
, int dy
, const gfx::Rect
& rect
);
185 // Commit the backing texture to the screen once the side effects some
186 // rendering up to an offscreen SwapBuffers are visible.
187 void CommitBackingTexture();
189 // Called when the out-of-process plugin implementing this instance crashed.
190 void InstanceCrashed();
192 // PPB_Instance and PPB_Instance_Private implementation.
193 bool full_frame() const { return full_frame_
; }
194 const ppapi::ViewData
& view_data() const { return view_data_
; }
196 // PPP_Instance and PPP_Instance_Private.
197 bool Initialize(const std::vector
<std::string
>& arg_names
,
198 const std::vector
<std::string
>& arg_values
,
200 bool HandleDocumentLoad(const blink::WebURLResponse
& response
);
201 bool HandleInputEvent(const blink::WebInputEvent
& event
,
202 blink::WebCursorInfo
* cursor_info
);
203 PP_Var
GetInstanceObject(v8::Isolate
* isolate
);
204 void ViewChanged(const gfx::Rect
& position
,
205 const gfx::Rect
& clip
,
206 const std::vector
<gfx::Rect
>& cut_outs_rects
);
208 // Handlers for composition events.
209 bool HandleCompositionStart(const base::string16
& text
);
210 bool HandleCompositionUpdate(
211 const base::string16
& text
,
212 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
215 bool HandleCompositionEnd(const base::string16
& text
);
216 bool HandleTextInput(const base::string16
& text
);
218 // Gets the current text input status.
219 ui::TextInputType
text_input_type() const { return text_input_type_
; }
220 gfx::Rect
GetCaretBounds() const;
221 bool IsPluginAcceptingCompositionEvents() const;
222 void GetSurroundingText(base::string16
* text
, gfx::Range
* range
) const;
224 // Notifications about focus changes, see has_webkit_focus_ below.
225 void SetWebKitFocus(bool has_focus
);
226 void SetContentAreaFocus(bool has_focus
);
228 // Notification about page visibility. The default is "visible".
229 void PageVisibilityChanged(bool is_visible
);
231 // Notifications that the view has started painting, and has flushed the
232 // painted content to the screen. These messages are used to send Flush
233 // callbacks to the plugin for DeviceContext2D/3D.
234 void ViewInitiatedPaint();
235 void ViewFlushedPaint();
237 // Tracks all live PluginObjects.
238 void AddPluginObject(PluginObject
* plugin_object
);
239 void RemovePluginObject(PluginObject
* plugin_object
);
241 base::string16
GetSelectedText(bool html
);
242 base::string16
GetLinkAtPosition(const gfx::Point
& point
);
243 void RequestSurroundingText(size_t desired_number_of_characters
);
244 void Zoom(double factor
, bool text_only
);
245 bool StartFind(const base::string16
& search_text
,
248 void SelectFindResult(bool forward
);
251 bool SupportsPrintInterface();
252 bool IsPrintScalingDisabled();
253 int PrintBegin(const blink::WebPrintParams
& print_params
);
254 bool PrintPage(int page_number
, blink::WebCanvas
* canvas
);
257 bool CanRotateView();
258 void RotateView(blink::WebPlugin::RotationType type
);
260 // There are 2 implementations of the fullscreen interface
261 // PPB_FlashFullscreen is used by Pepper Flash.
262 // PPB_Fullscreen is intended for other applications including NaCl.
263 // The two interface are mutually exclusive.
265 // Implementation of PPB_FlashFullscreen.
267 // Because going to fullscreen is asynchronous (but going out is not), there
269 // - normal : fullscreen_container_ == NULL
270 // flash_fullscreen_ == false
271 // - fullscreen pending: fullscreen_container_ != NULL
272 // flash_fullscreen_ == false
273 // - fullscreen : fullscreen_container_ != NULL
274 // flash_fullscreen_ == true
276 // In normal state, events come from webkit and painting goes back to it.
277 // In fullscreen state, events come from the fullscreen container, and
278 // painting goes back to it.
279 // In pending state, events from webkit are ignored, and as soon as we
280 // receive events from the fullscreen container, we go to the fullscreen
282 bool FlashIsFullscreenOrPending();
284 // Updates |flash_fullscreen_| and sends focus change notification if
286 void UpdateFlashFullscreenState(bool flash_fullscreen
);
288 FullscreenContainer
* fullscreen_container() const {
289 return fullscreen_container_
;
292 // Implementation of PPB_Fullscreen.
294 // Because going to/from fullscreen is asynchronous, there are 4 states:
295 // - normal : desired_fullscreen_state_ == false
296 // view_data_.is_fullscreen == false
297 // - fullscreen pending: desired_fullscreen_state_ == true
298 // view_data_.is_fullscreen == false
299 // - fullscreen : desired_fullscreen_state_ == true
300 // view_data_.is_fullscreen == true
301 // - normal pending : desired_fullscreen_state_ = false
302 // view_data_.is_fullscreen = true
303 bool IsFullscreenOrPending();
305 bool flash_fullscreen() const { return flash_fullscreen_
; }
307 // Switches between fullscreen and normal mode. The transition is
308 // asynchronous. WebKit will trigger corresponding VewChanged calls.
309 // Returns true on success, false on failure (e.g. trying to enter fullscreen
310 // when not processing a user gesture or trying to set fullscreen when
311 // already in fullscreen mode).
312 bool SetFullscreen(bool fullscreen
);
314 // Send the message on to the plugin.
315 void HandleMessage(ppapi::ScopedPPVar message
);
317 // Send the message synchronously to the plugin, and get a result. Returns
318 // true if the plugin handled the message, false if it didn't. The plugin
319 // won't handle the message if it has not registered a PPP_MessageHandler.
320 bool HandleBlockingMessage(ppapi::ScopedPPVar message
,
321 ppapi::ScopedPPVar
* result
);
323 // Returns true if the plugin is processing a user gesture.
324 bool IsProcessingUserGesture();
326 // Returns the user gesture token to use for creating a WebScopedUserGesture,
327 // if IsProcessingUserGesture returned true.
328 blink::WebUserGestureToken
CurrentUserGestureToken();
330 // A mouse lock request was pending and this reports success or failure.
331 void OnLockMouseACK(bool succeeded
);
332 // A mouse lock was in place, but has been lost.
333 void OnMouseLockLost();
334 // A mouse lock is enabled and mouse events are being delivered.
335 void HandleMouseLockedInputEvent(const blink::WebMouseEvent
& event
);
337 // Simulates an input event to the plugin by passing it down to WebKit,
338 // which sends it back up to the plugin as if it came from the user.
339 void SimulateInputEvent(const ppapi::InputEventData
& input_event
);
341 // Simulates an IME event at the level of RenderView which sends it back up to
342 // the plugin as if it came from the user.
343 bool SimulateIMEEvent(const ppapi::InputEventData
& input_event
);
344 void SimulateImeSetCompositionEvent(const ppapi::InputEventData
& input_event
);
346 // The document loader is valid when the plugin is "full-frame" and in this
347 // case is non-NULL as long as the corresponding loader resource is alive.
348 // This pointer is non-owning, so the loader must use set_document_loader to
349 // clear itself when it is destroyed.
350 blink::WebURLLoaderClient
* document_loader() const {
351 return document_loader_
;
353 void set_document_loader(blink::WebURLLoaderClient
* loader
) {
354 document_loader_
= loader
;
357 ContentDecryptorDelegate
* GetContentDecryptorDelegate();
359 // PluginInstance implementation
360 virtual RenderView
* GetRenderView() override
;
361 virtual blink::WebPluginContainer
* GetContainer() override
;
362 virtual v8::Isolate
* GetIsolate() const override
;
363 virtual ppapi::VarTracker
* GetVarTracker() override
;
364 virtual const GURL
& GetPluginURL() override
;
365 virtual base::FilePath
GetModulePath() override
;
366 virtual PP_Resource
CreateImage(gfx::ImageSkia
* source_image
,
367 float scale
) override
;
368 virtual PP_ExternalPluginResult
SwitchToOutOfProcessProxy(
369 const base::FilePath
& file_path
,
370 ppapi::PpapiPermissions permissions
,
371 const IPC::ChannelHandle
& channel_handle
,
372 base::ProcessId plugin_pid
,
373 int plugin_child_id
) override
;
374 virtual void SetAlwaysOnTop(bool on_top
) override
;
375 virtual bool IsFullPagePlugin() override
;
376 virtual bool FlashSetFullscreen(bool fullscreen
, bool delay_report
) override
;
377 virtual bool IsRectTopmost(const gfx::Rect
& rect
) override
;
378 virtual int32_t Navigate(const ppapi::URLRequestInfoData
& request
,
380 bool from_user_action
) override
;
381 virtual int MakePendingFileRefRendererHost(const base::FilePath
& path
)
383 virtual void SetEmbedProperty(PP_Var key
, PP_Var value
) override
;
384 virtual void SetSelectedText(const base::string16
& selected_text
) override
;
385 virtual void SetLinkUnderCursor(const std::string
& url
) override
;
386 virtual void SetTextInputType(ui::TextInputType type
) override
;
387 virtual void PostMessageToJavaScript(PP_Var message
) override
;
389 // PPB_Instance_API implementation.
390 virtual PP_Bool
BindGraphics(PP_Instance instance
,
391 PP_Resource device
) override
;
392 virtual PP_Bool
IsFullFrame(PP_Instance instance
) override
;
393 virtual const ppapi::ViewData
* GetViewData(PP_Instance instance
) override
;
394 virtual PP_Bool
FlashIsFullscreen(PP_Instance instance
) override
;
395 virtual PP_Var
GetWindowObject(PP_Instance instance
) override
;
396 virtual PP_Var
GetOwnerElementObject(PP_Instance instance
) override
;
397 virtual PP_Var
ExecuteScript(PP_Instance instance
,
399 PP_Var
* exception
) override
;
400 virtual uint32_t GetAudioHardwareOutputSampleRate(PP_Instance instance
)
402 virtual uint32_t GetAudioHardwareOutputBufferSize(PP_Instance instance
)
404 virtual PP_Var
GetDefaultCharSet(PP_Instance instance
) override
;
405 virtual void SetPluginToHandleFindRequests(PP_Instance
) override
;
406 virtual void NumberOfFindResultsChanged(PP_Instance instance
,
408 PP_Bool final_result
) override
;
409 virtual void SelectedFindResultChanged(PP_Instance instance
,
410 int32_t index
) override
;
411 virtual void SetTickmarks(PP_Instance instance
,
412 const PP_Rect
* tickmarks
,
413 uint32_t count
) override
;
414 virtual PP_Bool
IsFullscreen(PP_Instance instance
) override
;
415 virtual PP_Bool
SetFullscreen(PP_Instance instance
,
416 PP_Bool fullscreen
) override
;
417 virtual PP_Bool
GetScreenSize(PP_Instance instance
, PP_Size
* size
) override
;
418 virtual ppapi::Resource
* GetSingletonResource(PP_Instance instance
,
419 ppapi::SingletonResourceID id
)
421 virtual int32_t RequestInputEvents(PP_Instance instance
,
422 uint32_t event_classes
) override
;
423 virtual int32_t RequestFilteringInputEvents(PP_Instance instance
,
424 uint32_t event_classes
) override
;
425 virtual void ClearInputEventRequest(PP_Instance instance
,
426 uint32_t event_classes
) override
;
427 virtual void StartTrackingLatency(PP_Instance instance
) override
;
428 virtual void ZoomChanged(PP_Instance instance
, double factor
) override
;
429 virtual void ZoomLimitsChanged(PP_Instance instance
,
430 double minimum_factor
,
431 double maximum_factor
) override
;
432 virtual void PostMessage(PP_Instance instance
, PP_Var message
) override
;
433 virtual int32_t RegisterMessageHandler(PP_Instance instance
,
435 const PPP_MessageHandler_0_2
* handler
,
436 PP_Resource message_loop
) override
;
437 virtual int32_t RegisterMessageHandler_1_1_Deprecated(
438 PP_Instance instance
,
440 const PPP_MessageHandler_0_1_Deprecated
* handler
,
441 PP_Resource message_loop
) override
;
442 virtual void UnregisterMessageHandler(PP_Instance instance
) override
;
443 virtual PP_Bool
SetCursor(PP_Instance instance
,
444 PP_MouseCursor_Type type
,
446 const PP_Point
* hot_spot
) override
;
447 virtual int32_t LockMouse(PP_Instance instance
,
448 scoped_refptr
<ppapi::TrackedCallback
> callback
)
450 virtual void UnlockMouse(PP_Instance instance
) override
;
451 virtual void SetTextInputType(PP_Instance instance
,
452 PP_TextInput_Type type
) override
;
453 virtual void UpdateCaretPosition(PP_Instance instance
,
454 const PP_Rect
& caret
,
455 const PP_Rect
& bounding_box
) override
;
456 virtual void CancelCompositionText(PP_Instance instance
) override
;
457 virtual void SelectionChanged(PP_Instance instance
) override
;
458 virtual void UpdateSurroundingText(PP_Instance instance
,
461 uint32_t anchor
) override
;
462 virtual PP_Var
ResolveRelativeToDocument(PP_Instance instance
,
464 PP_URLComponents_Dev
* components
)
466 virtual PP_Bool
DocumentCanRequest(PP_Instance instance
, PP_Var url
) override
;
467 virtual PP_Bool
DocumentCanAccessDocument(PP_Instance instance
,
468 PP_Instance target
) override
;
469 virtual PP_Var
GetDocumentURL(PP_Instance instance
,
470 PP_URLComponents_Dev
* components
) override
;
471 virtual PP_Var
GetPluginInstanceURL(PP_Instance instance
,
472 PP_URLComponents_Dev
* components
)
474 virtual PP_Var
GetPluginReferrerURL(PP_Instance instance
,
475 PP_URLComponents_Dev
* components
)
478 // PPB_ContentDecryptor_Private implementation.
479 virtual void PromiseResolved(PP_Instance instance
,
480 uint32 promise_id
) override
;
481 virtual void PromiseResolvedWithSession(PP_Instance instance
,
483 PP_Var web_session_id_var
) override
;
484 virtual void PromiseResolvedWithKeyIds(PP_Instance instance
,
486 PP_Var key_ids_var
) override
;
487 virtual void PromiseRejected(PP_Instance instance
,
489 PP_CdmExceptionCode exception_code
,
491 PP_Var error_description_var
) override
;
492 virtual void SessionMessage(PP_Instance instance
,
493 PP_Var web_session_id_var
,
495 PP_Var destination_url_var
) override
;
496 virtual void SessionKeysChange(PP_Instance instance
,
497 PP_Var web_session_id_var
,
498 PP_Bool has_additional_usable_key
) override
;
499 virtual void SessionExpirationChange(PP_Instance instance
,
500 PP_Var web_session_id_var
,
501 PP_Time new_expiry_time
) override
;
502 virtual void SessionReady(PP_Instance instance
,
503 PP_Var web_session_id_var
) override
;
504 virtual void SessionClosed(PP_Instance instance
,
505 PP_Var web_session_id_var
) override
;
506 virtual void SessionError(PP_Instance instance
,
507 PP_Var web_session_id_var
,
508 PP_CdmExceptionCode exception_code
,
510 PP_Var error_description_var
) override
;
511 virtual void DeliverBlock(PP_Instance instance
,
512 PP_Resource decrypted_block
,
513 const PP_DecryptedBlockInfo
* block_info
) override
;
514 virtual void DecoderInitializeDone(PP_Instance instance
,
515 PP_DecryptorStreamType decoder_type
,
517 PP_Bool success
) override
;
518 virtual void DecoderDeinitializeDone(PP_Instance instance
,
519 PP_DecryptorStreamType decoder_type
,
520 uint32_t request_id
) override
;
521 virtual void DecoderResetDone(PP_Instance instance
,
522 PP_DecryptorStreamType decoder_type
,
523 uint32_t request_id
) override
;
524 virtual void DeliverFrame(PP_Instance instance
,
525 PP_Resource decrypted_frame
,
526 const PP_DecryptedFrameInfo
* frame_info
) override
;
527 virtual void DeliverSamples(PP_Instance instance
,
528 PP_Resource audio_frames
,
529 const PP_DecryptedSampleInfo
* sample_info
)
532 // Reset this instance as proxied. Assigns the instance a new module, resets
533 // cached interfaces to point to the out-of-process proxy and re-sends
534 // DidCreate, DidChangeView, and HandleDocumentLoad (if necessary).
535 // This should be used only when switching an in-process instance to an
536 // external out-of-process instance.
537 PP_ExternalPluginResult
ResetAsProxied(scoped_refptr
<PluginModule
> module
);
539 // Checks whether this is a valid instance of the given module. After calling
540 // ResetAsProxied above, a NaCl plugin instance's module changes, so external
541 // hosts won't recognize it as a valid instance of the original module. This
542 // method fixes that be checking that either module_ or original_module_ match
544 bool IsValidInstanceOf(PluginModule
* module
);
546 // cc::TextureLayerClient implementation.
547 virtual bool PrepareTextureMailbox(
548 cc::TextureMailbox
* mailbox
,
549 scoped_ptr
<cc::SingleReleaseCallback
>* release_callback
,
550 bool use_shared_memory
) override
;
552 // RenderFrameObserver
553 virtual void OnDestruct() override
;
555 void AddLatencyInfo(const std::vector
<ui::LatencyInfo
>& latency_info
);
558 friend class base::RefCounted
<PepperPluginInstanceImpl
>;
559 friend class PpapiPluginInstanceTest
;
560 friend class PpapiUnittest
;
562 // Delete should be called by the WebPlugin before this destructor.
563 virtual ~PepperPluginInstanceImpl();
565 // Class to record document load notifications and play them back once the
566 // real document loader becomes available. Used only by external instances.
567 class ExternalDocumentLoader
: public blink::WebURLLoaderClient
{
569 ExternalDocumentLoader();
570 virtual ~ExternalDocumentLoader();
572 void ReplayReceivedData(WebURLLoaderClient
* document_loader
);
574 // blink::WebURLLoaderClient implementation.
575 virtual void didReceiveData(blink::WebURLLoader
* loader
,
578 int encoded_data_length
);
579 virtual void didFinishLoading(blink::WebURLLoader
* loader
,
581 int64_t total_encoded_data_length
);
582 virtual void didFail(blink::WebURLLoader
* loader
,
583 const blink::WebURLError
& error
);
586 std::list
<std::string
> data_
;
587 bool finished_loading_
;
588 scoped_ptr
<blink::WebURLError
> error_
;
591 // Implements PPB_Gamepad_API. This is just to avoid having an excessive
592 // number of interfaces implemented by PepperPluginInstanceImpl.
593 class GamepadImpl
: public ppapi::thunk::PPB_Gamepad_API
,
594 public ppapi::Resource
{
597 // Resource implementation.
598 virtual ppapi::thunk::PPB_Gamepad_API
* AsPPB_Gamepad_API() override
;
599 virtual void Sample(PP_Instance instance
,
600 PP_GamepadsSampleData
* data
) override
;
603 virtual ~GamepadImpl();
606 // See the static Create functions above for creating PepperPluginInstanceImpl
607 // objects. This constructor is private so that we can hide the
608 // PPP_Instance_Combined details while still having 1 constructor to maintain
609 // for member initialization.
610 PepperPluginInstanceImpl(RenderFrameImpl
* render_frame
,
611 PluginModule
* module
,
612 ppapi::PPP_Instance_Combined
* instance_interface
,
613 blink::WebPluginContainer
* container
,
614 const GURL
& plugin_url
);
616 bool LoadFindInterface();
617 bool LoadInputEventInterface();
618 bool LoadMouseLockInterface();
619 bool LoadPdfInterface();
620 bool LoadPrintInterface();
621 bool LoadPrivateInterface();
622 bool LoadTextInputInterface();
623 bool LoadZoomInterface();
625 // Update any transforms that should be applied to the texture layer.
626 void UpdateLayerTransform();
628 // Determines if we think the plugin has focus, both content area and webkit
629 // (see has_webkit_focus_ below).
630 bool PluginHasFocus() const;
631 void SendFocusChangeNotification();
633 void UpdateTouchEventRequest();
635 // Returns true if the plugin has registered to accept wheel events.
636 bool IsAcceptingWheelEvents() const;
638 void ScheduleAsyncDidChangeView();
639 void SendAsyncDidChangeView();
640 void SendDidChangeView();
642 // Reports the current plugin geometry to the plugin by calling
644 void ReportGeometry();
646 // Queries the plugin for supported print formats and sets |format| to the
647 // best format to use. Returns false if the plugin does not support any
648 // print format that we can handle (we can handle only PDF).
649 bool GetPreferredPrintOutputFormat(PP_PrintOutputFormat_Dev
* format
);
650 bool PrintPDFOutput(PP_Resource print_output
, blink::WebCanvas
* canvas
);
652 // Updates the layer for compositing. This creates a layer and attaches to the
654 // - we have a bound Graphics3D and the Graphics3D has a texture, OR
655 // we have a bound Graphics2D and are using software compositing
656 // - we are not in Flash full-screen mode (or transitioning to it)
657 // Otherwise it destroys the layer.
658 // It does either operation lazily.
659 // device_changed: true if the bound device has been changed, and
660 // UpdateLayer() will be forced to recreate the layer and attaches to the
662 void UpdateLayer(bool device_changed
);
664 // Internal helper function for PrintPage().
665 bool PrintPageHelper(PP_PrintPageNumberRange_Dev
* page_ranges
,
667 blink::WebCanvas
* canvas
);
669 void DoSetCursor(blink::WebCursorInfo
* cursor
);
671 // Internal helper functions for HandleCompositionXXX().
672 bool SendCompositionEventToPlugin(PP_InputEvent_Type type
,
673 const base::string16
& text
);
674 bool SendCompositionEventWithUnderlineInformationToPlugin(
675 PP_InputEvent_Type type
,
676 const base::string16
& text
,
677 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
681 // Internal helper function for XXXInputEvents().
682 void RequestInputEventsHelper(uint32_t event_classes
);
684 // Checks if the security origin of the document containing this instance can
685 // assess the security origin of the main frame document.
686 bool CanAccessMainFrame() const;
688 // Returns true if the WebView the plugin is in renders via the accelerated
690 bool IsViewAccelerated();
692 // Track, set and reset size attributes to control the size of the plugin
693 // in and out of fullscreen mode.
694 void KeepSizeAttributesBeforeFullscreen();
695 void SetSizeAttributesForFullscreen();
696 void ResetSizeAttributesAfterFullscreen();
698 bool IsMouseLocked();
700 MouseLockDispatcher
* GetMouseLockDispatcher();
701 MouseLockDispatcher::LockTarget
* GetOrCreateLockTargetAdapter();
702 void UnSetAndDeleteLockTargetAdapter();
704 void DidDataFromWebURLResponse(const blink::WebURLResponse
& response
,
706 const ppapi::URLResponseInfoData
& data
);
708 void SetPluginThrottled(bool throttled
);
710 RenderFrameImpl
* render_frame_
;
711 base::Closure instance_deleted_callback_
;
712 scoped_refptr
<PluginModule
> module_
;
713 scoped_ptr
<ppapi::PPP_Instance_Combined
> instance_interface_
;
714 // If this is the NaCl plugin, we create a new module when we switch to the
715 // IPC-based PPAPI proxy. Store the original module and instance interface
716 // so we can shut down properly.
717 scoped_refptr
<PluginModule
> original_module_
;
718 scoped_ptr
<ppapi::PPP_Instance_Combined
> original_instance_interface_
;
720 PP_Instance pp_instance_
;
722 // NULL until we have been initialized.
723 blink::WebPluginContainer
* container_
;
724 scoped_refptr
<cc::Layer
> compositor_layer_
;
725 scoped_refptr
<cc::TextureLayer
> texture_layer_
;
726 scoped_ptr
<blink::WebLayer
> web_layer_
;
727 bool layer_bound_to_fullscreen_
;
728 bool layer_is_hardware_
;
733 // Indicates whether this plugin may be throttled to reduce power consumption.
734 bool power_saver_enabled_
;
736 // Indicates if the plugin is currently throttled.
737 bool plugin_throttled_
;
739 // Fake view data used by the Power Saver feature to throttle plugins.
740 const ppapi::ViewData empty_view_data_
;
742 // Responsible for turning on throttling if Power Saver is on.
743 scoped_ptr
<PepperPluginInstanceThrottler
> throttler_
;
745 // Indicates whether this is a full frame instance, which means it represents
746 // an entire document rather than an embed tag.
749 // Stores the current state of the plugin view.
750 ppapi::ViewData view_data_
;
751 // The last state sent to the plugin. It is only valid after
752 // |sent_initial_did_change_view_| is set to true.
753 ppapi::ViewData last_sent_view_data_
;
755 // Indicates if we've ever sent a didChangeView to the plugin. This ensures we
756 // always send an initial notification, even if the position and clip are the
757 // same as the default values.
758 bool sent_initial_did_change_view_
;
760 // The current device context for painting in 2D, 3D or compositor.
761 scoped_refptr
<PPB_Graphics3D_Impl
> bound_graphics_3d_
;
762 PepperGraphics2DHost
* bound_graphics_2d_platform_
;
763 PepperCompositorHost
* bound_compositor_
;
765 // We track two types of focus, one from WebKit, which is the focus among
766 // all elements of the page, one one from the browser, which is whether the
767 // tab/window has focus. We tell the plugin it has focus only when both of
768 // these values are set to true.
769 bool has_webkit_focus_
;
770 bool has_content_area_focus_
;
772 // The id of the current find operation, or -1 if none is in process.
773 int find_identifier_
;
775 // Helper object that creates resources.
776 scoped_ptr
<ppapi::thunk::ResourceCreationAPI
> resource_creation_
;
778 // The plugin-provided interfaces.
779 // When adding PPP interfaces, make sure to reset them in ResetAsProxied.
780 const PPP_Find_Private
* plugin_find_interface_
;
781 const PPP_InputEvent
* plugin_input_event_interface_
;
782 const PPP_MouseLock
* plugin_mouse_lock_interface_
;
783 const PPP_Pdf
* plugin_pdf_interface_
;
784 const PPP_Instance_Private
* plugin_private_interface_
;
785 const PPP_TextInput_Dev
* plugin_textinput_interface_
;
786 const PPP_Zoom_Dev
* plugin_zoom_interface_
;
788 // Flags indicating whether we have asked this plugin instance for the
789 // corresponding interfaces, so that we can ask only once.
790 // When adding flags, make sure to reset them in ResetAsProxied.
791 bool checked_for_plugin_input_event_interface_
;
792 bool checked_for_plugin_pdf_interface_
;
794 // This is only valid between a successful PrintBegin call and a PrintEnd
796 PP_PrintSettings_Dev current_print_settings_
;
797 #if defined(OS_MACOSX)
798 // On the Mac, when we draw the bitmap to the PDFContext, it seems necessary
799 // to keep the pixels valid until CGContextEndPage is called. We use this
800 // variable to hold on to the pixels.
801 scoped_refptr
<PPB_ImageData_Impl
> last_printed_page_
;
802 #endif // defined(OS_MACOSX)
803 // Always when printing to PDF on Linux and when printing for preview on Mac
804 // and Win, the entire document goes into one metafile. However, when users
805 // print only a subset of all the pages, it is impossible to know if a call
806 // to PrintPage() is the last call. Thus in PrintPage(), just store the page
807 // number in |ranges_|. The hack is in PrintEnd(), where a valid |canvas_|
808 // is preserved in PrintWebViewHelper::PrintPages. This makes it possible
809 // to generate the entire PDF given the variables below:
811 // The most recently used WebCanvas, guaranteed to be valid.
812 skia::RefPtr
<blink::WebCanvas
> canvas_
;
813 // An array of page ranges.
814 std::vector
<PP_PrintPageNumberRange_Dev
> ranges_
;
816 scoped_refptr
<ppapi::Resource
> gamepad_impl_
;
817 scoped_refptr
<ppapi::Resource
> uma_private_impl_
;
819 // The plugin print interface.
820 const PPP_Printing_Dev
* plugin_print_interface_
;
822 // The plugin 3D interface.
823 const PPP_Graphics3D
* plugin_graphics_3d_interface_
;
825 // Contains the cursor if it's set by the plugin.
826 scoped_ptr
<blink::WebCursorInfo
> cursor_
;
828 // Set to true if this plugin thinks it will always be on top. This allows us
829 // to use a more optimized painting path in some cases.
831 // Even if |always_on_top_| is true, the plugin is not fully visible if there
832 // are some cut-out areas (occupied by iframes higher in the stacking order).
833 // This information is used in the optimized painting path.
834 std::vector
<gfx::Rect
> cut_outs_rects_
;
836 // Implementation of PPB_FlashFullscreen.
838 // Plugin container for fullscreen mode. NULL if not in fullscreen mode. Note:
839 // there is a transition state where fullscreen_container_ is non-NULL but
840 // flash_fullscreen_ is false (see above).
841 FullscreenContainer
* fullscreen_container_
;
843 // True if we are in "flash" fullscreen mode. False if we are in normal mode
844 // or in transition to fullscreen. Normal fullscreen mode is indicated in
846 bool flash_fullscreen_
;
848 // Implementation of PPB_Fullscreen.
850 // Since entering fullscreen mode is an asynchronous operation, we set this
851 // variable to the desired state at the time we issue the fullscreen change
852 // request. The plugin will receive a DidChangeView event when it goes
854 bool desired_fullscreen_state_
;
856 // WebKit does not resize the plugin when going into fullscreen mode, so we do
857 // this here by modifying the various plugin attributes and then restoring
859 blink::WebString width_before_fullscreen_
;
860 blink::WebString height_before_fullscreen_
;
861 blink::WebString border_before_fullscreen_
;
862 blink::WebString style_before_fullscreen_
;
863 gfx::Size screen_size_for_fullscreen_
;
865 // The MessageChannel used to implement bidirectional postMessage for the
867 v8::Persistent
<v8::Object
> message_channel_object_
;
869 // A pointer to the MessageChannel underlying |message_channel_object_|. It is
870 // only valid as long as |message_channel_object_| is alive.
871 MessageChannel
* message_channel_
;
873 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
874 SkBitmap
* sad_plugin_
;
876 typedef std::set
<PluginObject
*> PluginObjectSet
;
877 PluginObjectSet live_plugin_objects_
;
879 // Classes of events that the plugin has registered for, both for filtering
880 // and not. The bits are PP_INPUTEVENT_CLASS_*.
881 uint32_t input_event_mask_
;
882 uint32_t filtered_input_event_mask_
;
884 // Text composition status.
885 ui::TextInputType text_input_type_
;
886 gfx::Rect text_input_caret_
;
887 gfx::Rect text_input_caret_bounds_
;
888 bool text_input_caret_set_
;
890 // Text selection status.
891 std::string surrounding_text_
;
892 size_t selection_caret_
;
893 size_t selection_anchor_
;
895 scoped_refptr
<ppapi::TrackedCallback
> lock_mouse_callback_
;
897 // Track pending user gestures so out-of-process plugins can respond to
898 // a user gesture after it has been processed.
899 PP_TimeTicks pending_user_gesture_
;
900 blink::WebUserGestureToken pending_user_gesture_token_
;
902 // We store the arguments so we can re-send them if we are reset to talk to
903 // NaCl via the IPC NaCl proxy.
904 std::vector
<std::string
> argn_
;
905 std::vector
<std::string
> argv_
;
907 // Non-owning pointer to the document loader, if any.
908 blink::WebURLLoaderClient
* document_loader_
;
909 // State for deferring document loads. Used only by external instances.
910 blink::WebURLResponse external_document_response_
;
911 scoped_ptr
<ExternalDocumentLoader
> external_document_loader_
;
912 bool external_document_load_
;
914 // The ContentDecryptorDelegate forwards PPP_ContentDecryptor_Private
915 // calls and handles PPB_ContentDecryptor_Private calls.
916 scoped_ptr
<ContentDecryptorDelegate
> content_decryptor_delegate_
;
918 // The link currently under the cursor.
919 base::string16 link_under_cursor_
;
921 // We store the isolate at construction so that we can be sure to use the
922 // Isolate in which this Instance was created when interacting with v8.
923 v8::Isolate
* isolate_
;
925 scoped_ptr
<MouseLockDispatcher::LockTarget
> lock_target_
;
929 // The text that is currently selected in the plugin.
930 base::string16 selected_text_
;
932 int64 last_input_number_
;
934 bool is_tracking_latency_
;
936 // We use a weak ptr factory for scheduling DidChangeView events so that we
937 // can tell whether updates are pending and consolidate them. When there's
938 // already a weak ptr pending (HasWeakPtrs is true), code should update the
939 // view_data_ but not send updates. This also allows us to cancel scheduled
940 // view change events.
941 base::WeakPtrFactory
<PepperPluginInstanceImpl
> view_change_weak_ptr_factory_
;
942 base::WeakPtrFactory
<PepperPluginInstanceImpl
> weak_factory_
;
944 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceImpl
);
947 } // namespace content
949 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_IMPL_H_