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
;
25 class BrowserPluginDelegate
;
26 class BrowserPluginManager
;
27 class ChildFrameCompositingHelper
;
29 class CONTENT_EXPORT BrowserPlugin
:
30 NON_EXPORTED_BASE(public blink::WebPlugin
),
31 public MouseLockDispatcher::LockTarget
{
33 static BrowserPlugin
* GetFromNode(blink::WebNode
& node
);
35 int render_frame_routing_id() const { return render_frame_routing_id_
; }
36 int browser_plugin_instance_id() const { return browser_plugin_instance_id_
; }
37 bool attached() const { return attached_
; }
39 bool OnMessageReceived(const IPC::Message
& msg
);
41 // Update Browser Plugin's DOM Node attribute |attribute_name| with the value
43 void UpdateDOMAttribute(const std::string
& attribute_name
,
44 const base::string16
& attribute_value
);
46 // Returns whether the guest process has crashed.
47 bool guest_crashed() const { return guest_crashed_
; }
49 // Informs the guest of an updated focus state.
50 void UpdateGuestFocusState(blink::WebFocusType focus_type
);
52 // Indicates whether the guest should be focused.
53 bool ShouldGuestBeFocused() const;
55 // A request to enable hardware compositing.
56 void EnableCompositing(bool enable
);
58 void UpdateInternalInstanceId();
60 // Provided that a guest instance ID has been allocated, this method attaches
61 // this BrowserPlugin instance to that guest.
64 // This method detaches this BrowserPlugin instance from the guest that it's
65 // currently attached to, if any.
68 // Notify the plugin about a compositor commit so that frame ACKs could be
70 void DidCommitCompositorFrame();
72 // Returns whether a message should be forwarded to BrowserPlugin.
73 static bool ShouldForwardToBrowserPlugin(const IPC::Message
& message
);
75 // blink::WebPlugin implementation.
76 virtual blink::WebPluginContainer
* container() const override
;
77 virtual bool initialize(blink::WebPluginContainer
* container
) override
;
78 virtual void destroy() override
;
79 virtual v8::Local
<v8::Object
> v8ScriptableObject(
80 v8::Isolate
* isolate
) override
;
81 virtual bool supportsKeyboardFocus() const override
;
82 virtual bool supportsEditCommands() const override
;
83 virtual bool supportsInputMethod() const override
;
84 virtual bool canProcessDrag() const override
;
85 virtual void layoutIfNeeded() override
{ }
87 blink::WebCanvas
* canvas
,
88 const blink::WebRect
& rect
) override
;
89 virtual void updateGeometry(
90 const blink::WebRect
& window_rect
,
91 const blink::WebRect
& clip_rect
,
92 const blink::WebRect
& unobscured_rect
,
93 const blink::WebVector
<blink::WebRect
>& cut_outs_rects
,
94 bool is_visible
) override
;
95 virtual void updateFocus(bool focused
,
96 blink::WebFocusType focus_type
) override
;
97 virtual void updateVisibility(bool visible
) override
;
98 virtual bool acceptsInputEvents() override
;
99 virtual bool handleInputEvent(
100 const blink::WebInputEvent
& event
,
101 blink::WebCursorInfo
& cursor_info
) override
;
102 virtual bool handleDragStatusUpdate(blink::WebDragStatus drag_status
,
103 const blink::WebDragData
& drag_data
,
104 blink::WebDragOperationsMask mask
,
105 const blink::WebPoint
& position
,
106 const blink::WebPoint
& screen
) override
;
107 virtual void didReceiveResponse(
108 const blink::WebURLResponse
& response
) override
;
109 virtual void didReceiveData(const char* data
, int data_length
) override
;
110 virtual void didFinishLoading() override
;
111 virtual void didFailLoading(const blink::WebURLError
& error
) override
;
112 virtual void didFinishLoadingFrameRequest(
113 const blink::WebURL
& url
,
114 void* notify_data
) override
;
115 virtual void didFailLoadingFrameRequest(
116 const blink::WebURL
& url
,
118 const blink::WebURLError
& error
) override
;
119 virtual bool executeEditCommand(const blink::WebString
& name
) override
;
120 virtual bool executeEditCommand(const blink::WebString
& name
,
121 const blink::WebString
& value
) override
;
122 virtual bool setComposition(
123 const blink::WebString
& text
,
124 const blink::WebVector
<blink::WebCompositionUnderline
>& underlines
,
126 int selectionEnd
) override
;
127 virtual bool confirmComposition(
128 const blink::WebString
& text
,
129 blink::WebWidget::ConfirmCompositionBehavior selectionBehavior
) override
;
130 virtual void extendSelectionAndDelete(int before
, int after
) override
;
132 // MouseLockDispatcher::LockTarget implementation.
133 void OnLockMouseACK(bool succeeded
) override
;
134 void OnMouseLockLost() override
;
135 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent
& event
) override
;
138 friend class base::DeleteHelper
<BrowserPlugin
>;
139 // Only the manager is allowed to create a BrowserPlugin.
140 friend class BrowserPluginManager
;
142 // A BrowserPlugin object is a controller that represents an instance of a
143 // browser plugin within the embedder renderer process. Once a BrowserPlugin
144 // does an initial navigation or is attached to a newly created guest, it
145 // acquires a browser_plugin_instance_id as well. The guest instance ID
146 // uniquely identifies a guest WebContents that's hosted by this
148 BrowserPlugin(RenderFrame
* render_frame
,
149 scoped_ptr
<BrowserPluginDelegate
> delegate
);
151 ~BrowserPlugin() override
;
153 gfx::Rect
view_rect() const { return view_rect_
; }
155 void ShowSadGraphic();
157 // IPC message handlers.
158 // Please keep in alphabetical order.
159 void OnAdvanceFocus(int instance_id
, bool reverse
);
160 void OnCompositorFrameSwapped(const IPC::Message
& message
);
161 void OnGuestGone(int instance_id
);
162 void OnSetContentsOpaque(int instance_id
, bool opaque
);
163 void OnSetCursor(int instance_id
, const WebCursor
& cursor
);
164 void OnSetMouseLock(int instance_id
, bool enable
);
165 void OnSetTooltipText(int browser_plugin_instance_id
,
166 const base::string16
& tooltip_text
);
167 void OnShouldAcceptTouchEvents(int instance_id
, bool accept
);
169 // This indicates whether this BrowserPlugin has been attached to a
170 // WebContents and is ready to receive IPCs.
172 // We cache the |render_frame_routing_id| because we need it on destruction.
173 // If the RenderFrame is destroyed before the BrowserPlugin is destroyed
174 // then we will attempt to access a nullptr.
175 const int render_frame_routing_id_
;
176 blink::WebPluginContainer
* container_
;
177 gfx::Rect view_rect_
;
178 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
179 SkBitmap
* sad_guest_
;
181 bool plugin_focused_
;
182 // Tracks the visibility of the browser plugin regardless of the whole
183 // embedder RenderView's visibility.
190 // This indicates that the BrowserPlugin has a geometry.
193 // Used for HW compositing.
194 scoped_refptr
<ChildFrameCompositingHelper
> compositing_helper_
;
196 // URL for the embedder frame.
197 int browser_plugin_instance_id_
;
199 // Indicates whether the guest content is opaque.
200 bool contents_opaque_
;
202 std::vector
<EditCommand
> edit_commands_
;
204 scoped_ptr
<BrowserPluginDelegate
> delegate_
;
206 // Weak factory used in v8 |MakeWeak| callback, since the v8 callback might
207 // get called after BrowserPlugin has been destroyed.
208 base::WeakPtrFactory
<BrowserPlugin
> weak_ptr_factory_
;
210 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin
);
213 } // namespace content
215 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_