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