Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / renderer / browser_plugin / browser_plugin.h
1 // Copyright 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.
4
5 #ifndef  CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_
6 #define  CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_
7
8 #include "third_party/WebKit/public/web/WebPlugin.h"
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/sequenced_task_runner_helpers.h"
13 #include "content/renderer/mouse_lock_dispatcher.h"
14 #include "content/renderer/render_view_impl.h"
15 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
16 #include "third_party/WebKit/public/web/WebDragStatus.h"
17 #include "third_party/WebKit/public/web/WebNode.h"
18 #include "third_party/WebKit/public/web/WebWidget.h"
19
20 struct BrowserPluginHostMsg_ResizeGuest_Params;
21 struct FrameMsg_BuffersSwapped_Params;
22
23 namespace content {
24
25 class BrowserPluginDelegate;
26 class ChildFrameCompositingHelper;
27 class BrowserPluginManager;
28 class MockBrowserPlugin;
29
30 class CONTENT_EXPORT BrowserPlugin :
31     NON_EXPORTED_BASE(public blink::WebPlugin),
32     public MouseLockDispatcher::LockTarget {
33  public:
34   static BrowserPlugin* GetFromNode(blink::WebNode& node);
35
36   RenderViewImpl* render_view() const { return render_view_.get(); }
37   int render_view_routing_id() const { return render_view_routing_id_; }
38   int browser_plugin_instance_id() const { return browser_plugin_instance_id_; }
39   bool attached() const { return attached_; }
40   bool ready() const { return attached_ || attach_pending_; }
41   BrowserPluginManager* browser_plugin_manager() const {
42     return browser_plugin_manager_.get();
43   }
44
45   bool OnMessageReceived(const IPC::Message& msg);
46
47   // Update Browser Plugin's DOM Node attribute |attribute_name| with the value
48   // |attribute_value|.
49   void UpdateDOMAttribute(const std::string& attribute_name,
50                           const base::string16& attribute_value);
51
52   // Returns whether the guest process has crashed.
53   bool guest_crashed() const { return guest_crashed_; }
54
55   // Informs the guest of an updated focus state.
56   void UpdateGuestFocusState();
57
58   // Indicates whether the guest should be focused.
59   bool ShouldGuestBeFocused() const;
60
61   // Embedder's device scale factor changed, we need to update the guest
62   // renderer.
63   void UpdateDeviceScaleFactor();
64
65   // A request to enable hardware compositing.
66   void EnableCompositing(bool enable);
67
68   // Provided that a guest instance ID has been allocated, this method attaches
69   // this BrowserPlugin instance to that guest.
70   void Attach();
71
72   // Notify the plugin about a compositor commit so that frame ACKs could be
73   // sent, if needed.
74   void DidCommitCompositorFrame();
75
76   // Returns whether a message should be forwarded to BrowserPlugin.
77   static bool ShouldForwardToBrowserPlugin(const IPC::Message& message);
78
79   // blink::WebPlugin implementation.
80   virtual blink::WebPluginContainer* container() const override;
81   virtual bool initialize(blink::WebPluginContainer* container) override;
82   virtual void destroy() override;
83   virtual bool supportsKeyboardFocus() const override;
84   virtual bool supportsEditCommands() const override;
85   virtual bool supportsInputMethod() const override;
86   virtual bool canProcessDrag() const override;
87   virtual void paint(
88       blink::WebCanvas* canvas,
89       const blink::WebRect& rect) override;
90   virtual void updateGeometry(
91       const blink::WebRect& frame_rect,
92       const blink::WebRect& clip_rect,
93       const blink::WebVector<blink::WebRect>& cut_outs_rects,
94       bool is_visible) override;
95   virtual void updateFocus(bool focused) override;
96   virtual void updateVisibility(bool visible) override;
97   virtual bool acceptsInputEvents() override;
98   virtual bool handleInputEvent(
99       const blink::WebInputEvent& event,
100       blink::WebCursorInfo& cursor_info) override;
101   virtual bool handleDragStatusUpdate(blink::WebDragStatus drag_status,
102                                       const blink::WebDragData& drag_data,
103                                       blink::WebDragOperationsMask mask,
104                                       const blink::WebPoint& position,
105                                       const blink::WebPoint& screen) override;
106   virtual void didReceiveResponse(
107       const blink::WebURLResponse& response) override;
108   virtual void didReceiveData(const char* data, int data_length) override;
109   virtual void didFinishLoading() override;
110   virtual void didFailLoading(const blink::WebURLError& error) override;
111   virtual void didFinishLoadingFrameRequest(
112       const blink::WebURL& url,
113       void* notify_data) override;
114   virtual void didFailLoadingFrameRequest(
115       const blink::WebURL& url,
116       void* notify_data,
117       const blink::WebURLError& error) override;
118   virtual bool executeEditCommand(const blink::WebString& name) override;
119   virtual bool executeEditCommand(const blink::WebString& name,
120                                   const blink::WebString& value) override;
121   virtual bool setComposition(
122       const blink::WebString& text,
123       const blink::WebVector<blink::WebCompositionUnderline>& underlines,
124       int selectionStart,
125       int selectionEnd) override;
126   virtual bool confirmComposition(
127       const blink::WebString& text,
128       blink::WebWidget::ConfirmCompositionBehavior selectionBehavior) override;
129   virtual void extendSelectionAndDelete(int before, int after) override;
130
131   // MouseLockDispatcher::LockTarget implementation.
132   void OnLockMouseACK(bool succeeded) override;
133   void OnMouseLockLost() override;
134   bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override;
135
136  private:
137   friend class base::DeleteHelper<BrowserPlugin>;
138   // Only the manager is allowed to create a BrowserPlugin.
139   friend class BrowserPluginManager;
140
141   // For unit/integration tests.
142   friend class MockBrowserPlugin;
143
144   // A BrowserPlugin object is a controller that represents an instance of a
145   // browser plugin within the embedder renderer process. Once a BrowserPlugin
146   // does an initial navigation or is attached to a newly created guest, it
147   // acquires a browser_plugin_instance_id as well. The guest instance ID
148   // uniquely identifies a guest WebContents that's hosted by this
149   // BrowserPlugin.
150   BrowserPlugin(RenderViewImpl* render_view,
151                 blink::WebFrame* frame,
152                 scoped_ptr<BrowserPluginDelegate> delegate);
153
154   ~BrowserPlugin() override;
155
156   int width() const { return plugin_rect_.width(); }
157   int height() const { return plugin_rect_.height(); }
158   gfx::Size plugin_size() const { return plugin_rect_.size(); }
159   gfx::Rect plugin_rect() const { return plugin_rect_; }
160
161   float GetDeviceScaleFactor() const;
162
163   void ShowSadGraphic();
164
165   // Populates BrowserPluginHostMsg_ResizeGuest_Params with resize state.
166   void PopulateResizeGuestParameters(
167       const gfx::Size& view_size,
168       BrowserPluginHostMsg_ResizeGuest_Params* params);
169
170   // IPC message handlers.
171   // Please keep in alphabetical order.
172   void OnAdvanceFocus(int instance_id, bool reverse);
173   void OnAttachACK(int browser_plugin_instance_id);
174   void OnCompositorFrameSwapped(const IPC::Message& message);
175   void OnGuestGone(int instance_id);
176   void OnSetContentsOpaque(int instance_id, bool opaque);
177   void OnSetCursor(int instance_id, const WebCursor& cursor);
178   void OnSetMouseLock(int instance_id, bool enable);
179   void OnSetTooltipText(int browser_plugin_instance_id,
180                         const base::string16& tooltip_text);
181   void OnShouldAcceptTouchEvents(int instance_id, bool accept);
182
183   // This indicates whether this BrowserPlugin has been attached to a
184   // WebContents.
185   bool attached_;
186   bool attach_pending_;
187   const base::WeakPtr<RenderViewImpl> render_view_;
188   // We cache the |render_view_|'s routing ID because we need it on destruction.
189   // If the |render_view_| is destroyed before the BrowserPlugin is destroyed
190   // then we will attempt to access a NULL pointer.
191   const int render_view_routing_id_;
192   blink::WebPluginContainer* container_;
193   gfx::Rect plugin_rect_;
194   float last_device_scale_factor_;
195   // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
196   SkBitmap* sad_guest_;
197   bool guest_crashed_;
198   bool plugin_focused_;
199   // Tracks the visibility of the browser plugin regardless of the whole
200   // embedder RenderView's visibility.
201   bool visible_;
202
203   WebCursor cursor_;
204
205   bool mouse_locked_;
206
207   // This indicates that the BrowserPlugin has a geometry.
208   bool ready_;
209
210   // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to
211   // store the BrowserPlugin's BrowserPluginManager in a member variable to
212   // avoid accessing the RenderViewImpl.
213   const scoped_refptr<BrowserPluginManager> browser_plugin_manager_;
214
215   // Used for HW compositing.
216   scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
217
218   // URL for the embedder frame.
219   int browser_plugin_instance_id_;
220
221   // Indicates whether the guest content is opaque.
222   bool contents_opaque_;
223
224   std::vector<EditCommand> edit_commands_;
225
226   scoped_ptr<BrowserPluginDelegate> delegate_;
227
228   // Weak factory used in v8 |MakeWeak| callback, since the v8 callback might
229   // get called after BrowserPlugin has been destroyed.
230   base::WeakPtrFactory<BrowserPlugin> weak_ptr_factory_;
231
232   DISALLOW_COPY_AND_ASSIGN(BrowserPlugin);
233 };
234
235 }  // namespace content
236
237 #endif  // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_