[Ozone-Gbm] Explicitly crash if trying software rendering on GBM
[chromium-blink-merge.git] / content / renderer / pepper / pepper_plugin_instance_impl.h
blob6de1847861a371487d89c8f16d2d35486ed772a9
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_
8 #include <list>
9 #include <set>
10 #include <string>
11 #include <vector>
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"
64 #include "url/gurl.h"
65 #include "v8/include/v8.h"
67 struct PP_Point;
68 struct _NPP;
70 class SkBitmap;
71 class TransportDIB;
73 namespace blink {
74 class WebInputEvent;
75 class WebLayer;
76 class WebMouseEvent;
77 class WebPluginContainer;
78 class WebURLLoader;
79 class WebURLResponse;
80 struct WebCompositionUnderline;
81 struct WebCursorInfo;
82 struct WebURLError;
83 struct WebPrintParams;
86 namespace cc {
87 class TextureLayer;
90 namespace gfx {
91 class Range;
94 namespace ppapi {
95 class Resource;
96 struct InputEventData;
97 struct PPP_Instance_Combined;
98 class ScopedPPVar;
101 namespace content {
103 class ContentDecryptorDelegate;
104 class FullscreenContainer;
105 class MessageChannel;
106 class PepperCompositorHost;
107 class PepperGraphics2DHost;
108 class PluginInstanceThrottlerImpl;
109 class PluginModule;
110 class PluginObject;
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
120 // ResourceTracker.
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) {
128 public:
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
145 // nonzero.
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.
169 void Delete();
171 // Returns true if Delete() has been called on this object.
172 bool is_deleted() const;
174 // Paints the current backing store to the web page.
175 void Paint(blink::WebCanvas* canvas,
176 const gfx::Rect& plugin_rect,
177 const gfx::Rect& paint_rect);
179 // Schedules a paint of the page for the given region. The coordinates are
180 // relative to the top-left of the plugin. This does nothing if the plugin
181 // has not yet been positioned. You can supply an empty gfx::Rect() to
182 // invalidate the entire plugin.
183 void InvalidateRect(const gfx::Rect& rect);
185 // Schedules a scroll of the plugin. This uses optimized scrolling only for
186 // full-frame plugins, as otherwise there could be other elements on top. The
187 // slow path can also be triggered if there is an overlapping frame.
188 void ScrollRect(int dx, int dy, const gfx::Rect& rect);
190 // Commit the backing texture to the screen once the side effects some
191 // rendering up to an offscreen SwapBuffers are visible.
192 void CommitBackingTexture();
194 // Called when the out-of-process plugin implementing this instance crashed.
195 void InstanceCrashed();
197 // PPB_Instance and PPB_Instance_Private implementation.
198 bool full_frame() const { return full_frame_; }
199 const ppapi::ViewData& view_data() const { return view_data_; }
201 // PPP_Instance and PPP_Instance_Private.
202 bool Initialize(const std::vector<std::string>& arg_names,
203 const std::vector<std::string>& arg_values,
204 bool full_frame,
205 scoped_ptr<PluginInstanceThrottlerImpl> throttler);
206 bool HandleDocumentLoad(const blink::WebURLResponse& response);
207 bool HandleInputEvent(const blink::WebInputEvent& event,
208 blink::WebCursorInfo* cursor_info);
209 PP_Var GetInstanceObject(v8::Isolate* isolate);
210 void ViewChanged(const gfx::Rect& position,
211 const gfx::Rect& clip,
212 const std::vector<gfx::Rect>& cut_outs_rects);
214 // Handlers for composition events.
215 bool HandleCompositionStart(const base::string16& text);
216 bool HandleCompositionUpdate(
217 const base::string16& text,
218 const std::vector<blink::WebCompositionUnderline>& underlines,
219 int selection_start,
220 int selection_end);
221 bool HandleCompositionEnd(const base::string16& text);
222 bool HandleTextInput(const base::string16& text);
224 // Gets the current text input status.
225 ui::TextInputType text_input_type() const { return text_input_type_; }
226 gfx::Rect GetCaretBounds() const;
227 bool IsPluginAcceptingCompositionEvents() const;
228 void GetSurroundingText(base::string16* text, gfx::Range* range) const;
230 // Notifications about focus changes, see has_webkit_focus_ below.
231 void SetWebKitFocus(bool has_focus);
232 void SetContentAreaFocus(bool has_focus);
234 // Notification about page visibility. The default is "visible".
235 void PageVisibilityChanged(bool is_visible);
237 // Notifications that the view has started painting. This message is used to
238 // send Flush callbacks to the plugin for Graphics2D/3D.
239 void ViewInitiatedPaint();
241 // Tracks all live PluginObjects.
242 void AddPluginObject(PluginObject* plugin_object);
243 void RemovePluginObject(PluginObject* plugin_object);
245 base::string16 GetSelectedText(bool html);
246 base::string16 GetLinkAtPosition(const gfx::Point& point);
247 void RequestSurroundingText(size_t desired_number_of_characters);
248 void Zoom(double factor, bool text_only);
249 bool StartFind(const base::string16& search_text,
250 bool case_sensitive,
251 int identifier);
252 void SelectFindResult(bool forward);
253 void StopFind();
255 bool SupportsPrintInterface();
256 bool IsPrintScalingDisabled();
257 int PrintBegin(const blink::WebPrintParams& print_params);
258 bool PrintPage(int page_number, blink::WebCanvas* canvas);
259 void PrintEnd();
260 bool GetPrintPresetOptionsFromDocument(
261 blink::WebPrintPresetOptions* preset_options);
263 bool CanRotateView();
264 void RotateView(blink::WebPlugin::RotationType type);
266 // There are 2 implementations of the fullscreen interface
267 // PPB_FlashFullscreen is used by Pepper Flash.
268 // PPB_Fullscreen is intended for other applications including NaCl.
269 // The two interface are mutually exclusive.
271 // Implementation of PPB_FlashFullscreen.
273 // Because going to fullscreen is asynchronous (but going out is not), there
274 // are 3 states:
275 // - normal : fullscreen_container_ == NULL
276 // flash_fullscreen_ == false
277 // - fullscreen pending: fullscreen_container_ != NULL
278 // flash_fullscreen_ == false
279 // - fullscreen : fullscreen_container_ != NULL
280 // flash_fullscreen_ == true
282 // In normal state, events come from webkit and painting goes back to it.
283 // In fullscreen state, events come from the fullscreen container, and
284 // painting goes back to it.
285 // In pending state, events from webkit are ignored, and as soon as we
286 // receive events from the fullscreen container, we go to the fullscreen
287 // state.
288 bool FlashIsFullscreenOrPending();
290 // Updates |flash_fullscreen_| and sends focus change notification if
291 // necessary.
292 void UpdateFlashFullscreenState(bool flash_fullscreen);
294 FullscreenContainer* fullscreen_container() const {
295 return fullscreen_container_;
298 // Implementation of PPB_Fullscreen.
300 // Because going to/from fullscreen is asynchronous, there are 4 states:
301 // - normal : desired_fullscreen_state_ == false
302 // view_data_.is_fullscreen == false
303 // - fullscreen pending: desired_fullscreen_state_ == true
304 // view_data_.is_fullscreen == false
305 // - fullscreen : desired_fullscreen_state_ == true
306 // view_data_.is_fullscreen == true
307 // - normal pending : desired_fullscreen_state_ = false
308 // view_data_.is_fullscreen = true
309 bool IsFullscreenOrPending();
311 bool flash_fullscreen() const { return flash_fullscreen_; }
313 // Switches between fullscreen and normal mode. The transition is
314 // asynchronous. WebKit will trigger corresponding VewChanged calls.
315 // Returns true on success, false on failure (e.g. trying to enter fullscreen
316 // when not processing a user gesture or trying to set fullscreen when
317 // already in fullscreen mode).
318 bool SetFullscreen(bool fullscreen);
320 // Send the message on to the plugin.
321 void HandleMessage(ppapi::ScopedPPVar message);
323 // Send the message synchronously to the plugin, and get a result. Returns
324 // true if the plugin handled the message, false if it didn't. The plugin
325 // won't handle the message if it has not registered a PPP_MessageHandler.
326 bool HandleBlockingMessage(ppapi::ScopedPPVar message,
327 ppapi::ScopedPPVar* result);
329 // Returns true if the plugin is processing a user gesture.
330 bool IsProcessingUserGesture();
332 // Returns the user gesture token to use for creating a WebScopedUserGesture,
333 // if IsProcessingUserGesture returned true.
334 blink::WebUserGestureToken CurrentUserGestureToken();
336 // A mouse lock request was pending and this reports success or failure.
337 void OnLockMouseACK(bool succeeded);
338 // A mouse lock was in place, but has been lost.
339 void OnMouseLockLost();
340 // A mouse lock is enabled and mouse events are being delivered.
341 void HandleMouseLockedInputEvent(const blink::WebMouseEvent& event);
343 // Simulates an input event to the plugin by passing it down to WebKit,
344 // which sends it back up to the plugin as if it came from the user.
345 void SimulateInputEvent(const ppapi::InputEventData& input_event);
347 // Simulates an IME event at the level of RenderView which sends it back up to
348 // the plugin as if it came from the user.
349 bool SimulateIMEEvent(const ppapi::InputEventData& input_event);
350 void SimulateImeSetCompositionEvent(const ppapi::InputEventData& input_event);
352 // The document loader is valid when the plugin is "full-frame" and in this
353 // case is non-NULL as long as the corresponding loader resource is alive.
354 // This pointer is non-owning, so the loader must use set_document_loader to
355 // clear itself when it is destroyed.
356 blink::WebURLLoaderClient* document_loader() const {
357 return document_loader_;
359 void set_document_loader(blink::WebURLLoaderClient* loader) {
360 document_loader_ = loader;
363 ContentDecryptorDelegate* GetContentDecryptorDelegate();
365 // PluginInstance implementation
366 RenderView* GetRenderView() override;
367 blink::WebPluginContainer* GetContainer() override;
368 v8::Isolate* GetIsolate() const override;
369 ppapi::VarTracker* GetVarTracker() override;
370 const GURL& GetPluginURL() override;
371 base::FilePath GetModulePath() override;
372 PP_Resource CreateImage(gfx::ImageSkia* source_image, float scale) override;
373 PP_ExternalPluginResult SwitchToOutOfProcessProxy(
374 const base::FilePath& file_path,
375 ppapi::PpapiPermissions permissions,
376 const IPC::ChannelHandle& channel_handle,
377 base::ProcessId plugin_pid,
378 int plugin_child_id) override;
379 void SetAlwaysOnTop(bool on_top) override;
380 bool IsFullPagePlugin() override;
381 bool FlashSetFullscreen(bool fullscreen, bool delay_report) override;
382 bool IsRectTopmost(const gfx::Rect& rect) override;
383 int32_t Navigate(const ppapi::URLRequestInfoData& request,
384 const char* target,
385 bool from_user_action) override;
386 int MakePendingFileRefRendererHost(const base::FilePath& path) override;
387 void SetEmbedProperty(PP_Var key, PP_Var value) override;
388 void SetSelectedText(const base::string16& selected_text) override;
389 void SetLinkUnderCursor(const std::string& url) override;
390 void SetTextInputType(ui::TextInputType type) override;
391 void PostMessageToJavaScript(PP_Var message) override;
393 // PPB_Instance_API implementation.
394 PP_Bool BindGraphics(PP_Instance instance, PP_Resource device) override;
395 PP_Bool IsFullFrame(PP_Instance instance) override;
396 const ppapi::ViewData* GetViewData(PP_Instance instance) override;
397 PP_Bool FlashIsFullscreen(PP_Instance instance) override;
398 PP_Var GetWindowObject(PP_Instance instance) override;
399 PP_Var GetOwnerElementObject(PP_Instance instance) override;
400 PP_Var ExecuteScript(PP_Instance instance,
401 PP_Var script,
402 PP_Var* exception) override;
403 uint32_t GetAudioHardwareOutputSampleRate(PP_Instance instance) override;
404 uint32_t GetAudioHardwareOutputBufferSize(PP_Instance instance) override;
405 PP_Var GetDefaultCharSet(PP_Instance instance) override;
406 void SetPluginToHandleFindRequests(PP_Instance) override;
407 void NumberOfFindResultsChanged(PP_Instance instance,
408 int32_t total,
409 PP_Bool final_result) override;
410 void SelectedFindResultChanged(PP_Instance instance, int32_t index) override;
411 void SetTickmarks(PP_Instance instance,
412 const PP_Rect* tickmarks,
413 uint32_t count) override;
414 PP_Bool IsFullscreen(PP_Instance instance) override;
415 PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) override;
416 PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) override;
417 ppapi::Resource* GetSingletonResource(PP_Instance instance,
418 ppapi::SingletonResourceID id) override;
419 int32_t RequestInputEvents(PP_Instance instance,
420 uint32_t event_classes) override;
421 int32_t RequestFilteringInputEvents(PP_Instance instance,
422 uint32_t event_classes) override;
423 void ClearInputEventRequest(PP_Instance instance,
424 uint32_t event_classes) override;
425 void StartTrackingLatency(PP_Instance instance) override;
426 void ZoomChanged(PP_Instance instance, double factor) override;
427 void ZoomLimitsChanged(PP_Instance instance,
428 double minimum_factor,
429 double maximum_factor) override;
430 void PostMessage(PP_Instance instance, PP_Var message) override;
431 int32_t RegisterMessageHandler(PP_Instance instance,
432 void* user_data,
433 const PPP_MessageHandler_0_2* handler,
434 PP_Resource message_loop) override;
435 int32_t RegisterMessageHandler_1_1_Deprecated(
436 PP_Instance instance,
437 void* user_data,
438 const PPP_MessageHandler_0_1_Deprecated* handler,
439 PP_Resource message_loop) override;
440 void UnregisterMessageHandler(PP_Instance instance) override;
441 PP_Bool SetCursor(PP_Instance instance,
442 PP_MouseCursor_Type type,
443 PP_Resource image,
444 const PP_Point* hot_spot) override;
445 int32_t LockMouse(PP_Instance instance,
446 scoped_refptr<ppapi::TrackedCallback> callback) override;
447 void UnlockMouse(PP_Instance instance) override;
448 void SetTextInputType(PP_Instance instance, PP_TextInput_Type type) override;
449 void UpdateCaretPosition(PP_Instance instance,
450 const PP_Rect& caret,
451 const PP_Rect& bounding_box) override;
452 void CancelCompositionText(PP_Instance instance) override;
453 void SelectionChanged(PP_Instance instance) override;
454 void UpdateSurroundingText(PP_Instance instance,
455 const char* text,
456 uint32_t caret,
457 uint32_t anchor) override;
458 PP_Var ResolveRelativeToDocument(PP_Instance instance,
459 PP_Var relative,
460 PP_URLComponents_Dev* components) override;
461 PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) override;
462 PP_Bool DocumentCanAccessDocument(PP_Instance instance,
463 PP_Instance target) override;
464 PP_Var GetDocumentURL(PP_Instance instance,
465 PP_URLComponents_Dev* components) override;
466 PP_Var GetPluginInstanceURL(PP_Instance instance,
467 PP_URLComponents_Dev* components) override;
468 PP_Var GetPluginReferrerURL(PP_Instance instance,
469 PP_URLComponents_Dev* components) override;
471 // PPB_ContentDecryptor_Private implementation.
472 void PromiseResolved(PP_Instance instance, uint32 promise_id) override;
473 void PromiseResolvedWithSession(PP_Instance instance,
474 uint32 promise_id,
475 PP_Var session_id_var) override;
476 void PromiseRejected(PP_Instance instance,
477 uint32 promise_id,
478 PP_CdmExceptionCode exception_code,
479 uint32 system_code,
480 PP_Var error_description_var) override;
481 void SessionMessage(PP_Instance instance,
482 PP_Var session_id_var,
483 PP_CdmMessageType message_type,
484 PP_Var message_var,
485 PP_Var legacy_destination_url) override;
486 void SessionKeysChange(
487 PP_Instance instance,
488 PP_Var session_id_var,
489 PP_Bool has_additional_usable_key,
490 uint32_t key_count,
491 const struct PP_KeyInformation key_information[]) override;
492 void SessionExpirationChange(PP_Instance instance,
493 PP_Var session_id_var,
494 PP_Time new_expiry_time) override;
495 void SessionClosed(PP_Instance instance, PP_Var session_id_var) override;
496 void SessionError(PP_Instance instance,
497 PP_Var session_id_var,
498 PP_CdmExceptionCode exception_code,
499 uint32 system_code,
500 PP_Var error_description_var) override;
501 void DeliverBlock(PP_Instance instance,
502 PP_Resource decrypted_block,
503 const PP_DecryptedBlockInfo* block_info) override;
504 void DecoderInitializeDone(PP_Instance instance,
505 PP_DecryptorStreamType decoder_type,
506 uint32_t request_id,
507 PP_Bool success) override;
508 void DecoderDeinitializeDone(PP_Instance instance,
509 PP_DecryptorStreamType decoder_type,
510 uint32_t request_id) override;
511 void DecoderResetDone(PP_Instance instance,
512 PP_DecryptorStreamType decoder_type,
513 uint32_t request_id) override;
514 void DeliverFrame(PP_Instance instance,
515 PP_Resource decrypted_frame,
516 const PP_DecryptedFrameInfo* frame_info) override;
517 void DeliverSamples(PP_Instance instance,
518 PP_Resource audio_frames,
519 const PP_DecryptedSampleInfo* sample_info) override;
521 // Reset this instance as proxied. Assigns the instance a new module, resets
522 // cached interfaces to point to the out-of-process proxy and re-sends
523 // DidCreate, DidChangeView, and HandleDocumentLoad (if necessary).
524 // This should be used only when switching an in-process instance to an
525 // external out-of-process instance.
526 PP_ExternalPluginResult ResetAsProxied(scoped_refptr<PluginModule> module);
528 // Checks whether this is a valid instance of the given module. After calling
529 // ResetAsProxied above, a NaCl plugin instance's module changes, so external
530 // hosts won't recognize it as a valid instance of the original module. This
531 // method fixes that be checking that either module_ or original_module_ match
532 // the given module.
533 bool IsValidInstanceOf(PluginModule* module);
535 // cc::TextureLayerClient implementation.
536 bool PrepareTextureMailbox(
537 cc::TextureMailbox* mailbox,
538 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
539 bool use_shared_memory) override;
541 // RenderFrameObserver
542 void OnDestruct() override;
544 // PluginInstanceThrottler::Observer
545 void OnThrottleStateChange() override;
546 void OnHiddenForPlaceholder(bool hidden) override;
548 void AddLatencyInfo(const std::vector<ui::LatencyInfo>& latency_info);
550 private:
551 friend class base::RefCounted<PepperPluginInstanceImpl>;
552 friend class PpapiPluginInstanceTest;
553 friend class PpapiUnittest;
555 // Delete should be called by the WebPlugin before this destructor.
556 ~PepperPluginInstanceImpl() override;
558 // Class to record document load notifications and play them back once the
559 // real document loader becomes available. Used only by external instances.
560 class ExternalDocumentLoader : public blink::WebURLLoaderClient {
561 public:
562 ExternalDocumentLoader();
563 virtual ~ExternalDocumentLoader();
565 void ReplayReceivedData(WebURLLoaderClient* document_loader);
567 // blink::WebURLLoaderClient implementation.
568 virtual void didReceiveData(blink::WebURLLoader* loader,
569 const char* data,
570 int data_length,
571 int encoded_data_length);
572 virtual void didFinishLoading(blink::WebURLLoader* loader,
573 double finish_time,
574 int64_t total_encoded_data_length);
575 virtual void didFail(blink::WebURLLoader* loader,
576 const blink::WebURLError& error);
578 private:
579 std::list<std::string> data_;
580 bool finished_loading_;
581 scoped_ptr<blink::WebURLError> error_;
584 // Implements PPB_Gamepad_API. This is just to avoid having an excessive
585 // number of interfaces implemented by PepperPluginInstanceImpl.
586 class GamepadImpl : public ppapi::thunk::PPB_Gamepad_API,
587 public ppapi::Resource {
588 public:
589 GamepadImpl();
590 // Resource implementation.
591 ppapi::thunk::PPB_Gamepad_API* AsPPB_Gamepad_API() override;
592 void Sample(PP_Instance instance, PP_GamepadsSampleData* data) override;
594 private:
595 ~GamepadImpl() override;
598 // See the static Create functions above for creating PepperPluginInstanceImpl
599 // objects. This constructor is private so that we can hide the
600 // PPP_Instance_Combined details while still having 1 constructor to maintain
601 // for member initialization.
602 PepperPluginInstanceImpl(RenderFrameImpl* render_frame,
603 PluginModule* module,
604 ppapi::PPP_Instance_Combined* instance_interface,
605 blink::WebPluginContainer* container,
606 const GURL& plugin_url);
608 bool LoadFindInterface();
609 bool LoadInputEventInterface();
610 bool LoadMouseLockInterface();
611 bool LoadPdfInterface();
612 bool LoadPrintInterface();
613 bool LoadPrivateInterface();
614 bool LoadTextInputInterface();
615 bool LoadZoomInterface();
617 // Update any transforms that should be applied to the texture layer.
618 void UpdateLayerTransform();
620 // Determines if we think the plugin has focus, both content area and webkit
621 // (see has_webkit_focus_ below).
622 bool PluginHasFocus() const;
623 void SendFocusChangeNotification();
625 void UpdateTouchEventRequest();
627 // Returns true if the plugin has registered to accept wheel events.
628 bool IsAcceptingWheelEvents() const;
630 void ScheduleAsyncDidChangeView();
631 void SendAsyncDidChangeView();
632 void SendDidChangeView();
634 // Reports the current plugin geometry to the plugin by calling
635 // DidChangeView.
636 void ReportGeometry();
638 // Queries the plugin for supported print formats and sets |format| to the
639 // best format to use. Returns false if the plugin does not support any
640 // print format that we can handle (we can handle only PDF).
641 bool GetPreferredPrintOutputFormat(PP_PrintOutputFormat_Dev* format);
642 bool PrintPDFOutput(PP_Resource print_output, blink::WebCanvas* canvas);
644 // Updates the layer for compositing. This creates a layer and attaches to the
645 // container if:
646 // - we have a bound Graphics3D and the Graphics3D has a texture, OR
647 // we have a bound Graphics2D and are using software compositing
648 // - we are not in Flash full-screen mode (or transitioning to it)
649 // Otherwise it destroys the layer.
650 // It does either operation lazily.
651 // device_changed: true if the bound device has been changed, and
652 // UpdateLayer() will be forced to recreate the layer and attaches to the
653 // container.
654 void UpdateLayer(bool device_changed);
656 // Internal helper function for PrintPage().
657 bool PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges,
658 int num_ranges,
659 blink::WebCanvas* canvas);
661 void DoSetCursor(blink::WebCursorInfo* cursor);
663 // Internal helper functions for HandleCompositionXXX().
664 bool SendCompositionEventToPlugin(PP_InputEvent_Type type,
665 const base::string16& text);
666 bool SendCompositionEventWithUnderlineInformationToPlugin(
667 PP_InputEvent_Type type,
668 const base::string16& text,
669 const std::vector<blink::WebCompositionUnderline>& underlines,
670 int selection_start,
671 int selection_end);
673 // Internal helper function for XXXInputEvents().
674 void RequestInputEventsHelper(uint32_t event_classes);
676 // Checks if the security origin of the document containing this instance can
677 // assess the security origin of the main frame document.
678 bool CanAccessMainFrame() const;
680 // Returns true if the WebView the plugin is in renders via the accelerated
681 // compositing path.
682 bool IsViewAccelerated();
684 // Track, set and reset size attributes to control the size of the plugin
685 // in and out of fullscreen mode.
686 void KeepSizeAttributesBeforeFullscreen();
687 void SetSizeAttributesForFullscreen();
688 void ResetSizeAttributesAfterFullscreen();
690 bool IsMouseLocked();
691 bool LockMouse();
692 MouseLockDispatcher* GetMouseLockDispatcher();
693 MouseLockDispatcher::LockTarget* GetOrCreateLockTargetAdapter();
694 void UnSetAndDeleteLockTargetAdapter();
696 void DidDataFromWebURLResponse(const blink::WebURLResponse& response,
697 int pending_host_id,
698 const ppapi::URLResponseInfoData& data);
700 void RecordFlashJavaScriptUse();
702 RenderFrameImpl* render_frame_;
703 base::Closure instance_deleted_callback_;
704 scoped_refptr<PluginModule> module_;
705 scoped_ptr<ppapi::PPP_Instance_Combined> instance_interface_;
706 // If this is the NaCl plugin, we create a new module when we switch to the
707 // IPC-based PPAPI proxy. Store the original module and instance interface
708 // so we can shut down properly.
709 scoped_refptr<PluginModule> original_module_;
710 scoped_ptr<ppapi::PPP_Instance_Combined> original_instance_interface_;
712 PP_Instance pp_instance_;
714 // NULL until we have been initialized.
715 blink::WebPluginContainer* container_;
716 scoped_refptr<cc::Layer> compositor_layer_;
717 scoped_refptr<cc::TextureLayer> texture_layer_;
718 scoped_ptr<blink::WebLayer> web_layer_;
719 bool layer_bound_to_fullscreen_;
720 bool layer_is_hardware_;
722 // Plugin URL.
723 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.
739 bool full_frame_;
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_;
747 // Indicates if we've ever sent a didChangeView to the plugin. This ensures we
748 // always send an initial notification, even if the position and clip are the
749 // same as the default values.
750 bool sent_initial_did_change_view_;
752 // The current device context for painting in 2D, 3D or compositor.
753 scoped_refptr<PPB_Graphics3D_Impl> bound_graphics_3d_;
754 PepperGraphics2DHost* bound_graphics_2d_platform_;
755 PepperCompositorHost* bound_compositor_;
757 // We track two types of focus, one from WebKit, which is the focus among
758 // all elements of the page, one one from the browser, which is whether the
759 // tab/window has focus. We tell the plugin it has focus only when both of
760 // these values are set to true.
761 bool has_webkit_focus_;
762 bool has_content_area_focus_;
764 // The id of the current find operation, or -1 if none is in process.
765 int find_identifier_;
767 // Helper object that creates resources.
768 scoped_ptr<ppapi::thunk::ResourceCreationAPI> resource_creation_;
770 // The plugin-provided interfaces.
771 // When adding PPP interfaces, make sure to reset them in ResetAsProxied.
772 const PPP_Find_Private* plugin_find_interface_;
773 const PPP_InputEvent* plugin_input_event_interface_;
774 const PPP_MouseLock* plugin_mouse_lock_interface_;
775 const PPP_Pdf* plugin_pdf_interface_;
776 const PPP_Instance_Private* plugin_private_interface_;
777 const PPP_TextInput_Dev* plugin_textinput_interface_;
778 const PPP_Zoom_Dev* plugin_zoom_interface_;
780 // Flags indicating whether we have asked this plugin instance for the
781 // corresponding interfaces, so that we can ask only once.
782 // When adding flags, make sure to reset them in ResetAsProxied.
783 bool checked_for_plugin_input_event_interface_;
784 bool checked_for_plugin_pdf_interface_;
786 // This is only valid between a successful PrintBegin call and a PrintEnd
787 // call.
788 PP_PrintSettings_Dev current_print_settings_;
789 #if defined(OS_MACOSX)
790 // On the Mac, when we draw the bitmap to the PDFContext, it seems necessary
791 // to keep the pixels valid until CGContextEndPage is called. We use this
792 // variable to hold on to the pixels.
793 scoped_refptr<PPB_ImageData_Impl> last_printed_page_;
794 #endif // defined(OS_MACOSX)
795 // Always when printing to PDF on Linux and when printing for preview on Mac
796 // and Win, the entire document goes into one metafile. However, when users
797 // print only a subset of all the pages, it is impossible to know if a call
798 // to PrintPage() is the last call. Thus in PrintPage(), just store the page
799 // number in |ranges_|. The hack is in PrintEnd(), where a valid |canvas_|
800 // is preserved in PrintWebViewHelper::PrintPages. This makes it possible
801 // to generate the entire PDF given the variables below:
803 // The most recently used WebCanvas, guaranteed to be valid.
804 skia::RefPtr<blink::WebCanvas> canvas_;
805 // An array of page ranges.
806 std::vector<PP_PrintPageNumberRange_Dev> ranges_;
808 scoped_refptr<ppapi::Resource> gamepad_impl_;
809 scoped_refptr<ppapi::Resource> uma_private_impl_;
811 // The plugin print interface.
812 const PPP_Printing_Dev* plugin_print_interface_;
814 // The plugin 3D interface.
815 const PPP_Graphics3D* plugin_graphics_3d_interface_;
817 // Contains the cursor if it's set by the plugin.
818 scoped_ptr<blink::WebCursorInfo> cursor_;
820 // Set to true if this plugin thinks it will always be on top. This allows us
821 // to use a more optimized painting path in some cases.
822 bool always_on_top_;
823 // Even if |always_on_top_| is true, the plugin is not fully visible if there
824 // are some cut-out areas (occupied by iframes higher in the stacking order).
825 // This information is used in the optimized painting path.
826 std::vector<gfx::Rect> cut_outs_rects_;
828 // Implementation of PPB_FlashFullscreen.
830 // Plugin container for fullscreen mode. NULL if not in fullscreen mode. Note:
831 // there is a transition state where fullscreen_container_ is non-NULL but
832 // flash_fullscreen_ is false (see above).
833 FullscreenContainer* fullscreen_container_;
835 // True if we are in "flash" fullscreen mode. False if we are in normal mode
836 // or in transition to fullscreen. Normal fullscreen mode is indicated in
837 // the ViewData.
838 bool flash_fullscreen_;
840 // Implementation of PPB_Fullscreen.
842 // Since entering fullscreen mode is an asynchronous operation, we set this
843 // variable to the desired state at the time we issue the fullscreen change
844 // request. The plugin will receive a DidChangeView event when it goes
845 // fullscreen.
846 bool desired_fullscreen_state_;
848 // WebKit does not resize the plugin when going into fullscreen mode, so we do
849 // this here by modifying the various plugin attributes and then restoring
850 // them on exit.
851 blink::WebString width_before_fullscreen_;
852 blink::WebString height_before_fullscreen_;
853 blink::WebString border_before_fullscreen_;
854 blink::WebString style_before_fullscreen_;
855 gfx::Size screen_size_for_fullscreen_;
857 // The MessageChannel used to implement bidirectional postMessage for the
858 // instance.
859 v8::Persistent<v8::Object> message_channel_object_;
861 // A pointer to the MessageChannel underlying |message_channel_object_|. It is
862 // only valid as long as |message_channel_object_| is alive.
863 MessageChannel* message_channel_;
865 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
866 SkBitmap* sad_plugin_;
868 typedef std::set<PluginObject*> PluginObjectSet;
869 PluginObjectSet live_plugin_objects_;
871 // Classes of events that the plugin has registered for, both for filtering
872 // and not. The bits are PP_INPUTEVENT_CLASS_*.
873 uint32_t input_event_mask_;
874 uint32_t filtered_input_event_mask_;
876 // Text composition status.
877 ui::TextInputType text_input_type_;
878 gfx::Rect text_input_caret_;
879 gfx::Rect text_input_caret_bounds_;
880 bool text_input_caret_set_;
882 // Text selection status.
883 std::string surrounding_text_;
884 size_t selection_caret_;
885 size_t selection_anchor_;
887 scoped_refptr<ppapi::TrackedCallback> lock_mouse_callback_;
889 // Track pending user gestures so out-of-process plugins can respond to
890 // a user gesture after it has been processed.
891 PP_TimeTicks pending_user_gesture_;
892 blink::WebUserGestureToken pending_user_gesture_token_;
894 // We store the arguments so we can re-send them if we are reset to talk to
895 // NaCl via the IPC NaCl proxy.
896 std::vector<std::string> argn_;
897 std::vector<std::string> argv_;
899 // Non-owning pointer to the document loader, if any.
900 blink::WebURLLoaderClient* document_loader_;
901 // State for deferring document loads. Used only by external instances.
902 blink::WebURLResponse external_document_response_;
903 scoped_ptr<ExternalDocumentLoader> external_document_loader_;
904 bool external_document_load_;
906 // The ContentDecryptorDelegate forwards PPP_ContentDecryptor_Private
907 // calls and handles PPB_ContentDecryptor_Private calls.
908 scoped_ptr<ContentDecryptorDelegate> content_decryptor_delegate_;
910 // The link currently under the cursor.
911 base::string16 link_under_cursor_;
913 // We store the isolate at construction so that we can be sure to use the
914 // Isolate in which this Instance was created when interacting with v8.
915 v8::Isolate* isolate_;
917 scoped_ptr<MouseLockDispatcher::LockTarget> lock_target_;
919 bool is_deleted_;
921 // The text that is currently selected in the plugin.
922 base::string16 selected_text_;
924 int64 last_input_number_;
926 bool is_tracking_latency_;
928 bool initialized_;
930 // We use a weak ptr factory for scheduling DidChangeView events so that we
931 // can tell whether updates are pending and consolidate them. When there's
932 // already a weak ptr pending (HasWeakPtrs is true), code should update the
933 // view_data_ but not send updates. This also allows us to cancel scheduled
934 // view change events.
935 base::WeakPtrFactory<PepperPluginInstanceImpl> view_change_weak_ptr_factory_;
936 base::WeakPtrFactory<PepperPluginInstanceImpl> weak_factory_;
938 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceImpl);
941 } // namespace content
943 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_IMPL_H_