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