Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / browser_plugin / browser_plugin.h
blob730b92149ec17f4252bf45784196552dae2012d7
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.
5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_
6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_
8 #include "third_party/WebKit/public/web/WebPlugin.h"
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"
20 struct BrowserPluginHostMsg_ResizeGuest_Params;
21 struct FrameMsg_BuffersSwapped_Params;
23 namespace cc {
24 struct SurfaceId;
25 struct SurfaceSequence;
28 namespace content {
30 class BrowserPluginDelegate;
31 class BrowserPluginManager;
32 class ChildFrameCompositingHelper;
34 class CONTENT_EXPORT BrowserPlugin :
35 NON_EXPORTED_BASE(public blink::WebPlugin),
36 public MouseLockDispatcher::LockTarget {
37 public:
38 static BrowserPlugin* GetFromNode(blink::WebNode& node);
40 int render_frame_routing_id() const { return render_frame_routing_id_; }
41 int browser_plugin_instance_id() const { return browser_plugin_instance_id_; }
42 bool attached() const { return attached_; }
44 bool OnMessageReceived(const IPC::Message& msg);
46 // Update Browser Plugin's DOM Node attribute |attribute_name| with the value
47 // |attribute_value|.
48 void UpdateDOMAttribute(const std::string& attribute_name,
49 const base::string16& attribute_value);
51 // Returns whether the guest process has crashed.
52 bool guest_crashed() const { return guest_crashed_; }
54 // Informs the guest of an updated focus state.
55 void UpdateGuestFocusState(blink::WebFocusType focus_type);
57 // Indicates whether the guest should be focused.
58 bool ShouldGuestBeFocused() const;
60 // A request to enable hardware compositing.
61 void EnableCompositing(bool enable);
63 // Called by CompositingHelper to send current SurfaceSequence to browser.
64 void SendSatisfySequence(const cc::SurfaceSequence& sequence);
66 // Provided that a guest instance ID has been allocated, this method attaches
67 // this BrowserPlugin instance to that guest.
68 void Attach();
70 // This method detaches this BrowserPlugin instance from the guest that it's
71 // currently attached to, if any.
72 void Detach();
74 // Notify the plugin about a compositor commit so that frame ACKs could be
75 // sent, if needed.
76 void DidCommitCompositorFrame();
78 // Returns whether a message should be forwarded to BrowserPlugin.
79 static bool ShouldForwardToBrowserPlugin(const IPC::Message& message);
81 // blink::WebPlugin implementation.
82 virtual blink::WebPluginContainer* container() const override;
83 virtual bool initialize(blink::WebPluginContainer* container) override;
84 virtual void destroy() override;
85 virtual v8::Local<v8::Object> v8ScriptableObject(
86 v8::Isolate* isolate) override;
87 virtual bool supportsKeyboardFocus() const override;
88 virtual bool supportsEditCommands() const override;
89 virtual bool supportsInputMethod() const override;
90 virtual bool canProcessDrag() const override;
91 virtual void layoutIfNeeded() override { }
92 virtual void paint(
93 blink::WebCanvas* canvas,
94 const blink::WebRect& rect) override;
95 virtual void updateGeometry(
96 const blink::WebRect& window_rect,
97 const blink::WebRect& clip_rect,
98 const blink::WebRect& unobscured_rect,
99 const blink::WebVector<blink::WebRect>& cut_outs_rects,
100 bool is_visible) override;
101 virtual void updateFocus(bool focused,
102 blink::WebFocusType focus_type) override;
103 virtual void updateVisibility(bool visible) override;
104 virtual bool acceptsInputEvents() override;
105 virtual bool handleInputEvent(
106 const blink::WebInputEvent& event,
107 blink::WebCursorInfo& cursor_info) override;
108 virtual bool handleDragStatusUpdate(blink::WebDragStatus drag_status,
109 const blink::WebDragData& drag_data,
110 blink::WebDragOperationsMask mask,
111 const blink::WebPoint& position,
112 const blink::WebPoint& screen) override;
113 virtual void didReceiveResponse(
114 const blink::WebURLResponse& response) override;
115 virtual void didReceiveData(const char* data, int data_length) override;
116 virtual void didFinishLoading() override;
117 virtual void didFailLoading(const blink::WebURLError& error) override;
118 virtual void didFinishLoadingFrameRequest(
119 const blink::WebURL& url,
120 void* notify_data) override;
121 virtual void didFailLoadingFrameRequest(
122 const blink::WebURL& url,
123 void* notify_data,
124 const blink::WebURLError& error) override;
125 virtual bool executeEditCommand(const blink::WebString& name) override;
126 virtual bool executeEditCommand(const blink::WebString& name,
127 const blink::WebString& value) override;
128 virtual bool setComposition(
129 const blink::WebString& text,
130 const blink::WebVector<blink::WebCompositionUnderline>& underlines,
131 int selectionStart,
132 int selectionEnd) override;
133 virtual bool confirmComposition(
134 const blink::WebString& text,
135 blink::WebWidget::ConfirmCompositionBehavior selectionBehavior) override;
136 virtual void extendSelectionAndDelete(int before, int after) override;
138 // MouseLockDispatcher::LockTarget implementation.
139 void OnLockMouseACK(bool succeeded) override;
140 void OnMouseLockLost() override;
141 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override;
143 private:
144 friend class base::DeleteHelper<BrowserPlugin>;
145 // Only the manager is allowed to create a BrowserPlugin.
146 friend class BrowserPluginManager;
148 // A BrowserPlugin object is a controller that represents an instance of a
149 // browser plugin within the embedder renderer process. Once a BrowserPlugin
150 // does an initial navigation or is attached to a newly created guest, it
151 // acquires a browser_plugin_instance_id as well. The guest instance ID
152 // uniquely identifies a guest WebContents that's hosted by this
153 // BrowserPlugin.
154 BrowserPlugin(RenderFrame* render_frame,
155 const base::WeakPtr<BrowserPluginDelegate>& delegate);
157 ~BrowserPlugin() override;
159 gfx::Rect view_rect() const { return view_rect_; }
161 void ShowSadGraphic();
162 void UpdateInternalInstanceId();
164 // IPC message handlers.
165 // Please keep in alphabetical order.
166 void OnAdvanceFocus(int instance_id, bool reverse);
167 void OnCompositorFrameSwapped(const IPC::Message& message);
168 void OnGuestGone(int instance_id);
169 void OnSetChildFrameSurface(int instance_id,
170 const cc::SurfaceId& surface_id,
171 const gfx::Size& frame_size,
172 float scale_factor,
173 const cc::SurfaceSequence& sequence);
174 void OnSetContentsOpaque(int instance_id, bool opaque);
175 void OnSetCursor(int instance_id, const WebCursor& cursor);
176 void OnSetMouseLock(int instance_id, bool enable);
177 void OnSetTooltipText(int browser_plugin_instance_id,
178 const base::string16& tooltip_text);
179 void OnShouldAcceptTouchEvents(int instance_id, bool accept);
181 // This indicates whether this BrowserPlugin has been attached to a
182 // WebContents and is ready to receive IPCs.
183 bool attached_;
184 // We cache the |render_frame_routing_id| because we need it on destruction.
185 // If the RenderFrame is destroyed before the BrowserPlugin is destroyed
186 // then we will attempt to access a nullptr.
187 const int render_frame_routing_id_;
188 blink::WebPluginContainer* container_;
189 gfx::Rect view_rect_;
190 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
191 SkBitmap* sad_guest_;
192 bool guest_crashed_;
193 bool plugin_focused_;
194 // Tracks the visibility of the browser plugin regardless of the whole
195 // embedder RenderView's visibility.
196 bool visible_;
198 WebCursor cursor_;
200 bool mouse_locked_;
202 // This indicates that the BrowserPlugin has a geometry.
203 bool ready_;
205 // Used for HW compositing.
206 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
208 // URL for the embedder frame.
209 int browser_plugin_instance_id_;
211 // Indicates whether the guest content is opaque.
212 bool contents_opaque_;
214 std::vector<EditCommand> edit_commands_;
216 // We call lifetime managing methods on |delegate_|, but we do not directly
217 // own this. The delegate destroys itself.
218 base::WeakPtr<BrowserPluginDelegate> delegate_;
220 // Weak factory used in v8 |MakeWeak| callback, since the v8 callback might
221 // get called after BrowserPlugin has been destroyed.
222 base::WeakPtrFactory<BrowserPlugin> weak_ptr_factory_;
224 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin);
227 } // namespace content
229 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_