Add ICU message format support
[chromium-blink-merge.git] / content / renderer / pepper / pepper_plugin_instance_impl.h
blob632e76b5d93549d27701ece8b479c7d72e3d2bc8
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_text_input_dev.h"
32 #include "ppapi/c/pp_completion_callback.h"
33 #include "ppapi/c/pp_instance.h"
34 #include "ppapi/c/pp_time.h"
35 #include "ppapi/c/pp_var.h"
36 #include "ppapi/c/ppb_audio_config.h"
37 #include "ppapi/c/ppb_gamepad.h"
38 #include "ppapi/c/ppb_input_event.h"
39 #include "ppapi/c/ppp_graphics_3d.h"
40 #include "ppapi/c/ppp_input_event.h"
41 #include "ppapi/c/ppp_mouse_lock.h"
42 #include "ppapi/c/private/ppb_content_decryptor_private.h"
43 #include "ppapi/c/private/ppp_find_private.h"
44 #include "ppapi/c/private/ppp_instance_private.h"
45 #include "ppapi/c/private/ppp_pdf.h"
46 #include "ppapi/shared_impl/ppb_instance_shared.h"
47 #include "ppapi/shared_impl/ppb_view_shared.h"
48 #include "ppapi/shared_impl/singleton_resource_id.h"
49 #include "ppapi/shared_impl/tracked_callback.h"
50 #include "ppapi/thunk/ppb_gamepad_api.h"
51 #include "ppapi/thunk/resource_creation_api.h"
52 #include "skia/ext/refptr.h"
53 #include "third_party/WebKit/public/platform/WebCanvas.h"
54 #include "third_party/WebKit/public/platform/WebString.h"
55 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
56 #include "third_party/WebKit/public/platform/WebURLResponse.h"
57 #include "third_party/WebKit/public/web/WebPlugin.h"
58 #include "third_party/WebKit/public/web/WebUserGestureToken.h"
59 #include "ui/base/ime/text_input_type.h"
60 #include "ui/gfx/geometry/rect.h"
61 #include "url/gurl.h"
62 #include "v8/include/v8.h"
64 struct PP_Point;
65 struct _NPP;
67 class SkBitmap;
68 class TransportDIB;
70 namespace blink {
71 class WebInputEvent;
72 class WebLayer;
73 class WebMouseEvent;
74 class WebPluginContainer;
75 class WebURLLoader;
76 class WebURLResponse;
77 struct WebCompositionUnderline;
78 struct WebCursorInfo;
79 struct WebURLError;
80 struct WebPrintParams;
83 namespace cc {
84 class TextureLayer;
87 namespace gfx {
88 class Range;
91 namespace ppapi {
92 class Resource;
93 struct InputEventData;
94 struct PPP_Instance_Combined;
95 class ScopedPPVar;
98 namespace content {
100 class ContentDecryptorDelegate;
101 class FullscreenContainer;
102 class MessageChannel;
103 class PepperCompositorHost;
104 class PepperGraphics2DHost;
105 class PluginInstanceThrottlerImpl;
106 class PluginModule;
107 class PluginObject;
108 class PPB_Graphics3D_Impl;
109 class PPB_ImageData_Impl;
110 class PPB_URLLoader_Impl;
111 class RenderFrameImpl;
112 class RenderViewImpl;
114 // Represents one time a plugin appears on one web page.
116 // Note: to get from a PP_Instance to a PepperPluginInstance*, use the
117 // ResourceTracker.
118 class CONTENT_EXPORT PepperPluginInstanceImpl
119 : public base::RefCounted<PepperPluginInstanceImpl>,
120 public NON_EXPORTED_BASE(PepperPluginInstance),
121 public ppapi::PPB_Instance_Shared,
122 public NON_EXPORTED_BASE(cc::TextureLayerClient),
123 public RenderFrameObserver,
124 public NON_EXPORTED_BASE(PluginInstanceThrottler::Observer) {
125 public:
126 // Create and return a PepperPluginInstanceImpl object which supports the most
127 // recent version of PPP_Instance possible by querying the given
128 // get_plugin_interface function. If the plugin does not support any valid
129 // PPP_Instance interface, returns NULL.
130 static PepperPluginInstanceImpl* Create(RenderFrameImpl* render_frame,
131 PluginModule* module,
132 blink::WebPluginContainer* container,
133 const GURL& plugin_url);
134 RenderFrameImpl* render_frame() const { return render_frame_; }
135 PluginModule* module() const { return module_.get(); }
137 blink::WebPluginContainer* container() const { return container_; }
139 PluginInstanceThrottlerImpl* throttler() const { return throttler_.get(); }
141 // Returns the PP_Instance uniquely identifying this instance. Guaranteed
142 // nonzero.
143 PP_Instance pp_instance() const { return pp_instance_; }
145 ppapi::thunk::ResourceCreationAPI& resource_creation() {
146 return *resource_creation_.get();
149 MessageChannel* message_channel() { return message_channel_; }
150 v8::Local<v8::Object> GetMessageChannelObject();
151 // Called when |message_channel_| is destroyed as it may be destroyed prior to
152 // the plugin being destroyed.
153 void MessageChannelDestroyed();
155 // Return the v8 context for the frame that the plugin is contained in. Care
156 // should be taken to use the correct context for plugin<->JS interactions.
157 // In cases where JS calls into the plugin, the caller's context should
158 // typically be used. When calling from the plugin into JS, this context
159 // should typically used.
160 v8::Local<v8::Context> GetMainWorldContext();
162 // Does some pre-destructor cleanup on the instance. This is necessary
163 // because some cleanup depends on the plugin instance still existing (like
164 // calling the plugin's DidDestroy function). This function is called from
165 // the WebPlugin implementation when WebKit is about to remove the plugin.
166 void Delete();
168 // Returns true if Delete() has been called on this object.
169 bool is_deleted() const;
171 GURL document_url() const { return document_url_; }
173 // Paints the current backing store to the web page.
174 void Paint(blink::WebCanvas* canvas,
175 const gfx::Rect& plugin_rect,
176 const gfx::Rect& paint_rect);
178 // Schedules a paint of the page for the given region. The coordinates are
179 // relative to the top-left of the plugin. This does nothing if the plugin
180 // has not yet been positioned. You can supply an empty gfx::Rect() to
181 // invalidate the entire plugin.
182 void InvalidateRect(const gfx::Rect& rect);
184 // Schedules a scroll of the plugin. This uses optimized scrolling only for
185 // full-frame plugins, as otherwise there could be other elements on top. The
186 // slow path can also be triggered if there is an overlapping frame.
187 void ScrollRect(int dx, int dy, const gfx::Rect& rect);
189 // Commit the backing texture to the screen once the side effects some
190 // rendering up to an offscreen SwapBuffers are visible.
191 void CommitBackingTexture();
193 // Called when the out-of-process plugin implementing this instance crashed.
194 void InstanceCrashed();
196 // PPB_Instance and PPB_Instance_Private implementation.
197 bool full_frame() const { return full_frame_; }
198 const ppapi::ViewData& view_data() const { return view_data_; }
200 // PPP_Instance and PPP_Instance_Private.
201 bool Initialize(const std::vector<std::string>& arg_names,
202 const std::vector<std::string>& arg_values,
203 bool full_frame,
204 scoped_ptr<PluginInstanceThrottlerImpl> throttler);
205 bool HandleDocumentLoad(const blink::WebURLResponse& response);
206 bool HandleInputEvent(const blink::WebInputEvent& event,
207 blink::WebCursorInfo* cursor_info);
208 PP_Var GetInstanceObject(v8::Isolate* isolate);
209 void ViewChanged(const gfx::Rect& window,
210 const gfx::Rect& clip,
211 const gfx::Rect& unobscured,
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 bool StartFind(const base::string16& search_text,
249 bool case_sensitive,
250 int identifier);
251 void SelectFindResult(bool forward);
252 void StopFind();
254 bool SupportsPrintInterface();
255 bool IsPrintScalingDisabled();
256 int PrintBegin(const blink::WebPrintParams& print_params);
257 void PrintPage(int page_number, blink::WebCanvas* canvas);
258 void PrintEnd();
259 bool GetPrintPresetOptionsFromDocument(
260 blink::WebPrintPresetOptions* preset_options);
262 bool CanRotateView();
263 void RotateView(blink::WebPlugin::RotationType type);
265 // There are 2 implementations of the fullscreen interface
266 // PPB_FlashFullscreen is used by Pepper Flash.
267 // PPB_Fullscreen is intended for other applications including NaCl.
268 // The two interface are mutually exclusive.
270 // Implementation of PPB_FlashFullscreen.
272 // Because going to fullscreen is asynchronous (but going out is not), there
273 // are 3 states:
274 // - normal : fullscreen_container_ == NULL
275 // flash_fullscreen_ == false
276 // - fullscreen pending: fullscreen_container_ != NULL
277 // flash_fullscreen_ == false
278 // - fullscreen : fullscreen_container_ != NULL
279 // flash_fullscreen_ == true
281 // In normal state, events come from webkit and painting goes back to it.
282 // In fullscreen state, events come from the fullscreen container, and
283 // painting goes back to it.
284 // In pending state, events from webkit are ignored, and as soon as we
285 // receive events from the fullscreen container, we go to the fullscreen
286 // state.
287 bool FlashIsFullscreenOrPending();
289 // Updates |flash_fullscreen_| and sends focus change notification if
290 // necessary.
291 void UpdateFlashFullscreenState(bool flash_fullscreen);
293 FullscreenContainer* fullscreen_container() const {
294 return fullscreen_container_;
297 // Implementation of PPB_Fullscreen.
299 // Because going to/from fullscreen is asynchronous, there are 4 states:
300 // - normal : desired_fullscreen_state_ == false
301 // view_data_.is_fullscreen == false
302 // - fullscreen pending: desired_fullscreen_state_ == true
303 // view_data_.is_fullscreen == false
304 // - fullscreen : desired_fullscreen_state_ == true
305 // view_data_.is_fullscreen == true
306 // - normal pending : desired_fullscreen_state_ = false
307 // view_data_.is_fullscreen = true
308 bool IsFullscreenOrPending();
310 bool flash_fullscreen() const { return flash_fullscreen_; }
312 // Switches between fullscreen and normal mode. The transition is
313 // asynchronous. WebKit will trigger corresponding VewChanged calls.
314 // Returns true on success, false on failure (e.g. trying to enter fullscreen
315 // when not processing a user gesture or trying to set fullscreen when
316 // already in fullscreen mode).
317 bool SetFullscreen(bool fullscreen);
319 // Send the message on to the plugin.
320 void HandleMessage(ppapi::ScopedPPVar message);
322 // Send the message synchronously to the plugin, and get a result. Returns
323 // true if the plugin handled the message, false if it didn't. The plugin
324 // won't handle the message if it has not registered a PPP_MessageHandler.
325 bool HandleBlockingMessage(ppapi::ScopedPPVar message,
326 ppapi::ScopedPPVar* result);
328 // Returns true if the plugin is processing a user gesture.
329 bool IsProcessingUserGesture();
331 // Returns the user gesture token to use for creating a WebScopedUserGesture,
332 // if IsProcessingUserGesture returned true.
333 blink::WebUserGestureToken CurrentUserGestureToken();
335 // A mouse lock request was pending and this reports success or failure.
336 void OnLockMouseACK(bool succeeded);
337 // A mouse lock was in place, but has been lost.
338 void OnMouseLockLost();
339 // A mouse lock is enabled and mouse events are being delivered.
340 void HandleMouseLockedInputEvent(const blink::WebMouseEvent& event);
342 // Simulates an input event to the plugin by passing it down to WebKit,
343 // which sends it back up to the plugin as if it came from the user.
344 void SimulateInputEvent(const ppapi::InputEventData& input_event);
346 // Simulates an IME event at the level of RenderView which sends it back up to
347 // the plugin as if it came from the user.
348 bool SimulateIMEEvent(const ppapi::InputEventData& input_event);
349 void SimulateImeSetCompositionEvent(const ppapi::InputEventData& input_event);
351 // The document loader is valid when the plugin is "full-frame" and in this
352 // case is non-NULL as long as the corresponding loader resource is alive.
353 // This pointer is non-owning, so the loader must use set_document_loader to
354 // clear itself when it is destroyed.
355 blink::WebURLLoaderClient* document_loader() const {
356 return document_loader_;
358 void set_document_loader(blink::WebURLLoaderClient* loader) {
359 document_loader_ = loader;
362 ContentDecryptorDelegate* GetContentDecryptorDelegate();
364 // PluginInstance implementation
365 RenderView* GetRenderView() override;
366 blink::WebPluginContainer* GetContainer() override;
367 v8::Isolate* GetIsolate() const override;
368 ppapi::VarTracker* GetVarTracker() override;
369 const GURL& GetPluginURL() override;
370 base::FilePath GetModulePath() override;
371 PP_Resource CreateImage(gfx::ImageSkia* source_image, float scale) override;
372 PP_ExternalPluginResult SwitchToOutOfProcessProxy(
373 const base::FilePath& file_path,
374 ppapi::PpapiPermissions permissions,
375 const IPC::ChannelHandle& channel_handle,
376 base::ProcessId plugin_pid,
377 int plugin_child_id) override;
378 void SetAlwaysOnTop(bool on_top) override;
379 bool IsFullPagePlugin() override;
380 bool FlashSetFullscreen(bool fullscreen, bool delay_report) override;
381 bool IsRectTopmost(const gfx::Rect& rect) override;
382 int32_t Navigate(const ppapi::URLRequestInfoData& request,
383 const char* target,
384 bool from_user_action) override;
385 int MakePendingFileRefRendererHost(const base::FilePath& path) override;
386 void SetEmbedProperty(PP_Var key, PP_Var value) override;
387 void SetSelectedText(const base::string16& selected_text) override;
388 void SetLinkUnderCursor(const std::string& url) override;
389 void SetTextInputType(ui::TextInputType type) override;
390 void PostMessageToJavaScript(PP_Var message) override;
392 // PPB_Instance_API implementation.
393 PP_Bool BindGraphics(PP_Instance instance, PP_Resource device) override;
394 PP_Bool IsFullFrame(PP_Instance instance) override;
395 const ppapi::ViewData* GetViewData(PP_Instance instance) override;
396 PP_Bool FlashIsFullscreen(PP_Instance instance) override;
397 PP_Var GetWindowObject(PP_Instance instance) override;
398 PP_Var GetOwnerElementObject(PP_Instance instance) override;
399 PP_Var ExecuteScript(PP_Instance instance,
400 PP_Var script,
401 PP_Var* exception) override;
402 uint32_t GetAudioHardwareOutputSampleRate(PP_Instance instance) override;
403 uint32_t GetAudioHardwareOutputBufferSize(PP_Instance instance) override;
404 PP_Var GetDefaultCharSet(PP_Instance instance) override;
405 void SetPluginToHandleFindRequests(PP_Instance) override;
406 void NumberOfFindResultsChanged(PP_Instance instance,
407 int32_t total,
408 PP_Bool final_result) override;
409 void SelectedFindResultChanged(PP_Instance instance, int32_t index) override;
410 void SetTickmarks(PP_Instance instance,
411 const PP_Rect* tickmarks,
412 uint32_t count) override;
413 PP_Bool IsFullscreen(PP_Instance instance) override;
414 PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) override;
415 PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) override;
416 ppapi::Resource* GetSingletonResource(PP_Instance instance,
417 ppapi::SingletonResourceID id) override;
418 int32_t RequestInputEvents(PP_Instance instance,
419 uint32_t event_classes) override;
420 int32_t RequestFilteringInputEvents(PP_Instance instance,
421 uint32_t event_classes) override;
422 void ClearInputEventRequest(PP_Instance instance,
423 uint32_t event_classes) override;
424 void PostMessage(PP_Instance instance, PP_Var message) override;
425 int32_t RegisterMessageHandler(PP_Instance instance,
426 void* user_data,
427 const PPP_MessageHandler_0_2* handler,
428 PP_Resource message_loop) override;
429 void UnregisterMessageHandler(PP_Instance instance) override;
430 PP_Bool SetCursor(PP_Instance instance,
431 PP_MouseCursor_Type type,
432 PP_Resource image,
433 const PP_Point* hot_spot) override;
434 int32_t LockMouse(PP_Instance instance,
435 scoped_refptr<ppapi::TrackedCallback> callback) override;
436 void UnlockMouse(PP_Instance instance) override;
437 void SetTextInputType(PP_Instance instance, PP_TextInput_Type type) override;
438 void UpdateCaretPosition(PP_Instance instance,
439 const PP_Rect& caret,
440 const PP_Rect& bounding_box) override;
441 void CancelCompositionText(PP_Instance instance) override;
442 void SelectionChanged(PP_Instance instance) override;
443 void UpdateSurroundingText(PP_Instance instance,
444 const char* text,
445 uint32_t caret,
446 uint32_t anchor) override;
447 PP_Var ResolveRelativeToDocument(PP_Instance instance,
448 PP_Var relative,
449 PP_URLComponents_Dev* components) override;
450 PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) override;
451 PP_Bool DocumentCanAccessDocument(PP_Instance instance,
452 PP_Instance target) override;
453 PP_Var GetDocumentURL(PP_Instance instance,
454 PP_URLComponents_Dev* components) override;
455 PP_Var GetPluginInstanceURL(PP_Instance instance,
456 PP_URLComponents_Dev* components) override;
457 PP_Var GetPluginReferrerURL(PP_Instance instance,
458 PP_URLComponents_Dev* components) override;
460 // PPB_ContentDecryptor_Private implementation.
461 void PromiseResolved(PP_Instance instance, uint32 promise_id) override;
462 void PromiseResolvedWithSession(PP_Instance instance,
463 uint32 promise_id,
464 PP_Var session_id_var) override;
465 void PromiseRejected(PP_Instance instance,
466 uint32 promise_id,
467 PP_CdmExceptionCode exception_code,
468 uint32 system_code,
469 PP_Var error_description_var) override;
470 void SessionMessage(PP_Instance instance,
471 PP_Var session_id_var,
472 PP_CdmMessageType message_type,
473 PP_Var message_var,
474 PP_Var legacy_destination_url) override;
475 void SessionKeysChange(
476 PP_Instance instance,
477 PP_Var session_id_var,
478 PP_Bool has_additional_usable_key,
479 uint32_t key_count,
480 const struct PP_KeyInformation key_information[]) override;
481 void SessionExpirationChange(PP_Instance instance,
482 PP_Var session_id_var,
483 PP_Time new_expiry_time) override;
484 void SessionClosed(PP_Instance instance, PP_Var session_id_var) override;
485 void LegacySessionError(PP_Instance instance,
486 PP_Var session_id_var,
487 PP_CdmExceptionCode exception_code,
488 uint32 system_code,
489 PP_Var error_description_var) override;
490 void DeliverBlock(PP_Instance instance,
491 PP_Resource decrypted_block,
492 const PP_DecryptedBlockInfo* block_info) override;
493 void DecoderInitializeDone(PP_Instance instance,
494 PP_DecryptorStreamType decoder_type,
495 uint32_t request_id,
496 PP_Bool success) override;
497 void DecoderDeinitializeDone(PP_Instance instance,
498 PP_DecryptorStreamType decoder_type,
499 uint32_t request_id) override;
500 void DecoderResetDone(PP_Instance instance,
501 PP_DecryptorStreamType decoder_type,
502 uint32_t request_id) override;
503 void DeliverFrame(PP_Instance instance,
504 PP_Resource decrypted_frame,
505 const PP_DecryptedFrameInfo* frame_info) override;
506 void DeliverSamples(PP_Instance instance,
507 PP_Resource audio_frames,
508 const PP_DecryptedSampleInfo* sample_info) override;
510 // Reset this instance as proxied. Assigns the instance a new module, resets
511 // cached interfaces to point to the out-of-process proxy and re-sends
512 // DidCreate, DidChangeView, and HandleDocumentLoad (if necessary).
513 // This should be used only when switching an in-process instance to an
514 // external out-of-process instance.
515 PP_ExternalPluginResult ResetAsProxied(scoped_refptr<PluginModule> module);
517 // Checks whether this is a valid instance of the given module. After calling
518 // ResetAsProxied above, a NaCl plugin instance's module changes, so external
519 // hosts won't recognize it as a valid instance of the original module. This
520 // method fixes that be checking that either module_ or original_module_ match
521 // the given module.
522 bool IsValidInstanceOf(PluginModule* module);
524 // cc::TextureLayerClient implementation.
525 bool PrepareTextureMailbox(
526 cc::TextureMailbox* mailbox,
527 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
528 bool use_shared_memory) override;
530 // RenderFrameObserver
531 void OnDestruct() override;
533 // PluginInstanceThrottler::Observer
534 void OnThrottleStateChange() override;
535 void OnHiddenForPlaceholder(bool hidden) override;
537 private:
538 friend class base::RefCounted<PepperPluginInstanceImpl>;
539 friend class PpapiPluginInstanceTest;
540 friend class PpapiUnittest;
542 // Delete should be called by the WebPlugin before this destructor.
543 ~PepperPluginInstanceImpl() override;
545 // Class to record document load notifications and play them back once the
546 // real document loader becomes available. Used only by external instances.
547 class ExternalDocumentLoader : public blink::WebURLLoaderClient {
548 public:
549 ExternalDocumentLoader();
550 virtual ~ExternalDocumentLoader();
552 void ReplayReceivedData(WebURLLoaderClient* document_loader);
554 // blink::WebURLLoaderClient implementation.
555 void didReceiveData(blink::WebURLLoader* loader,
556 const char* data,
557 int data_length,
558 int encoded_data_length) override;
559 void didFinishLoading(blink::WebURLLoader* loader,
560 double finish_time,
561 int64_t total_encoded_data_length) override;
562 void didFail(blink::WebURLLoader* loader,
563 const blink::WebURLError& error) override;
565 private:
566 std::list<std::string> data_;
567 bool finished_loading_;
568 scoped_ptr<blink::WebURLError> error_;
571 // Implements PPB_Gamepad_API. This is just to avoid having an excessive
572 // number of interfaces implemented by PepperPluginInstanceImpl.
573 class GamepadImpl : public ppapi::thunk::PPB_Gamepad_API,
574 public ppapi::Resource {
575 public:
576 GamepadImpl();
577 // Resource implementation.
578 ppapi::thunk::PPB_Gamepad_API* AsPPB_Gamepad_API() override;
579 void Sample(PP_Instance instance, PP_GamepadsSampleData* data) override;
581 private:
582 ~GamepadImpl() override;
585 // See the static Create functions above for creating PepperPluginInstanceImpl
586 // objects. This constructor is private so that we can hide the
587 // PPP_Instance_Combined details while still having 1 constructor to maintain
588 // for member initialization.
589 PepperPluginInstanceImpl(RenderFrameImpl* render_frame,
590 PluginModule* module,
591 ppapi::PPP_Instance_Combined* instance_interface,
592 blink::WebPluginContainer* container,
593 const GURL& plugin_url);
595 bool LoadFindInterface();
596 bool LoadInputEventInterface();
597 bool LoadMouseLockInterface();
598 bool LoadPdfInterface();
599 bool LoadPrintInterface();
600 bool LoadPrivateInterface();
601 bool LoadTextInputInterface();
603 // Update any transforms that should be applied to the texture layer.
604 void UpdateLayerTransform();
606 // Determines if we think the plugin has focus, both content area and webkit
607 // (see has_webkit_focus_ below).
608 bool PluginHasFocus() const;
609 void SendFocusChangeNotification();
611 void UpdateTouchEventRequest();
613 // Returns true if the plugin has registered to accept wheel events.
614 bool IsAcceptingWheelEvents() const;
616 void ScheduleAsyncDidChangeView();
617 void SendAsyncDidChangeView();
618 void SendDidChangeView();
620 // Reports the current plugin geometry to the plugin by calling
621 // DidChangeView.
622 void ReportGeometry();
624 // Queries the plugin for supported print formats and sets |format| to the
625 // best format to use. Returns false if the plugin does not support any
626 // print format that we can handle (we can handle only PDF).
627 bool GetPreferredPrintOutputFormat(PP_PrintOutputFormat_Dev* format);
628 bool PrintPDFOutput(PP_Resource print_output, blink::WebCanvas* canvas);
630 // Updates the layer for compositing. This creates a layer and attaches to the
631 // container if:
632 // - we have a bound Graphics3D and the Graphics3D has a texture, OR
633 // we have a bound Graphics2D and are using software compositing
634 // - we are not in Flash full-screen mode (or transitioning to it)
635 // Otherwise it destroys the layer.
636 // It does either operation lazily.
637 // device_changed: true if the bound device has been changed, and
638 // UpdateLayer() will be forced to recreate the layer and attaches to the
639 // container.
640 void UpdateLayer(bool device_changed);
642 // Internal helper function for PrintPage().
643 void PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges,
644 int num_ranges,
645 blink::WebCanvas* canvas);
647 void DoSetCursor(blink::WebCursorInfo* cursor);
649 // Internal helper functions for HandleCompositionXXX().
650 bool SendCompositionEventToPlugin(PP_InputEvent_Type type,
651 const base::string16& text);
652 bool SendCompositionEventWithUnderlineInformationToPlugin(
653 PP_InputEvent_Type type,
654 const base::string16& text,
655 const std::vector<blink::WebCompositionUnderline>& underlines,
656 int selection_start,
657 int selection_end);
659 // Internal helper function for XXXInputEvents().
660 void RequestInputEventsHelper(uint32_t event_classes);
662 // Checks if the security origin of the document containing this instance can
663 // assess the security origin of the main frame document.
664 bool CanAccessMainFrame() const;
666 // Returns true if the WebView the plugin is in renders via the accelerated
667 // compositing path.
668 bool IsViewAccelerated();
670 // Track, set and reset size attributes to control the size of the plugin
671 // in and out of fullscreen mode.
672 void KeepSizeAttributesBeforeFullscreen();
673 void SetSizeAttributesForFullscreen();
674 void ResetSizeAttributesAfterFullscreen();
676 bool IsMouseLocked();
677 bool LockMouse();
678 MouseLockDispatcher* GetMouseLockDispatcher();
679 MouseLockDispatcher::LockTarget* GetOrCreateLockTargetAdapter();
680 void UnSetAndDeleteLockTargetAdapter();
682 void DidDataFromWebURLResponse(const blink::WebURLResponse& response,
683 int pending_host_id,
684 const ppapi::URLResponseInfoData& data);
686 void RecordFlashJavaScriptUse();
688 RenderFrameImpl* render_frame_;
689 base::Closure instance_deleted_callback_;
690 scoped_refptr<PluginModule> module_;
691 scoped_ptr<ppapi::PPP_Instance_Combined> instance_interface_;
692 // If this is the NaCl plugin, we create a new module when we switch to the
693 // IPC-based PPAPI proxy. Store the original module and instance interface
694 // so we can shut down properly.
695 scoped_refptr<PluginModule> original_module_;
696 scoped_ptr<ppapi::PPP_Instance_Combined> original_instance_interface_;
698 PP_Instance pp_instance_;
700 // NULL until we have been initialized.
701 blink::WebPluginContainer* container_;
702 scoped_refptr<cc::Layer> compositor_layer_;
703 scoped_refptr<cc::TextureLayer> texture_layer_;
704 scoped_ptr<blink::WebLayer> web_layer_;
705 bool layer_bound_to_fullscreen_;
706 bool layer_is_hardware_;
708 // Plugin URL.
709 const GURL plugin_url_;
711 GURL document_url_;
713 // Used to track Flash-specific metrics.
714 const bool is_flash_plugin_;
716 // Set to true the first time the plugin is clicked. Used to collect metrics.
717 bool has_been_clicked_;
719 // Used to track if JavaScript has ever been used for this plugin instance.
720 bool javascript_used_;
722 // Responsible for turning on throttling if Power Saver is on.
723 scoped_ptr<PluginInstanceThrottlerImpl> throttler_;
725 // Indicates whether this is a full frame instance, which means it represents
726 // an entire document rather than an embed tag.
727 bool full_frame_;
729 // Stores the current state of the plugin view.
730 ppapi::ViewData view_data_;
731 // The last state sent to the plugin. It is only valid after
732 // |sent_initial_did_change_view_| is set to true.
733 ppapi::ViewData last_sent_view_data_;
734 // The current unobscured portion of the plugin.
735 gfx::Rect unobscured_rect_;
737 // Indicates if we've ever sent a didChangeView to the plugin. This ensures we
738 // always send an initial notification, even if the position and clip are the
739 // same as the default values.
740 bool sent_initial_did_change_view_;
742 // The current device context for painting in 2D, 3D or compositor.
743 scoped_refptr<PPB_Graphics3D_Impl> bound_graphics_3d_;
744 PepperGraphics2DHost* bound_graphics_2d_platform_;
745 PepperCompositorHost* bound_compositor_;
747 // We track two types of focus, one from WebKit, which is the focus among
748 // all elements of the page, one one from the browser, which is whether the
749 // tab/window has focus. We tell the plugin it has focus only when both of
750 // these values are set to true.
751 bool has_webkit_focus_;
752 bool has_content_area_focus_;
754 // The id of the current find operation, or -1 if none is in process.
755 int find_identifier_;
757 // Helper object that creates resources.
758 scoped_ptr<ppapi::thunk::ResourceCreationAPI> resource_creation_;
760 // The plugin-provided interfaces.
761 // When adding PPP interfaces, make sure to reset them in ResetAsProxied.
762 const PPP_Find_Private* plugin_find_interface_;
763 const PPP_InputEvent* plugin_input_event_interface_;
764 const PPP_MouseLock* plugin_mouse_lock_interface_;
765 const PPP_Pdf* plugin_pdf_interface_;
766 const PPP_Instance_Private* plugin_private_interface_;
767 const PPP_TextInput_Dev* plugin_textinput_interface_;
769 // Flags indicating whether we have asked this plugin instance for the
770 // corresponding interfaces, so that we can ask only once.
771 // When adding flags, make sure to reset them in ResetAsProxied.
772 bool checked_for_plugin_input_event_interface_;
773 bool checked_for_plugin_pdf_interface_;
775 // This is only valid between a successful PrintBegin call and a PrintEnd
776 // call.
777 PP_PrintSettings_Dev current_print_settings_;
778 #if defined(OS_MACOSX)
779 // On the Mac, when we draw the bitmap to the PDFContext, it seems necessary
780 // to keep the pixels valid until CGContextEndPage is called. We use this
781 // variable to hold on to the pixels.
782 scoped_refptr<PPB_ImageData_Impl> last_printed_page_;
783 #endif // defined(OS_MACOSX)
784 // Always when printing to PDF on Linux and when printing for preview on Mac
785 // and Win, the entire document goes into one metafile. However, when users
786 // print only a subset of all the pages, it is impossible to know if a call
787 // to PrintPage() is the last call. Thus in PrintPage(), just store the page
788 // number in |ranges_|. The hack is in PrintEnd(), where a valid |canvas_|
789 // is preserved in PrintWebViewHelper::PrintPages. This makes it possible
790 // to generate the entire PDF given the variables below:
792 // The most recently used WebCanvas, guaranteed to be valid.
793 skia::RefPtr<blink::WebCanvas> canvas_;
794 // An array of page ranges.
795 std::vector<PP_PrintPageNumberRange_Dev> ranges_;
797 scoped_refptr<ppapi::Resource> gamepad_impl_;
798 scoped_refptr<ppapi::Resource> uma_private_impl_;
800 // The plugin print interface.
801 const PPP_Printing_Dev* plugin_print_interface_;
803 // The plugin 3D interface.
804 const PPP_Graphics3D* plugin_graphics_3d_interface_;
806 // Contains the cursor if it's set by the plugin.
807 scoped_ptr<blink::WebCursorInfo> cursor_;
809 // Set to true if this plugin thinks it will always be on top. This allows us
810 // to use a more optimized painting path in some cases.
811 bool always_on_top_;
812 // Even if |always_on_top_| is true, the plugin is not fully visible if there
813 // are some cut-out areas (occupied by iframes higher in the stacking order).
814 // This information is used in the optimized painting path.
815 std::vector<gfx::Rect> cut_outs_rects_;
817 // Implementation of PPB_FlashFullscreen.
819 // Plugin container for fullscreen mode. NULL if not in fullscreen mode. Note:
820 // there is a transition state where fullscreen_container_ is non-NULL but
821 // flash_fullscreen_ is false (see above).
822 FullscreenContainer* fullscreen_container_;
824 // True if we are in "flash" fullscreen mode. False if we are in normal mode
825 // or in transition to fullscreen. Normal fullscreen mode is indicated in
826 // the ViewData.
827 bool flash_fullscreen_;
829 // Implementation of PPB_Fullscreen.
831 // Since entering fullscreen mode is an asynchronous operation, we set this
832 // variable to the desired state at the time we issue the fullscreen change
833 // request. The plugin will receive a DidChangeView event when it goes
834 // fullscreen.
835 bool desired_fullscreen_state_;
837 // WebKit does not resize the plugin when going into fullscreen mode, so we do
838 // this here by modifying the various plugin attributes and then restoring
839 // them on exit.
840 blink::WebString width_before_fullscreen_;
841 blink::WebString height_before_fullscreen_;
842 blink::WebString border_before_fullscreen_;
843 blink::WebString style_before_fullscreen_;
844 gfx::Size screen_size_for_fullscreen_;
846 // The MessageChannel used to implement bidirectional postMessage for the
847 // instance.
848 v8::Persistent<v8::Object> message_channel_object_;
850 // A pointer to the MessageChannel underlying |message_channel_object_|. It is
851 // only valid as long as |message_channel_object_| is alive.
852 MessageChannel* message_channel_;
854 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
855 SkBitmap* sad_plugin_;
857 typedef std::set<PluginObject*> PluginObjectSet;
858 PluginObjectSet live_plugin_objects_;
860 // Classes of events that the plugin has registered for, both for filtering
861 // and not. The bits are PP_INPUTEVENT_CLASS_*.
862 uint32_t input_event_mask_;
863 uint32_t filtered_input_event_mask_;
865 // Text composition status.
866 ui::TextInputType text_input_type_;
867 gfx::Rect text_input_caret_;
868 gfx::Rect text_input_caret_bounds_;
869 bool text_input_caret_set_;
871 // Text selection status.
872 std::string surrounding_text_;
873 size_t selection_caret_;
874 size_t selection_anchor_;
876 scoped_refptr<ppapi::TrackedCallback> lock_mouse_callback_;
878 // Track pending user gestures so out-of-process plugins can respond to
879 // a user gesture after it has been processed.
880 PP_TimeTicks pending_user_gesture_;
881 blink::WebUserGestureToken pending_user_gesture_token_;
883 // We store the arguments so we can re-send them if we are reset to talk to
884 // NaCl via the IPC NaCl proxy.
885 std::vector<std::string> argn_;
886 std::vector<std::string> argv_;
888 // Non-owning pointer to the document loader, if any.
889 blink::WebURLLoaderClient* document_loader_;
890 // State for deferring document loads. Used only by external instances.
891 blink::WebURLResponse external_document_response_;
892 scoped_ptr<ExternalDocumentLoader> external_document_loader_;
893 bool external_document_load_;
895 // The ContentDecryptorDelegate forwards PPP_ContentDecryptor_Private
896 // calls and handles PPB_ContentDecryptor_Private calls.
897 scoped_ptr<ContentDecryptorDelegate> content_decryptor_delegate_;
899 // The link currently under the cursor.
900 base::string16 link_under_cursor_;
902 // We store the isolate at construction so that we can be sure to use the
903 // Isolate in which this Instance was created when interacting with v8.
904 v8::Isolate* isolate_;
906 scoped_ptr<MouseLockDispatcher::LockTarget> lock_target_;
908 bool is_deleted_;
910 // The text that is currently selected in the plugin.
911 base::string16 selected_text_;
913 bool initialized_;
915 // We use a weak ptr factory for scheduling DidChangeView events so that we
916 // can tell whether updates are pending and consolidate them. When there's
917 // already a weak ptr pending (HasWeakPtrs is true), code should update the
918 // view_data_ but not send updates. This also allows us to cancel scheduled
919 // view change events.
920 base::WeakPtrFactory<PepperPluginInstanceImpl> view_change_weak_ptr_factory_;
921 base::WeakPtrFactory<PepperPluginInstanceImpl> weak_factory_;
923 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceImpl);
926 } // namespace content
928 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_IMPL_H_