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
;
86 blink::WebCanvas
* canvas
,
87 const blink::WebRect
& rect
) override
;
88 virtual void updateGeometry(
89 const blink::WebRect
& frame_rect
,
90 const blink::WebRect
& clip_rect
,
91 const blink::WebVector
<blink::WebRect
>& cut_outs_rects
,
92 bool is_visible
) override
;
93 virtual void updateFocus(bool focused
,
94 blink::WebFocusType focus_type
) override
;
95 virtual void updateVisibility(bool visible
) override
;
96 virtual bool acceptsInputEvents() override
;
97 virtual bool handleInputEvent(
98 const blink::WebInputEvent
& event
,
99 blink::WebCursorInfo
& cursor_info
) override
;
100 virtual bool handleDragStatusUpdate(blink::WebDragStatus drag_status
,
101 const blink::WebDragData
& drag_data
,
102 blink::WebDragOperationsMask mask
,
103 const blink::WebPoint
& position
,
104 const blink::WebPoint
& screen
) override
;
105 virtual void didReceiveResponse(
106 const blink::WebURLResponse
& response
) override
;
107 virtual void didReceiveData(const char* data
, int data_length
) override
;
108 virtual void didFinishLoading() override
;
109 virtual void didFailLoading(const blink::WebURLError
& error
) override
;
110 virtual void didFinishLoadingFrameRequest(
111 const blink::WebURL
& url
,
112 void* notify_data
) override
;
113 virtual void didFailLoadingFrameRequest(
114 const blink::WebURL
& url
,
116 const blink::WebURLError
& error
) override
;
117 virtual bool executeEditCommand(const blink::WebString
& name
) override
;
118 virtual bool executeEditCommand(const blink::WebString
& name
,
119 const blink::WebString
& value
) override
;
120 virtual bool setComposition(
121 const blink::WebString
& text
,
122 const blink::WebVector
<blink::WebCompositionUnderline
>& underlines
,
124 int selectionEnd
) override
;
125 virtual bool confirmComposition(
126 const blink::WebString
& text
,
127 blink::WebWidget::ConfirmCompositionBehavior selectionBehavior
) override
;
128 virtual void extendSelectionAndDelete(int before
, int after
) override
;
130 // MouseLockDispatcher::LockTarget implementation.
131 void OnLockMouseACK(bool succeeded
) override
;
132 void OnMouseLockLost() override
;
133 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent
& event
) override
;
136 friend class base::DeleteHelper
<BrowserPlugin
>;
137 // Only the manager is allowed to create a BrowserPlugin.
138 friend class BrowserPluginManager
;
140 // A BrowserPlugin object is a controller that represents an instance of a
141 // browser plugin within the embedder renderer process. Once a BrowserPlugin
142 // does an initial navigation or is attached to a newly created guest, it
143 // acquires a browser_plugin_instance_id as well. The guest instance ID
144 // uniquely identifies a guest WebContents that's hosted by this
146 BrowserPlugin(RenderFrame
* render_frame
,
147 scoped_ptr
<BrowserPluginDelegate
> delegate
);
149 ~BrowserPlugin() override
;
151 gfx::Rect
view_rect() const { return view_rect_
; }
153 void ShowSadGraphic();
155 // IPC message handlers.
156 // Please keep in alphabetical order.
157 void OnAdvanceFocus(int instance_id
, bool reverse
);
158 void OnCompositorFrameSwapped(const IPC::Message
& message
);
159 void OnGuestGone(int instance_id
);
160 void OnSetContentsOpaque(int instance_id
, bool opaque
);
161 void OnSetCursor(int instance_id
, const WebCursor
& cursor
);
162 void OnSetMouseLock(int instance_id
, bool enable
);
163 void OnSetTooltipText(int browser_plugin_instance_id
,
164 const base::string16
& tooltip_text
);
165 void OnShouldAcceptTouchEvents(int instance_id
, bool accept
);
167 // This indicates whether this BrowserPlugin has been attached to a
168 // WebContents and is ready to receive IPCs.
170 // We cache the |render_frame_routing_id| because we need it on destruction.
171 // If the RenderFrame is destroyed before the BrowserPlugin is destroyed
172 // then we will attempt to access a nullptr.
173 const int render_frame_routing_id_
;
174 blink::WebPluginContainer
* container_
;
175 gfx::Rect view_rect_
;
176 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
177 SkBitmap
* sad_guest_
;
179 bool plugin_focused_
;
180 // Tracks the visibility of the browser plugin regardless of the whole
181 // embedder RenderView's visibility.
188 // This indicates that the BrowserPlugin has a geometry.
191 // Used for HW compositing.
192 scoped_refptr
<ChildFrameCompositingHelper
> compositing_helper_
;
194 // URL for the embedder frame.
195 int browser_plugin_instance_id_
;
197 // Indicates whether the guest content is opaque.
198 bool contents_opaque_
;
200 std::vector
<EditCommand
> edit_commands_
;
202 scoped_ptr
<BrowserPluginDelegate
> delegate_
;
204 // Weak factory used in v8 |MakeWeak| callback, since the v8 callback might
205 // get called after BrowserPlugin has been destroyed.
206 base::WeakPtrFactory
<BrowserPlugin
> weak_ptr_factory_
;
208 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin
);
211 } // namespace content
213 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_