[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 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. |
| 4 | |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 5 | // A BrowserPluginGuest is the browser side of a browser <--> embedder |
| 6 | // renderer channel. A BrowserPlugin (a WebPlugin) is on the embedder |
| 7 | // renderer side of browser <--> embedder renderer communication. |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 8 | // |
[email protected] | 864297a | 2013-10-30 19:25:31 | [diff] [blame] | 9 | // BrowserPluginGuest lives on the UI thread of the browser process. Any |
| 10 | // messages about the guest render process that the embedder might be interested |
| 11 | // in receiving should be listened for here. |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 12 | // |
[email protected] | aec80ed | 2014-05-27 00:01:15 | [diff] [blame] | 13 | // BrowserPluginGuest is a WebContentsObserver for the guest WebContents. |
| 14 | // BrowserPluginGuest operates under the assumption that the guest will be |
| 15 | // accessible through only one RenderViewHost for the lifetime of |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 16 | // the guest WebContents. Thus, cross-process navigation is not supported. |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 17 | |
| 18 | #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
| 19 | #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
| 20 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 23 | #include <map> |
limasdf | 85735f4 | 2016-10-21 02:24:55 | [diff] [blame] | 24 | #include <memory> |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 25 | |
| 26 | #include "base/compiler_specific.h" |
Brett Wilson | cc8623d | 2017-09-12 03:28:10 | [diff] [blame] | 27 | #include "base/containers/circular_deque.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 28 | #include "base/macros.h" |
[email protected] | e4a55a5 | 2013-03-09 01:32:49 | [diff] [blame] | 29 | #include "base/memory/weak_ptr.h" |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 30 | #include "base/values.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 31 | #include "build/build_config.h" |
Fady Samuel | 84d8a1f7 | 2018-11-08 00:26:17 | [diff] [blame] | 32 | #include "components/viz/common/surfaces/local_surface_id_allocation.h" |
Chris Blume | 12a2646 | 2018-04-22 02:00:12 | [diff] [blame] | 33 | #include "components/viz/common/surfaces/scoped_surface_id_allocator.h" |
Albert J. Wong | eb28e7e | 2018-10-12 00:57:43 | [diff] [blame] | 34 | #include "content/browser/renderer_host/input_event_shim.h" |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 35 | #include "content/common/edit_command.h" |
[email protected] | 4c0e827 | 2013-07-03 23:39:22 | [diff] [blame] | 36 | #include "content/public/browser/browser_plugin_guest_delegate.h" |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 37 | #include "content/public/browser/guest_host.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 38 | #include "content/public/browser/web_contents_observer.h" |
Dave Tapuska | 66c183b2 | 2017-10-23 16:04:35 | [diff] [blame] | 39 | #include "content/public/common/input_event_ack_state.h" |
Fady Samuel | 85a1bf7 | 2017-10-27 14:30:20 | [diff] [blame] | 40 | #include "content/public/common/screen_info.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 41 | #include "third_party/blink/public/platform/web_drag_operation.h" |
| 42 | #include "third_party/blink/public/platform/web_focus_type.h" |
| 43 | #include "third_party/blink/public/platform/web_input_event.h" |
| 44 | #include "third_party/blink/public/web/web_drag_status.h" |
| 45 | #include "third_party/blink/public/web/web_ime_text_span.h" |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 46 | #include "ui/base/ime/text_input_mode.h" |
| 47 | #include "ui/base/ime/text_input_type.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 48 | #include "ui/gfx/geometry/rect.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 49 | |
[email protected] | 4b4ed58 | 2013-05-01 00:16:23 | [diff] [blame] | 50 | struct BrowserPluginHostMsg_Attach_Params; |
ekaramad | b62c343 | 2017-03-15 21:59:46 | [diff] [blame] | 51 | struct BrowserPluginHostMsg_SetComposition_Params; |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 52 | |
[email protected] | 4f89d9d | 2012-12-12 01:38:48 | [diff] [blame] | 53 | #if defined(OS_MACOSX) |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 54 | struct FrameHostMsg_ShowPopup_Params; |
[email protected] | 4f89d9d | 2012-12-12 01:38:48 | [diff] [blame] | 55 | #endif |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 56 | |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 57 | namespace gfx { |
| 58 | class Range; |
fsamuel | 04a6f5f | 2014-09-04 22:42:14 | [diff] [blame] | 59 | } // namespace gfx |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 60 | |
Fady Samuel | e392fd5 | 2018-05-11 17:16:43 | [diff] [blame] | 61 | namespace cc { |
| 62 | class RenderFrameMetadata; |
| 63 | } // namespace cc |
| 64 | |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 65 | namespace viz { |
Fady Samuel | 84d8a1f7 | 2018-11-08 00:26:17 | [diff] [blame] | 66 | class LocalSurfaceIdAllocation; |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 67 | } // namespace viz |
| 68 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 69 | namespace content { |
| 70 | |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 71 | class BrowserPluginGuestManager; |
Rakina Zata Amni | 3d10bb3c | 2019-04-19 03:12:07 | [diff] [blame] | 72 | class RenderFrameHostImpl; |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 73 | class RenderViewHostImpl; |
fsamuel | 9e3d9ad | 2014-09-11 00:59:30 | [diff] [blame] | 74 | class RenderWidgetHost; |
ekaramad | 51ca209 | 2016-11-17 06:05:58 | [diff] [blame] | 75 | class RenderWidgetHostImpl; |
[email protected] | 4432769 | 2013-02-26 21:21:22 | [diff] [blame] | 76 | class RenderWidgetHostView; |
lazyboy | a34ff62 | 2015-04-07 02:21:17 | [diff] [blame] | 77 | class RenderWidgetHostViewBase; |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 78 | class SiteInstance; |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 79 | struct DropData; |
Fady Samuel | 799e7219 | 2018-04-25 21:16:57 | [diff] [blame] | 80 | struct FrameVisualProperties; |
Fady Samuel | 85a1bf7 | 2017-10-27 14:30:20 | [diff] [blame] | 81 | struct ScreenInfo; |
ekaramad | 9053e57b | 2016-04-26 20:00:38 | [diff] [blame] | 82 | struct TextInputState; |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 83 | |
| 84 | // A browser plugin guest provides functionality for WebContents to operate in |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 85 | // the guest role and implements guest-specific overrides for ViewHostMsg_* |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 86 | // messages. |
| 87 | // |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 88 | // When a guest is initially created, it is in an unattached state. That is, |
| 89 | // it is not visible anywhere and has no embedder WebContents assigned. |
| 90 | // A BrowserPluginGuest is said to be "attached" if it has an embedder. |
| 91 | // A BrowserPluginGuest can also create a new unattached guest via |
| 92 | // CreateNewWindow. The newly created guest will live in the same partition, |
| 93 | // which means it can share storage and can script this guest. |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 94 | // |
| 95 | // Note: in --site-per-process, all IPCs sent out from this class will be |
| 96 | // dropped on the floor since we don't have a BrowserPlugin. |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 97 | class CONTENT_EXPORT BrowserPluginGuest : public GuestHost, |
paulmeyer | 0968abad | 2015-01-10 00:02:45 | [diff] [blame] | 98 | public WebContentsObserver { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 99 | public: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 100 | ~BrowserPluginGuest() override; |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 101 | |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 102 | // The WebContents passed into the factory method here has not been |
| 103 | // initialized yet and so it does not yet hold a SiteInstance. |
| 104 | // BrowserPluginGuest must be constructed and installed into a WebContents |
| 105 | // prior to its initialization because WebContents needs to determine what |
| 106 | // type of WebContentsView to construct on initialization. The content |
| 107 | // embedder needs to be aware of |guest_site_instance| on the guest's |
| 108 | // construction and so we pass it in here. |
Albert J. Wong | c55cc64d | 2018-10-12 02:50:04 | [diff] [blame] | 109 | // |
| 110 | // After this, a new BrowserPluginGuest is created with ownership transferred |
| 111 | // into the |web_contents|. |
| 112 | static void CreateInWebContents(WebContentsImpl* web_contents, |
| 113 | BrowserPluginGuestDelegate* delegate); |
[email protected] | 0c6d4175 | 2013-05-01 15:49:09 | [diff] [blame] | 114 | |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 115 | // Returns whether the given WebContents is a BrowserPlugin guest. |
| 116 | static bool IsGuest(WebContentsImpl* web_contents); |
| 117 | |
| 118 | // Returns whether the given RenderviewHost is a BrowserPlugin guest. |
| 119 | static bool IsGuest(RenderViewHostImpl* render_view_host); |
| 120 | |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 121 | // BrowserPluginGuest::Init is called after the associated guest WebContents |
| 122 | // initializes. If this guest cannot navigate without being attached to a |
| 123 | // container, then this call is a no-op. For guest types that can be |
| 124 | // navigated, this call adds the associated RenderWdigetHostViewGuest to the |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 125 | // view hierarchy and sets up the appropriate |
| 126 | // blink::mojom::RendererPreferences so that this guest can navigate and |
| 127 | // resize offscreen. |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 128 | void Init(); |
| 129 | |
Albert J. Wong | eb28e7e | 2018-10-12 00:57:43 | [diff] [blame] | 130 | // Returns an InputEventShim if this BrowserPluginGuest needs to intercept |
| 131 | // input events normally handled by a RenderWidgetHost. |
| 132 | InputEventShim* GetInputEventShim(); |
| 133 | |
[email protected] | 8fb60c3 | 2014-02-02 17:46:40 | [diff] [blame] | 134 | // Returns a WeakPtr to this BrowserPluginGuest. |
| 135 | base::WeakPtr<BrowserPluginGuest> AsWeakPtr(); |
| 136 | |
fsamuel | 9e3d9ad | 2014-09-11 00:59:30 | [diff] [blame] | 137 | // Sets the focus state of the current RenderWidgetHostView. |
fsamuel | 5ec049d | 2015-01-19 16:57:41 | [diff] [blame] | 138 | void SetFocus(RenderWidgetHost* rwh, |
| 139 | bool focused, |
| 140 | blink::WebFocusType focus_type); |
fsamuel | 9e3d9ad | 2014-09-11 00:59:30 | [diff] [blame] | 141 | |
[email protected] | 660f18e | 2014-05-15 20:53:05 | [diff] [blame] | 142 | // Sets the lock state of the pointer. Returns true if |allowed| is true and |
| 143 | // the mouse has been successfully locked. |
| 144 | bool LockMouse(bool allowed); |
| 145 | |
[email protected] | 0b09400 | 2014-08-20 18:28:10 | [diff] [blame] | 146 | // Return true if the mouse is locked. |
| 147 | bool mouse_locked() const { return mouse_locked_; } |
| 148 | |
[email protected] | e0c6dc9 | 2013-10-10 21:17:51 | [diff] [blame] | 149 | // Called when the embedder WebContents changes visibility. |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 150 | void EmbedderVisibilityChanged(Visibility visibility); |
[email protected] | e0c6dc9 | 2013-10-10 21:17:51 | [diff] [blame] | 151 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 152 | // Creates a new guest WebContentsImpl with the provided |params| with |this| |
| 153 | // as the |opener|. |
| 154 | WebContentsImpl* CreateNewGuestWindow( |
| 155 | const WebContents::CreateParams& params); |
| 156 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 157 | // Returns the identifier that uniquely identifies a browser plugin guest |
| 158 | // within an embedder. |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 159 | int browser_plugin_instance_id() const { return browser_plugin_instance_id_; } |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 160 | |
Fady Samuel | 85a1bf7 | 2017-10-27 14:30:20 | [diff] [blame] | 161 | // Returns the ScreenInfo used by the guest to render. |
| 162 | const ScreenInfo& screen_info() const { return screen_info_; } |
| 163 | |
| 164 | // Returns the current rect used by the guest to render. |
| 165 | const gfx::Rect& frame_rect() const { return frame_rect_; } |
| 166 | |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 167 | bool OnMessageReceivedFromEmbedder(const IPC::Message& message); |
| 168 | |
[email protected] | ca61ce14 | 2012-11-27 21:32:57 | [diff] [blame] | 169 | WebContentsImpl* embedder_web_contents() const { |
fsamuel | 7df36b2 | 2015-01-21 20:13:07 | [diff] [blame] | 170 | return attached_ ? owner_web_contents_ : nullptr; |
[email protected] | ca61ce14 | 2012-11-27 21:32:57 | [diff] [blame] | 171 | } |
[email protected] | e17b7c6 | 2012-09-21 21:05:46 | [diff] [blame] | 172 | |
[email protected] | 68d5ab7 | 2014-01-23 22:22:57 | [diff] [blame] | 173 | // Returns the embedder's RenderWidgetHostView if it is available. |
fsamuel | 7df36b2 | 2015-01-21 20:13:07 | [diff] [blame] | 174 | // Returns nullptr otherwise. |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 175 | RenderWidgetHostView* GetOwnerRenderWidgetHostView(); |
[email protected] | 4432769 | 2013-02-26 21:21:22 | [diff] [blame] | 176 | |
Rakina Zata Amni | 3d10bb3c | 2019-04-19 03:12:07 | [diff] [blame] | 177 | // Returns the embedder frame. |
| 178 | RenderFrameHostImpl* GetEmbedderFrame() const; |
| 179 | |
[email protected] | 6a121f2 | 2012-10-30 03:19:48 | [diff] [blame] | 180 | bool focused() const { return focused_; } |
[email protected] | 93564f7 | 2013-02-15 13:26:19 | [diff] [blame] | 181 | bool visible() const { return guest_visible_; } |
Fady Samuel | f3f9b83 | 2017-09-01 17:11:17 | [diff] [blame] | 182 | |
Fady Samuel | 84d8a1f7 | 2018-11-08 00:26:17 | [diff] [blame] | 183 | // Returns the viz::LocalSurfaceIdAllocation propagated from the parent to be |
| 184 | // used by this guest. |
| 185 | const viz::LocalSurfaceIdAllocation& local_surface_id_allocation() const { |
| 186 | return local_surface_id_allocation_; |
Fady Samuel | b655f45 | 2018-11-06 00:48:34 | [diff] [blame] | 187 | } |
| 188 | |
[email protected] | 3f6fa6d4 | 2013-08-16 21:19:49 | [diff] [blame] | 189 | bool is_in_destruction() { return is_in_destruction_; } |
[email protected] | 6a13c9f | 2012-10-08 16:25:08 | [diff] [blame] | 190 | |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 191 | void UpdateVisibility(); |
| 192 | |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 193 | BrowserPluginGuestManager* GetBrowserPluginGuestManager() const; |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 194 | |
Fady Samuel | d4e14c8 | 2018-04-04 00:56:29 | [diff] [blame] | 195 | void EnableAutoResize(const gfx::Size& min_size, const gfx::Size& max_size); |
| 196 | void DisableAutoResize(); |
Fady Samuel | e392fd5 | 2018-05-11 17:16:43 | [diff] [blame] | 197 | void DidUpdateVisualProperties(const cc::RenderFrameMetadata& metadata); |
Fady Samuel | d10aadd8 | 2017-11-03 18:23:57 | [diff] [blame] | 198 | |
Albert J. Wong | eb28e7e | 2018-10-12 00:57:43 | [diff] [blame] | 199 | // Methods to handle events from InputEventShim. |
| 200 | void DidSetHasTouchEventHandlers(bool accept); |
| 201 | void DidTextInputStateChange(const TextInputState& params); |
| 202 | void DidLockMouse(bool user_gesture, bool privileged); |
| 203 | void DidUnlockMouse(); |
| 204 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 205 | // WebContentsObserver implementation. |
jam | be38048 | 2017-01-27 01:01:09 | [diff] [blame] | 206 | void DidFinishNavigation(NavigationHandle* navigation_handle) override; |
[email protected] | eb92f63 | 2012-10-19 00:56:12 | [diff] [blame] | 207 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 208 | void RenderViewReady() override; |
| 209 | void RenderProcessGone(base::TerminationStatus status) override; |
| 210 | bool OnMessageReceived(const IPC::Message& message) override; |
| 211 | bool OnMessageReceived(const IPC::Message& message, |
| 212 | RenderFrameHost* render_frame_host) override; |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 213 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 214 | // GuestHost implementation. |
| 215 | int LoadURLWithParams( |
| 216 | const NavigationController::LoadURLParams& load_params) override; |
paulmeyer | 0968abad | 2015-01-10 00:02:45 | [diff] [blame] | 217 | void SizeContents(const gfx::Size& new_size) override; |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 218 | void WillDestroy() override; |
paulmeyer | 0968abad | 2015-01-10 00:02:45 | [diff] [blame] | 219 | |
[email protected] | e17b7c6 | 2012-09-21 21:05:46 | [diff] [blame] | 220 | // Exposes the protected web_contents() from WebContentsObserver. |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 221 | WebContentsImpl* GetWebContents() const; |
[email protected] | e17b7c6 | 2012-09-21 21:05:46 | [diff] [blame] | 222 | |
[email protected] | ca61ce14 | 2012-11-27 21:32:57 | [diff] [blame] | 223 | gfx::Point GetScreenCoordinates(const gfx::Point& relative_position) const; |
| 224 | |
fsamuel | 6c1dfeb | 2014-12-18 19:21:33 | [diff] [blame] | 225 | // Helper to send messages to embedder. If this guest is not yet attached, |
| 226 | // then IPCs will be queued until attachment. |
limasdf | 85735f4 | 2016-10-21 02:24:55 | [diff] [blame] | 227 | void SendMessageToEmbedder(std::unique_ptr<IPC::Message> msg); |
[email protected] | 747c3065 | 2012-12-18 20:35:53 | [diff] [blame] | 228 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 229 | // Returns whether the guest is attached to an embedder. |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 230 | bool attached() const { return attached_; } |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 231 | |
| 232 | // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| |
| 233 | // and initializes the guest with the provided |params|. Attaching a guest |
| 234 | // to an embedder implies that this guest's lifetime is no longer managed |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 235 | // by its opener, and it can begin loading resources. |
| 236 | void Attach(int browser_plugin_instance_id, |
| 237 | WebContentsImpl* embedder_web_contents, |
| 238 | const BrowserPluginHostMsg_Attach_Params& params); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 239 | |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 240 | // Returns whether BrowserPluginGuest is interested in receiving the given |
| 241 | // |message|. |
| 242 | static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message); |
| 243 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 244 | void DragSourceEndedAt(float client_x, |
| 245 | float client_y, |
| 246 | float screen_x, |
| 247 | float screen_y, |
| 248 | blink::WebDragOperation operation); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 249 | |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 250 | // Called when the drag started by this guest ends at an OS-level. |
lazyboy | f569b4f6 | 2015-02-03 17:22:54 | [diff] [blame] | 251 | void EmbedderSystemDragEnded(); |
| 252 | void EndSystemDragIfApplicable(); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 253 | |
[email protected] | af1718c | 2013-08-12 19:59:19 | [diff] [blame] | 254 | void RespondToPermissionRequest(int request_id, |
| 255 | bool should_allow, |
| 256 | const std::string& user_input); |
| 257 | |
[email protected] | 7a128089 | 2014-04-16 17:18:25 | [diff] [blame] | 258 | void PointerLockPermissionResponse(bool allow); |
| 259 | |
wjmaclean | 73b15a2 | 2015-09-25 15:56:40 | [diff] [blame] | 260 | void ResendEventToEmbedder(const blink::WebInputEvent& event); |
| 261 | |
ekaramad | aeddbee | 2017-01-26 21:17:24 | [diff] [blame] | 262 | gfx::Point GetCoordinatesInEmbedderWebContents( |
| 263 | const gfx::Point& relative_point); |
| 264 | |
wjmaclean | 53032adf | 2015-06-15 16:49:22 | [diff] [blame] | 265 | protected: |
[email protected] | e17b7c6 | 2012-09-21 21:05:46 | [diff] [blame] | 266 | |
[email protected] | c61b317c7 | 2013-11-14 06:40:46 | [diff] [blame] | 267 | // BrowserPluginGuest is a WebContentsObserver of |web_contents| and |
| 268 | // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. |
wjmaclean | 53032adf | 2015-06-15 16:49:22 | [diff] [blame] | 269 | // Constructor protected for testing. |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 270 | BrowserPluginGuest(bool has_render_view, |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 271 | WebContentsImpl* web_contents, |
| 272 | BrowserPluginGuestDelegate* delegate); |
[email protected] | e17b7c6 | 2012-09-21 21:05:46 | [diff] [blame] | 273 | |
wjmaclean | 321584d | 2015-06-30 19:21:56 | [diff] [blame] | 274 | void set_attached_for_test(bool attached) { |
| 275 | attached_ = attached; |
| 276 | } |
| 277 | |
wjmaclean | 53032adf | 2015-06-15 16:49:22 | [diff] [blame] | 278 | private: |
| 279 | class EmbedderVisibilityObserver; |
| 280 | |
Albert J. Wong | eb28e7e | 2018-10-12 00:57:43 | [diff] [blame] | 281 | // InputEventShim implementation. |
| 282 | class InputEventShimImpl : public InputEventShim { |
| 283 | public: |
| 284 | explicit InputEventShimImpl(BrowserPluginGuest* browser_plugin_guest); |
| 285 | ~InputEventShimImpl() override; |
| 286 | |
| 287 | void DidSetHasTouchEventHandlers(bool accept) override; |
| 288 | void DidTextInputStateChange(const TextInputState& params) override; |
| 289 | void DidLockMouse(bool user_gesture, bool privileged) override; |
| 290 | void DidUnlockMouse() override; |
| 291 | |
| 292 | private: |
| 293 | BrowserPluginGuest* browser_plugin_guest_; |
| 294 | }; |
| 295 | |
ekaramad | 51ca209 | 2016-11-17 06:05:58 | [diff] [blame] | 296 | // The RenderWidgetHostImpl corresponding to the owner frame of BrowserPlugin. |
| 297 | RenderWidgetHostImpl* GetOwnerRenderWidgetHost() const; |
| 298 | |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 299 | void InitInternal(const BrowserPluginHostMsg_Attach_Params& params, |
| 300 | WebContentsImpl* owner_web_contents); |
[email protected] | 10b21b3 | 2014-06-07 09:54:33 | [diff] [blame] | 301 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 302 | // Message handlers for messages from embedder. |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 303 | void OnDetach(int instance_id); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 304 | // Handles drag events from the embedder. |
| 305 | // When dragging, the drag events go to the embedder first, and if the drag |
| 306 | // happens on the browser plugin, then the plugin sends a corresponding |
| 307 | // drag-message to the guest. This routes the drag-message to the guest |
| 308 | // renderer. |
| 309 | void OnDragStatusUpdate(int instance_id, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 310 | blink::WebDragStatus drag_status, |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 311 | const DropData& drop_data, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 312 | blink::WebDragOperationsMask drag_mask, |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 313 | const gfx::PointF& location); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 314 | // Instructs the guest to execute an edit command decoded in the embedder. |
| 315 | void OnExecuteEditCommand(int instance_id, |
| 316 | const std::string& command); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 317 | |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 318 | void OnLockMouseAck(int instance_id, bool succeeded); |
[email protected] | 5501d5df | 2014-04-29 09:12:54 | [diff] [blame] | 319 | // Resizes the guest's web contents. |
fsamuel | 5ec049d | 2015-01-19 16:57:41 | [diff] [blame] | 320 | void OnSetFocus(int instance_id, |
| 321 | bool focused, |
| 322 | blink::WebFocusType focus_type); |
[email protected] | 204deb5 | 2014-05-23 07:17:15 | [diff] [blame] | 323 | // Sets the name of the guest so that other guests in the same partition can |
| 324 | // access it. |
| 325 | void OnSetName(int instance_id, const std::string& name); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 326 | // Updates the size state of the guest. |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 327 | void OnSetEditCommandsForNextKeyEvent( |
| 328 | int instance_id, |
| 329 | const std::vector<EditCommand>& edit_commands); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 330 | // The guest WebContents is visible if both its embedder is visible and |
| 331 | // the browser plugin element is visible. If either one is not then the |
| 332 | // WebContents is marked as hidden. A hidden WebContents will consume |
| 333 | // fewer GPU and CPU resources. |
| 334 | // |
| 335 | // When every WebContents in a RenderProcessHost is hidden, it will lower |
Bo Liu | eb218ee | 2018-03-21 20:24:35 | [diff] [blame] | 336 | // the priority of the process (see |
| 337 | // RenderProcessHostImpl::UpdateClientPriority). |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 338 | // |
| 339 | // It will also send a message to the guest renderer process to cleanup |
| 340 | // resources such as dropping back buffers and adjusting memory limits (if in |
| 341 | // compositing mode, see CCLayerTreeHost::setVisible). |
| 342 | // |
| 343 | // Additionally, it will slow down Javascript execution and garbage |
| 344 | // collection. See RenderThreadImpl::IdleHandler (executed when hidden) and |
| 345 | // RenderThreadImpl::IdleHandlerInForegroundTab (executed when visible). |
| 346 | void OnSetVisibility(int instance_id, bool visible); |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 347 | void OnUnlockMouseAck(int instance_id); |
Fady Samuel | 799e7219 | 2018-04-25 21:16:57 | [diff] [blame] | 348 | void OnSynchronizeVisualProperties( |
| 349 | int instance_id, |
Fady Samuel | 799e7219 | 2018-04-25 21:16:57 | [diff] [blame] | 350 | const FrameVisualProperties& visual_properties); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 351 | |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 352 | void OnImeSetComposition( |
| 353 | int instance_id, |
ekaramad | b62c343 | 2017-03-15 21:59:46 | [diff] [blame] | 354 | const BrowserPluginHostMsg_SetComposition_Params& params); |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 355 | void OnImeCommitText(int instance_id, |
| 356 | const base::string16& text, |
| 357 | const std::vector<blink::WebImeTextSpan>& ime_text_spans, |
| 358 | const gfx::Range& replacement_range, |
| 359 | int relative_cursor_pos); |
ekaramad | f035886c | 2017-05-23 18:10:13 | [diff] [blame] | 360 | void OnImeFinishComposingText(int instance_id, bool keep_selection); |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 361 | void OnExtendSelectionAndDelete(int instance_id, int before, int after); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 362 | |
| 363 | // Message handlers for messages from guest. |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 364 | void OnHandleInputEventAck( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 365 | blink::WebInputEvent::Type event_type, |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 366 | InputEventAckState ack_result); |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 367 | #if defined(OS_MACOSX) |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 368 | // On MacOS X popups are painted by the browser process. We handle them here |
| 369 | // so that they are positioned correctly. |
| 370 | void OnShowPopup(RenderFrameHost* render_frame_host, |
| 371 | const FrameHostMsg_ShowPopup_Params& params); |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 372 | #endif |
Albert J. Wong | f6e13ed | 2018-09-18 15:25:47 | [diff] [blame] | 373 | void OnShowWidget(int widget_route_id, const gfx::Rect& initial_rect); |
[email protected] | 204deb5 | 2014-05-23 07:17:15 | [diff] [blame] | 374 | void OnTakeFocus(bool reverse); |
| 375 | void OnUpdateFrameName(int frame_id, |
| 376 | bool is_top_level, |
| 377 | const std::string& name); |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 378 | |
hanxi | 9bd85fa | 2015-05-05 19:55:00 | [diff] [blame] | 379 | // Called when WillAttach is complete. |
| 380 | void OnWillAttachComplete(WebContentsImpl* embedder_web_contents, |
| 381 | const BrowserPluginHostMsg_Attach_Params& params); |
| 382 | |
wjmaclean | 6f63918 | 2015-10-16 19:57:24 | [diff] [blame] | 383 | // Returns identical message with current browser_plugin_instance_id() if |
| 384 | // the input was created with browser_plugin::kInstanceIdNone, else it returns |
| 385 | // the input message unmodified. If no current browser_plugin_instance_id() |
| 386 | // is set, or anything goes wrong, the input message is returned. |
limasdf | 85735f4 | 2016-10-21 02:24:55 | [diff] [blame] | 387 | std::unique_ptr<IPC::Message> UpdateInstanceIdIfNecessary( |
| 388 | std::unique_ptr<IPC::Message> msg) const; |
wjmaclean | 6f63918 | 2015-10-16 19:57:24 | [diff] [blame] | 389 | |
[email protected] | 697f16b5 | 2013-05-10 06:01:18 | [diff] [blame] | 390 | // Forwards all messages from the |pending_messages_| queue to the embedder. |
| 391 | void SendQueuedMessages(); |
| 392 | |
lazyboy | a34ff62 | 2015-04-07 02:21:17 | [diff] [blame] | 393 | void SendTextInputTypeChangedToView(RenderWidgetHostViewBase* guest_rwhv); |
| 394 | |
arthursonzogni | ba36c21 | 2019-05-21 08:09:00 | [diff] [blame] | 395 | // Creates, if necessary, and returns the routing ID of a render view for the |
| 396 | // guest in the owner's renderer process. |
| 397 | int GetGuestRenderViewRoutingID(); |
| 398 | |
paulmeyer | e80cfc9 | 2014-10-10 03:37:43 | [diff] [blame] | 399 | // The last tooltip that was set with SetTooltipText(). |
| 400 | base::string16 current_tooltip_text_; |
| 401 | |
Albert J. Wong | eb28e7e | 2018-10-12 00:57:43 | [diff] [blame] | 402 | InputEventShimImpl input_event_shim_impl_; |
| 403 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 404 | std::unique_ptr<EmbedderVisibilityObserver> embedder_visibility_observer_; |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 405 | WebContentsImpl* owner_web_contents_; |
| 406 | |
| 407 | // Indicates whether this guest has been attached to a container. |
| 408 | bool attached_; |
[email protected] | 40974d0 | 2013-04-09 22:11:19 | [diff] [blame] | 409 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 410 | // An identifier that uniquely identifies a browser plugin within an embedder. |
| 411 | int browser_plugin_instance_id_; |
Fady Samuel | 85a1bf7 | 2017-10-27 14:30:20 | [diff] [blame] | 412 | gfx::Rect frame_rect_; |
[email protected] | 6a121f2 | 2012-10-30 03:19:48 | [diff] [blame] | 413 | bool focused_; |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 414 | bool mouse_locked_; |
[email protected] | a25acea7 | 2013-03-10 23:41:28 | [diff] [blame] | 415 | bool pending_lock_request_; |
[email protected] | 93564f7 | 2013-02-15 13:26:19 | [diff] [blame] | 416 | bool guest_visible_; |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 417 | Visibility embedder_visibility_; |
raymes | 0fa0be5 | 2014-10-13 20:38:09 | [diff] [blame] | 418 | // Whether the browser plugin is inside a plugin document. |
| 419 | bool is_full_page_plugin_; |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 420 | |
[email protected] | 0c6d4175 | 2013-05-01 15:49:09 | [diff] [blame] | 421 | // Indicates that this BrowserPluginGuest has associated renderer-side state. |
| 422 | // This is used to determine whether or not to create a new RenderView when |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 423 | // this guest is attached. A BrowserPluginGuest would have renderer-side state |
| 424 | // prior to attachment if it is created via a call to window.open and |
| 425 | // maintains a JavaScript reference to its opener. |
[email protected] | 0c6d4175 | 2013-05-01 15:49:09 | [diff] [blame] | 426 | bool has_render_view_; |
| 427 | |
[email protected] | 3f6fa6d4 | 2013-08-16 21:19:49 | [diff] [blame] | 428 | bool is_in_destruction_; |
| 429 | |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 430 | // BrowserPluginGuest::Init can only be called once. This flag allows it to |
| 431 | // exit early if it's already been called. |
| 432 | bool initialized_; |
| 433 | |
[email protected] | 63c33bd6 | 2014-02-08 04:45:40 | [diff] [blame] | 434 | // Text input type states. |
shuchen | f93c297 | 2015-09-11 01:52:37 | [diff] [blame] | 435 | // Using scoped_ptr to avoid including the header file: view_messages.h. |
ekaramad | 9053e57b | 2016-04-26 20:00:38 | [diff] [blame] | 436 | std::unique_ptr<const TextInputState> last_text_input_state_; |
[email protected] | 63c33bd6 | 2014-02-08 04:45:40 | [diff] [blame] | 437 | |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 438 | // The is the routing ID for a swapped out RenderView for the guest |
| 439 | // WebContents in the embedder's process. |
arthursonzogni | ba36c21 | 2019-05-21 08:09:00 | [diff] [blame] | 440 | int guest_render_view_routing_id_; |
lazyboy | f569b4f6 | 2015-02-03 17:22:54 | [diff] [blame] | 441 | // Last seen state of drag status update. |
| 442 | blink::WebDragStatus last_drag_status_; |
| 443 | // Whether or not our embedder has seen a SystemDragEnded() call. |
| 444 | bool seen_embedder_system_drag_ended_; |
| 445 | // Whether or not our embedder has seen a DragSourceEndedAt() call. |
| 446 | bool seen_embedder_drag_source_ended_at_; |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 447 | |
hush | 8915b50 | 2016-06-15 19:32:23 | [diff] [blame] | 448 | // Ignore the URL dragged into guest that is coming from guest. |
| 449 | bool ignore_dragged_url_; |
fsamuel | bdfc1ad | 2015-02-24 02:10:02 | [diff] [blame] | 450 | |
[email protected] | 697f16b5 | 2013-05-10 06:01:18 | [diff] [blame] | 451 | // This is a queue of messages that are destined to be sent to the embedder |
| 452 | // once the guest is attached to a particular embedder. |
Brett Wilson | cc8623d | 2017-09-12 03:28:10 | [diff] [blame] | 453 | base::circular_deque<std::unique_ptr<IPC::Message>> pending_messages_; |
[email protected] | 697f16b5 | 2013-05-10 06:01:18 | [diff] [blame] | 454 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 455 | BrowserPluginGuestDelegate* const delegate_; |
[email protected] | 4c0e827 | 2013-07-03 23:39:22 | [diff] [blame] | 456 | |
Fady Samuel | 84d8a1f7 | 2018-11-08 00:26:17 | [diff] [blame] | 457 | viz::LocalSurfaceIdAllocation local_surface_id_allocation_; |
Fady Samuel | 85a1bf7 | 2017-10-27 14:30:20 | [diff] [blame] | 458 | ScreenInfo screen_info_; |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 459 | double zoom_level_ = 0.0; |
Vladimir Levin | 98d76dad | 2018-04-21 00:21:29 | [diff] [blame] | 460 | uint32_t capture_sequence_number_ = 0u; |
Fady Samuel | f3f9b83 | 2017-09-01 17:11:17 | [diff] [blame] | 461 | |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 462 | // Weak pointer used to ask GeolocationPermissionContext about geolocation |
| 463 | // permission. |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 464 | base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_{this}; |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 465 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 466 | DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
| 467 | }; |
| 468 | |
| 469 | } // namespace content |
| 470 | |
| 471 | #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |