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/texture_layer_client.h"
21 #include "content/common/content_export.h"
22 #include "content/public/renderer/pepper_plugin_instance.h"
23 #include "content/public/renderer/render_frame_observer.h"
24 #include "content/renderer/mouse_lock_dispatcher.h"
25 #include "ppapi/c/dev/pp_cursor_type_dev.h"
26 #include "ppapi/c/dev/ppp_find_dev.h"
27 #include "ppapi/c/dev/ppp_printing_dev.h"
28 #include "ppapi/c/dev/ppp_selection_dev.h"
29 #include "ppapi/c/dev/ppp_text_input_dev.h"
30 #include "ppapi/c/dev/ppp_zoom_dev.h"
31 #include "ppapi/c/pp_completion_callback.h"
32 #include "ppapi/c/pp_instance.h"
33 #include "ppapi/c/pp_time.h"
34 #include "ppapi/c/pp_var.h"
35 #include "ppapi/c/ppb_audio_config.h"
36 #include "ppapi/c/ppb_gamepad.h"
37 #include "ppapi/c/ppb_input_event.h"
38 #include "ppapi/c/ppp_graphics_3d.h"
39 #include "ppapi/c/ppp_input_event.h"
40 #include "ppapi/c/ppp_messaging.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_instance_private.h"
44 #include "ppapi/c/private/ppp_pdf.h"
45 #include "ppapi/shared_impl/ppb_instance_shared.h"
46 #include "ppapi/shared_impl/ppb_view_shared.h"
47 #include "ppapi/shared_impl/singleton_resource_id.h"
48 #include "ppapi/shared_impl/tracked_callback.h"
49 #include "ppapi/thunk/ppb_gamepad_api.h"
50 #include "ppapi/thunk/resource_creation_api.h"
51 #include "skia/ext/refptr.h"
52 #include "third_party/WebKit/public/platform/WebCanvas.h"
53 #include "third_party/WebKit/public/platform/WebString.h"
54 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
55 #include "third_party/WebKit/public/platform/WebURLResponse.h"
56 #include "third_party/WebKit/public/web/WebPlugin.h"
57 #include "third_party/WebKit/public/web/WebUserGestureToken.h"
58 #include "ui/base/ime/text_input_type.h"
59 #include "ui/gfx/rect.h"
72 class WebPluginContainer;
75 struct WebCompositionUnderline;
78 struct WebPrintParams;
91 struct InputEventData;
92 struct PPP_Instance_Combined;
101 class ContentDecryptorDelegate;
102 class FullscreenContainer;
103 class MessageChannel;
104 class PepperGraphics2DHost;
107 class PPB_Graphics3D_Impl;
108 class PPB_ImageData_Impl;
109 class PPB_URLLoader_Impl;
110 class RenderFrameImpl;
111 class RenderViewImpl;
113 // Represents one time a plugin appears on one web page.
115 // Note: to get from a PP_Instance to a PepperPluginInstance*, use the
117 class CONTENT_EXPORT PepperPluginInstanceImpl
118 : public base::RefCounted<PepperPluginInstanceImpl>,
119 public NON_EXPORTED_BASE(PepperPluginInstance),
120 public ppapi::PPB_Instance_Shared,
121 public NON_EXPORTED_BASE(cc::TextureLayerClient),
122 public RenderFrameObserver {
124 // Create and return a PepperPluginInstanceImpl object which supports the most
125 // recent version of PPP_Instance possible by querying the given
126 // get_plugin_interface function. If the plugin does not support any valid
127 // PPP_Instance interface, returns NULL.
128 static PepperPluginInstanceImpl* Create(
129 RenderFrameImpl* render_frame,
130 PluginModule* module,
131 blink::WebPluginContainer* container,
132 const GURL& plugin_url);
133 RenderFrameImpl* render_frame() const { return render_frame_; }
134 PluginModule* module() const { return module_.get(); }
135 MessageChannel& message_channel() { return *message_channel_; }
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 // Does some pre-destructor cleanup on the instance. This is necessary
148 // because some cleanup depends on the plugin instance still existing (like
149 // calling the plugin's DidDestroy function). This function is called from
150 // the WebPlugin implementation when WebKit is about to remove the plugin.
153 // Returns true if Delete() has been called on this object.
154 bool is_deleted() const;
156 // Paints the current backing store to the web page.
157 void Paint(blink::WebCanvas* canvas,
158 const gfx::Rect& plugin_rect,
159 const gfx::Rect& paint_rect);
161 // Schedules a paint of the page for the given region. The coordinates are
162 // relative to the top-left of the plugin. This does nothing if the plugin
163 // has not yet been positioned. You can supply an empty gfx::Rect() to
164 // invalidate the entire plugin.
165 void InvalidateRect(const gfx::Rect& rect);
167 // Schedules a scroll of the plugin. This uses optimized scrolling only for
168 // full-frame plugins, as otherwise there could be other elements on top. The
169 // slow path can also be triggered if there is an overlapping frame.
170 void ScrollRect(int dx, int dy, const gfx::Rect& rect);
172 // Commit the backing texture to the screen once the side effects some
173 // rendering up to an offscreen SwapBuffers are visible.
174 void CommitBackingTexture();
176 // Called when the out-of-process plugin implementing this instance crashed.
177 void InstanceCrashed();
179 // PPB_Instance and PPB_Instance_Private implementation.
180 bool full_frame() const { return full_frame_; }
181 const ppapi::ViewData& view_data() const { return view_data_; }
183 // PPP_Instance and PPP_Instance_Private.
184 bool Initialize(const std::vector<std::string>& arg_names,
185 const std::vector<std::string>& arg_values,
187 bool HandleDocumentLoad(const blink::WebURLResponse& response);
188 bool HandleInputEvent(const blink::WebInputEvent& event,
189 blink::WebCursorInfo* cursor_info);
190 PP_Var GetInstanceObject();
191 void ViewChanged(const gfx::Rect& position, const gfx::Rect& clip,
192 const std::vector<gfx::Rect>& cut_outs_rects);
194 // Handlers for composition events.
195 bool HandleCompositionStart(const base::string16& text);
196 bool HandleCompositionUpdate(
197 const base::string16& text,
198 const std::vector<blink::WebCompositionUnderline>& underlines,
201 bool HandleCompositionEnd(const base::string16& text);
202 bool HandleTextInput(const base::string16& text);
204 // Gets the current text input status.
205 ui::TextInputType text_input_type() const { return text_input_type_; }
206 gfx::Rect GetCaretBounds() const;
207 bool IsPluginAcceptingCompositionEvents() const;
208 void GetSurroundingText(base::string16* text, gfx::Range* range) const;
210 // Notifications about focus changes, see has_webkit_focus_ below.
211 void SetWebKitFocus(bool has_focus);
212 void SetContentAreaFocus(bool has_focus);
214 // Notification about page visibility. The default is "visible".
215 void PageVisibilityChanged(bool is_visible);
217 // Notifications that the view has started painting, and has flushed the
218 // painted content to the screen. These messages are used to send Flush
219 // callbacks to the plugin for DeviceContext2D/3D.
220 void ViewInitiatedPaint();
221 void ViewFlushedPaint();
223 // If this plugin can be painted merely by copying the backing store to the
224 // screen, and the plugin bounds encloses the given paint bounds, returns
225 // true. In this case, the location, clipping, and ID of the backing store
226 // will be filled into the given output parameters.
227 bool GetBitmapForOptimizedPluginPaint(
228 const gfx::Rect& paint_bounds,
230 gfx::Rect* dib_bounds,
232 float* scale_factor);
234 // Tracks all live PluginObjects.
235 void AddPluginObject(PluginObject* plugin_object);
236 void RemovePluginObject(PluginObject* plugin_object);
238 base::string16 GetSelectedText(bool html);
239 base::string16 GetLinkAtPosition(const gfx::Point& point);
240 void RequestSurroundingText(size_t desired_number_of_characters);
241 void Zoom(double factor, bool text_only);
242 bool StartFind(const base::string16& search_text,
245 void SelectFindResult(bool forward);
248 bool SupportsPrintInterface();
249 bool IsPrintScalingDisabled();
250 int PrintBegin(const blink::WebPrintParams& print_params);
251 bool PrintPage(int page_number, blink::WebCanvas* canvas);
254 bool CanRotateView();
255 void RotateView(blink::WebPlugin::RotationType type);
257 // There are 2 implementations of the fullscreen interface
258 // PPB_FlashFullscreen is used by Pepper Flash.
259 // PPB_Fullscreen is intended for other applications including NaCl.
260 // The two interface are mutually exclusive.
262 // Implementation of PPB_FlashFullscreen.
264 // Because going to fullscreen is asynchronous (but going out is not), there
266 // - normal : fullscreen_container_ == NULL
267 // flash_fullscreen_ == false
268 // - fullscreen pending: fullscreen_container_ != NULL
269 // flash_fullscreen_ == false
270 // - fullscreen : fullscreen_container_ != NULL
271 // flash_fullscreen_ == true
273 // In normal state, events come from webkit and painting goes back to it.
274 // In fullscreen state, events come from the fullscreen container, and
275 // painting goes back to it.
276 // In pending state, events from webkit are ignored, and as soon as we
277 // receive events from the fullscreen container, we go to the fullscreen
279 bool FlashIsFullscreenOrPending();
281 // Updates |flash_fullscreen_| and sends focus change notification if
283 void UpdateFlashFullscreenState(bool flash_fullscreen);
285 FullscreenContainer* fullscreen_container() const {
286 return fullscreen_container_;
289 // Implementation of PPB_Fullscreen.
291 // Because going to/from fullscreen is asynchronous, there are 4 states:
292 // - normal : desired_fullscreen_state_ == false
293 // view_data_.is_fullscreen == false
294 // - fullscreen pending: desired_fullscreen_state_ == true
295 // view_data_.is_fullscreen == false
296 // - fullscreen : desired_fullscreen_state_ == true
297 // view_data_.is_fullscreen == true
298 // - normal pending : desired_fullscreen_state_ = false
299 // view_data_.is_fullscreen = true
300 bool IsFullscreenOrPending();
302 bool flash_fullscreen() const { return flash_fullscreen_; }
304 // Switches between fullscreen and normal mode. The transition is
305 // asynchronous. WebKit will trigger corresponding VewChanged calls.
306 // Returns true on success, false on failure (e.g. trying to enter fullscreen
307 // when not processing a user gesture or trying to set fullscreen when
308 // already in fullscreen mode).
309 bool SetFullscreen(bool fullscreen);
311 // Implementation of PPP_Messaging.
312 void HandleMessage(PP_Var message);
314 // Returns true if the plugin is processing a user gesture.
315 bool IsProcessingUserGesture();
317 // Returns the user gesture token to use for creating a WebScopedUserGesture,
318 // if IsProcessingUserGesture returned true.
319 blink::WebUserGestureToken CurrentUserGestureToken();
321 // A mouse lock request was pending and this reports success or failure.
322 void OnLockMouseACK(bool succeeded);
323 // A mouse lock was in place, but has been lost.
324 void OnMouseLockLost();
325 // A mouse lock is enabled and mouse events are being delivered.
326 void HandleMouseLockedInputEvent(const blink::WebMouseEvent& event);
328 // Simulates an input event to the plugin by passing it down to WebKit,
329 // which sends it back up to the plugin as if it came from the user.
330 void SimulateInputEvent(const ppapi::InputEventData& input_event);
332 // Simulates an IME event at the level of RenderView which sends it back up to
333 // the plugin as if it came from the user.
334 bool SimulateIMEEvent(const ppapi::InputEventData& input_event);
335 void SimulateImeSetCompositionEvent(
336 const ppapi::InputEventData& input_event);
338 // The document loader is valid when the plugin is "full-frame" and in this
339 // case is non-NULL as long as the corresponding loader resource is alive.
340 // This pointer is non-owning, so the loader must use set_document_loader to
341 // clear itself when it is destroyed.
342 blink::WebURLLoaderClient* document_loader() const {
343 return document_loader_;
345 void set_document_loader(blink::WebURLLoaderClient* loader) {
346 document_loader_ = loader;
349 ContentDecryptorDelegate* GetContentDecryptorDelegate();
351 // PluginInstance implementation
352 virtual RenderView* GetRenderView() OVERRIDE;
353 virtual blink::WebPluginContainer* GetContainer() OVERRIDE;
354 virtual v8::Isolate* GetIsolate() const OVERRIDE;
355 virtual ppapi::VarTracker* GetVarTracker() OVERRIDE;
356 virtual const GURL& GetPluginURL() OVERRIDE;
357 virtual base::FilePath GetModulePath() OVERRIDE;
358 virtual PP_Resource CreateImage(gfx::ImageSkia* source_image,
359 float scale) OVERRIDE;
360 virtual PP_ExternalPluginResult SwitchToOutOfProcessProxy(
361 const base::FilePath& file_path,
362 ppapi::PpapiPermissions permissions,
363 const IPC::ChannelHandle& channel_handle,
364 base::ProcessId plugin_pid,
365 int plugin_child_id) OVERRIDE;
366 virtual void SetAlwaysOnTop(bool on_top) OVERRIDE;
367 virtual bool IsFullPagePlugin() OVERRIDE;
368 virtual bool FlashSetFullscreen(bool fullscreen, bool delay_report) OVERRIDE;
369 virtual bool IsRectTopmost(const gfx::Rect& rect) OVERRIDE;
370 virtual int32_t Navigate(const ppapi::URLRequestInfoData& request,
372 bool from_user_action) OVERRIDE;
373 virtual int MakePendingFileRefRendererHost(
374 const base::FilePath& path) OVERRIDE;
375 virtual void SetEmbedProperty(PP_Var key, PP_Var value) OVERRIDE;
376 virtual void SetSelectedText(const base::string16& selected_text) OVERRIDE;
377 virtual void SetLinkUnderCursor(const std::string& url) OVERRIDE;
379 // PPB_Instance_API implementation.
380 virtual PP_Bool BindGraphics(PP_Instance instance,
381 PP_Resource device) OVERRIDE;
382 virtual PP_Bool IsFullFrame(PP_Instance instance) OVERRIDE;
383 virtual const ppapi::ViewData* GetViewData(PP_Instance instance) OVERRIDE;
384 virtual PP_Bool FlashIsFullscreen(PP_Instance instance) OVERRIDE;
385 virtual PP_Var GetWindowObject(PP_Instance instance) OVERRIDE;
386 virtual PP_Var GetOwnerElementObject(PP_Instance instance) OVERRIDE;
387 virtual PP_Var ExecuteScript(PP_Instance instance,
389 PP_Var* exception) OVERRIDE;
390 virtual uint32_t GetAudioHardwareOutputSampleRate(PP_Instance instance)
392 virtual uint32_t GetAudioHardwareOutputBufferSize(PP_Instance instance)
394 virtual PP_Var GetDefaultCharSet(PP_Instance instance) OVERRIDE;
395 virtual void NumberOfFindResultsChanged(PP_Instance instance,
397 PP_Bool final_result) OVERRIDE;
398 virtual void SelectedFindResultChanged(PP_Instance instance,
399 int32_t index) OVERRIDE;
400 virtual PP_Bool IsFullscreen(PP_Instance instance) OVERRIDE;
401 virtual PP_Bool SetFullscreen(PP_Instance instance,
402 PP_Bool fullscreen) OVERRIDE;
403 virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size)
405 virtual ppapi::Resource* GetSingletonResource(PP_Instance instance,
406 ppapi::SingletonResourceID id) OVERRIDE;
407 virtual int32_t RequestInputEvents(PP_Instance instance,
408 uint32_t event_classes) OVERRIDE;
409 virtual int32_t RequestFilteringInputEvents(PP_Instance instance,
410 uint32_t event_classes) OVERRIDE;
411 virtual void ClearInputEventRequest(PP_Instance instance,
412 uint32_t event_classes) OVERRIDE;
413 virtual void ZoomChanged(PP_Instance instance, double factor) OVERRIDE;
414 virtual void ZoomLimitsChanged(PP_Instance instance,
415 double minimum_factor,
416 double maximum_factor) OVERRIDE;
417 virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE;
418 virtual PP_Bool SetCursor(PP_Instance instance,
419 PP_MouseCursor_Type type,
421 const PP_Point* hot_spot) OVERRIDE;
422 virtual int32_t LockMouse(
423 PP_Instance instance,
424 scoped_refptr<ppapi::TrackedCallback> callback) OVERRIDE;
425 virtual void UnlockMouse(PP_Instance instance) OVERRIDE;
426 virtual void SetTextInputType(PP_Instance instance,
427 PP_TextInput_Type type) OVERRIDE;
428 virtual void UpdateCaretPosition(PP_Instance instance,
429 const PP_Rect& caret,
430 const PP_Rect& bounding_box) OVERRIDE;
431 virtual void CancelCompositionText(PP_Instance instance) OVERRIDE;
432 virtual void SelectionChanged(PP_Instance instance) OVERRIDE;
433 virtual void UpdateSurroundingText(PP_Instance instance,
436 uint32_t anchor) OVERRIDE;
437 virtual PP_Var ResolveRelativeToDocument(
438 PP_Instance instance,
440 PP_URLComponents_Dev* components) OVERRIDE;
441 virtual PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) OVERRIDE;
442 virtual PP_Bool DocumentCanAccessDocument(PP_Instance instance,
443 PP_Instance target) OVERRIDE;
444 virtual PP_Var GetDocumentURL(PP_Instance instance,
445 PP_URLComponents_Dev* components) OVERRIDE;
446 virtual PP_Var GetPluginInstanceURL(
447 PP_Instance instance,
448 PP_URLComponents_Dev* components) OVERRIDE;
449 virtual PP_Var GetPluginReferrerURL(
450 PP_Instance instance,
451 PP_URLComponents_Dev* components) OVERRIDE;
453 // PPB_ContentDecryptor_Private implementation.
454 virtual void SessionCreated(PP_Instance instance,
456 PP_Var web_session_id_var) OVERRIDE;
457 virtual void SessionMessage(PP_Instance instance,
460 PP_Var destination_url) OVERRIDE;
461 virtual void SessionReady(PP_Instance instance, uint32_t session_id) OVERRIDE;
462 virtual void SessionClosed(PP_Instance instance,
463 uint32_t session_id) OVERRIDE;
464 virtual void SessionError(PP_Instance instance,
467 int32_t system_code) OVERRIDE;
468 virtual void DeliverBlock(PP_Instance instance,
469 PP_Resource decrypted_block,
470 const PP_DecryptedBlockInfo* block_info) OVERRIDE;
471 virtual void DecoderInitializeDone(PP_Instance instance,
472 PP_DecryptorStreamType decoder_type,
474 PP_Bool success) OVERRIDE;
475 virtual void DecoderDeinitializeDone(PP_Instance instance,
476 PP_DecryptorStreamType decoder_type,
477 uint32_t request_id) OVERRIDE;
478 virtual void DecoderResetDone(PP_Instance instance,
479 PP_DecryptorStreamType decoder_type,
480 uint32_t request_id) OVERRIDE;
481 virtual void DeliverFrame(PP_Instance instance,
482 PP_Resource decrypted_frame,
483 const PP_DecryptedFrameInfo* frame_info) OVERRIDE;
484 virtual void DeliverSamples(
485 PP_Instance instance,
486 PP_Resource audio_frames,
487 const PP_DecryptedSampleInfo* sample_info) OVERRIDE;
489 // Reset this instance as proxied. Assigns the instance a new module, resets
490 // cached interfaces to point to the out-of-process proxy and re-sends
491 // DidCreate, DidChangeView, and HandleDocumentLoad (if necessary).
492 // This should be used only when switching an in-process instance to an
493 // external out-of-process instance.
494 PP_ExternalPluginResult ResetAsProxied(scoped_refptr<PluginModule> module);
496 // Checks whether this is a valid instance of the given module. After calling
497 // ResetAsProxied above, a NaCl plugin instance's module changes, so external
498 // hosts won't recognize it as a valid instance of the original module. This
499 // method fixes that be checking that either module_ or original_module_ match
501 bool IsValidInstanceOf(PluginModule* module);
503 // Returns the plugin NPP identifier that this plugin will use to identify
504 // itself when making NPObject scripting calls to WebBindings.
505 struct _NPP* instanceNPP();
507 // cc::TextureLayerClient implementation.
508 virtual unsigned PrepareTexture() OVERRIDE;
509 virtual bool PrepareTextureMailbox(
510 cc::TextureMailbox* mailbox,
511 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
512 bool use_shared_memory) OVERRIDE;
514 // RenderFrameObserver
515 virtual void OnDestruct() OVERRIDE;
517 // Update any transforms that should be applied to the texture layer.
518 void UpdateLayerTransform();
521 friend class base::RefCounted<PepperPluginInstanceImpl>;
522 friend class PpapiUnittest;
524 // Delete should be called by the WebPlugin before this destructor.
525 virtual ~PepperPluginInstanceImpl();
527 // Class to record document load notifications and play them back once the
528 // real document loader becomes available. Used only by external instances.
529 class ExternalDocumentLoader : public blink::WebURLLoaderClient {
531 ExternalDocumentLoader();
532 virtual ~ExternalDocumentLoader();
534 void ReplayReceivedData(WebURLLoaderClient* document_loader);
536 // blink::WebURLLoaderClient implementation.
537 virtual void didReceiveData(blink::WebURLLoader* loader,
540 int encoded_data_length);
541 virtual void didFinishLoading(blink::WebURLLoader* loader,
543 int64_t total_encoded_data_length);
544 virtual void didFail(blink::WebURLLoader* loader,
545 const blink::WebURLError& error);
548 std::list<std::string> data_;
549 bool finished_loading_;
550 scoped_ptr<blink::WebURLError> error_;
553 // Implements PPB_Gamepad_API. This is just to avoid having an excessive
554 // number of interfaces implemented by PepperPluginInstanceImpl.
555 class GamepadImpl : public ppapi::thunk::PPB_Gamepad_API,
556 public ppapi::Resource {
559 // Resource implementation.
560 virtual ppapi::thunk::PPB_Gamepad_API* AsPPB_Gamepad_API() OVERRIDE;
561 virtual void Sample(PP_Instance instance,
562 PP_GamepadsSampleData* data) OVERRIDE;
564 virtual ~GamepadImpl();
567 // See the static Create functions above for creating PepperPluginInstanceImpl
568 // objects. This constructor is private so that we can hide the
569 // PPP_Instance_Combined details while still having 1 constructor to maintain
570 // for member initialization.
571 PepperPluginInstanceImpl(RenderFrameImpl* render_frame,
572 PluginModule* module,
573 ppapi::PPP_Instance_Combined* instance_interface,
574 blink::WebPluginContainer* container,
575 const GURL& plugin_url);
577 bool LoadFindInterface();
578 bool LoadInputEventInterface();
579 bool LoadMessagingInterface();
580 bool LoadMouseLockInterface();
581 bool LoadPdfInterface();
582 bool LoadPrintInterface();
583 bool LoadPrivateInterface();
584 bool LoadSelectionInterface();
585 bool LoadTextInputInterface();
586 bool LoadZoomInterface();
588 // Determines if we think the plugin has focus, both content area and webkit
589 // (see has_webkit_focus_ below).
590 bool PluginHasFocus() const;
591 void SendFocusChangeNotification();
593 void UpdateTouchEventRequest();
595 // Returns true if the plugin has registered to accept wheel events.
596 bool IsAcceptingWheelEvents() const;
598 void ScheduleAsyncDidChangeView();
599 void SendAsyncDidChangeView();
600 void SendDidChangeView();
602 // Reports the current plugin geometry to the plugin by calling
604 void ReportGeometry();
606 // Queries the plugin for supported print formats and sets |format| to the
607 // best format to use. Returns false if the plugin does not support any
608 // print format that we can handle (we can handle only PDF).
609 bool GetPreferredPrintOutputFormat(PP_PrintOutputFormat_Dev* format);
610 bool PrintPDFOutput(PP_Resource print_output, blink::WebCanvas* canvas);
612 // Updates the layer for compositing. This creates a layer and attaches to the
614 // - we have a bound Graphics3D and the Graphics3D has a texture, OR
615 // we have a bound Graphics2D and are using software compositing
616 // - we are not in Flash full-screen mode (or transitioning to it)
617 // Otherwise it destroys the layer.
618 // It does either operation lazily.
621 // Internal helper function for PrintPage().
622 bool PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges,
624 blink::WebCanvas* canvas);
626 void DoSetCursor(blink::WebCursorInfo* cursor);
628 // Internal helper functions for HandleCompositionXXX().
629 bool SendCompositionEventToPlugin(
630 PP_InputEvent_Type type,
631 const base::string16& text);
632 bool SendCompositionEventWithUnderlineInformationToPlugin(
633 PP_InputEvent_Type type,
634 const base::string16& text,
635 const std::vector<blink::WebCompositionUnderline>& underlines,
639 // Internal helper function for XXXInputEvents().
640 void RequestInputEventsHelper(uint32_t event_classes);
642 // Checks if the security origin of the document containing this instance can
643 // assess the security origin of the main frame document.
644 bool CanAccessMainFrame() const;
646 // Returns true if the WebView the plugin is in renders via the accelerated
648 bool IsViewAccelerated();
650 // Track, set and reset size attributes to control the size of the plugin
651 // in and out of fullscreen mode.
652 void KeepSizeAttributesBeforeFullscreen();
653 void SetSizeAttributesForFullscreen();
654 void ResetSizeAttributesAfterFullscreen();
656 bool IsMouseLocked();
658 MouseLockDispatcher* GetMouseLockDispatcher();
659 MouseLockDispatcher::LockTarget* GetOrCreateLockTargetAdapter();
660 void UnSetAndDeleteLockTargetAdapter();
662 void DidDataFromWebURLResponse(
663 const blink::WebURLResponse& response,
665 const ppapi::URLResponseInfoData& data);
667 RenderFrameImpl* render_frame_;
668 base::Closure instance_deleted_callback_;
669 scoped_refptr<PluginModule> module_;
670 scoped_ptr<ppapi::PPP_Instance_Combined> instance_interface_;
671 // If this is the NaCl plugin, we create a new module when we switch to the
672 // IPC-based PPAPI proxy. Store the original module and instance interface
673 // so we can shut down properly.
674 scoped_refptr<PluginModule> original_module_;
675 scoped_ptr<ppapi::PPP_Instance_Combined> original_instance_interface_;
677 PP_Instance pp_instance_;
679 // NULL until we have been initialized.
680 blink::WebPluginContainer* container_;
681 scoped_refptr<cc::TextureLayer> texture_layer_;
682 scoped_ptr<blink::WebLayer> web_layer_;
683 bool layer_bound_to_fullscreen_;
684 bool layer_is_hardware_;
689 // Indicates whether this is a full frame instance, which means it represents
690 // an entire document rather than an embed tag.
693 // Stores the current state of the plugin view.
694 ppapi::ViewData view_data_;
695 // The last state sent to the plugin. It is only valid after
696 // |sent_initial_did_change_view_| is set to true.
697 ppapi::ViewData last_sent_view_data_;
699 // Indicates if we've ever sent a didChangeView to the plugin. This ensures we
700 // always send an initial notification, even if the position and clip are the
701 // same as the default values.
702 bool sent_initial_did_change_view_;
704 // The current device context for painting in 2D and 3D.
705 scoped_refptr<PPB_Graphics3D_Impl> bound_graphics_3d_;
706 PepperGraphics2DHost* bound_graphics_2d_platform_;
708 // We track two types of focus, one from WebKit, which is the focus among
709 // all elements of the page, one one from the browser, which is whether the
710 // tab/window has focus. We tell the plugin it has focus only when both of
711 // these values are set to true.
712 bool has_webkit_focus_;
713 bool has_content_area_focus_;
715 // The id of the current find operation, or -1 if none is in process.
716 int find_identifier_;
718 // Helper object that creates resources.
719 scoped_ptr<ppapi::thunk::ResourceCreationAPI> resource_creation_;
721 // The plugin-provided interfaces.
722 // When adding PPP interfaces, make sure to reset them in ResetAsProxied.
723 const PPP_Find_Dev* plugin_find_interface_;
724 const PPP_InputEvent* plugin_input_event_interface_;
725 const PPP_Messaging* plugin_messaging_interface_;
726 const PPP_MouseLock* plugin_mouse_lock_interface_;
727 const PPP_Pdf* plugin_pdf_interface_;
728 const PPP_Instance_Private* plugin_private_interface_;
729 const PPP_Selection_Dev* plugin_selection_interface_;
730 const PPP_TextInput_Dev* plugin_textinput_interface_;
731 const PPP_Zoom_Dev* plugin_zoom_interface_;
733 // Flags indicating whether we have asked this plugin instance for the
734 // corresponding interfaces, so that we can ask only once.
735 // When adding flags, make sure to reset them in ResetAsProxied.
736 bool checked_for_plugin_input_event_interface_;
737 bool checked_for_plugin_messaging_interface_;
738 bool checked_for_plugin_pdf_interface_;
740 // This is only valid between a successful PrintBegin call and a PrintEnd
742 PP_PrintSettings_Dev current_print_settings_;
743 #if defined(OS_MACOSX)
744 // On the Mac, when we draw the bitmap to the PDFContext, it seems necessary
745 // to keep the pixels valid until CGContextEndPage is called. We use this
746 // variable to hold on to the pixels.
747 scoped_refptr<PPB_ImageData_Impl> last_printed_page_;
748 #endif // defined(OS_MACOSX)
749 // Always when printing to PDF on Linux and when printing for preview on Mac
750 // and Win, the entire document goes into one metafile. However, when users
751 // print only a subset of all the pages, it is impossible to know if a call
752 // to PrintPage() is the last call. Thus in PrintPage(), just store the page
753 // number in |ranges_|. The hack is in PrintEnd(), where a valid |canvas_|
754 // is preserved in PrintWebViewHelper::PrintPages. This makes it possible
755 // to generate the entire PDF given the variables below:
757 // The most recently used WebCanvas, guaranteed to be valid.
758 skia::RefPtr<blink::WebCanvas> canvas_;
759 // An array of page ranges.
760 std::vector<PP_PrintPageNumberRange_Dev> ranges_;
762 scoped_refptr<ppapi::Resource> gamepad_impl_;
763 scoped_refptr<ppapi::Resource> uma_private_impl_;
765 // The plugin print interface.
766 const PPP_Printing_Dev* plugin_print_interface_;
768 // The plugin 3D interface.
769 const PPP_Graphics3D* plugin_graphics_3d_interface_;
771 // Contains the cursor if it's set by the plugin.
772 scoped_ptr<blink::WebCursorInfo> cursor_;
774 // Set to true if this plugin thinks it will always be on top. This allows us
775 // to use a more optimized painting path in some cases.
777 // Even if |always_on_top_| is true, the plugin is not fully visible if there
778 // are some cut-out areas (occupied by iframes higher in the stacking order).
779 // This information is used in the optimized painting path.
780 std::vector<gfx::Rect> cut_outs_rects_;
782 // Implementation of PPB_FlashFullscreen.
784 // Plugin container for fullscreen mode. NULL if not in fullscreen mode. Note:
785 // there is a transition state where fullscreen_container_ is non-NULL but
786 // flash_fullscreen_ is false (see above).
787 FullscreenContainer* fullscreen_container_;
789 // True if we are in "flash" fullscreen mode. False if we are in normal mode
790 // or in transition to fullscreen. Normal fullscreen mode is indicated in
792 bool flash_fullscreen_;
794 // Implementation of PPB_Fullscreen.
796 // Since entering fullscreen mode is an asynchronous operation, we set this
797 // variable to the desired state at the time we issue the fullscreen change
798 // request. The plugin will receive a DidChangeView event when it goes
800 bool desired_fullscreen_state_;
802 // WebKit does not resize the plugin when going into fullscreen mode, so we do
803 // this here by modifying the various plugin attributes and then restoring
805 blink::WebString width_before_fullscreen_;
806 blink::WebString height_before_fullscreen_;
807 blink::WebString border_before_fullscreen_;
808 blink::WebString style_before_fullscreen_;
809 gfx::Size screen_size_for_fullscreen_;
811 // The MessageChannel used to implement bidirectional postMessage for the
813 scoped_ptr<MessageChannel> message_channel_;
815 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
816 SkBitmap* sad_plugin_;
818 typedef std::set<PluginObject*> PluginObjectSet;
819 PluginObjectSet live_plugin_objects_;
821 // Classes of events that the plugin has registered for, both for filtering
822 // and not. The bits are PP_INPUTEVENT_CLASS_*.
823 uint32_t input_event_mask_;
824 uint32_t filtered_input_event_mask_;
826 // Text composition status.
827 ui::TextInputType text_input_type_;
828 gfx::Rect text_input_caret_;
829 gfx::Rect text_input_caret_bounds_;
830 bool text_input_caret_set_;
832 // Text selection status.
833 std::string surrounding_text_;
834 size_t selection_caret_;
835 size_t selection_anchor_;
837 scoped_refptr<ppapi::TrackedCallback> lock_mouse_callback_;
839 // Track pending user gestures so out-of-process plugins can respond to
840 // a user gesture after it has been processed.
841 PP_TimeTicks pending_user_gesture_;
842 blink::WebUserGestureToken pending_user_gesture_token_;
844 // We store the arguments so we can re-send them if we are reset to talk to
845 // NaCl via the IPC NaCl proxy.
846 std::vector<std::string> argn_;
847 std::vector<std::string> argv_;
849 // Non-owning pointer to the document loader, if any.
850 blink::WebURLLoaderClient* document_loader_;
851 // State for deferring document loads. Used only by external instances.
852 blink::WebURLResponse external_document_response_;
853 scoped_ptr<ExternalDocumentLoader> external_document_loader_;
854 bool external_document_load_;
856 // The ContentDecryptorDelegate forwards PPP_ContentDecryptor_Private
857 // calls and handles PPB_ContentDecryptor_Private calls.
858 scoped_ptr<ContentDecryptorDelegate> content_decryptor_delegate_;
860 // The link currently under the cursor.
861 base::string16 link_under_cursor_;
863 // Dummy NPP value used when calling in to WebBindings, to allow the bindings
864 // to correctly track NPObjects belonging to this plugin instance.
865 scoped_ptr<struct _NPP> npp_;
867 // We store the isolate at construction so that we can be sure to use the
868 // Isolate in which this Instance was created when interacting with v8.
869 v8::Isolate* isolate_;
871 scoped_ptr<MouseLockDispatcher::LockTarget> lock_target_;
875 // The text that is currently selected in the plugin.
876 base::string16 selected_text_;
878 // We use a weak ptr factory for scheduling DidChangeView events so that we
879 // can tell whether updates are pending and consolidate them. When there's
880 // already a weak ptr pending (HasWeakPtrs is true), code should update the
881 // view_data_ but not send updates. This also allows us to cancel scheduled
882 // view change events.
883 base::WeakPtrFactory<PepperPluginInstanceImpl> view_change_weak_ptr_factory_;
884 base::WeakPtrFactory<PepperPluginInstanceImpl> weak_factory_;
886 friend class PpapiPluginInstanceTest;
887 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceImpl);
890 } // namespace content
892 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_IMPL_H_