blob: d0f98a742a2b478b352f9de05cc01026c2650dac [file] [log] [blame]
[email protected]9f4f3322012-01-18 22:29:561// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#ifndef CONTENT_RENDERER_RENDER_WIDGET_H_
6#define CONTENT_RENDERER_RENDER_WIDGET_H_
initial.commit09911bf2008-07-26 23:55:297
avi1023d012015-12-25 02:39:148#include <stddef.h>
9#include <stdint.h>
10
[email protected]0e241b4b2012-08-18 09:06:2711#include <map>
dchengcedca5612016-04-09 01:40:1512#include <memory>
xlai180af792016-08-26 22:07:4213#include <queue>
pwnallef669312017-01-07 01:17:2914#include <string>
15#include <vector>
[email protected]010ea08a2009-10-11 20:21:3216
[email protected]586871b2014-07-22 17:05:1117#include "base/callback.h"
Fady Samuel1ee6fb5c2018-02-16 03:27:4618#include "base/cancelable_callback.h"
[email protected]f3112a52011-09-30 23:47:4919#include "base/compiler_specific.h"
avi1023d012015-12-25 02:39:1420#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1521#include "base/memory/ref_counted.h"
wjmaclean1d970622017-01-21 22:28:2422#include "base/memory/weak_ptr.h"
[email protected]bffc8302014-01-23 20:52:1623#include "base/observer_list.h"
Gabriel Charette14520232018-04-30 23:27:2224#include "base/single_thread_task_runner.h"
[email protected]abb522162013-06-28 01:54:1625#include "base/time/time.h"
avi1023d012015-12-25 02:39:1426#include "build/build_config.h"
Sandra Sunac5cdd832017-12-11 03:27:1327#include "cc/input/overscroll_behavior.h"
xidachenfa0199e72017-05-11 11:34:2628#include "cc/input/touch_action.h"
danakj4b347212018-07-04 17:55:1729#include "cc/trees/layer_tree_settings.h"
30#include "cc/trees/managed_memory_policy.h"
Fady Samuel644df1d2017-07-13 01:13:0231#include "components/viz/common/surfaces/local_surface_id.h"
Scott Violetc78fef732018-03-06 17:42:5332#include "content/common/buildflags.h"
[email protected]f3112a52011-09-30 23:47:4933#include "content/common/content_export.h"
[email protected]c2809346d2014-03-20 00:11:0334#include "content/common/cursors/webcursor.h"
paulmeyer6ef5a792016-11-08 20:33:5835#include "content/common/drag_event_source_info.h"
alexmos56567492016-09-13 00:52:4636#include "content/common/edit_command.h"
Dave Tapuska1bdf1832017-07-07 18:07:1937#include "content/common/widget.mojom.h"
paulmeyer90f6c31d2016-11-12 00:17:5938#include "content/public/common/drop_data.h"
ccameron2f451532016-09-07 21:49:2739#include "content/public/common/screen_info.h"
danakj829cdd142018-09-14 21:13:2740#include "content/public/common/widget_type.h"
mfomitchev2600fd7c2016-02-17 20:53:3941#include "content/renderer/devtools/render_widget_screen_metrics_emulator_delegate.h"
danakja6c10012018-07-06 14:25:3642#include "content/renderer/gpu/layer_tree_view_delegate.h"
dtapuska9ec1a912017-04-21 15:18:3143#include "content/renderer/input/main_thread_event_queue.h"
fsamuel72464894f2015-12-15 06:59:3144#include "content/renderer/input/render_widget_input_handler.h"
45#include "content/renderer/input/render_widget_input_handler_delegate.h"
lfgbee1e0a2016-06-08 21:24:2146#include "content/renderer/mouse_lock_dispatcher.h"
47#include "content/renderer/render_widget_mouse_lock_dispatcher.h"
[email protected]4f86bdb2012-11-10 19:11:1948#include "ipc/ipc_listener.h"
nick4df698d82016-11-11 20:39:2349#include "ipc/ipc_message.h"
[email protected]4f86bdb2012-11-10 19:11:1950#include "ipc/ipc_sender.h"
Dave Tapuska1bdf1832017-07-07 18:07:1951#include "mojo/public/cpp/bindings/binding.h"
Scott Violet02e38b92018-03-27 23:42:1452#include "ppapi/buildflags/buildflags.h"
Richard Li49fe04d2018-10-21 09:07:1953#include "services/network/public/mojom/referrer_policy.mojom.h"
Dmitry Gozman88ca5a992018-05-18 00:13:3354#include "third_party/blink/public/common/manifest/web_display_mode.h"
Blink Reformata30d4232018-04-07 15:31:0655#include "third_party/blink/public/platform/web_input_event.h"
56#include "third_party/blink/public/platform/web_rect.h"
Blink Reformata30d4232018-04-07 15:31:0657#include "third_party/blink/public/platform/web_text_input_info.h"
58#include "third_party/blink/public/web/web_ime_text_span.h"
Blink Reformata30d4232018-04-07 15:31:0659#include "third_party/blink/public/web/web_text_direction.h"
60#include "third_party/blink/public/web/web_widget.h"
61#include "third_party/blink/public/web/web_widget_client.h"
[email protected]b256eca2013-07-11 10:57:4062#include "ui/base/ime/text_input_mode.h"
[email protected]ad26ef42011-06-17 07:59:4563#include "ui/base/ime/text_input_type.h"
[email protected]a09d53ce2014-01-31 00:46:4264#include "ui/base/ui_base_types.h"
tfarina93bfa912014-12-05 14:23:1565#include "ui/gfx/geometry/rect.h"
tfarina93bfa912014-12-05 14:23:1566#include "ui/gfx/geometry/vector2d_f.h"
[email protected]08397d52011-02-05 01:53:3867#include "ui/gfx/native_widget_types.h"
[email protected]db4fc1e2013-09-06 20:01:5168#include "ui/gfx/range/range.h"
[email protected]d353541f2012-05-03 22:45:4169#include "ui/surface/transport_dib.h"
initial.commit09911bf2008-07-26 23:55:2970
[email protected]484955942010-08-19 16:13:1871namespace IPC {
[email protected]586871b2014-07-22 17:05:1172class SyncMessageFilter;
[email protected]484955942010-08-19 16:13:1873}
74
[email protected]180ef242013-11-07 06:50:4675namespace blink {
skyostil529caa292016-08-10 17:44:5176namespace scheduler {
Yuta Kitamura39219b42018-04-06 10:28:1477class WebRenderWidgetSchedulingState;
skyostil529caa292016-08-10 17:44:5178}
[email protected]19193682014-04-03 15:01:4379struct WebDeviceEmulationParams;
paulmeyer6ef5a792016-11-08 20:33:5880class WebDragData;
lfgcaab5142016-02-26 19:06:5281class WebFrameWidget;
[email protected]41d86852012-11-07 12:23:2482class WebGestureEvent;
ekaramad2daaf672016-11-10 20:29:0183class WebInputMethodController;
kenrba7199832015-01-22 23:44:5984class WebLocalFrame;
[email protected]6a8ddba52010-09-05 04:38:0685class WebMouseEvent;
pwnallef669312017-01-07 01:17:2986} // namespace blink
[email protected]526476902011-10-06 20:34:0687
[email protected]586871b2014-07-22 17:05:1188namespace cc {
David Bokanc8e38d02018-10-08 21:56:0189struct ApplyViewportChangesArgs;
[email protected]586871b2014-07-22 17:05:1190class SwapPromise;
91}
[email protected]ba91a792013-02-06 09:48:2892
[email protected]db4fc1e2013-09-06 20:01:5193namespace gfx {
danakja2c9d0a92018-07-25 20:01:1894class ColorSpace;
[email protected]4de6d1692011-10-12 08:45:4495class Range;
96}
97
chongza8ba91fc2016-08-16 21:39:1798namespace ui {
99struct DidOverscrollParams;
100}
101
[email protected]e9ff79c2012-10-19 21:31:26102namespace content {
Saman Samid189e5dfd2017-12-20 22:55:31103class BrowserPlugin;
danakj6e3bf8012014-12-16 18:27:53104class CompositorDependencies;
[email protected]b2e4c70132013-10-03 02:07:51105class ExternalPopupMenu;
[email protected]586871b2014-07-22 17:05:11106class FrameSwapMessageQueue;
changwanf2a707b2015-10-30 08:22:16107class ImeEventGuard;
danakja6c10012018-07-06 14:25:36108class LayerTreeView;
dtapuska9ec1a912017-04-21 15:18:31109class MainThreadEventQueue;
ekaramad2a46d632016-07-19 13:33:09110class PepperPluginInstanceImpl;
[email protected]bffc8302014-01-23 20:52:16111class RenderFrameImpl;
[email protected]e3244ed2014-06-20 20:04:27112class RenderFrameProxy;
nickf7b38222016-11-22 21:59:35113class RenderViewImpl;
avi40b5be7a2016-03-03 21:13:44114class RenderWidgetOwnerDelegate;
mfomitchev2600fd7c2016-02-17 20:53:39115class RenderWidgetScreenMetricsEmulator;
[email protected]5b45ad42013-10-25 00:42:04116class ResizingModeSelector;
ekaramad330ba4232016-09-23 17:57:47117class TextInputClientObserver;
Dave Tapuska9db80842017-07-24 17:24:26118class WidgetInputHandlerManager;
[email protected]b2e4c70132013-10-03 02:07:51119struct ContextMenuParams;
Fady Samuel799e72192018-04-25 21:16:57120struct VisualProperties;
[email protected]e9ff79c2012-10-19 21:31:26121
initial.commit09911bf2008-07-26 23:55:29122// RenderWidget provides a communication bridge between a WebWidget and
123// a RenderWidgetHost, the latter of which lives in a different process.
dchengd96a27a2015-07-24 20:17:32124//
125// RenderWidget is used to implement:
126// - RenderViewImpl (deprecated)
127// - Fullscreen mode (RenderWidgetFullScreen)
128// - Popup "menus" (like the color chooser and date picker)
129// - Widgets for frames (for out-of-process iframe support)
[email protected]f3112a52011-09-30 23:47:49130class CONTENT_EXPORT RenderWidget
[email protected]c47317e2012-06-20 22:35:31131 : public IPC::Listener,
132 public IPC::Sender,
danakj9a8a9cf2018-07-17 23:52:12133 public blink::WebWidgetClient,
Dave Tapuska1bdf1832017-07-07 18:07:19134 public mojom::Widget,
danakja6c10012018-07-06 14:25:36135 public LayerTreeViewDelegate,
fsamuel72464894f2015-12-15 06:59:31136 public RenderWidgetInputHandlerDelegate,
mfomitchev2600fd7c2016-02-17 20:53:39137 public RenderWidgetScreenMetricsEmulatorDelegate,
dtapuska9ec1a912017-04-21 15:18:31138 public base::RefCounted<RenderWidget>,
139 public MainThreadEventQueueClient {
initial.commit09911bf2008-07-26 23:55:29140 public:
danakjdf1ceb72018-07-18 20:02:25141 using ShowCallback =
142 base::OnceCallback<void(RenderWidget* widget_to_show,
143 blink::WebNavigationPolicy policy,
144 const gfx::Rect& initial_rect)>;
145
danakj53802692018-07-25 21:46:44146 // Time-To-First-Active-Paint(TTFAP) type
147 enum {
148 TTFAP_AFTER_PURGED,
149 TTFAP_5MIN_AFTER_BACKGROUNDED,
150 };
151
danakj6a816592018-09-25 18:30:56152 // An Init*() method must be called after creating a RenderWidget, which will
153 // make the RenderWidget self-referencing. Then it can be deleted by calling
154 // Close().
155 RenderWidget(int32_t widget_routing_id,
156 CompositorDependencies* compositor_deps,
157 WidgetType widget_type,
158 const ScreenInfo& screen_info,
159 blink::WebDisplayMode display_mode,
160 bool swapped_out,
161 bool hidden,
162 bool never_visible,
163 mojom::WidgetRequest widget_request = nullptr);
164
danakj25ec6e2b2018-09-26 17:01:31165 // Initialize a new RenderWidget for a popup. The |show_callback| is called
166 // when RenderWidget::Show() happens. This method increments the reference
167 // count on the RenderWidget, making it self-referencing, which can be
168 // released by calling Close().
169 void InitForPopup(ShowCallback show_callback,
170 blink::WebPagePopup* web_page_popup);
initial.commit09911bf2008-07-26 23:55:29171
danakj6a816592018-09-25 18:30:56172 // Initialize a new RenderWidget that will be attached to a RenderFrame (via
173 // the WebFrameWidget), for a frame that is a local root, but not the main
174 // frame. This method increments the reference count on the RenderWidget,
175 // making it self-referencing, which can be released by calling Close().
176 void InitForChildLocalRoot(blink::WebFrameWidget* web_frame_widget);
lfg1568d112016-08-30 16:06:29177
danakj53802692018-07-25 21:46:44178 void set_owner_delegate(RenderWidgetOwnerDelegate* owner_delegate) {
179 DCHECK(!owner_delegate_);
180 owner_delegate_ = owner_delegate;
181 }
182 RenderWidgetOwnerDelegate* owner_delegate() const { return owner_delegate_; }
183
Albert J. Wongcb004632018-07-10 22:58:25184 // Returns the RenderWidget for the given routing ID.
185 static RenderWidget* FromRoutingID(int32_t routing_id);
186
dchengda9b4bb2015-07-20 20:58:08187 // Closes a RenderWidget that was created by |CreateForFrame|.
danakja2c9d0a92018-07-25 20:01:18188 void CloseForFrame();
[email protected]484955942010-08-19 16:13:18189
nick8331f8ad2016-11-15 20:42:45190 int32_t routing_id() const { return routing_id_; }
fsamuele8326c742016-01-12 00:49:39191
danakj6e3bf8012014-12-16 18:27:53192 CompositorDependencies* compositor_deps() const { return compositor_deps_; }
Ken Buchananed449bb2018-02-01 21:02:05193
194 // This can return nullptr while the RenderWidget is closing.
danakja2c9d0a92018-07-25 20:01:18195 blink::WebWidget* GetWebWidget() const;
ekaramad2daaf672016-11-10 20:29:01196
197 // Returns the current instance of WebInputMethodController which is to be
198 // used for IME related tasks. This instance corresponds to the one from
199 // focused frame and can be nullptr.
200 blink::WebInputMethodController* GetInputMethodController() const;
201
mfomitchev2600fd7c2016-02-17 20:53:39202 const gfx::Size& size() const { return size_; }
Christopher Cameron58089372018-03-08 23:11:13203 const gfx::Size& compositor_viewport_pixel_size() const {
Christopher Cameronaad15a0d2018-03-09 03:47:33204 return compositor_viewport_pixel_size_;
Christopher Cameron58089372018-03-08 23:11:13205 }
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12206 bool is_fullscreen_granted() const { return is_fullscreen_granted_; }
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12207 blink::WebDisplayMode display_mode() const { return display_mode_; }
[email protected]204f1df2012-01-04 20:21:13208 bool is_hidden() const { return is_hidden_; }
[email protected]4ee64622014-03-21 22:34:15209 // Temporary for debugging purposes...
210 bool closing() const { return closing_; }
pwnallef669312017-01-07 01:17:29211 bool has_host_context_menu_location() const {
[email protected]be1af0662014-07-29 19:55:51212 return has_host_context_menu_location_;
213 }
pwnallef669312017-01-07 01:17:29214 gfx::Point host_context_menu_location() const {
[email protected]be1af0662014-07-29 19:55:51215 return host_context_menu_location_;
[email protected]4ee64622014-03-21 22:34:15216 }
Ken Buchananb2c9e262018-03-10 16:53:31217 const gfx::Size& visible_viewport_size() const {
218 return visible_viewport_size_;
219 }
[email protected]589621b2010-09-23 22:01:07220
danakj53802692018-07-25 21:46:44221 ScreenInfo screen_info() const { return screen_info_; }
222 void set_screen_info(const ScreenInfo& info) { screen_info_ = info; }
avi40b5be7a2016-03-03 21:13:44223
alexmos78c9c0d2016-10-14 18:57:03224 // Sets whether this RenderWidget has been swapped out to be displayed by
225 // a RenderWidget in a different process. If so, no new IPC messages will be
226 // sent (only ACKs) and the process is free to exit when there are no other
danakj678f0252018-11-09 21:46:34227 // active RenderWidgets. The RenderWidget is not used for compositing as there
228 // is no WebWidget that should display content when swapped out.
danakjde8b7482018-11-15 23:45:02229 void SetSwappedOut(bool is_swapped_out);
pwnallef669312017-01-07 01:17:29230 bool is_swapped_out() const { return is_swapped_out_; }
alexmos78c9c0d2016-10-14 18:57:03231
danakj678f0252018-11-09 21:46:34232 // This is true once a Close IPC has been received. The actual action of
233 // closing must be done on another stack frame, in case the IPC receipt
234 // is in a nested message loop and will unwind back up to javascript (from
235 // plugins). So this will be true between those two things, to avoid work
236 // when the RenderWidget will be closed.
237 // Additionally, as an optimization, this is true after we know the renderer
238 // has asked the browser to close this RenderWidget.
239 //
240 // TODO(crbug.com/545684): Once RenderViewImpl and RenderWidget are split,
241 // attempt to combine two states so the shutdown logic is cleaner.
242 bool is_closing() const { return host_will_close_this_ || closing_; }
243
alexmos56567492016-09-13 00:52:46244 // Manage edit commands to be used for the next keyboard event.
245 const EditCommands& edit_commands() const { return edit_commands_; }
246 void SetEditCommandForNextKeyEvent(const std::string& name,
247 const std::string& value);
248 void ClearEditCommands();
249
[email protected]bffc8302014-01-23 20:52:16250 // Functions to track out-of-process frames for special notifications.
[email protected]e3244ed2014-06-20 20:04:27251 void RegisterRenderFrameProxy(RenderFrameProxy* proxy);
252 void UnregisterRenderFrameProxy(RenderFrameProxy* proxy);
[email protected]bffc8302014-01-23 20:52:16253
[email protected]de3c5d82014-05-28 22:12:59254 // Functions to track all RenderFrame objects associated with this
255 // RenderWidget.
256 void RegisterRenderFrame(RenderFrameImpl* frame);
257 void UnregisterRenderFrame(RenderFrameImpl* frame);
258
Saman Samid189e5dfd2017-12-20 22:55:31259 // BrowserPlugins embedded by this RenderWidget register themselves here.
260 // These plugins need to be notified about changes to ScreenInfo.
261 void RegisterBrowserPlugin(BrowserPlugin* browser_plugin);
262 void UnregisterBrowserPlugin(BrowserPlugin* browser_plugin);
263
[email protected]c47317e2012-06-20 22:35:31264 // IPC::Listener
dcheng6d18e402014-10-21 12:32:52265 bool OnMessageReceived(const IPC::Message& msg) override;
initial.commit09911bf2008-07-26 23:55:29266
[email protected]c47317e2012-06-20 22:35:31267 // IPC::Sender
dcheng6d18e402014-10-21 12:32:52268 bool Send(IPC::Message* msg) override;
initial.commit09911bf2008-07-26 23:55:29269
danakja6c10012018-07-06 14:25:36270 // LayerTreeViewDelegate
David Bokanc8e38d02018-10-08 21:56:01271 void ApplyViewportChanges(const cc::ApplyViewportChangesArgs& args) override;
sahel1b47fda72017-03-28 17:03:07272 void RecordWheelAndTouchScrollingCount(bool has_scrolled_by_wheel,
273 bool has_scrolled_by_touch) override;
Daniel Cheng224569ee2018-04-25 05:45:06274 void BeginMainFrame(base::TimeTicks frame_time) override;
danakjc7afae52017-06-20 21:12:41275 void RequestNewLayerTreeFrameSink(
danakja6c10012018-07-06 14:25:36276 LayerTreeFrameSinkCallback callback) override;
fsamuel78f86e42016-01-20 04:10:23277 void DidCommitAndDrawCompositorFrame() override;
278 void DidCommitCompositorFrame() override;
279 void DidCompletePageScaleAnimation() override;
Stephen Chenney9879a5c2018-09-26 14:21:42280 void RecordEndOfFrameMetrics(base::TimeTicks frame_begin_time) override;
danakj53eccbc2016-03-02 22:51:07281 void RequestScheduleAnimation() override;
Robert Flack3ef2ffb2018-09-06 20:38:20282 void UpdateVisualState() override;
fsamuel78f86e42016-01-20 04:10:23283 void WillBeginCompositorFrame() override;
jbroman6ccbc7d472016-07-27 04:45:41284 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:04285 std::unique_ptr<viz::CopyOutputRequest> request) override;
fsamuel78f86e42016-01-20 04:10:23286
fsamuel72464894f2015-12-15 06:59:31287 // RenderWidgetInputHandlerDelegate
288 void FocusChangeComplete() override;
Sandra Sunac5cdd832017-12-11 03:27:13289 void ObserveGestureEventAndResult(
290 const blink::WebGestureEvent& gesture_event,
291 const gfx::Vector2dF& unused_delta,
292 const cc::OverscrollBehavior& overscroll_behavior,
293 bool event_processed) override;
dtapuska1827dd22016-03-11 15:24:59294
fsamuel72464894f2015-12-15 06:59:31295 void OnDidHandleKeyEvent() override;
chongza8ba91fc2016-08-16 21:39:17296 void OnDidOverscroll(const ui::DidOverscrollParams& params) override;
fsamuele8326c742016-01-12 00:49:39297 void SetInputHandler(RenderWidgetInputHandler* input_handler) override;
changwan75e3b2072017-01-16 02:55:00298 void ShowVirtualKeyboard() override;
299 void UpdateTextInputState() override;
changwan62f57292017-02-17 08:28:25300 void ClearTextInputState() override;
fsamuel72464894f2015-12-15 06:59:31301 bool WillHandleGestureEvent(const blink::WebGestureEvent& event) override;
302 bool WillHandleMouseEvent(const blink::WebMouseEvent& event) override;
303
Scott Violet1098538e2017-10-05 19:23:33304 // RenderWidgetScreenMetricsEmulatorDelegate
mfomitchev2600fd7c2016-02-17 20:53:39305 void Redraw() override;
Fady Samuel799e72192018-04-25 21:16:57306 void SynchronizeVisualProperties(
307 const VisualProperties& resize_params) override;
mfomitchev2600fd7c2016-02-17 20:53:39308 void SetScreenMetricsEmulationParameters(
309 bool enabled,
310 const blink::WebDeviceEmulationParams& params) override;
Albert J. Wong3c93c182018-09-27 17:29:43311 void SetScreenRects(const gfx::Rect& widget_screen_rect,
mfomitchev2600fd7c2016-02-17 20:53:39312 const gfx::Rect& window_screen_rect) override;
313
[email protected]180ef242013-11-07 06:50:46314 // blink::WebWidgetClient
Chris Harrelsond7ab99b2018-01-24 17:51:36315 void IntrinsicSizingInfoChanged(
316 const blink::WebIntrinsicSizingInfo&) override;
Blink Reformat1c4d759e2017-04-09 16:34:54317 void DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) override;
318 void DidChangeCursor(const blink::WebCursorInfo&) override;
aelias5971e47d2017-06-16 02:39:38319 void AutoscrollStart(const blink::WebFloatPoint& point) override;
320 void AutoscrollFling(const blink::WebFloatSize& velocity) override;
321 void AutoscrollEnd() override;
Blink Reformat1c4d759e2017-04-09 16:34:54322 void CloseWidgetSoon() override;
323 void Show(blink::WebNavigationPolicy) override;
324 blink::WebRect WindowRect() override;
325 blink::WebRect ViewRect() override;
326 void SetToolTipText(const blink::WebString& text,
avi5c77d212015-09-25 20:08:25327 blink::WebTextDirection hint) override;
Blink Reformat1c4d759e2017-04-09 16:34:54328 void SetWindowRect(const blink::WebRect&) override;
Blink Reformat1c4d759e2017-04-09 16:34:54329 void DidHandleGestureEvent(const blink::WebGestureEvent& event,
avi5c77d212015-09-25 20:08:25330 bool event_cancelled) override;
Blink Reformat1c4d759e2017-04-09 16:34:54331 void DidOverscroll(const blink::WebFloatSize& overscrollDelta,
bokane53a10f2016-04-13 23:48:31332 const blink::WebFloatSize& accumulatedOverscroll,
avi5c77d212015-09-25 20:08:25333 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:54334 const blink::WebFloatSize& velocity,
danakje819b622018-05-01 20:27:14335 const cc::OverscrollBehavior& behavior) override;
Blink Reformat1c4d759e2017-04-09 16:34:54336 void ShowVirtualKeyboardOnElementFocus() override;
337 void ConvertViewportToWindow(blink::WebRect* rect) override;
338 void ConvertWindowToViewport(blink::WebFloatRect* rect) override;
339 bool RequestPointerLock() override;
340 void RequestPointerUnlock() override;
341 bool IsPointerLocked() override;
Richard Li49fe04d2018-10-21 09:07:19342 void StartDragging(network::mojom::ReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:58343 const blink::WebDragData& data,
344 blink::WebDragOperationsMask mask,
danakj0c75ad82018-07-10 19:50:12345 const SkBitmap& drag_image,
danakjef1735a2018-11-13 19:34:44346 const gfx::Point& image_offset) override;
danakj53802692018-07-25 21:46:44347 void SetTouchAction(cc::TouchAction touch_action) override;
348 void RequestUnbufferedInputEvents() override;
Navid Zolghadr8fdb6114e2018-08-29 19:00:54349 void HasPointerRawMoveEventHandlers(bool has_handlers) override;
danakj53802692018-07-25 21:46:44350 void HasTouchEventHandlers(bool has_handlers) override;
351 void SetNeedsLowLatencyInput(bool) override;
[email protected]4873c7d2009-07-16 06:36:28352
fsamuel72464894f2015-12-15 06:59:31353 // Override point to obtain that the current input method state and caret
354 // position.
danakja2c9d0a92018-07-25 20:01:18355 ui::TextInputType GetTextInputType();
fsamuel72464894f2015-12-15 06:59:31356
danakj4b347212018-07-04 17:55:17357 static cc::LayerTreeSettings GenerateLayerTreeSettings(
358 CompositorDependencies* compositor_deps,
359 bool is_for_subframe,
360 const gfx::Size& initial_screen_size,
361 float initial_device_scale_factor);
danakj4b347212018-07-04 17:55:17362 static cc::ManagedMemoryPolicy GetGpuMemoryPolicy(
363 const cc::ManagedMemoryPolicy& policy,
364 const gfx::Size& initial_screen_size,
365 float initial_device_scale_factor);
366
danakja6c10012018-07-06 14:25:36367 LayerTreeView* layer_tree_view() const { return layer_tree_view_.get(); }
Dave Tapuska9db80842017-07-24 17:24:26368 WidgetInputHandlerManager* widget_input_handler_manager() {
369 return widget_input_handler_manager_.get();
370 }
fsamuel72464894f2015-12-15 06:59:31371 const RenderWidgetInputHandler& input_handler() const {
fsamuele8326c742016-01-12 00:49:39372 return *input_handler_;
fsamuel72464894f2015-12-15 06:59:31373 }
374
danakj53802692018-07-25 21:46:44375 void SetHandlingInputEvent(bool handling_input_event);
376
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:49377 // Delivers |message| together with compositor state change updates.
[email protected]586871b2014-07-22 17:05:11378 // This mechanism is not a drop-in replacement for IPC: messages sent this way
379 // will not be automatically available to BrowserMessageFilter, for example.
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:49380 // FIFO ordering is preserved between messages enqueued.
[email protected]586871b2014-07-22 17:05:11381 //
382 // |msg| message to send, ownership of |msg| is transferred.
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:49383 void QueueMessage(IPC::Message* msg);
[email protected]586871b2014-07-22 17:05:11384
changwanf2a707b2015-10-30 08:22:16385 // Handle start and finish of IME event guard.
386 void OnImeEventGuardStart(ImeEventGuard* guard);
387 void OnImeEventGuardFinish(ImeEventGuard* guard);
[email protected]66fca5bc2013-05-23 06:58:29388
danakj53802692018-07-25 21:46:44389 void ApplyEmulatedScreenMetricsForPopupWidget(RenderWidget* origin_widget);
[email protected]b2e4c70132013-10-03 02:07:51390
[email protected]2d6836f42014-07-02 17:25:31391 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51392
[email protected]7a4e2532013-12-02 21:30:02393 // Checks if the selection bounds have been changed. If they are changed,
394 // the new value will be sent to the browser process.
395 void UpdateSelectionBounds();
396
danakja2c9d0a92018-07-25 20:01:18397 void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end);
[email protected]e5e438d62014-03-27 21:47:16398
[email protected]a09d53ce2014-01-31 00:46:42399 void OnShowHostContextMenu(ContextMenuParams* params);
[email protected]7a4e2532013-12-02 21:30:02400
[email protected]7a4e2532013-12-02 21:30:02401 // Checks if the composition range or composition character bounds have been
402 // changed. If they are changed, the new value will be sent to the browser
yukawa5f21c6a2014-10-27 17:09:30403 // process. This method does nothing when the browser process is not able to
404 // handle composition range and composition character bounds.
nonafa291792016-08-10 02:36:18405 // If immediate_request is true, render sends the latest composition info to
406 // the browser even if the composition info is not changed.
407 void UpdateCompositionInfo(bool immediate_request);
[email protected]7a4e2532013-12-02 21:30:02408
danakja2c9d0a92018-07-25 20:01:18409 // Override point to obtain that the current composition character bounds.
410 // In the case of surrogate pairs, the character is treated as two characters:
411 // the bounds for first character is actual one, and the bounds for second
412 // character is zero width rectangle.
413 void GetCompositionCharacterBounds(std::vector<gfx::Rect>* character_bounds);
414
lfgb00fcad2016-07-14 14:16:33415 // Called when the Widget has changed size as a result of an auto-resize.
416 void DidAutoResize(const gfx::Size& new_size);
417
Albert J. Wongcb004632018-07-10 22:58:25418 void DidPresentForceDrawFrame(int snapshot_id,
419 const gfx::PresentationFeedback& feedback);
420
lfge0c2792ec2016-05-11 18:52:08421 // Indicates whether this widget has focus.
422 bool has_focus() const { return has_focus_; }
423
pwnallef669312017-01-07 01:17:29424 MouseLockDispatcher* mouse_lock_dispatcher() const {
lfgbee1e0a2016-06-08 21:24:21425 return mouse_lock_dispatcher_.get();
426 }
427
Fady Samuela863f152018-03-09 16:10:03428 // Returns the ScreenInfo exposed to Blink. In device emulation, this
429 // may not match the compositor ScreenInfo.
430 const ScreenInfo& GetWebScreenInfo() const;
Christopher Camerone9a30c12018-03-07 08:23:38431
Fady Samuela863f152018-03-09 16:10:03432 // When emulated, this returns the original (non-emulated) ScreenInfo.
433 const ScreenInfo& GetOriginalScreenInfo() const;
lfg1f9011c2016-08-17 21:18:42434
paulmeyer90f6c31d2016-11-12 00:17:59435 // Helper to convert |point| using ConvertWindowToViewport().
Ella Ge80a52dce2017-11-15 18:01:52436 gfx::PointF ConvertWindowPointToViewport(const gfx::PointF& point);
paulmeyer90f6c31d2016-11-12 00:17:59437 gfx::Point ConvertWindowPointToViewport(const gfx::Point& point);
kenrb5d78b842017-03-06 21:06:01438 uint32_t GetContentSourceId();
Saman Samif7731342018-01-24 22:18:44439 void DidNavigate();
kenrb5d78b842017-03-06 21:06:01440
Fady Samuele62be402018-03-29 03:19:53441 bool auto_resize_mode() const { return auto_resize_mode_; }
442
Fady Samuele62be402018-03-29 03:19:53443 const gfx::Size& min_size_for_auto_resize() const {
444 return min_size_for_auto_resize_;
445 }
446
447 const gfx::Size& max_size_for_auto_resize() const {
448 return max_size_for_auto_resize_;
449 }
Vladimir Levin98d76dad2018-04-21 00:21:29450
451 uint32_t capture_sequence_number() const {
452 return last_capture_sequence_number_;
453 }
454
dtapuska9ec1a912017-04-21 15:18:31455 // MainThreadEventQueueClient overrides.
456
457 // Requests a BeginMainFrame callback from the compositor.
458 void SetNeedsMainFrame() override;
459
Xianzhu Wangf02017ac2018-10-17 01:47:33460 viz::FrameSinkId GetFrameSinkIdAtPoint(const gfx::PointF& point,
Ken Buchanan44d7e2f2018-08-23 14:18:05461 gfx::PointF* local_point);
Navid Zolghadr0d86e5f2017-10-23 18:09:22462
Dave Tapuskaea83d3bd2017-06-13 16:14:55463 void HandleInputEvent(const blink::WebCoalescedInputEvent& input_event,
464 const ui::LatencyInfo& latency_info,
465 HandledEventCallback callback) override;
Dave Tapuska139a72f2017-09-06 21:57:03466
467 void SetupWidgetInputHandler(mojom::WidgetInputHandlerRequest request,
468 mojom::WidgetInputHandlerHostPtr host) override;
dtapuska9ec1a912017-04-21 15:18:31469
dtapuska9d46ef7d2017-05-26 19:06:06470 scoped_refptr<MainThreadEventQueue> GetInputEventQueue();
471
Albert J. Wongcb004632018-07-10 22:58:25472 void OnSetActive(bool active);
danakja2c9d0a92018-07-25 20:01:18473 void OnSetFocus(bool enable);
Albert J. Wongcb004632018-07-10 22:58:25474 void OnSetBackgroundOpaque(bool opaque);
Dave Tapuska9db80842017-07-24 17:24:26475 void OnMouseCaptureLost();
476 void OnCursorVisibilityChange(bool is_visible);
477 void OnSetEditCommandsForNextKeyEvent(const EditCommands& edit_commands);
478 void OnImeSetComposition(
479 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:11480 const std::vector<blink::WebImeTextSpan>& ime_text_spans,
Dave Tapuska9db80842017-07-24 17:24:26481 const gfx::Range& replacement_range,
482 int selection_start,
483 int selection_end);
Ryan Landay9e42fd742017-08-12 01:59:11484 void OnImeCommitText(const base::string16& text,
485 const std::vector<blink::WebImeTextSpan>& ime_text_spans,
486 const gfx::Range& replacement_range,
487 int relative_cursor_pos);
Dave Tapuska9db80842017-07-24 17:24:26488 void OnImeFinishComposingText(bool keep_selection);
489
danakja2c9d0a92018-07-25 20:01:18490 // This does the actual focus change, but is called in more situations than
491 // just as an IPC message.
492 void SetFocus(bool enable);
493
Dave Tapuska9db80842017-07-24 17:24:26494 // Called by the browser process to update text input state.
495 void OnRequestTextInputStateUpdate();
496
497 // Called by the browser process to update the cursor and composition
Dave Tapuska04bc5ee92018-04-17 19:03:31498 // information by sending WidgetInputHandlerHost::ImeCompositionRangeChanged.
499 // If |immediate_request| is true, an IPC is sent back with current state.
Dave Tapuska9db80842017-07-24 17:24:26500 // When |monitor_update| is true, then RenderWidget will send the updates
501 // in each compositor frame when there are changes. Outside of compositor
502 // frame updates, a change in text selection might also lead to an update for
503 // composition info (when in monitor mode).
504 void OnRequestCompositionUpdates(bool immediate_request,
505 bool monitor_updates);
Dave Tapuska485aca92017-08-08 00:47:58506 void SetWidgetBinding(mojom::WidgetRequest request);
Dave Tapuska9db80842017-07-24 17:24:26507
Ken Buchanan94c0beb62018-06-22 19:56:24508 void SetMouseCapture(bool capture);
509
danakj53802692018-07-25 21:46:44510 void SetWindowScreenRect(const gfx::Rect& window_screen_rect);
Takashi SAKAMOTO870f6262017-08-22 04:08:27511
Fady Samuelca9ecb72018-05-05 05:59:27512 bool IsSurfaceSynchronizationEnabled() const;
513
W. James MacLean2a90bff2018-11-05 20:52:47514 void PageScaleFactorChanged(float page_scale_factor);
515
danakj53802692018-07-25 21:46:44516 void UseSynchronousResizeModeForTesting(bool enable);
danakja2c9d0a92018-07-25 20:01:18517 void SetDeviceScaleFactorForTesting(float factor);
518 void SetDeviceColorSpaceForTesting(const gfx::ColorSpace& color_space);
519 void SetWindowRectSynchronouslyForTesting(const gfx::Rect& new_window_rect);
520 void EnableAutoResizeForTesting(const gfx::Size& min_size,
521 const gfx::Size& max_size);
522 void DisableAutoResizeForTesting(const gfx::Size& new_size);
523
Saman Sami50d1e0c2018-03-13 20:03:49524 base::WeakPtr<RenderWidget> AsWeakPtr();
525
initial.commit09911bf2008-07-26 23:55:29526 protected:
dcheng6d18e402014-10-21 12:32:52527 ~RenderWidget() override;
initial.commit09911bf2008-07-26 23:55:29528
nick4df698d82016-11-11 20:39:23529 // Called by Create() functions and subclasses to finish initialization.
danakj53802692018-07-25 21:46:44530 // |show_callback| will be invoked once WebWidgetClient::Show() occurs, and
531 // should be null if Show() won't be triggered for this widget.
Scott Violetae08f332018-07-27 17:37:23532 void Init(ShowCallback show_callback, blink::WebWidget* web_widget);
[email protected]484955942010-08-19 16:13:18533
danakj53802692018-07-25 21:46:44534 // Update the web view's device scale factor.
535 void UpdateWebViewWithDeviceScaleFactor();
danakj53802692018-07-25 21:46:44536
537 // Close the underlying WebWidget and stop the compositor.
538 virtual void Close();
539
540 // Notify subclasses that we initiated the paint operation.
541 virtual void DidInitiatePaint() {}
542
danakj53802692018-07-25 21:46:44543 // RenderWidget IPC message handler that can be overridden by subclasses.
544 virtual void OnSynchronizeVisualProperties(const VisualProperties& params);
545
danakj53802692018-07-25 21:46:44546 private:
547 // Friend RefCounted so that the dtor can be non-public. Using this class
548 // without ref-counting is an error.
549 friend class base::RefCounted<RenderWidget>;
550
551 // TODO(nasko): Temporarily friend RenderFrameImpl for WasSwappedOut(),
552 // while we move frame specific code away from RenderViewImpl/RenderWidget.
553 friend class RenderFrameImpl;
554
555 // For unit tests.
556 friend class InteractiveRenderWidget;
557 friend class PopupRenderWidget;
558 friend class QueueMessageSwapPromiseTest;
559 friend class RenderWidgetTest;
560 friend class RenderViewImplTest;
561 FRIEND_TEST_ALL_PREFIXES(RenderWidgetPopupUnittest, EmulatingPopupRect);
danakja2c9d0a92018-07-25 20:01:18562
Hajime Hoshi315a61f2018-08-14 17:27:28563 static scoped_refptr<base::SingleThreadTaskRunner> GetCleanupTaskRunner();
564
danakjde8b7482018-11-15 23:45:02565 // Creates the compositor, but leaves it in a stopped state, where it will
566 // not set up IPC channels or begin trying to produce frames until started
567 // via StartCompositor().
danakj17216f4d2018-10-16 22:57:32568 LayerTreeView* InitializeLayerTreeView();
569
danakjde8b7482018-11-15 23:45:02570 // Initiates the compositor to set up IPC channels and begin its scheduler.
571 void StartCompositor();
572 // Pauses the compositor's scheduler and tears down its IPC channels.
573 void StopCompositor();
574
[email protected]2533ce12009-05-09 00:02:24575 void DoDeferredClose();
dgozmancf9039cd2015-04-06 12:01:31576 void NotifyOnClose();
dchengda9b4bb2015-07-20 20:58:08577
bokanc63441c2016-04-27 15:49:12578 gfx::Size GetSizeForWebWidget() const;
danakja2c9d0a92018-07-25 20:01:18579 void ResizeWebWidget();
bokanc63441c2016-04-27 15:49:12580
Ken Buchananed449bb2018-02-01 21:02:05581 // Just Close the WebWidget, in cases where the Close() will be deferred.
582 // It is safe to call this multiple times, which happens in the case of
583 // frame widgets beings closed, since subsequent calls are ignored.
584 void CloseWebWidget();
585
thakis18e426412017-03-15 12:06:37586#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51587 void SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39588 ExternalPopupMenu* popup,
589 RenderWidgetScreenMetricsEmulator* emulator);
[email protected]53907862014-03-25 15:42:40590#endif
[email protected]61e2b3cc2012-03-02 16:13:34591
danakj53802692018-07-25 21:46:44592 // RenderWidget IPC message handlers.
nzolghadr5d8596502017-01-23 22:59:35593 void OnHandleInputEvent(
594 const blink::WebInputEvent* event,
595 const std::vector<const blink::WebInputEvent*>& coalesced_events,
596 const ui::LatencyInfo& latency_info,
597 InputEventDispatchType dispatch_type);
naskoc288745f2015-05-01 22:54:21598 void OnClose();
[email protected]fc4404d2012-11-07 19:53:30599 void OnCreatingNewAck();
dgozman9260b0a12015-03-16 13:45:20600 void OnEnableDeviceEmulation(const blink::WebDeviceEmulationParams& params);
601 void OnDisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:18602 void OnWasHidden();
Saman Samie61e5c032018-11-05 22:11:44603 void OnWasShown(base::TimeTicks show_request_timestamp, bool was_evicted);
avi1023d012015-12-25 02:39:14604 void OnCreateVideoAck(int32_t video_id);
605 void OnUpdateVideoAck(int32_t video_id);
Avi Drissman014dec72018-06-07 02:34:01606 void OnRequestSetBoundsAck();
Albert J. Wongcb004632018-07-10 22:58:25607 void OnForceRedraw(int snapshot_id);
danakja2c9d0a92018-07-25 20:01:18608 void OnShowContextMenu(ui::MenuSourceType source_type,
609 const gfx::Point& location);
oshimad5279032015-12-16 18:22:33610
[email protected]180ef242013-11-07 06:50:46611 void OnSetTextDirection(blink::WebTextDirection direction);
[email protected]872ae5b2011-05-26 20:20:50612 void OnGetFPS();
Albert J. Wong3c93c182018-09-27 17:29:43613 void OnUpdateScreenRects(const gfx::Rect& widget_screen_rect,
[email protected]80ad8622012-11-07 16:33:03614 const gfx::Rect& window_screen_rect);
Ken Buchananb2c9e262018-03-10 16:53:31615 void OnSetViewportIntersection(const gfx::Rect& viewport_intersection,
Stefan Zager54e25832018-08-14 22:15:31616 const gfx::Rect& compositor_visible_rect,
617 bool occluded_or_obscured);
kenrb04323782017-06-23 01:23:32618 void OnSetIsInert(bool);
sunxd540a9962018-05-24 22:51:06619 void OnSetInheritedEffectiveTouchAction(cc::TouchAction touch_action);
Ken Buchanan8a319fb2017-11-15 18:37:12620 void OnUpdateRenderThrottlingStatus(bool is_throttled,
621 bool subtree_throttled);
paulmeyer90f6c31d2016-11-12 00:17:59622 void OnDragTargetDragEnter(
623 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:52624 const gfx::PointF& client_pt,
625 const gfx::PointF& screen_pt,
paulmeyer90f6c31d2016-11-12 00:17:59626 blink::WebDragOperationsMask operations_allowed,
627 int key_modifiers);
Ella Ge80a52dce2017-11-15 18:01:52628 void OnDragTargetDragOver(const gfx::PointF& client_pt,
629 const gfx::PointF& screen_pt,
paulmeyer90f6c31d2016-11-12 00:17:59630 blink::WebDragOperationsMask operations_allowed,
631 int key_modifiers);
Ella Ge80a52dce2017-11-15 18:01:52632 void OnDragTargetDragLeave(const gfx::PointF& client_point,
633 const gfx::PointF& screen_point);
paulmeyer90f6c31d2016-11-12 00:17:59634 void OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:52635 const gfx::PointF& client_pt,
636 const gfx::PointF& screen_pt,
paulmeyer90f6c31d2016-11-12 00:17:59637 int key_modifiers);
Ella Ge80a52dce2017-11-15 18:01:52638 void OnDragSourceEnded(const gfx::PointF& client_point,
639 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:21640 blink::WebDragOperation drag_operation);
641 void OnDragSourceSystemDragEnded();
lfg8d649cc2017-04-28 18:04:30642 void OnOrientationChange();
danakj53802692018-07-25 21:46:44643 void OnWaitNextFrameForTests(int routing_id);
[email protected]65225772011-05-12 21:10:24644
[email protected]bee16aab2009-08-26 15:55:03645 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
646 // use this method so that we can properly inform the RenderThread of our
647 // state.
648 void SetHidden(bool hidden);
649
[email protected]2b624c562011-10-27 22:58:26650 void DidToggleFullscreen();
651
Ken Buchananb2c9e262018-03-10 16:53:31652 // Returns a rect that the compositor needs to raster. For a main frame this
Darwin Huang2c485f8e2018-10-12 21:06:00653 // is always the entire viewport, but for out-of-process iframes this can be
Ken Buchananb2c9e262018-03-10 16:53:31654 // constrained to limit overdraw.
655 gfx::Rect ViewportVisibleRect();
656
[email protected]586871b2014-07-22 17:05:11657 // QueueMessage implementation extracted into a static method for easy
658 // testing.
dchengcedca5612016-04-09 01:40:15659 static std::unique_ptr<cc::SwapPromise> QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:11660 IPC::Message* msg,
[email protected]586871b2014-07-22 17:05:11661 FrameSwapMessageQueue* frame_swap_message_queue,
662 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:11663 int source_frame_number);
664
[email protected]88dbe32f2013-06-20 23:31:36665 // Returns the range of the text that is being composed or the selection if
666 // the composition does not exist.
danakja2c9d0a92018-07-25 20:01:18667 void GetCompositionRange(gfx::Range* range);
[email protected]88dbe32f2013-06-20 23:31:36668
[email protected]58b48a0d2012-06-13 07:01:35669 // Returns true if the composition range or composition character bounds
670 // should be sent to the browser process.
671 bool ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:51672 const gfx::Range& range,
[email protected]58b48a0d2012-06-13 07:01:35673 const std::vector<gfx::Rect>& bounds);
674
[email protected]ad26ef42011-06-17 07:59:45675 // Override point to obtain that the current input method state about
676 // composition text.
danakja2c9d0a92018-07-25 20:01:18677 bool CanComposeInline();
[email protected]56ea1a62011-05-30 07:05:57678
[email protected]2533ce12009-05-09 00:02:24679 // Set the pending window rect.
680 // Because the real render_widget is hosted in another process, there is
681 // a time period where we may have set a new window rect which has not yet
682 // been processed by the browser. So we maintain a pending window rect
683 // size. If JS code sets the WindowRect, and then immediately calls
684 // GetWindowRect() we'll use this pending window rect as the size.
[email protected]180ef242013-11-07 06:50:46685 void SetPendingWindowRect(const blink::WebRect& r);
[email protected]2533ce12009-05-09 00:02:24686
danakj53802692018-07-25 21:46:44687 // TODO(ekaramad): This method should not be confused with its RenderView
688 // variant, GetWebFrameWidget(). Currently Cast and AndroidWebview's
689 // ContentRendererClients are the only users of the public variant. The public
690 // method will eventually be removed from RenderView and uses of the method
691 // will obtain WebFrameWidget from WebLocalFrame.
692 // Returns the WebFrameWidget associated with this RenderWidget if any.
693 // Returns nullptr if GetWebWidget() returns nullptr or returns a WebWidget
694 // that is not a WebFrameWidget. A WebFrameWidget only makes sense when there
695 // a local root associated with it. RenderWidgetFullscreenPepper and a swapped
696 // out RenderWidgets are amongst the cases where this method returns nullptr.
697 blink::WebFrameWidget* GetFrameWidget() const;
[email protected]ce6689f2013-03-29 12:52:55698
danakj53802692018-07-25 21:46:44699 // Applies/Removes the DevTools device emulation transformation to/from a
700 // window rect.
701 void ScreenRectToEmulatedIfNeeded(blink::WebRect* window_rect) const;
702 void EmulatedToScreenRectIfNeeded(blink::WebRect* window_rect) const;
Dave Tapuskadfe486c12017-06-09 16:53:13703
danakj53802692018-07-25 21:46:44704 void UpdateSurfaceAndScreenInfo(
Fady Samuel1c1ad3692018-11-06 23:28:40705 const viz::LocalSurfaceIdAllocation& new_local_surface_id_allocation,
danakj53802692018-07-25 21:46:44706 const gfx::Size& new_compositor_viewport_pixel_size,
707 const ScreenInfo& new_screen_info);
[email protected]5d0bbdfa92013-12-10 00:35:51708
danakj53802692018-07-25 21:46:44709 // Used to force the size of a window when running layout tests.
710 void SetWindowRectSynchronously(const gfx::Rect& new_window_rect);
711
712 void UpdateCaptureSequenceNumber(uint32_t capture_sequence_number);
713
714 // A variant of Send but is fatal if it fails. The browser may
715 // be waiting for this IPC Message and if the send fails the browser will
716 // be left in a state waiting for something that never comes. And if it
717 // never comes then it may later determine this is a hung renderer; so
718 // instead fail right away.
719 void SendOrCrash(IPC::Message* msg);
720
721 // Determines whether or not RenderWidget should process IME events from the
722 // browser. It always returns true unless there is no WebFrameWidget to
723 // handle the event, or there is no page focus.
724 bool ShouldHandleImeEvents() const;
725
726 void UpdateTextInputStateInternal(bool show_virtual_keyboard,
727 bool reply_to_request);
728
729 gfx::ColorSpace GetRasterColorSpace() const;
730
danakj53802692018-07-25 21:46:44731 void UpdateZoom(double zoom_level);
732
733#if BUILDFLAG(ENABLE_PLUGINS)
734 // Returns the focused pepper plugin, if any, inside the WebWidget. That is
735 // the pepper plugin which is focused inside a frame which belongs to the
736 // local root associated with this RenderWidget.
737 PepperPluginInstanceImpl* GetFocusedPepperPluginInsideWidget();
738#endif
739 void RecordTimeToFirstActivePaint();
740
danakj53802692018-07-25 21:46:44741 // This method returns the WebLocalFrame which is currently focused and
742 // belongs to the frame tree associated with this RenderWidget.
743 blink::WebLocalFrame* GetFocusedWebLocalFrameInWidget() const;
lfg43e08e62016-02-03 18:51:37744
initial.commit09911bf2008-07-26 23:55:29745 // Routing ID that allows us to communicate to the parent browser process
nick8331f8ad2016-11-15 20:42:45746 // RenderWidgetHost.
747 const int32_t routing_id_;
initial.commit09911bf2008-07-26 23:55:29748
danakj6e3bf8012014-12-16 18:27:53749 // Dependencies for initializing a compositor, including flags for optional
750 // features.
dcheng35d31c112015-07-22 00:17:36751 CompositorDependencies* const compositor_deps_;
danakj6e3bf8012014-12-16 18:27:53752
lfg8ff33912016-09-13 20:59:21753 // Use GetWebWidget() instead of using webwidget_internal_ directly.
[email protected]c5b3b5e2009-02-13 06:41:11754 // We are responsible for destroying this object via its Close method.
[email protected]4ee64622014-03-21 22:34:15755 // May be NULL when the window is closing.
lfg8ff33912016-09-13 20:59:21756 blink::WebWidget* webwidget_internal_;
initial.commit09911bf2008-07-26 23:55:29757
avi40b5be7a2016-03-03 21:13:44758 // The delegate of the owner of this object.
759 RenderWidgetOwnerDelegate* owner_delegate_;
760
[email protected]8926c602013-01-23 05:32:06761 // This is lazily constructed and must not outlive webwidget_.
danakja6c10012018-07-06 14:25:36762 std::unique_ptr<LayerTreeView> layer_tree_view_;
[email protected]8926c602013-01-23 05:32:06763
bokanc007c3a2015-02-03 07:15:56764 // The rect where this view should be initially shown.
765 gfx::Rect initial_rect_;
initial.commit09911bf2008-07-26 23:55:29766
initial.commit09911bf2008-07-26 23:55:29767 // We store the current cursor object so we can avoid spamming SetCursor
768 // messages.
769 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59770
danakja2c9d0a92018-07-25 20:01:18771 base::Optional<float> device_scale_factor_for_testing_;
772
Christopher Cameronbe7ecea2018-02-27 00:47:19773 // The size of the RenderWidget in DIPs. This may differ from
Christopher Cameronaad15a0d2018-03-09 03:47:33774 // |compositor_viewport_pixel_size_| in the following (and possibly other)
775 // cases: * On Android, for top and bottom controls * On OOPIF, due to
776 // rounding
initial.commit09911bf2008-07-26 23:55:29777 gfx::Size size_;
778
Christopher Cameronbe7ecea2018-02-27 00:47:19779 // The size of the compositor's surface in pixels.
Christopher Cameronaad15a0d2018-03-09 03:47:33780 gfx::Size compositor_viewport_pixel_size_;
[email protected]60d47ac2013-03-01 23:42:44781
Christopher Cameronbe7ecea2018-02-27 00:47:19782 // The size of the visible viewport in pixels.
[email protected]bb6378fe2014-04-28 21:19:44783 gfx::Size visible_viewport_size_;
784
[email protected]847a2582013-03-09 02:29:51785 // Whether the WebWidget is in auto resize mode, which is used for example
786 // by extension popups.
787 bool auto_resize_mode_;
788
Fady Samuele62be402018-03-29 03:19:53789 // The minimum size to use for auto-resize.
790 gfx::Size min_size_for_auto_resize_;
791
792 // The maximum size to use for auto-resize.
793 gfx::Size max_size_for_auto_resize_;
794
initial.commit09911bf2008-07-26 23:55:29795 // Indicates that we shouldn't bother generated paint events.
796 bool is_hidden_;
797
[email protected]7912e822014-04-16 02:37:03798 // Indicates that we are never visible, so never produce graphical output.
sievers71c62dd52015-10-07 01:44:39799 const bool compositor_never_visible_;
[email protected]7912e822014-04-16 02:37:03800
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12801 // Indicates whether tab-initiated fullscreen was granted.
802 bool is_fullscreen_granted_;
[email protected]ee41e7d22011-10-14 19:34:09803
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12804 // Indicates the display mode.
805 blink::WebDisplayMode display_mode_;
806
changwanf2a707b2015-10-30 08:22:16807 // It is possible that one ImeEventGuard is nested inside another
808 // ImeEventGuard. We keep track of the outermost one, and update it as needed.
809 ImeEventGuard* ime_event_guard_;
[email protected]e8f775f2013-02-14 21:00:50810
initial.commit09911bf2008-07-26 23:55:29811 // True if we have requested this widget be closed. No more messages will
812 // be sent, except for a Close.
813 bool closing_;
814
[email protected]aeeedad2014-08-22 18:16:22815 // True if it is known that the host is in the process of being shut down.
danakj5c5269b2018-11-06 00:39:11816 bool host_will_close_this_;
[email protected]aeeedad2014-08-22 18:16:22817
[email protected]992db4c2011-05-12 15:37:15818 // Whether this RenderWidget is currently swapped out, such that the view is
819 // being rendered by another process. If all RenderWidgets in a process are
820 // swapped out, the process can exit.
821 bool is_swapped_out_;
822
[email protected]5b739cb2012-08-21 20:35:21823 // Stores information about the current text input.
[email protected]180ef242013-11-07 06:50:46824 blink::WebTextInputInfo text_input_info_;
[email protected]5b739cb2012-08-21 20:35:21825
dglazkov97b6c2b2016-10-25 17:35:55826 // Stores the current text input type of |webwidget_|.
827 ui::TextInputType text_input_type_;
828
[email protected]b256eca2013-07-11 10:57:40829 // Stores the current text input mode of |webwidget_|.
830 ui::TextInputMode text_input_mode_;
831
shuchen82ce8c52014-10-23 01:55:20832 // Stores the current text input flags of |webwidget_|.
833 int text_input_flags_;
834
AJITH KUMAR V041c0b02017-08-08 10:39:20835 // Indicates whether currently focused input field has next/previous focusable
836 // form input field.
837 int next_previous_flags_;
838
[email protected]86ba5fcb2013-09-04 00:36:53839 // Stores the current type of composition text rendering of |webwidget_|.
840 bool can_compose_inline_;
841
[email protected]e99ef6f2011-10-16 01:13:00842 // Stores the current selection bounds.
[email protected]7c8873e2013-02-05 08:03:01843 gfx::Rect selection_focus_rect_;
844 gfx::Rect selection_anchor_rect_;
initial.commit09911bf2008-07-26 23:55:29845
[email protected]58b48a0d2012-06-13 07:01:35846 // Stores the current composition character bounds.
847 std::vector<gfx::Rect> composition_character_bounds_;
848
849 // Stores the current composition range.
[email protected]db4fc1e2013-09-06 20:01:51850 gfx::Range composition_range_;
[email protected]58b48a0d2012-06-13 07:01:35851
[email protected]3e2b375b2010-04-07 17:03:12852 // The kind of popup this widget represents, NONE if not a popup.
danakj6a816592018-09-25 18:30:56853 WidgetType widget_type_;
[email protected]0ebf3872008-11-07 21:35:03854
[email protected]80ad8622012-11-07 16:33:03855 // While we are waiting for the browser to update window sizes, we track the
856 // pending size temporarily.
[email protected]2533ce12009-05-09 00:02:24857 int pending_window_rect_count_;
lfg0140a452016-07-19 19:15:05858 gfx::Rect pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:24859
[email protected]80ad8622012-11-07 16:33:03860 // The screen rects of the view and the window that contains it.
Albert J. Wong3c93c182018-09-27 17:29:43861 gfx::Rect widget_screen_rect_;
[email protected]80ad8622012-11-07 16:33:03862 gfx::Rect window_screen_rect_;
863
Dave Tapuska9db80842017-07-24 17:24:26864 scoped_refptr<WidgetInputHandlerManager> widget_input_handler_manager_;
865
dchengcedca5612016-04-09 01:40:15866 std::unique_ptr<RenderWidgetInputHandler> input_handler_;
[email protected]12fbad812009-09-01 18:21:24867
[email protected]fd847792013-10-24 17:12:35868 // The time spent in input handlers this frame. Used to throttle input acks.
869 base::TimeDelta total_input_handling_time_this_frame_;
870
[email protected]842f10652012-06-06 01:54:04871 // Properties of the screen hosting this RenderWidget instance.
ccameron2f451532016-09-07 21:49:27872 ScreenInfo screen_info_;
[email protected]842f10652012-06-06 01:54:04873
nonafa291792016-08-10 02:36:18874 // True if the IME requests updated composition info.
875 bool monitor_composition_info_;
876
dchengcedca5612016-04-09 01:40:15877 std::unique_ptr<RenderWidgetScreenMetricsEmulator> screen_metrics_emulator_;
[email protected]b2e4c70132013-10-03 02:07:51878
879 // Popups may be displaced when screen metrics emulation is enabled.
880 // These values are used to properly adjust popup position.
danakj2ef31b82015-10-21 18:18:02881 gfx::Point popup_view_origin_for_emulation_;
882 gfx::Point popup_screen_origin_for_emulation_;
[email protected]b2e4c70132013-10-03 02:07:51883 float popup_origin_scale_for_emulation_;
884
[email protected]586871b2014-07-22 17:05:11885 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_;
dchengcedca5612016-04-09 01:40:15886 std::unique_ptr<ResizingModeSelector> resizing_mode_selector_;
[email protected]5b45ad42013-10-25 00:42:04887
[email protected]e3244ed2014-06-20 20:04:27888 // Lists of RenderFrameProxy objects that need to be notified of
889 // compositing-related events (e.g. DidCommitCompositorFrame).
Trent Apteda250ec3ab2018-08-19 08:52:19890 base::ObserverList<RenderFrameProxy>::Unchecked render_frame_proxies_;
[email protected]bffc8302014-01-23 20:52:16891
[email protected]de3c5d82014-05-28 22:12:59892 // A list of RenderFrames associated with this RenderWidget. Notifications
893 // are sent to each frame in the list for events such as changing
894 // visibility state for example.
Trent Apteda250ec3ab2018-08-19 08:52:19895 base::ObserverList<RenderFrameImpl>::Unchecked render_frames_;
[email protected]de3c5d82014-05-28 22:12:59896
Trent Apteda250ec3ab2018-08-19 08:52:19897 base::ObserverList<BrowserPlugin>::Unchecked browser_plugins_;
Saman Samid189e5dfd2017-12-20 22:55:31898
[email protected]be1af0662014-07-29 19:55:51899 bool has_host_context_menu_location_;
900 gfx::Point host_context_menu_location_;
[email protected]a09d53ce2014-01-31 00:46:42901
Yuta Kitamura39219b42018-04-06 10:28:14902 std::unique_ptr<blink::scheduler::WebRenderWidgetSchedulingState>
alexclarke7fa93942015-10-21 15:37:11903 render_widget_scheduling_state_;
904
lfgbee1e0a2016-06-08 21:24:21905 // Mouse Lock dispatcher attached to this view.
906 std::unique_ptr<RenderWidgetMouseLockDispatcher> mouse_lock_dispatcher_;
907
908 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
909 std::unique_ptr<MouseLockDispatcher::LockTarget> webwidget_mouse_lock_target_;
910
Fady Samuel1c1ad3692018-11-06 23:28:40911 viz::LocalSurfaceIdAllocation local_surface_id_allocation_from_parent_;
Fady Samuelda839bb2018-03-26 17:34:48912
lfge0c2792ec2016-05-11 18:52:08913 // Indicates whether this widget has focus.
914 bool has_focus_;
915
Nicolas Pena75a35d662018-04-05 20:13:44916 // Whether this RenderWidget is for an out-of-process iframe or not.
917 bool for_oopif_;
918
nickf7b38222016-11-22 21:59:35919 // A callback into the creator/opener of this widget, to be executed when
danakjdf1ceb72018-07-18 20:02:25920 // WebWidgetClient::Show() occurs.
nickf7b38222016-11-22 21:59:35921 ShowCallback show_callback_;
922
ekaramad330ba4232016-09-23 17:57:47923#if defined(OS_MACOSX)
924 // Responds to IPCs from TextInputClientMac regarding getting string at given
925 // position or range as well as finding character index at a given position.
926 std::unique_ptr<TextInputClientObserver> text_input_client_observer_;
927#endif
928
alexmos56567492016-09-13 00:52:46929 // Stores edit commands associated to the next key event.
930 // Will be cleared as soon as the next key event is processed.
931 EditCommands edit_commands_;
932
paulmeyer6ef5a792016-11-08 20:33:58933 // This field stores drag/drop related info for the event that is currently
934 // being handled. If the current event results in starting a drag/drop
935 // session, this info is sent to the browser along with other drag/drop info.
936 DragEventSourceInfo possible_drag_event_info_;
937
Takashi SAKAMOTO870f6262017-08-22 04:08:27938 bool first_update_visual_state_after_hidden_;
tasakb95dbb50c2017-02-08 18:07:50939 base::TimeTicks was_shown_time_;
940
danakja2c9d0a92018-07-25 20:01:18941 // Whether or not Blink's viewport size should be shrunk by the height of the
942 // URL-bar.
943 bool browser_controls_shrink_blink_size_ = false;
944 // The height of the browser top controls.
945 float top_controls_height_ = 0.f;
946 // The height of the browser bottom controls.
947 float bottom_controls_height_ = 0.f;
948
W. James MacLean2a90bff2018-11-05 20:52:47949 // The page scale factor reported by the main-frame's RenderWidget, via
950 // SynchronizeVisualProperties.
951 float page_scale_factor_from_mainframe_ = 1.f;
952
kenrb5d78b842017-03-06 21:06:01953 // This is initialized to zero and is incremented on each non-same-page
954 // navigation commit by RenderFrameImpl. At that time it is sent to the
955 // compositor so that it can tag compositor frames, and RenderFrameImpl is
956 // responsible for sending it to the browser process to be used to match
957 // each compositor frame to the most recent page navigation before it was
958 // generated.
959 // This only applies to main frames, and is not touched for subframe
960 // RenderWidgets, where there is no concern around displaying unloaded
961 // content.
962 // TODO(kenrb, fsamuel): This should be removed when SurfaceIDs can be used
963 // to replace it. See https://crbug.com/695579.
964 uint32_t current_content_source_id_;
965
dtapuska9ec1a912017-04-21 15:18:31966 scoped_refptr<MainThreadEventQueue> input_event_queue_;
967
Dave Tapuska1bdf1832017-07-07 18:07:19968 mojo::Binding<mojom::Widget> widget_binding_;
Hajime Hoshiabb3c8f2017-12-04 18:41:39969
Ken Buchananb2c9e262018-03-10 16:53:31970 gfx::Rect compositor_visible_rect_;
971
W. James MacLean662d5382018-03-29 18:33:08972 // Different consumers in the browser process makes different assumptions, so
973 // must always send the first IPC regardless of value.
974 base::Optional<bool> has_touch_handlers_;
975
Vladimir Levin98d76dad2018-04-21 00:21:29976 uint32_t last_capture_sequence_number_ = 0u;
977
wjmaclean1d970622017-01-21 22:28:24978 base::WeakPtrFactory<RenderWidget> weak_ptr_factory_;
979
[email protected]05d478752009-04-08 23:38:16980 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:29981};
982
[email protected]e9ff79c2012-10-19 21:31:26983} // namespace content
984
[email protected]2cff0052011-03-18 16:51:44985#endif // CONTENT_RENDERER_RENDER_WIDGET_H_