blob: 410269f9cf775c8ba00bf8967c892499160e05c0 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// 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#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
danakj4b347212018-07-04 17:55:177#include <cmath>
8#include <limits>
dcheng07945f632015-12-26 07:59:329#include <utility>
10
[email protected]c27dd4f2014-05-22 18:05:1911#include "base/auto_reset.h"
danakj4b347212018-07-04 17:55:1712#include "base/base_switches.h"
[email protected]32876ae2011-11-15 22:25:2113#include "base/bind.h"
Sebastien Marchand17fa2782019-01-25 19:28:1014#include "base/bind_helpers.h"
[email protected]4fb66842009-12-04 21:41:0015#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1216#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/logging.h"
avi1023d012015-12-25 02:39:1418#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1519#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4020#include "base/memory/singleton.h"
asvitkine8d51e9d2016-09-02 23:55:4321#include "base/metrics/histogram_macros.h"
[email protected]aa4117f2011-12-09 22:19:2122#include "base/stl_util.h"
danakj4b347212018-07-04 17:55:1723#include "base/strings/string_number_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0024#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0325#include "base/system/sys_info.h"
fdoraya19b7702016-12-23 14:19:3126#include "base/threading/thread_task_runner_handle.h"
primiano9e38d552015-01-28 04:18:0127#include "base/trace_event/trace_event.h"
[email protected]661eb9d2009-02-03 02:11:4828#include "build/build_config.h"
loyso6e6efc42017-01-21 02:23:0329#include "cc/animation/animation_host.h"
danakj4b347212018-07-04 17:55:1730#include "cc/base/switches.h"
xidachenfa0199e72017-05-11 11:34:2631#include "cc/input/touch_action.h"
Erik Chend44f1632019-08-20 17:31:0632#include "cc/paint/paint_worklet_layer_painter.h"
danakjba65a0912017-09-21 16:38:4233#include "cc/trees/layer_tree_frame_sink.h"
loyso6e6efc42017-01-21 02:23:0334#include "cc/trees/layer_tree_host.h"
danakj4c987652018-07-05 15:49:4135#include "cc/trees/ukm_manager.h"
danakj4b347212018-07-04 17:55:1736#include "components/viz/common/features.h"
Fady Samuelc645ffe2017-07-24 17:28:2037#include "components/viz/common/frame_sinks/begin_frame_source.h"
danakjf20f4502017-09-26 17:13:3138#include "components/viz/common/frame_sinks/copy_output_request.h"
danakj4b347212018-07-04 17:55:1739#include "components/viz/common/switches.h"
40#include "content/common/content_switches_internal.h"
paulmeyer6ef5a792016-11-08 20:33:5841#include "content/common/drag_event_source_info.h"
42#include "content/common/drag_messages.h"
jonrossa2ff4f82018-02-16 17:27:4643#include "content/common/render_frame_metadata.mojom.h"
jcivelliae1560a2016-11-01 22:40:2344#include "content/common/render_message_filter.mojom.h"
Nasko Oskovf97e8b02017-07-25 02:45:4245#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3846#include "content/common/text_input_state.h"
Albert J. Wong3c93c182018-09-27 17:29:4347#include "content/common/widget_messages.h"
mlamouriafca06dd2017-01-27 23:35:1848#include "content/public/common/content_client.h"
changwan7ded3752016-03-09 23:25:1249#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2950#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4251#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5952#include "content/public/common/drop_data.h"
Khushal3e96e662017-10-30 23:16:5053#include "content/public/common/service_names.mojom.h"
Jaebaek Seo655110e2017-12-19 23:27:3954#include "content/public/common/use_zoom_for_dsf_policy.h"
mlamouriafca06dd2017-01-27 23:35:1855#include "content/public/renderer/content_renderer_client.h"
Avi Drissman07d22452019-03-25 17:56:3956#include "content/public/renderer/render_thread.h"
Saman Samid189e5dfd2017-12-20 22:55:3157#include "content/renderer/browser_plugin/browser_plugin.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1358#include "content/renderer/compositor/layer_tree_view.h"
paulmeyer6ef5a792016-11-08 20:33:5859#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5160#include "content/renderer/external_popup_menu.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1361#include "content/renderer/frame_swap_message_queue.h"
[email protected]66fca5bc2013-05-23 06:58:2962#include "content/renderer/ime_event_guard.h"
dtapuska9ec1a912017-04-21 15:18:3163#include "content/renderer/input/main_thread_event_queue.h"
Dave Tapuska9db80842017-07-24 17:24:2664#include "content/renderer/input/widget_input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3265#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1366#include "content/renderer/queue_message_swap_promise.h"
[email protected]bffc8302014-01-23 20:52:1667#include "content/renderer/render_frame_impl.h"
danakj4b347212018-07-04 17:55:1768#include "content/renderer/render_frame_metadata_observer_impl.h"
[email protected]e3244ed2014-06-20 20:04:2769#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0570#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4471#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5572#include "content/renderer/render_view_impl.h"
Abhijeet Kandalkardccbd612019-04-08 17:37:0973#include "content/renderer/render_widget_screen_metrics_emulator.h"
tfarina556a7232014-10-05 01:02:0974#include "content/renderer/renderer_blink_platform_impl.h"
danakj4b347212018-07-04 17:55:1775#include "gpu/command_buffer/service/gpu_switches.h"
ekaramad330ba4232016-09-23 17:57:4776#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1877#include "ipc/ipc_sync_message.h"
Antoine Laboure55c9ef82017-11-10 18:51:2378#include "ipc/ipc_sync_message_filter.h"
danakj4b347212018-07-04 17:55:1779#include "media/base/media_switches.h"
Scott Violet02e38b92018-03-27 23:42:1480#include "ppapi/buildflags/buildflags.h"
[email protected]661eb9d2009-02-03 02:11:4881#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:0682#include "third_party/blink/public/platform/file_path_conversion.h"
Hajime Hoshi315a61f2018-08-14 17:27:2883#include "third_party/blink/public/platform/platform.h"
Blink Reformata30d4232018-04-07 15:31:0684#include "third_party/blink/public/platform/scheduler/web_render_widget_scheduling_state.h"
Yuta Kitamuradeb91bb2018-05-29 05:53:2085#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
Blink Reformata30d4232018-04-07 15:31:0686#include "third_party/blink/public/platform/web_cursor_info.h"
87#include "third_party/blink/public/platform/web_drag_data.h"
88#include "third_party/blink/public/platform/web_drag_operation.h"
89#include "third_party/blink/public/platform/web_mouse_event.h"
90#include "third_party/blink/public/platform/web_point.h"
91#include "third_party/blink/public/platform/web_rect.h"
92#include "third_party/blink/public/platform/web_runtime_features.h"
93#include "third_party/blink/public/platform/web_size.h"
94#include "third_party/blink/public/platform/web_string.h"
95#include "third_party/blink/public/web/web_autofill_client.h"
96#include "third_party/blink/public/web/web_device_emulation_params.h"
97#include "third_party/blink/public/web/web_frame_widget.h"
98#include "third_party/blink/public/web/web_input_method_controller.h"
99#include "third_party/blink/public/web/web_local_frame.h"
100#include "third_party/blink/public/web/web_node.h"
101#include "third_party/blink/public/web/web_page_popup.h"
102#include "third_party/blink/public/web/web_popup_menu_info.h"
103#include "third_party/blink/public/web/web_range.h"
104#include "third_party/blink/public/web/web_settings.h"
105#include "third_party/blink/public/web/web_view.h"
106#include "third_party/blink/public/web/web_widget.h"
[email protected]d353541f2012-05-03 22:45:41107#include "third_party/skia/include/core/SkShader.h"
Maksim Sisova33072d22019-01-24 15:44:25108#include "ui/base/clipboard/clipboard_constants.h"
Scott Violet8ff9c302018-02-22 22:28:35109#include "ui/base/ui_base_features.h"
danakj4b347212018-07-04 17:55:17110#include "ui/base/ui_base_switches.h"
dtapuska97286c882017-02-24 23:14:43111#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:50112#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:09113#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32114#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48115#include "ui/gfx/skia_util.h"
danakj4b347212018-07-04 17:55:17116#include "ui/gfx/switches.h"
[email protected]c9e2cbbb2012-05-12 21:17:27117#include "ui/gl/gl_switches.h"
danakj4b347212018-07-04 17:55:17118#include "ui/native_theme/native_theme_features.h"
119#include "ui/native_theme/overlay_scrollbar_constants_aura.h"
[email protected]d353541f2012-05-03 22:45:41120#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48121
[email protected]eeb93112013-05-01 19:41:10122#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15123#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24124#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10125#endif
126
[email protected]661eb9d2009-02-03 02:11:48127#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52128#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41129#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48130#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44131
Ryan Landay9e42fd742017-08-12 01:59:11132using blink::WebImeTextSpan;
[email protected]180ef242013-11-07 06:50:46133using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43134using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59135using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58136using blink::WebDragOperationsMask;
137using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59138using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46139using blink::WebGestureEvent;
140using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49141using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01142using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58143using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46144using blink::WebMouseEvent;
145using blink::WebMouseWheelEvent;
146using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11147using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46148using blink::WebPagePopup;
dglazkove353a372016-09-01 01:33:48149using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46150using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46151using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59152using blink::WebString;
[email protected]180ef242013-11-07 06:50:46153using blink::WebTextDirection;
154using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25155using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46156using blink::WebVector;
157using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26158
paulmeyer90f6c31d2016-11-12 00:17:59159namespace content {
160
[email protected]6a4d7f62013-01-07 21:32:13161namespace {
[email protected]b256eca2013-07-11 10:57:40162
Albert J. Wong2727e8a82019-02-15 16:56:11163RenderWidget::CreateRenderWidgetFunction g_create_render_widget_for_frame =
164 nullptr;
165
Albert J. Wongcb004632018-07-10 22:58:25166using RoutingIDWidgetMap = std::map<int32_t, RenderWidget*>;
167base::LazyInstance<RoutingIDWidgetMap>::Leaky g_routing_id_widget_map =
168 LAZY_INSTANCE_INITIALIZER;
169
danakj4b347212018-07-04 17:55:17170const base::Feature kUnpremultiplyAndDitherLowBitDepthTiles = {
171 "UnpremultiplyAndDitherLowBitDepthTiles", base::FEATURE_ENABLED_BY_DEFAULT};
172
[email protected]b256eca2013-07-11 10:57:40173typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
174
AJITH KUMAR V041c0b02017-08-08 10:39:20175static const int kInvalidNextPreviousFlagsValue = -1;
yiyix6b90ef52018-10-09 19:55:30176static const char* kOOPIF = "OOPIF";
177static const char* kRenderer = "Renderer";
AJITH KUMAR V041c0b02017-08-08 10:39:20178
Ian Vollick7a847a82019-06-14 19:58:59179#if defined(OS_ANDROID)
180// With 32 bit pixels, this would mean less than 400kb per buffer. Much less
181// than required for, say, nHD.
182static const int kSmallScreenPixelThreshold = 1e5;
183bool IsSmallScreen(const gfx::Size& size) {
184 int area = 0;
185 if (!size.GetCheckedArea().AssignIfValid(&area))
186 return false;
187 return area < kSmallScreenPixelThreshold;
188}
189#endif
190
lfgbee1e0a2016-06-08 21:24:21191class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
192 public:
193 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
194 : webwidget_(webwidget) {}
195
196 void OnLockMouseACK(bool succeeded) override {
197 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54198 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21199 else
Blink Reformat1c4d759e2017-04-09 16:34:54200 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21201 }
202
Blink Reformat1c4d759e2017-04-09 16:34:54203 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21204
205 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
206 // The WebWidget handles mouse lock in Blink's handleInputEvent().
207 return false;
208 }
209
210 private:
211 blink::WebWidget* webwidget_;
212};
213
Stephen Chenneyd56b5382019-01-29 00:37:02214class ScopedUkmRafAlignedInputTimer {
215 public:
216 explicit ScopedUkmRafAlignedInputTimer(blink::WebWidget* webwidget)
217 : webwidget_(webwidget) {
218 webwidget_->BeginRafAlignedInput();
219 }
220
221 ~ScopedUkmRafAlignedInputTimer() { webwidget_->EndRafAlignedInput(); }
222
223 private:
224 blink::WebWidget* webwidget_;
225
226 DISALLOW_COPY_AND_ASSIGN(ScopedUkmRafAlignedInputTimer);
227};
228
dglazkov97b6c2b2016-10-25 17:35:55229bool IsDateTimeInput(ui::TextInputType type) {
230 return type == ui::TEXT_INPUT_TYPE_DATE ||
231 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
232 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
233 type == ui::TEXT_INPUT_TYPE_MONTH ||
234 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
235}
236
paulmeyer90f6c31d2016-11-12 00:17:59237WebDragData DropMetaDataToWebDragData(
238 const std::vector<DropData::Metadata>& drop_meta_data) {
239 std::vector<WebDragData::Item> item_list;
240 for (const auto& meta_data_item : drop_meta_data) {
241 if (meta_data_item.kind == DropData::Kind::STRING) {
242 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54243 item.storage_type = WebDragData::Item::kStorageTypeString;
244 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59245 // Have to pass a dummy URL here instead of an empty URL because the
246 // DropData received by browser_plugins goes through a round trip:
247 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
248 // will contain an empty URL (which means no URL is dragged) if the URL in
249 // WebDragData is empty.
Maksim Sisova33072d22019-01-24 15:44:25250 if (base::EqualsASCII(meta_data_item.mime_type, ui::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54251 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59252 }
253 item_list.push_back(item);
254 continue;
255 }
256
257 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
258 // just the mimetype. This is needed to drag files to WebView on Android
259 // platform.
260 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
261 !meta_data_item.filename.empty()) {
262 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54263 item.storage_type = WebDragData::Item::kStorageTypeFilename;
264 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59265 item_list.push_back(item);
266 continue;
267 }
268
269 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
270 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54271 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
272 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59273 item_list.push_back(item);
274 continue;
275 }
276 }
277
278 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54279 result.Initialize();
280 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59281 return result;
282}
283
284WebDragData DropDataToWebDragData(const DropData& drop_data) {
285 std::vector<WebDragData::Item> item_list;
286
287 // These fields are currently unused when dragging into WebKit.
288 DCHECK(drop_data.download_metadata.empty());
289 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23290 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59291
292 if (!drop_data.text.is_null()) {
293 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54294 item.storage_type = WebDragData::Item::kStorageTypeString;
Maksim Sisova33072d22019-01-24 15:44:25295 item.string_type = WebString::FromUTF8(ui::kMimeTypeText);
Blink Reformat1c4d759e2017-04-09 16:34:54296 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59297 item_list.push_back(item);
298 }
299
300 if (!drop_data.url.is_empty()) {
301 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54302 item.storage_type = WebDragData::Item::kStorageTypeString;
Maksim Sisova33072d22019-01-24 15:44:25303 item.string_type = WebString::FromUTF8(ui::kMimeTypeURIList);
Blink Reformat1c4d759e2017-04-09 16:34:54304 item.string_data = WebString::FromUTF8(drop_data.url.spec());
305 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59306 item_list.push_back(item);
307 }
308
309 if (!drop_data.html.is_null()) {
310 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54311 item.storage_type = WebDragData::Item::kStorageTypeString;
Maksim Sisova33072d22019-01-24 15:44:25312 item.string_type = WebString::FromUTF8(ui::kMimeTypeHTML);
Blink Reformat1c4d759e2017-04-09 16:34:54313 item.string_data = WebString::FromUTF16(drop_data.html.string());
314 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59315 item_list.push_back(item);
316 }
317
Darwin Huangb2ad4892019-05-13 20:15:39318 for (const ui::FileInfo& filename : drop_data.filenames) {
paulmeyer90f6c31d2016-11-12 00:17:59319 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54320 item.storage_type = WebDragData::Item::kStorageTypeFilename;
Darwin Huangb2ad4892019-05-13 20:15:39321 item.filename_data = blink::FilePathToWebString(filename.path);
Blink Reformat1c4d759e2017-04-09 16:34:54322 item.display_name_data =
Darwin Huangb2ad4892019-05-13 20:15:39323 blink::FilePathToWebString(base::FilePath(filename.display_name));
paulmeyer90f6c31d2016-11-12 00:17:59324 item_list.push_back(item);
325 }
326
Darwin Huangb2ad4892019-05-13 20:15:39327 for (const DropData::FileSystemFileInfo& file : drop_data.file_system_files) {
paulmeyer90f6c31d2016-11-12 00:17:59328 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54329 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
Darwin Huangb2ad4892019-05-13 20:15:39330 item.file_system_url = file.url;
331 item.file_system_file_size = file.size;
332 item.file_system_id = blink::WebString::FromASCII(file.filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59333 item_list.push_back(item);
334 }
335
Darwin Huangb2ad4892019-05-13 20:15:39336 for (const auto& data : drop_data.custom_data) {
paulmeyer90f6c31d2016-11-12 00:17:59337 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54338 item.storage_type = WebDragData::Item::kStorageTypeString;
Darwin Huangb2ad4892019-05-13 20:15:39339 item.string_type = WebString::FromUTF16(data.first);
340 item.string_data = WebString::FromUTF16(data.second);
paulmeyer90f6c31d2016-11-12 00:17:59341 item_list.push_back(item);
342 }
343
344 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54345 result.Initialize();
346 result.SetItems(item_list);
347 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59348 return result;
349}
350
dtapuskac4dd5be2016-10-25 15:11:10351ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
352 // Check the type is in the range representable by ui::TextInputType.
353 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
354 << "blink::WebTextInputType and ui::TextInputType not synchronized";
355 return static_cast<ui::TextInputType>(type);
356}
357
358ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
359 // Check the mode is in the range representable by ui::TextInputMode.
360 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
361 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
362 return static_cast<ui::TextInputMode>(mode);
363}
364
Mitsuru Oshima3c07b332018-02-06 04:56:50365// Returns true if the device scale is high enough that losing subpixel
366// antialiasing won't have a noticeable effect on text quality.
367static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
368#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
369 // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to
370 // composite all scrollers so that we get animated overlay scrollbars.
371 return true;
372#else
373 // 1.5 is a common touchscreen tablet device scale factor. For such
374 // devices main thread antialiasing is a heavy burden.
375 return device_scale_factor >= 1.5f;
376#endif
377}
378
379static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
380 float device_scale_factor) {
381 const base::CommandLine& command_line =
382 *base::CommandLine::ForCurrentProcess();
383 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
384 return false;
385 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
386 return true;
387 if (!compositor_deps->IsLcdTextEnabled())
388 return true;
Sam Fortiner263211222019-08-09 16:44:41389 if (base::FeatureList::IsEnabled(features::kPreferCompositingToLCDText))
390 return true;
Mitsuru Oshima3c07b332018-02-06 04:56:50391 return DeviceScaleEnsuresTextQuality(device_scale_factor);
392}
393
[email protected]b256eca2013-07-11 10:57:40394} // namespace
395
[email protected]b2e4c70132013-10-03 02:07:51396// RenderWidget ---------------------------------------------------------------
397
Albert J. Wong2727e8a82019-02-15 16:56:11398// static
399void RenderWidget::InstallCreateForFrameHook(
400 CreateRenderWidgetFunction create_widget) {
401 g_create_render_widget_for_frame = create_widget;
402}
403
Erik Chen3433ee02019-08-05 20:14:26404std::unique_ptr<RenderWidget> RenderWidget::CreateForFrame(
Albert J. Wong2727e8a82019-02-15 16:56:11405 int32_t widget_routing_id,
406 CompositorDependencies* compositor_deps,
407 const ScreenInfo& screen_info,
408 blink::WebDisplayMode display_mode,
409 bool is_frozen,
Erik Chen10e9b022019-08-21 23:33:23410 bool never_visible) {
Albert J. Wong2727e8a82019-02-15 16:56:11411 if (g_create_render_widget_for_frame) {
Erik Chen10e9b022019-08-21 23:33:23412 return g_create_render_widget_for_frame(widget_routing_id, compositor_deps,
413 screen_info, display_mode,
414 is_frozen, never_visible, nullptr);
Albert J. Wong2727e8a82019-02-15 16:56:11415 }
416
Erik Chen3433ee02019-08-05 20:14:26417 return std::make_unique<RenderWidget>(
Albert J. Wong2727e8a82019-02-15 16:56:11418 widget_routing_id, compositor_deps, screen_info, display_mode, is_frozen,
Erik Chen10e9b022019-08-21 23:33:23419 /*hidden=*/true, never_visible, nullptr);
Albert J. Wong2727e8a82019-02-15 16:56:11420}
421
Erik Chen3433ee02019-08-05 20:14:26422RenderWidget* RenderWidget::CreateForPopup(
Albert J. Wong2727e8a82019-02-15 16:56:11423 int32_t widget_routing_id,
424 CompositorDependencies* compositor_deps,
425 const ScreenInfo& screen_info,
426 blink::WebDisplayMode display_mode,
427 bool is_frozen,
428 bool hidden,
429 bool never_visible,
430 mojom::WidgetRequest widget_request) {
Erik Chen3433ee02019-08-05 20:14:26431 return new RenderWidget(widget_routing_id, compositor_deps, screen_info,
432 display_mode, is_frozen, hidden, never_visible,
433 std::move(widget_request));
Albert J. Wong2727e8a82019-02-15 16:56:11434}
435
danakj829cdd142018-09-14 21:13:27436RenderWidget::RenderWidget(int32_t widget_routing_id,
437 CompositorDependencies* compositor_deps,
danakj829cdd142018-09-14 21:13:27438 const ScreenInfo& screen_info,
439 blink::WebDisplayMode display_mode,
danakj6dcbc5962018-11-16 16:45:42440 bool is_frozen,
danakj829cdd142018-09-14 21:13:27441 bool hidden,
442 bool never_visible,
443 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45444 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36445 compositor_deps_(compositor_deps),
[email protected]1ac10dca2013-08-20 20:47:04446 is_hidden_(hidden),
danakj2d2889a2019-04-05 21:22:08447 compositor_never_visible_(never_visible),
danakj73dd3032018-07-28 17:49:53448 display_mode_(display_mode),
danakj6dcbc5962018-11-16 16:45:42449 is_frozen_(is_frozen),
AJITH KUMAR V041c0b02017-08-08 10:39:20450 next_previous_flags_(kInvalidNextPreviousFlagsValue),
Scott Violetae08f332018-07-27 17:37:23451 screen_info_(screen_info),
samans26510e442017-06-01 22:29:12452 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
danakj2d2889a2019-04-05 21:22:08453 widget_binding_(this, std::move(widget_request)) {
nick8331f8ad2016-11-15 20:42:45454 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
Avi Drissman07d22452019-03-25 17:56:39455 DCHECK(RenderThread::IsMainThread());
alexclarke7fa93942015-10-21 15:37:11456
457 // In tests there may not be a RenderThreadImpl.
458 if (RenderThreadImpl::current()) {
459 render_widget_scheduling_state_ = RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:25460 ->GetWebMainThreadScheduler()
dcheng07945f632015-12-26 07:59:32461 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11462 render_widget_scheduling_state_->SetHidden(is_hidden_);
463 }
Albert J. Wongcb004632018-07-10 22:58:25464
465 if (routing_id_ != MSG_ROUTING_NONE)
466 g_routing_id_widget_map.Get().emplace(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29467}
468
469RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21470 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
Erik Chen3433ee02019-08-05 20:14:26471 DCHECK(closed_)
472 << " RenderWidget must be destroyed via RenderWidget::Close()";
Albert J. Wong7bbf22d2018-12-20 00:27:27473
Albert J. Wongcb004632018-07-10 22:58:25474 // TODO(ajwong): Add in check that routing_id_ has been removed from
475 // g_routing_id_widget_map once the shutdown semantics for RenderWidget
476 // and RenderViewImpl are rationalized. Currently, too many unit and
477 // browser tests delete a RenderWidget without correclty going through
478 // the shutdown. https://crbug.com/545684
initial.commit09911bf2008-07-26 23:55:29479}
480
[email protected]484955942010-08-19 16:13:18481// static
Albert J. Wongcb004632018-07-10 22:58:25482RenderWidget* RenderWidget::FromRoutingID(int32_t routing_id) {
Avi Drissman07d22452019-03-25 17:56:39483 DCHECK(RenderThread::IsMainThread());
Albert J. Wongcb004632018-07-10 22:58:25484 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05485 auto it = widgets->find(routing_id);
Albert J. Wongcb004632018-07-10 22:58:25486 return it == widgets->end() ? NULL : it->second;
487}
488
danakj25ec6e2b2018-09-26 17:01:31489void RenderWidget::InitForPopup(ShowCallback show_callback,
490 blink::WebPagePopup* web_page_popup) {
Erik Chen3433ee02019-08-05 20:14:26491 popup_ = true;
danakj25ec6e2b2018-09-26 17:01:31492 Init(std::move(show_callback), web_page_popup);
initial.commit09911bf2008-07-26 23:55:29493}
494
danakj6a816592018-09-25 18:30:56495void RenderWidget::InitForChildLocalRoot(
496 blink::WebFrameWidget* web_frame_widget) {
danakj6dcbc5962018-11-16 16:45:42497 for_child_local_root_frame_ = true;
danakj6a816592018-09-25 18:30:56498 // Init() increments the reference count on |this|, making it
499 // self-referencing.
500 Init(base::NullCallback(), web_frame_widget);
dchengda9b4bb2015-07-20 20:58:08501}
502
Erik Chen3433ee02019-08-05 20:14:26503void RenderWidget::CloseForFrame(std::unique_ptr<RenderWidget> widget) {
danakj8f0bd6c2019-03-14 15:35:24504 DCHECK(for_child_local_root_frame_);
Erik Chen3433ee02019-08-05 20:14:26505 PrepareForClose();
506
507 // The RenderWidget may be deattached from JS, which in turn may be called
508 // in a re-entrant context. We cannot synchronously destroy the object, so we
509 // post a task to do so later.
510 GetCleanupTaskRunner()->PostNonNestableTask(
511 FROM_HERE,
512 base::BindOnce(&RenderWidget::Close, close_weak_ptr_factory_.GetWeakPtr(),
513 std::move(widget)));
kenrba7199832015-01-22 23:44:59514}
515
Scott Violetae08f332018-07-27 17:37:23516void RenderWidget::Init(ShowCallback show_callback, WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21517 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23518 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29519
danakj17216f4d2018-10-16 22:57:32520 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
521
Jeremy Roman04f27c372017-10-27 15:20:55522 input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45523
danakj17216f4d2018-10-16 22:57:32524 LayerTreeView* layer_tree_view = InitializeLayerTreeView();
Erik Chena2819852019-08-28 01:02:28525
526 // TODO(https://crbug.com/995981): This conditional is temporary logic to
527 // handle the case of remote main frame RenderWidgets [which shouldn't exist
528 // to begin with].
529 if (web_widget)
530 web_widget->SetAnimationHost(layer_tree_view->animation_host());
Dave Tapuska9db80842017-07-24 17:24:26531
danakj31699d5b2018-09-18 15:39:17532 blink::scheduler::WebThreadScheduler* main_thread_scheduler = nullptr;
533 if (render_thread_impl)
534 main_thread_scheduler = render_thread_impl->GetWebMainThreadScheduler();
Alexander Timin41e917d2018-07-02 16:25:35535 blink::scheduler::WebThreadScheduler* compositor_thread_scheduler =
536 blink::scheduler::WebThreadScheduler::CompositorThreadScheduler();
danakj31699d5b2018-09-18 15:39:17537 scoped_refptr<base::SingleThreadTaskRunner> compositor_input_task_runner;
danakj89ae4532018-12-12 22:52:55538 // Use the compositor thread task runner unless this is a popup or other such
539 // non-frame widgets. The |compositor_thread_scheduler| can be null in tests
540 // without a compositor thread.
541 if (for_frame() && compositor_thread_scheduler) {
542 compositor_input_task_runner =
543 compositor_thread_scheduler->InputTaskRunner();
danakj31699d5b2018-09-18 15:39:17544 }
Alexander Timin41e917d2018-07-02 16:25:35545
David Bokan3fc68482019-03-13 04:48:49546 // We only use an external input handler for frame RenderWidgets because only
547 // frames use the compositor for input handling. Other kinds of RenderWidgets
548 // (e.g. popups, plugins) must forward their input directly through
549 // RenderWidgetInputHandler into Blink.
550 bool uses_input_handler = for_frame();
Dave Tapuska04bc5ee92018-04-17 19:03:31551 widget_input_handler_manager_ = WidgetInputHandlerManager::Create(
danakj31699d5b2018-09-18 15:39:17552 weak_ptr_factory_.GetWeakPtr(), std::move(compositor_input_task_runner),
David Bokan3fc68482019-03-13 04:48:49553 main_thread_scheduler, uses_input_handler);
Stephen Chenneybccdd0302019-08-15 12:21:28554 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
555 if (command_line->HasSwitch(switches::kAllowPreCommitInput))
556 widget_input_handler_manager_->AllowEarlyInputForTesting();
Dave Tapuska9db80842017-07-24 17:24:26557
danakjdf1ceb72018-07-18 20:02:25558 show_callback_ = std::move(show_callback);
initial.commit09911bf2008-07-26 23:55:29559
lfg8ff33912016-09-13 20:59:21560 webwidget_internal_ = web_widget;
561 webwidget_mouse_lock_target_.reset(
562 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21563 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29564
nick4df698d82016-11-11 20:39:23565 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29566}
567
danakj53802692018-07-25 21:46:44568void RenderWidget::ApplyEmulatedScreenMetricsForPopupWidget(
569 RenderWidget* origin_widget) {
570 RenderWidgetScreenMetricsEmulator* emulator =
571 origin_widget->screen_metrics_emulator_.get();
572 if (!emulator)
573 return;
[email protected]b2e4c70132013-10-03 02:07:51574 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43575 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00576 popup_screen_origin_for_emulation_ =
Lei Zhang9b359d32017-11-28 00:57:02577 emulator->original_screen_rect().origin();
Fady Samuel1c1ad3692018-11-06 23:28:40578 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
danakj0d963bd2019-02-20 18:00:46579 CompositorViewportSize(),
Fady Samuel1c1ad3692018-11-06 23:28:40580 emulator->original_screen_info());
[email protected]b2e4c70132013-10-03 02:07:51581}
582
[email protected]2d6836f42014-07-02 17:25:31583gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
584 if (screen_metrics_emulator_)
585 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
586 return anchor;
587}
588
thakis18e426412017-03-15 12:06:37589#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51590void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
Albert J. Wong7bbf22d2018-12-20 00:27:27591 ExternalPopupMenu* popup) {
592 if (screen_metrics_emulator_)
593 popup->SetOriginScaleForEmulation(screen_metrics_emulator_->scale());
[email protected]b2e4c70132013-10-03 02:07:51594}
[email protected]53907862014-03-25 15:42:40595#endif
[email protected]b2e4c70132013-10-03 02:07:51596
597void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
598 if (screen_metrics_emulator_)
599 screen_metrics_emulator_->OnShowContextMenu(params);
600}
601
[email protected]a95986a82010-12-24 06:19:28602bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47603#if defined(OS_MACOSX)
604 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
605 return text_input_client_observer_->OnMessageReceived(message);
606#endif
lfgbee1e0a2016-06-08 21:24:21607 if (mouse_lock_dispatcher_ &&
608 mouse_lock_dispatcher_->OnMessageReceived(message))
609 return true;
610
[email protected]a95986a82010-12-24 06:19:28611 bool handled = true;
612 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
Albert J. Wong3c93c182018-09-27 17:29:43613 IPC_MESSAGE_HANDLER(WidgetMsg_ShowContextMenu, OnShowContextMenu)
614 IPC_MESSAGE_HANDLER(WidgetMsg_Close, OnClose)
615 IPC_MESSAGE_HANDLER(WidgetMsg_SynchronizeVisualProperties,
Fady Samuel799e72192018-04-25 21:16:57616 OnSynchronizeVisualProperties)
Albert J. Wong3c93c182018-09-27 17:29:43617 IPC_MESSAGE_HANDLER(WidgetMsg_EnableDeviceEmulation,
dgozman9260b0a12015-03-16 13:45:20618 OnEnableDeviceEmulation)
Albert J. Wong3c93c182018-09-27 17:29:43619 IPC_MESSAGE_HANDLER(WidgetMsg_DisableDeviceEmulation,
dgozman9260b0a12015-03-16 13:45:20620 OnDisableDeviceEmulation)
Albert J. Wong3c93c182018-09-27 17:29:43621 IPC_MESSAGE_HANDLER(WidgetMsg_WasHidden, OnWasHidden)
622 IPC_MESSAGE_HANDLER(WidgetMsg_WasShown, OnWasShown)
623 IPC_MESSAGE_HANDLER(WidgetMsg_SetActive, OnSetActive)
Albert J. Wong3c93c182018-09-27 17:29:43624 IPC_MESSAGE_HANDLER(WidgetMsg_SetTextDirection, OnSetTextDirection)
625 IPC_MESSAGE_HANDLER(WidgetMsg_SetBounds_ACK, OnRequestSetBoundsAck)
626 IPC_MESSAGE_HANDLER(WidgetMsg_UpdateScreenRects, OnUpdateScreenRects)
627 IPC_MESSAGE_HANDLER(WidgetMsg_ForceRedraw, OnForceRedraw)
628 IPC_MESSAGE_HANDLER(WidgetMsg_SetViewportIntersection,
kenrbea731792017-01-13 15:10:48629 OnSetViewportIntersection)
Albert J. Wong3c93c182018-09-27 17:29:43630 IPC_MESSAGE_HANDLER(WidgetMsg_SetIsInert, OnSetIsInert)
631 IPC_MESSAGE_HANDLER(WidgetMsg_SetInheritedEffectiveTouchAction,
sunxd540a9962018-05-24 22:51:06632 OnSetInheritedEffectiveTouchAction)
Albert J. Wong3c93c182018-09-27 17:29:43633 IPC_MESSAGE_HANDLER(WidgetMsg_UpdateRenderThrottlingStatus,
Ken Buchanan8a319fb2017-11-15 18:37:12634 OnUpdateRenderThrottlingStatus)
Albert J. Wong3c93c182018-09-27 17:29:43635 IPC_MESSAGE_HANDLER(WidgetMsg_WaitForNextFrameForTests,
lfg43e08e62016-02-03 18:51:37636 OnWaitNextFrameForTests)
paulmeyer90f6c31d2016-11-12 00:17:59637 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
638 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
639 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
640 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21641 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
642 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
643 OnDragSourceSystemDragEnded)
[email protected]a95986a82010-12-24 06:19:28644 IPC_MESSAGE_UNHANDLED(handled = false)
645 IPC_END_MESSAGE_MAP()
646 return handled;
647}
initial.commit09911bf2008-07-26 23:55:29648
649bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42650 // Don't send any messages after the browser has told us to close, and filter
danakj6dcbc5962018-11-16 16:45:42651 // most outgoing messages when frozen.
652 if (closing_) {
653 delete message;
654 return false;
655 }
danakj3130f122019-07-16 17:49:47656 // TODO(danakj): We believe that we should be able to not block IPC sending.
657 // When there's a provisional main frame using this widget, we should not be
658 // sending messages with the RenderWidget yet. And when the widget is frozen
659 // because there is no local main frame, there should be no code using
660 // RenderWidget and sending messages through it.
661 // We should CHECK() that the RenderWidget is not frozen and that the frame
662 // attached to it is not provisional, instead of dropping messages.
663 if (is_frozen_) {
initial.commit09911bf2008-07-26 23:55:29664 delete message;
665 return false;
666 }
667
668 // If given a messsage without a routing ID, then assign our routing ID.
669 if (message->routing_id() == MSG_ROUTING_NONE)
670 message->set_routing_id(routing_id_);
671
[email protected]380244092011-10-07 17:26:27672 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44673}
674
dtapuska014ed082016-11-11 21:58:48675void RenderWidget::SendOrCrash(IPC::Message* message) {
676 bool result = Send(message);
677 CHECK(closing_ || result) << "Failed to send message";
678}
679
ekaramad5aff1942017-01-06 01:26:35680bool RenderWidget::ShouldHandleImeEvents() const {
Albert J. Wong7bbf22d2018-12-20 00:27:27681 if (delegate())
danakj89ae4532018-12-12 22:52:55682 return has_focus_;
683 if (for_child_local_root_frame_) {
684 // TODO(ekaramad): We track page focus in all RenderViews on the page but
685 // the RenderWidgets corresponding to child local roots do not get the
686 // update. For now, this method returns true when the RenderWidget is for a
687 // child local frame, i.e., IME events will be processed regardless of page
688 // focus. We should revisit this after page focus for OOPIFs has been fully
689 // resolved (https://crbug.com/689777).
690 return true;
691 }
692 // Not a frame widget.
693 return false;
ekaramad5aff1942017-01-06 01:26:35694}
695
initial.commit09911bf2008-07-26 23:55:29696void RenderWidget::OnClose() {
Erik Chen3433ee02019-08-05 20:14:26697 DCHECK(popup_ || pepper_fullscreen_);
698
699 // It is always safe to synchronously destroy this object from an IPC message.
700 // That's because the IPC message is asynchronous, which means it can never be
701 // called from a nested context.
702 PrepareForClose();
703 Close(base::WrapUnique(this));
704}
705
706void RenderWidget::PrepareForClose() {
Avi Drissman07d22452019-03-25 17:56:39707 DCHECK(RenderThread::IsMainThread());
dchengd96a27a2015-07-24 20:17:32708 if (closing_)
709 return;
danakj292b63e2018-11-19 20:47:06710 for (auto& observer : render_frames_)
711 observer.WidgetWillClose();
dchengd96a27a2015-07-24 20:17:32712 closing_ = true;
713
714 // Browser correspondence is no longer needed at this point.
715 if (routing_id_ != MSG_ROUTING_NONE) {
716 RenderThread::Get()->RemoveRoute(routing_id_);
Albert J. Wongcb004632018-07-10 22:58:25717 g_routing_id_widget_map.Get().erase(routing_id_);
dchengd96a27a2015-07-24 20:17:32718 }
719
danakj327a4fe2019-01-26 00:00:35720 // Stop handling main thread input events immediately so we don't have them
721 // running while things are partly shut down.
722 if (input_event_queue_)
723 input_event_queue_->ClearClient();
724
Erik Chen3433ee02019-08-05 20:14:26725 CloseWebWidget();
initial.commit09911bf2008-07-26 23:55:29726}
727
Fady Samuel799e72192018-04-25 21:16:57728void RenderWidget::OnSynchronizeVisualProperties(
Albert J. Wong0a918192019-08-28 01:05:28729 const VisualProperties& visual_properties_from_browser) {
danakja2c9d0a92018-07-25 20:01:18730 TRACE_EVENT0("renderer", "RenderWidget::OnSynchronizeVisualProperties");
EhsanKbd2cea992017-11-23 18:49:08731
Albert J. Wong0a918192019-08-28 01:05:28732 VisualProperties visual_properties = visual_properties_from_browser;
danakj01474dd2019-01-28 10:46:04733 // Web tests can override the device scale factor in the renderer.
734 if (device_scale_factor_for_testing_) {
Albert J. Wong0a918192019-08-28 01:05:28735 visual_properties.screen_info.device_scale_factor =
736 device_scale_factor_for_testing_;
737 visual_properties.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
738 visual_properties.new_size,
739 visual_properties.screen_info.device_scale_factor);
danakj01474dd2019-01-28 10:46:04740 }
danakj04d128a2019-01-25 02:10:20741
742 // Inform the rendering thread of the color space indicating the presence of
743 // HDR capabilities. The HDR bit happens to be globally true/false for all
744 // browser windows (on Windows OS) and thus would be the same for all
745 // RenderWidgets, so clobbering each other works out since only the HDR bit is
746 // used. See https://crbug.com/803451 and
747 // https://chromium-review.googlesource.com/c/chromium/src/+/852912/15#message-68bbd3e25c3b421a79cd028b2533629527d21fee
748 //
749 // The RenderThreadImpl can be null in tests.
750 {
751 RenderThreadImpl* render_thread = RenderThreadImpl::current();
752 if (render_thread)
Albert J. Wong0a918192019-08-28 01:05:28753 render_thread->SetRenderingColorSpace(
754 visual_properties.screen_info.color_space);
danakj04d128a2019-01-25 02:10:20755 }
756
Albert J. Wong7bbf22d2018-12-20 00:27:27757 if (delegate()) {
Albert J. Wong0a918192019-08-28 01:05:28758 if (size_ != visual_properties.new_size) {
danakj84bbf552019-01-21 21:33:31759 // Only hide popups when the size changes. Eg https://crbug.com/761908.
760 delegate()->CancelPagePopupForWidget();
761 }
danakja2c9d0a92018-07-25 20:01:18762
Albert J. Wong0a918192019-08-28 01:05:28763 if (display_mode_ != visual_properties.display_mode) {
764 display_mode_ = visual_properties.display_mode;
765 delegate()->ApplyNewDisplayModeForWidget(visual_properties.display_mode);
danakja2c9d0a92018-07-25 20:01:18766 }
767
768 bool auto_resize_mode_changed =
Albert J. Wong0a918192019-08-28 01:05:28769 auto_resize_mode_ != visual_properties.auto_resize_enabled;
770 auto_resize_mode_ = visual_properties.auto_resize_enabled;
771 min_size_for_auto_resize_ = visual_properties.min_size_for_auto_resize;
772 max_size_for_auto_resize_ = visual_properties.max_size_for_auto_resize;
danakja2c9d0a92018-07-25 20:01:18773
774 if (auto_resize_mode_) {
775 gfx::Size min_auto_size = min_size_for_auto_resize_;
776 gfx::Size max_auto_size = max_size_for_auto_resize_;
777 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
778 min_auto_size = gfx::ScaleToCeiledSize(
Albert J. Wong0a918192019-08-28 01:05:28779 min_auto_size, visual_properties.screen_info.device_scale_factor);
danakja2c9d0a92018-07-25 20:01:18780 max_auto_size = gfx::ScaleToCeiledSize(
Albert J. Wong0a918192019-08-28 01:05:28781 max_auto_size, visual_properties.screen_info.device_scale_factor);
danakja2c9d0a92018-07-25 20:01:18782 }
Albert J. Wong7bbf22d2018-12-20 00:27:27783 delegate()->ApplyAutoResizeLimitsForWidget(min_auto_size, max_auto_size);
danakja2c9d0a92018-07-25 20:01:18784 } else if (auto_resize_mode_changed) {
Albert J. Wong7bbf22d2018-12-20 00:27:27785 delegate()->DisableAutoResizeForWidget();
Albert J. Wong0a918192019-08-28 01:05:28786 if (visual_properties.new_size.IsEmpty())
danakja2c9d0a92018-07-25 20:01:18787 return;
788 }
789
790 browser_controls_shrink_blink_size_ =
Albert J. Wong0a918192019-08-28 01:05:28791 visual_properties.browser_controls_shrink_blink_size;
792 top_controls_height_ = visual_properties.top_controls_height;
793 bottom_controls_height_ = visual_properties.bottom_controls_height;
[email protected]b2e4c70132013-10-03 02:07:51794 }
795
danakj7602f4f2019-01-31 18:03:23796 bool ignore_resize_ipc = false;
797 if (synchronous_resize_mode_for_testing_) {
798 // We can ignore browser-initialized resizing during synchronous
799 // (renderer-controlled) mode, unless it is switching us to/from
800 // fullsreen mode or changing the device scale factor.
801 // TODO(danakj): Does the browser actually change DSF inside a web test??
802 // TODO(danakj): Isn't the display mode check redundant with the fullscreen
803 // one?
Albert J. Wong0a918192019-08-28 01:05:28804 if (visual_properties.is_fullscreen_granted == is_fullscreen_granted_ &&
805 visual_properties.display_mode == display_mode_ &&
806 visual_properties.screen_info.device_scale_factor ==
danakj7602f4f2019-01-31 18:03:23807 screen_info_.device_scale_factor)
808 ignore_resize_ipc = true;
809 }
810
811 // When controlling the size in the renderer, we should ignore sizes given by
812 // the browser IPC here.
813 // TODO(danakj): There are many things also being ignored that aren't the
814 // widget's size params. It works because tests that use this mode don't
815 // change those parameters, I guess. But it's more complicated then because it
816 // looks like they are related to sync resize mode. Let's move them out of
817 // this block.
818 // TODO(danakj): It would be nice if we can still use the emulator to emulate
819 // things other than the size if we are in sync resize mode - if the emulator
820 // is even used in sync resize tests. It probably isn't though, so either way
821 // it'd be good to get the emulator out of this block (maybe by overwriting
Albert J. Wong0a918192019-08-28 01:05:28822 // some of |visual_properties| in sync resize mode instead of just
823 // skipping the emulator.
danakj7602f4f2019-01-31 18:03:23824 if (!ignore_resize_ipc) {
danakja2c9d0a92018-07-25 20:01:18825 if (screen_metrics_emulator_) {
danakj7602f4f2019-01-31 18:03:23826 // This will call our SynchronizeVisualProperties() method with a
827 // different set of VisualProperties, holding emulated values. Though not
828 // all VisualProperties are modified by the metrics emulator, so it's a
829 // bit unclear to do this with the full structure. Anything it does not
830 // modify can be consumed directly here instead of in
831 // SynchronizeVisualProperties().
Albert J. Wong0a918192019-08-28 01:05:28832 screen_metrics_emulator_->OnSynchronizeVisualProperties(
833 visual_properties);
danakja2c9d0a92018-07-25 20:01:18834 } else {
danakj0246bba02019-01-23 23:12:27835 if (!delegate()) {
836 // The main frame controls the page scale factor, from blink. For other
837 // frame widgets, the page scale is received from its parent as part of
838 // the visual properties here. While blink doesn't need to know this
839 // page scale factor outside the main frame, the compositor does in
840 // order to produce its output at the correct scale.
W. James MacLean2cd99b62019-04-08 13:54:43841 layer_tree_view_->SetExternalPageScaleFactor(
Albert J. Wong0a918192019-08-28 01:05:28842 visual_properties.page_scale_factor,
843 visual_properties.is_pinch_gesture_active);
danakj0246bba02019-01-23 23:12:27844 // Store the value to give to any new RenderFrameProxy that is
845 // registered.
Albert J. Wong0a918192019-08-28 01:05:28846 page_scale_factor_from_mainframe_ = visual_properties.page_scale_factor;
W. James MacLean2cd99b62019-04-08 13:54:43847 // Similarly, only the main frame knows when a pinch gesture is active,
848 // but this information is needed in subframes so they can throttle
849 // re-rastering in the same manner as the main frame.
850 // |is_pinch_gesture_active| follows the same path to the subframe
851 // compositor(s) as |page_scale_factor|.
852 is_pinch_gesture_active_from_mainframe_ =
Albert J. Wong0a918192019-08-28 01:05:28853 visual_properties.is_pinch_gesture_active;
danakj0246bba02019-01-23 23:12:27854 // Push the page scale factor down to any child RenderWidgets via our
855 // child proxy frames.
856 // TODO(danakj): This ends up setting the page scale factor in the
857 // RenderWidgetHost of the child RenderWidget, so that it can bounce
858 // the value down to its RenderWidget. Since this is essentially a
859 // global value per-page, we could instead store it once in the browser
860 // (such as in RenderViewHost) and distribute it to each frame-hosted
861 // RenderWidget from there.
W. James MacLean2cd99b62019-04-08 13:54:43862 for (auto& child_proxy : render_frame_proxies_) {
Albert J. Wong0a918192019-08-28 01:05:28863 child_proxy.OnPageScaleFactorChanged(
864 visual_properties.page_scale_factor,
865 visual_properties.is_pinch_gesture_active);
W. James MacLean2cd99b62019-04-08 13:54:43866 }
danakj0246bba02019-01-23 23:12:27867 }
868
danakja2c9d0a92018-07-25 20:01:18869 gfx::Size old_visible_viewport_size = visible_viewport_size_;
Albert J. Wong0a918192019-08-28 01:05:28870 SynchronizeVisualProperties(visual_properties);
danakja2c9d0a92018-07-25 20:01:18871 if (old_visible_viewport_size != visible_viewport_size_) {
872 for (auto& render_frame : render_frames_)
Sushanth Rajasankarceaee202019-03-18 15:44:17873 render_frame.ResetHasScrolledFocusedEditableIntoView();
danakja2c9d0a92018-07-25 20:01:18874 }
875 }
Fady Samuel799e72192018-04-25 21:16:57876 }
877
Sushanth Rajasankarceaee202019-03-18 15:44:17878 // TODO(crbug.com/939118): ScrollFocusedNodeIntoViewForWidget does not work
879 // when the focused node is inside an OOPIF. This code path where
880 // scroll_focused_node_into_view is set is used only for WebView, crbug
881 // 939118 tracks fixing webviews to not use scroll_focused_node_into_view.
Albert J. Wong0a918192019-08-28 01:05:28882 if (delegate() && visual_properties.scroll_focused_node_into_view)
Albert J. Wong7bbf22d2018-12-20 00:27:27883 delegate()->ScrollFocusedNodeIntoViewForWidget();
initial.commit09911bf2008-07-26 23:55:29884}
885
dgozman9260b0a12015-03-16 13:45:20886void RenderWidget::OnEnableDeviceEmulation(
Lei Zhang9b359d32017-11-28 00:57:02887 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39888 if (!screen_metrics_emulator_) {
Fady Samuel4255c182018-05-24 20:42:36889 VisualProperties visual_properties;
890 visual_properties.screen_info = screen_info_;
891 visual_properties.new_size = size_;
danakj0d963bd2019-02-20 18:00:46892 visual_properties.compositor_viewport_pixel_size = CompositorViewportSize();
Fady Samuel84d8a1f72018-11-08 00:26:17893 visual_properties.local_surface_id_allocation =
894 local_surface_id_allocation_from_parent_;
Fady Samuel4255c182018-05-24 20:42:36895 visual_properties.visible_viewport_size = visible_viewport_size_;
896 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
897 visual_properties.display_mode = display_mode_;
mfomitchev2600fd7c2016-02-17 20:53:39898 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
Albert J. Wong3c93c182018-09-27 17:29:43899 this, params, visual_properties, widget_screen_rect_,
Fady Samuel4255c182018-05-24 20:42:36900 window_screen_rect_));
oshima50872a72016-03-04 13:26:18901 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39902 } else {
dgozman9260b0a12015-03-16 13:45:20903 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39904 }
dgozman9260b0a12015-03-16 13:45:20905}
906
907void RenderWidget::OnDisableDeviceEmulation() {
908 screen_metrics_emulator_.reset();
909}
910
initial.commit09911bf2008-07-26 23:55:29911void RenderWidget::OnWasHidden() {
danakj14e00a8322019-02-07 17:12:06912 // A frozen main frame widget will never be hidden since that would require it
913 // to be shown first. It must be thawed before changing visibility.
914 DCHECK(!is_frozen_);
915
[email protected]9c3085f2011-06-09 02:10:31916 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
danakj14e00a8322019-02-07 17:12:06917
[email protected]bee16aab2009-08-26 15:55:03918 SetHidden(true);
danakj14e00a8322019-02-07 17:12:06919
Francois Doray687e70a2019-05-16 02:24:55920 tab_switch_time_recorder_.TabWasHidden();
921
ericwilligers88e69742016-10-17 19:29:55922 for (auto& observer : render_frames_)
923 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29924}
925
Sebastien Marchand5f06ca32019-05-17 18:03:42926void RenderWidget::OnWasShown(
927 base::TimeTicks show_request_timestamp,
928 bool was_evicted,
929 const base::Optional<content::RecordTabSwitchTimeRequest>&
930 record_tab_switch_time_request) {
danakj14e00a8322019-02-07 17:12:06931 // A frozen main frame widget does not become shown, since it has no frame
932 // associated with it. It must be thawed before changing visibility.
933 DCHECK(!is_frozen_);
934
Edwin Joea4069f42019-02-20 15:06:24935 TRACE_EVENT_WITH_FLOW0("renderer", "RenderWidget::OnWasShown", routing_id(),
936 TRACE_EVENT_FLAG_FLOW_IN);
danakj678f0252018-11-09 21:46:34937
tasakb95dbb50c2017-02-08 18:07:50938 was_shown_time_ = base::TimeTicks::Now();
danakj14e00a8322019-02-07 17:12:06939
[email protected]bee16aab2009-08-26 15:55:03940 SetHidden(false);
Sebastien Marchand5f06ca32019-05-17 18:03:42941 if (record_tab_switch_time_request) {
danakja6c10012018-07-06 14:25:36942 layer_tree_view_->layer_tree_host()->RequestPresentationTimeForNextFrame(
Sebastien Marchand5f06ca32019-05-17 18:03:42943 tab_switch_time_recorder_.TabWasShown(
944 false /* has_saved_frames */,
945 record_tab_switch_time_request.value(), show_request_timestamp));
[email protected]3399dd822014-08-09 11:14:24946 }
danakj14e00a8322019-02-07 17:12:06947
948 for (auto& observer : render_frames_)
949 observer.WasShown();
950 if (was_evicted) {
951 for (auto& observer : render_frame_proxies_)
952 observer.WasEvicted();
953 }
initial.commit09911bf2008-07-26 23:55:29954}
955
Avi Drissman014dec72018-06-07 02:34:01956void RenderWidget::OnRequestSetBoundsAck() {
[email protected]53d3f302009-12-21 04:42:05957 DCHECK(pending_window_rect_count_);
958 pending_window_rect_count_--;
959}
960
Albert J. Wongcb004632018-07-10 22:58:25961void RenderWidget::OnForceRedraw(int snapshot_id) {
David Bokanf92eaf22019-03-01 01:54:51962 RequestPresentation(base::BindOnce(&RenderWidget::DidPresentForceDrawFrame,
963 weak_ptr_factory_.GetWeakPtr(),
964 snapshot_id));
965}
966
967void RenderWidget::RequestPresentation(PresentationTimeCallback callback) {
danakj125a29e2019-01-24 23:25:29968 layer_tree_view_->layer_tree_host()->RequestPresentationTimeForNextFrame(
David Bokanf92eaf22019-03-01 01:54:51969 std::move(callback));
danakjda15621e2019-04-05 20:34:43970 layer_tree_view_->layer_tree_host()->SetNeedsCommitWithForcedRedraw();
Albert J. Wongcb004632018-07-10 22:58:25971}
972
973void RenderWidget::DidPresentForceDrawFrame(
974 int snapshot_id,
975 const gfx::PresentationFeedback& feedback) {
Albert J. Wong3c93c182018-09-27 17:29:43976 Send(new WidgetHostMsg_ForceRedrawComplete(routing_id(), snapshot_id));
Albert J. Wongcb004632018-07-10 22:58:25977}
978
Xianzhu Wangf02017ac2018-10-17 01:47:33979viz::FrameSinkId RenderWidget::GetFrameSinkIdAtPoint(const gfx::PointF& point,
Ken Buchanan44d7e2f2018-08-23 14:18:05980 gfx::PointF* local_point) {
981 return input_handler_->GetFrameSinkIdAtPoint(point, local_point);
Navid Zolghadr0d86e5f2017-10-23 18:09:22982}
983
danakj77821e252019-03-27 19:58:04984bool RenderWidget::HasPendingPageScaleAnimation() const {
985 return layer_tree_view_->layer_tree_host()->HasPendingPageScaleAnimation();
986}
987
danakj327a4fe2019-01-26 00:00:35988bool RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31989 const blink::WebCoalescedInputEvent& input_event,
990 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55991 HandledEventCallback callback) {
danakj327a4fe2019-01-26 00:00:35992 if (is_frozen_)
993 return false;
Dave Tapuskaea83d3bd2017-06-13 16:14:55994 input_handler_->HandleInputEvent(input_event, latency_info,
995 std::move(callback));
danakj327a4fe2019-01-26 00:00:35996 return true;
dtapuska9ec1a912017-04-21 15:18:31997}
998
danakj125a29e2019-01-24 23:25:29999void RenderWidget::SetNeedsMainFrame() {
danakj0719e0652019-03-14 21:19:111000 ScheduleAnimation();
danakj125a29e2019-01-24 23:25:291001}
1002
dtapuska9d46ef7d2017-05-26 19:06:061003scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
1004 return input_event_queue_;
1005}
1006
fsamuel78f86e42016-01-20 04:10:231007void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:211008 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541009 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:231010}
1011
[email protected]76b082c2019-03-22 03:45:461012void RenderWidget::OnFallbackCursorModeToggled(bool is_on) {
1013 if (GetWebWidget())
1014 GetWebWidget()->OnFallbackCursorModeToggled(is_on);
1015}
1016
fsamuel78f86e42016-01-20 04:10:231017void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:211018 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541019 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:231020}
1021
alexmos56567492016-09-13 00:52:461022void RenderWidget::OnSetEditCommandsForNextKeyEvent(
1023 const EditCommands& edit_commands) {
1024 edit_commands_ = edit_commands;
1025}
1026
Albert J. Wongcb004632018-07-10 22:58:251027void RenderWidget::OnSetActive(bool active) {
Albert J. Wong7bbf22d2018-12-20 00:27:271028 if (delegate())
1029 delegate()->SetActiveForWidget(active);
Albert J. Wongcb004632018-07-10 22:58:251030}
1031
fsamuel78f86e42016-01-20 04:10:231032void RenderWidget::OnSetFocus(bool enable) {
Albert J. Wong7bbf22d2018-12-20 00:27:271033 if (delegate())
1034 delegate()->DidReceiveSetFocusEventForWidget();
danakja2c9d0a92018-07-25 20:01:181035 SetFocus(enable);
1036}
1037
1038void RenderWidget::SetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:081039 has_focus_ = enable;
1040
lfg8ff33912016-09-13 20:59:211041 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541042 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:081043
ericwilligers88e69742016-10-17 19:29:551044 for (auto& observer : render_frames_)
1045 observer.RenderWidgetSetFocus(enable);
danakja2c9d0a92018-07-25 20:01:181046
Albert J. Wong7bbf22d2018-12-20 00:27:271047 if (delegate())
1048 delegate()->DidChangeFocusForWidget();
fsamuel78f86e42016-01-20 04:10:231049}
1050
1051///////////////////////////////////////////////////////////////////////////////
danakja6c10012018-07-06 14:25:361052// LayerTreeViewDelegate
fsamuel78f86e42016-01-20 04:10:231053
David Bokanc8e38d02018-10-08 21:56:011054void RenderWidget::ApplyViewportChanges(
1055 const cc::ApplyViewportChangesArgs& args) {
Ken Buchananed449bb2018-02-01 21:02:051056 if (!GetWebWidget())
1057 return;
David Bokanc8e38d02018-10-08 21:56:011058 GetWebWidget()->ApplyViewportChanges(args);
fsamuel78f86e42016-01-20 04:10:231059}
1060
Allison Pastewka5ac6e7eb2019-06-11 23:13:471061void RenderWidget::RecordManipulationTypeCounts(cc::ManipulationInfo info) {
Ken Buchananed449bb2018-02-01 21:02:051062 if (!GetWebWidget())
1063 return;
Allison Pastewka5ac6e7eb2019-06-11 23:13:471064 GetWebWidget()->RecordManipulationTypeCounts(info);
sahel1b47fda72017-03-28 17:03:071065}
1066
Sahel Sharify676580c2019-01-10 21:49:491067void RenderWidget::SendOverscrollEventFromImplSide(
1068 const gfx::Vector2dF& overscroll_delta,
1069 cc::ElementId scroll_latched_element_id) {
1070 if (!GetWebWidget())
1071 return;
1072 GetWebWidget()->SendOverscrollEventFromImplSide(overscroll_delta,
1073 scroll_latched_element_id);
1074}
1075void RenderWidget::SendScrollEndEventFromImplSide(
1076 cc::ElementId scroll_latched_element_id) {
1077 if (!GetWebWidget())
1078 return;
1079 GetWebWidget()->SendScrollEndEventFromImplSide(scroll_latched_element_id);
1080}
1081
Daniel Cheng224569ee2018-04-25 05:45:061082void RenderWidget::BeginMainFrame(base::TimeTicks frame_time) {
Ken Buchananed449bb2018-02-01 21:02:051083 if (!GetWebWidget())
1084 return;
dtapuska3d5624d32016-08-30 04:34:001085
danakj22b4e8b2019-08-01 23:14:391086 DCHECK(!is_frozen_);
1087
Stephen Chenneyd56b5382019-01-29 00:37:021088 // We record metrics only when running in multi-threaded mode, not
1089 // single-thread mode for testing.
1090 bool record_main_frame_metrics =
1091 !!compositor_deps_->GetCompositorImplThreadTaskRunner();
1092 if (input_event_queue_) {
1093 base::Optional<ScopedUkmRafAlignedInputTimer> ukm_timer;
Stephen Chenney1d064cf2019-06-06 14:54:101094 if (record_main_frame_metrics) {
Stephen Chenneyd56b5382019-01-29 00:37:021095 ukm_timer.emplace(GetWebWidget());
Stephen Chenney1d064cf2019-06-06 14:54:101096 }
Stephen Chenneyd56b5382019-01-29 00:37:021097 input_event_queue_->DispatchRafAlignedInput(frame_time);
1098 }
1099
Stephen Chenneybccdd0302019-08-15 12:21:281100 // The input handler wants to know about the main frame for metric purposes.
Stephen Chenney1d064cf2019-06-06 14:54:101101 DCHECK(widget_input_handler_manager_);
Stephen Chenneyf661f062019-08-02 20:12:421102 widget_input_handler_manager_->BeginMainFrame();
Stephen Chenney1d064cf2019-06-06 14:54:101103
Stephen Chenneyd56b5382019-01-29 00:37:021104 GetWebWidget()->BeginFrame(frame_time, record_main_frame_metrics);
fsamuel78f86e42016-01-20 04:10:231105}
1106
Stefan Zager148248c2019-02-20 23:24:081107void RenderWidget::DidBeginMainFrame() {
1108 if (!GetWebWidget())
1109 return;
1110 GetWebWidget()->DidBeginFrame();
1111}
1112
danakjc7afae52017-06-20 21:12:411113void RenderWidget::RequestNewLayerTreeFrameSink(
danakja6c10012018-07-06 14:25:361114 LayerTreeFrameSinkCallback callback) {
[email protected]7912e822014-04-16 02:37:031115 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:411116 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:391117 DCHECK(!compositor_never_visible_);
danakjf87460792018-12-04 20:14:221118 // Frozen RenderWidgets should not be doing any compositing.
Scott Violetb04f16c2018-11-27 00:48:461119 DCHECK(!is_frozen_);
danakj678f0252018-11-09 21:46:341120
1121 if (is_closing()) {
1122 // In this case, we drop the request which means the compositor waits
1123 // forever, which is fine since we're going to destroy it.
1124 return;
1125 }
jonrossa2ff4f82018-02-16 17:27:461126
danakjf87460792018-12-04 20:14:221127 // If we have a warmup in progress, wait for that and store the callback
1128 // to be run when the warmup completes.
1129 if (warmup_frame_sink_request_pending_) {
1130 after_warmup_callback_ = std::move(callback);
1131 return;
1132 }
1133 // If a warmup previously completed, use the result.
1134 if (warmup_frame_sink_) {
1135 std::move(callback).Run(std::move(warmup_frame_sink_));
1136 return;
1137 }
1138
1139 DoRequestNewLayerTreeFrameSink(std::move(callback));
1140}
1141
1142void RenderWidget::DoRequestNewLayerTreeFrameSink(
1143 LayerTreeFrameSinkCallback callback) {
Erik Chen15476cef2019-08-27 17:28:061144 // TODO:(https://crbug.com/995981): If there is no WebWidget, then the
1145 // RenderWidget should also be destroyed, and this DCHECK should not be
1146 // necessary.
1147 DCHECK(GetWebWidget());
1148
jonrossa2ff4f82018-02-16 17:27:461149 // TODO(jonross): have this generated by the LayerTreeFrameSink itself, which
1150 // would then handle binding.
1151 mojom::RenderFrameMetadataObserverPtr ptr;
1152 mojom::RenderFrameMetadataObserverRequest request = mojo::MakeRequest(&ptr);
1153 mojom::RenderFrameMetadataObserverClientPtrInfo client_info;
1154 mojom::RenderFrameMetadataObserverClientRequest client_request =
1155 mojo::MakeRequest(&client_info);
danakj4b347212018-07-04 17:55:171156 auto render_frame_metadata_observer =
1157 std::make_unique<RenderFrameMetadataObserverImpl>(std::move(request),
1158 std::move(client_info));
danakja6c10012018-07-06 14:25:361159 layer_tree_view_->SetRenderFrameObserver(
danakj4b347212018-07-04 17:55:171160 std::move(render_frame_metadata_observer));
danakjf51754372018-12-13 23:20:011161 GURL url = GetWebWidget()->GetURLForDebugTrace();
danakjefabf312018-10-05 19:03:071162 // The |url| is not always available, fallback to a fixed string.
1163 if (url.is_empty())
1164 url = GURL("chrome://gpu/RenderWidget::RequestNewLayerTreeFrameSink");
danakj6dcbc5962018-11-16 16:45:421165 // TODO(danakj): This may not be accurate, depending on the intent. A child
1166 // local root could be in the same process as the view, so if the client is
1167 // meant to designate the process type, it seems kRenderer would be the
1168 // correct choice. If client is meant to designate the widget type, then
1169 // kOOPIF would denote that it is not for the main frame. However, kRenderer
1170 // would also be used for other widgets such as popups.
1171 const char* client_name = for_child_local_root_frame_ ? kOOPIF : kRenderer;
danakj2d2889a2019-04-05 21:22:081172 compositor_deps_->RequestNewLayerTreeFrameSink(
Scott Violetb04f16c2018-11-27 00:48:461173 routing_id_, frame_swap_message_queue_, std::move(url),
1174 std::move(callback), std::move(client_request), std::move(ptr),
1175 client_name);
[email protected]ba91a792013-02-06 09:48:281176}
1177
fsamuel78f86e42016-01-20 04:10:231178void RenderWidget::DidCommitAndDrawCompositorFrame() {
1179 // NOTE: Tests may break if this event is renamed or moved. See
1180 // tab_capture_performancetest.cc.
1181 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:081182
Stephen Chenney1d064cf2019-06-06 14:54:101183 // The input handler wants to know about the commit for metric purposes
Stephen Chenneybccdd0302019-08-15 12:21:281184 // and to resume input if suspended pending a frame.
Stephen Chenney1d064cf2019-06-06 14:54:101185 DCHECK(widget_input_handler_manager_);
Stephen Chenneyf661f062019-08-02 20:12:421186 widget_input_handler_manager_->CompositorDidCommit();
Stephen Chenney1d064cf2019-06-06 14:54:101187
ericwilligers88e69742016-10-17 19:29:551188 for (auto& observer : render_frames_)
1189 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:081190
fsamuel78f86e42016-01-20 04:10:231191 // Notify subclasses that we initiated the paint operation.
1192 DidInitiatePaint();
Yiming Zhou0f8836c22018-09-13 22:22:111193
Albert J. Wongfb64e142018-10-16 01:10:451194 Send(new WidgetHostMsg_DidCommitAndDrawCompositorFrame(routing_id_));
fsamuel78f86e42016-01-20 04:10:231195}
1196
Stephen Chenney23880392019-04-02 18:36:541197void RenderWidget::WillCommitCompositorFrame() {
1198 if (GetWebWidget())
1199 GetWebWidget()->BeginCommitCompositorFrame();
1200}
1201
Saman Sami766e0b02018-01-31 17:19:201202void RenderWidget::DidCommitCompositorFrame() {
Albert J. Wong7bbf22d2018-12-20 00:27:271203 if (delegate())
1204 delegate()->DidCommitCompositorFrameForWidget();
Stephen Chenney23880392019-04-02 18:36:541205 if (GetWebWidget())
1206 GetWebWidget()->EndCommitCompositorFrame();
Saman Sami766e0b02018-01-31 17:19:201207}
fsamuel78f86e42016-01-20 04:10:231208
danakja2c9d0a92018-07-25 20:01:181209void RenderWidget::DidCompletePageScaleAnimation() {
Albert J. Wong7bbf22d2018-12-20 00:27:271210 if (delegate())
1211 delegate()->DidCompletePageScaleAnimationForWidget();
danakja2c9d0a92018-07-25 20:01:181212}
fsamuel78f86e42016-01-20 04:10:231213
danakjcd417502019-03-13 16:13:211214void RenderWidget::SetLayerTreeMutator(
1215 std::unique_ptr<cc::LayerTreeMutator> mutator) {
1216 layer_tree_view_->layer_tree_host()->SetLayerTreeMutator(std::move(mutator));
1217}
1218
Xida Chen83f1a0d12019-03-21 18:21:301219void RenderWidget::SetPaintWorkletLayerPainterClient(
1220 std::unique_ptr<cc::PaintWorkletLayerPainter> client) {
1221 layer_tree_view_->layer_tree_host()->SetPaintWorkletLayerPainter(
1222 std::move(client));
1223}
1224
danakj26b99912019-02-08 18:58:191225void RenderWidget::SetRootLayer(scoped_refptr<cc::Layer> layer) {
1226 layer_tree_view_->layer_tree_host()->SetRootLayer(std::move(layer));
1227}
1228
danakj53f46b82018-12-11 20:55:551229void RenderWidget::ScheduleAnimation() {
1230 // This call is not needed in single thread mode for tests without a
danakj0719e0652019-03-14 21:19:111231 // scheduler, but they override this method in order to schedule a synchronous
1232 // composite task themselves.
danakj53f46b82018-12-11 20:55:551233 layer_tree_view_->SetNeedsBeginFrame();
initial.commit09911bf2008-07-26 23:55:291234}
1235
danakjefcb8432019-01-16 18:47:141236void RenderWidget::SetShowFPSCounter(bool show) {
1237 cc::LayerTreeHost* host = layer_tree_view_->layer_tree_host();
1238 cc::LayerTreeDebugState debug_state = host->GetDebugState();
1239 debug_state.show_fps_counter = show;
1240 host->SetDebugState(debug_state);
1241}
1242
rnasricabcba42019-06-07 15:30:331243void RenderWidget::SetShowLayoutShiftRegions(bool show) {
1244 cc::LayerTreeHost* host = layer_tree_view_->layer_tree_host();
1245 cc::LayerTreeDebugState debug_state = host->GetDebugState();
1246 debug_state.show_layout_shift_regions = show;
1247 host->SetDebugState(debug_state);
1248}
1249
danakje691e852019-01-16 22:49:041250void RenderWidget::SetShowPaintRects(bool show) {
1251 cc::LayerTreeHost* host = layer_tree_view_->layer_tree_host();
1252 cc::LayerTreeDebugState debug_state = host->GetDebugState();
1253 debug_state.show_paint_rects = show;
1254 host->SetDebugState(debug_state);
1255}
1256
1257void RenderWidget::SetShowDebugBorders(bool show) {
1258 cc::LayerTreeHost* host = layer_tree_view_->layer_tree_host();
1259 cc::LayerTreeDebugState debug_state = host->GetDebugState();
1260 if (show)
1261 debug_state.show_debug_borders.set();
1262 else
1263 debug_state.show_debug_borders.reset();
1264 host->SetDebugState(debug_state);
1265}
1266
1267void RenderWidget::SetShowScrollBottleneckRects(bool show) {
1268 cc::LayerTreeHost* host = layer_tree_view_->layer_tree_host();
1269 cc::LayerTreeDebugState debug_state = host->GetDebugState();
1270 debug_state.show_touch_event_handler_rects = show;
1271 debug_state.show_wheel_event_handler_rects = show;
1272 debug_state.show_non_fast_scrollable_rects = show;
1273 host->SetDebugState(debug_state);
1274}
1275
1276void RenderWidget::SetShowHitTestBorders(bool show) {
1277 cc::LayerTreeHost* host = layer_tree_view_->layer_tree_host();
1278 cc::LayerTreeDebugState debug_state = host->GetDebugState();
1279 debug_state.show_hit_test_borders = show;
1280 host->SetDebugState(debug_state);
1281}
1282
danakj40d07932019-02-28 18:07:101283void RenderWidget::SetBackgroundColor(SkColor color) {
1284 layer_tree_view_->layer_tree_host()->set_background_color(color);
1285}
1286
Stephen Chenneyd56b5382019-01-29 00:37:021287void RenderWidget::UpdateVisualState() {
Ken Buchananed449bb2018-02-01 21:02:051288 if (!GetWebWidget())
1289 return;
1290
danakj22b4e8b2019-08-01 23:14:391291 DCHECK(!is_frozen_);
1292
Stephen Chenneyd56b5382019-01-29 00:37:021293 // We record metrics only when running in multi-threaded mode, not
1294 // single-thread mode for testing.
1295 bool record_main_frame_metrics =
1296 !!compositor_deps_->GetCompositorImplThreadTaskRunner();
1297
Stephen Chenneyec4312612018-11-21 12:40:161298 // When recording main frame metrics set the lifecycle reason to
1299 // kBeginMainFrame, because this is the calller of UpdateLifecycle
1300 // for the main frame. Otherwise, set the reason to kTests, which is
Stephen Chenneybccdd0302019-08-15 12:21:281301 // the only other reason this method is called.
Stephen Chenneyec4312612018-11-21 12:40:161302 WebWidget::LifecycleUpdateReason lifecycle_reason =
1303 record_main_frame_metrics
1304 ? WebWidget::LifecycleUpdateReason::kBeginMainFrame
1305 : WebWidget::LifecycleUpdateReason::kTest;
1306 GetWebWidget()->UpdateLifecycle(WebWidget::LifecycleUpdate::kAll,
1307 lifecycle_reason);
Blink Reformat1c4d759e2017-04-09 16:34:541308 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:501309
Robert Flack3ef2ffb2018-09-06 20:38:201310 if (first_update_visual_state_after_hidden_) {
Takashi SAKAMOTO870f6262017-08-22 04:08:271311 RecordTimeToFirstActivePaint();
1312 first_update_visual_state_after_hidden_ = false;
1313 }
1314}
tasakb95dbb50c2017-02-08 18:07:501315
Takashi SAKAMOTO870f6262017-08-22 04:08:271316void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501317 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501318 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271319 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1320 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1321 sample);
1322 }
1323 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1324 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1325 UMA_HISTOGRAM_TIMES(
1326 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1327 "AfterBackgrounded.5min",
1328 sample);
1329 }
fsamuel78f86e42016-01-20 04:10:231330}
1331
Stephen Chenneyd56b5382019-01-29 00:37:021332void RenderWidget::RecordStartOfFrameMetrics() {
Stephen Chenney23880392019-04-02 18:36:541333 if (GetWebWidget())
1334 GetWebWidget()->RecordStartOfFrameMetrics();
Stephen Chenneyd56b5382019-01-29 00:37:021335}
1336
Stephen Chenney9879a5c2018-09-26 14:21:421337void RenderWidget::RecordEndOfFrameMetrics(base::TimeTicks frame_begin_time) {
Stephen Chenney23880392019-04-02 18:36:541338 if (GetWebWidget())
1339 GetWebWidget()->RecordEndOfFrameMetrics(frame_begin_time);
1340}
Stephen Chenney9879a5c2018-09-26 14:21:421341
Stephen Chenney23880392019-04-02 18:36:541342void RenderWidget::BeginUpdateLayers() {
1343 if (GetWebWidget())
1344 GetWebWidget()->BeginUpdateLayers();
1345}
1346
1347void RenderWidget::EndUpdateLayers() {
1348 if (GetWebWidget())
Stephen Chenneyc3c5987d2019-04-15 20:40:071349 GetWebWidget()->EndUpdateLayers();
Stephen Chenney9879a5c2018-09-26 14:21:421350}
1351
fsamuel78f86e42016-01-20 04:10:231352void RenderWidget::WillBeginCompositorFrame() {
1353 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1354
Ken Buchananed449bb2018-02-01 21:02:051355 if (!GetWebWidget())
1356 return;
1357
Blink Reformat1c4d759e2017-04-09 16:34:541358 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291359
dglazkov06854c5c2016-08-31 00:19:591360 // The UpdateTextInputState can result in further layout and possibly
1361 // enable GPU acceleration so they need to be called before any painting
1362 // is done.
changwan75e3b2072017-01-16 02:55:001363 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591364 UpdateSelectionBounds();
Vladimir Levinaf8cc0fa2019-07-19 17:54:001365
1366 if (auto* frame_widget = GetFrameWidget()) {
1367 frame_widget->UpdateRenderThrottlingStatus(is_throttled_,
1368 subtree_throttled_);
1369 }
initial.commit09911bf2008-07-26 23:55:291370}
1371
fsamuel72464894f2015-12-15 06:59:311372///////////////////////////////////////////////////////////////////////////////
1373// RenderWidgetInputHandlerDelegate
1374
avid7d6b2e2016-03-04 19:41:171375void RenderWidget::FocusChangeComplete() {
Ehsan Karamad655d7b8a2018-01-12 18:38:381376 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1377 if (!frame_widget)
ekaramad27ca69b12017-04-20 18:34:291378 return;
Ehsan Karamad655d7b8a2018-01-12 18:38:381379
ekaramad27ca69b12017-04-20 18:34:291380 blink::WebLocalFrame* focused =
Ehsan Karamad655d7b8a2018-01-12 18:38:381381 frame_widget->LocalRoot()->View()->FocusedFrame();
1382
ekaramad27ca69b12017-04-20 18:34:291383 if (focused && focused->AutofillClient())
1384 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171385}
fsamuel72464894f2015-12-15 06:59:311386
dtapuska1827dd22016-03-11 15:24:591387void RenderWidget::ObserveGestureEventAndResult(
1388 const blink::WebGestureEvent& gesture_event,
1389 const gfx::Vector2dF& unused_delta,
Sandra Sunac5cdd832017-12-11 03:27:131390 const cc::OverscrollBehavior& overscroll_behavior,
dtapuska1827dd22016-03-11 15:24:591391 bool event_processed) {
1392 if (!compositor_deps_->IsElasticOverscrollEnabled())
1393 return;
1394
1395 cc::InputHandlerScrollResult scroll_result;
1396 scroll_result.did_scroll = event_processed;
1397 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1398 scroll_result.unused_scroll_delta = unused_delta;
Sandra Sunac5cdd832017-12-11 03:27:131399 scroll_result.overscroll_behavior = overscroll_behavior;
dtapuska1827dd22016-03-11 15:24:591400
Dave Tapuska04bc5ee92018-04-17 19:03:311401 widget_input_handler_manager_->ObserveGestureEventOnMainThread(gesture_event,
1402 scroll_result);
dtapuska1827dd22016-03-11 15:24:591403}
1404
avid7d6b2e2016-03-04 19:41:171405void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461406 ClearEditCommands();
1407}
1408
1409void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1410 const std::string& value) {
1411 ClearEditCommands();
1412 edit_commands_.emplace_back(name, value);
1413}
1414
1415void RenderWidget::ClearEditCommands() {
1416 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171417}
fsamuel72464894f2015-12-15 06:59:311418
chongza8ba91fc2016-08-16 21:39:171419void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska04bc5ee92018-04-17 19:03:311420 if (mojom::WidgetInputHandlerHost* host =
1421 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1422 host->DidOverscroll(params);
Dave Tapuska139a72f2017-09-06 21:57:031423 }
fsamuel72464894f2015-12-15 06:59:311424}
1425
fsamuele8326c742016-01-12 00:49:391426void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1427 // Nothing to do here. RenderWidget created the |input_handler| and will take
1428 // ownership of it. We just verify here that we don't already have an input
1429 // handler.
1430 DCHECK(!input_handler_);
1431}
1432
changwan75e3b2072017-01-16 02:55:001433void RenderWidget::ShowVirtualKeyboard() {
danakj125a29e2019-01-24 23:25:291434 // Blink can continue running and change input state between the Close IPC
1435 // and the task that actually closes this class.
1436 if (closing_)
1437 return;
changwan75e3b2072017-01-16 02:55:001438 UpdateTextInputStateInternal(true, false);
1439}
1440
changwan62f57292017-02-17 08:28:251441void RenderWidget::ClearTextInputState() {
1442 text_input_info_ = blink::WebTextInputInfo();
1443 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1444 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1445 can_compose_inline_ = false;
1446 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201447 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251448}
1449
changwan75e3b2072017-01-16 02:55:001450void RenderWidget::UpdateTextInputState() {
danakj125a29e2019-01-24 23:25:291451 // Blink can continue running and change input state between the Close IPC
1452 // and the task that actually closes this class.
1453 if (closing_)
1454 return;
changwan75e3b2072017-01-16 02:55:001455 UpdateTextInputStateInternal(false, false);
1456}
1457
1458void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1459 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311460 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001461
fsamuel72464894f2015-12-15 06:59:311462 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001463 DCHECK(!reply_to_request);
1464 // show_virtual_keyboard should still be effective even if it was set inside
1465 // the IME
fsamuel72464894f2015-12-15 06:59:311466 // event guard.
changwan75e3b2072017-01-16 02:55:001467 if (show_virtual_keyboard)
1468 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311469 return;
1470 }
1471
dglazkov97b6c2b2016-10-25 17:35:551472 ui::TextInputType new_type = GetTextInputType();
1473 if (IsDateTimeInput(new_type))
1474 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311475
dglazkov97b6c2b2016-10-25 17:35:551476 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351477 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541478 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101479 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541480 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311481
1482 bool new_can_compose_inline = CanComposeInline();
1483
Jan Wilken Dörrie3d4843c2019-08-02 14:30:281484 // Check whether the keyboard should always be hidden for the currently
1485 // focused element.
1486 auto* focused_frame = GetFocusedWebLocalFrameInWidget();
1487 bool always_hide_ime =
1488 focused_frame && focused_frame->ShouldSuppressKeyboardForFocusedElement();
1489
fsamuel72464894f2015-12-15 06:59:311490 // Only sends text input params if they are changed or if the ime should be
1491 // shown.
changwan75e3b2072017-01-16 02:55:001492 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561493 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1494 text_input_info_ != new_info ||
Jan Wilken Dörrie3d4843c2019-08-02 14:30:281495 can_compose_inline_ != new_can_compose_inline ||
1496 always_hide_ime_ != always_hide_ime) {
ekaramad9053e57b2016-04-26 20:00:381497 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551498 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311499 params.mode = new_mode;
Dave Tapuskaf0698ee2019-05-21 21:12:331500 params.action = new_info.action;
fsamuel72464894f2015-12-15 06:59:311501 params.flags = new_info.flags;
AJITH KUMAR V9e7b5572017-11-14 00:54:211502#if defined(OS_ANDROID)
AJITH KUMAR V041c0b02017-08-08 10:39:201503 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1504 // Due to a focus change, values will be reset by the frame.
1505 // That case we only need fresh NEXT/PREVIOUS information.
Albert J. Wong3c93c182018-09-27 17:29:431506 // Also we won't send WidgetHostMsg_TextInputStateChanged if next/previous
AJITH KUMAR V041c0b02017-08-08 10:39:201507 // focusable status is changed.
1508 if (auto* controller = GetInputMethodController()) {
1509 next_previous_flags_ =
1510 controller->ComputeWebTextInputNextPreviousFlags();
1511 } else {
1512 // For safety in case GetInputMethodController() is null, because -1 is
1513 // invalid value to send to browser process.
1514 next_previous_flags_ = 0;
1515 }
1516 }
AJITH KUMAR V9e7b5572017-11-14 00:54:211517#else
1518 next_previous_flags_ = 0;
1519#endif
AJITH KUMAR V041c0b02017-08-08 10:39:201520 params.flags |= next_previous_flags_;
Yuichiro Hanada1b19cf852019-01-18 16:12:261521 params.value = new_info.value.Utf16();
Blink Reformat1c4d759e2017-04-09 16:34:541522 params.selection_start = new_info.selection_start;
1523 params.selection_end = new_info.selection_end;
1524 params.composition_start = new_info.composition_start;
1525 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311526 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001527 // TODO(changwan): change instances of show_ime_if_needed to
1528 // show_virtual_keyboard.
1529 params.show_ime_if_needed = show_virtual_keyboard;
Jan Wilken Dörrie3d4843c2019-08-02 14:30:281530 params.always_hide_ime = always_hide_ime;
changwan75e3b2072017-01-16 02:55:001531 params.reply_to_request = reply_to_request;
Albert J. Wong3c93c182018-09-27 17:29:431532 Send(new WidgetHostMsg_TextInputStateChanged(routing_id(), params));
fsamuel72464894f2015-12-15 06:59:311533
1534 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551535 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311536 text_input_mode_ = new_mode;
1537 can_compose_inline_ = new_can_compose_inline;
Jan Wilken Dörrie3d4843c2019-08-02 14:30:281538 always_hide_ime_ = always_hide_ime;
fsamuel72464894f2015-12-15 06:59:311539 text_input_flags_ = new_info.flags;
Eric Karl706ea6712018-12-21 22:41:381540
1541#if defined(OS_ANDROID)
1542 // If we send a new TextInputStateChanged message, we must also deliver a
1543 // new RenderFrameMetadata, as the IME will need this info to be updated.
1544 // TODO(ericrk): Consider folding the above IPC into RenderFrameMetadata.
1545 // https://crbug.com/912309
kylechara352d2d12019-08-15 19:11:411546 layer_tree_view_->RequestForceSendMetadata();
Eric Karl706ea6712018-12-21 22:41:381547#endif
fsamuel72464894f2015-12-15 06:59:311548 }
1549}
1550
1551bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581552 possible_drag_event_info_.event_source =
1553 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1554 possible_drag_event_info_.event_location =
Ella Ge1116059d2018-03-21 02:06:131555 gfx::ToFlooredPoint(event.PositionInScreen());
avid7d6b2e2016-03-04 19:41:171556
fsamuel72464894f2015-12-15 06:59:311557 return false;
1558}
1559
1560bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551561 for (auto& observer : render_frames_)
1562 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081563
paulmeyer6ef5a792016-11-08 20:33:581564 possible_drag_event_info_.event_source =
1565 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1566 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541567 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581568
Albert J. Wong7bbf22d2018-12-20 00:27:271569 if (delegate())
1570 return delegate()->RenderWidgetWillHandleMouseEventForWidget(event);
avid7d6b2e2016-03-04 19:41:171571
fsamuel72464894f2015-12-15 06:59:311572 return false;
[email protected]fd847792013-10-24 17:12:351573}
1574
initial.commit09911bf2008-07-26 23:55:291575///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391576// RenderWidgetScreenMetricsDelegate
1577
bokanc63441c2016-04-27 15:49:121578void RenderWidget::ResizeWebWidget() {
danakja2c9d0a92018-07-25 20:01:181579 gfx::Size size = GetSizeForWebWidget();
Albert J. Wong7bbf22d2018-12-20 00:27:271580 if (delegate()) {
1581 delegate()->ResizeWebWidgetForWidget(size, top_controls_height_,
1582 bottom_controls_height_,
1583 browser_controls_shrink_blink_size_);
danakja2c9d0a92018-07-25 20:01:181584 return;
1585 }
Erik Chen15476cef2019-08-27 17:28:061586 // TODO:(https://crbug.com/995981): If there is no WebWidget, then the
1587 // RenderWidget should also be destroyed, and this DCHECK should not be
1588 // necessary.
1589 DCHECK(GetWebWidget());
danakja2c9d0a92018-07-25 20:01:181590 GetWebWidget()->Resize(size);
bokanc63441c2016-04-27 15:49:121591}
1592
1593gfx::Size RenderWidget::GetSizeForWebWidget() const {
danakj4b347212018-07-04 17:55:171594 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:031595 return gfx::ScaleToCeiledSize(size_,
1596 GetOriginalScreenInfo().device_scale_factor);
1597 }
bokanc63441c2016-04-27 15:49:121598
1599 return size_;
1600}
1601
danakj0d963bd2019-02-20 18:00:461602gfx::Size RenderWidget::CompositorViewportSize() const {
1603 return layer_tree_view_->layer_tree_host()->device_viewport_size();
1604}
1605
akaba3483d8f2018-07-10 21:43:091606void RenderWidget::UpdateZoom(double zoom_level) {
akabac6bd1212018-06-25 20:10:481607 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1608 if (!frame_widget)
1609 return;
1610 RenderFrameImpl* render_frame =
1611 RenderFrameImpl::FromWebFrame(frame_widget->LocalRoot());
1612
akaba3483d8f2018-07-10 21:43:091613 // Return early if zoom level is unchanged.
1614 if (render_frame->GetZoomLevel() == zoom_level) {
akabac6bd1212018-06-25 20:10:481615 return;
1616 }
1617
akaba3483d8f2018-07-10 21:43:091618 render_frame->SetZoomLevel(zoom_level);
akabac6bd1212018-06-25 20:10:481619
1620 for (auto& observer : render_frame_proxies_)
akaba3483d8f2018-07-10 21:43:091621 observer.OnZoomLevelChanged(zoom_level);
akabac6bd1212018-06-25 20:10:481622
1623 for (auto& plugin : browser_plugins_)
akaba3483d8f2018-07-10 21:43:091624 plugin.OnZoomLevelChanged(zoom_level);
akabac6bd1212018-06-25 20:10:481625}
1626
Albert J. Wong0a918192019-08-28 01:05:281627void RenderWidget::SynchronizeVisualProperties(
1628 const VisualProperties& visual_properties) {
Fady Samuele62be402018-03-29 03:19:531629 gfx::Size new_compositor_viewport_pixel_size =
Albert J. Wong0a918192019-08-28 01:05:281630 visual_properties.auto_resize_enabled
1631 ? gfx::ScaleToCeiledSize(
1632 size_, visual_properties.screen_info.device_scale_factor)
1633 : visual_properties.compositor_viewport_pixel_size;
1634 UpdateSurfaceAndScreenInfo(
1635 visual_properties.local_surface_id_allocation.value_or(
1636 viz::LocalSurfaceIdAllocation()),
1637 new_compositor_viewport_pixel_size, visual_properties.screen_info);
1638 UpdateCaptureSequenceNumber(visual_properties.capture_sequence_number);
Erik Chenad7f4a1e2019-08-05 20:38:051639 layer_tree_view_->layer_tree_host()->SetBrowserControlsHeight(
Albert J. Wong0a918192019-08-28 01:05:281640 visual_properties.top_controls_height,
1641 visual_properties.bottom_controls_height,
1642 visual_properties.browser_controls_shrink_blink_size);
mfomitchev2600fd7c2016-02-17 20:53:391643
Albert J. Wong0a918192019-08-28 01:05:281644 UpdateZoom(visual_properties.zoom_level);
akabac6bd1212018-06-25 20:10:481645
Albert J. Wong0a918192019-08-28 01:05:281646 if (!visual_properties.auto_resize_enabled) {
1647 visible_viewport_size_ = visual_properties.visible_viewport_size;
1648 display_mode_ = visual_properties.display_mode;
1649 size_ = visual_properties.new_size;
mfomitchev2600fd7c2016-02-17 20:53:391650
danakj21604ce2018-12-19 16:01:221651 ResizeWebWidget();
mfomitchev2600fd7c2016-02-17 20:53:391652
danakjb4cec102019-01-30 19:22:131653 gfx::Size visual_viewport_size = visible_viewport_size_;
danakj21604ce2018-12-19 16:01:221654 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
danakjb4cec102019-01-30 19:22:131655 visual_viewport_size = gfx::ScaleToCeiledSize(
1656 visual_viewport_size, GetOriginalScreenInfo().device_scale_factor);
danakj21604ce2018-12-19 16:01:221657 }
W. James MacLean7c8581072019-06-18 18:07:531658 // When this function is invoked for a main frame widget, it is only if
1659 // (i) we are initializing the widget, or (ii) the widget supports a local
1660 // mainframe. For widgets supporting a remote main frame, the visual
1661 // viewport is updated through the RenderView.
1662 if (delegate())
1663 delegate()->ResizeVisualViewportForWidget(visual_viewport_size);
bokan71cb5b12016-04-27 03:45:221664
danakjf9284772019-01-23 18:29:141665 // NOTE: We may have entered fullscreen mode without changing our size.
Albert J. Wong0a918192019-08-28 01:05:281666 SetIsFullscreen(visual_properties.is_fullscreen_granted);
mfomitchev2600fd7c2016-02-17 20:53:391667 }
mfomitchev2600fd7c2016-02-17 20:53:391668}
1669
1670void RenderWidget::SetScreenMetricsEmulationParameters(
1671 bool enabled,
1672 const blink::WebDeviceEmulationParams& params) {
Albert J. Wong7bbf22d2018-12-20 00:27:271673 // This is only supported in RenderView, which has an delegate().
1674 DCHECK(delegate());
1675 delegate()->SetScreenMetricsEmulationParametersForWidget(enabled, params);
mfomitchev2600fd7c2016-02-17 20:53:391676}
1677
Albert J. Wong3c93c182018-09-27 17:29:431678void RenderWidget::SetScreenRects(const gfx::Rect& widget_screen_rect,
mfomitchev2600fd7c2016-02-17 20:53:391679 const gfx::Rect& window_screen_rect) {
Albert J. Wong3c93c182018-09-27 17:29:431680 widget_screen_rect_ = widget_screen_rect;
mfomitchev2600fd7c2016-02-17 20:53:391681 window_screen_rect_ = window_screen_rect;
1682}
1683
1684///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461685// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291686
Chris Harrelsond7ab99b2018-01-24 17:51:361687void RenderWidget::IntrinsicSizingInfoChanged(
1688 const blink::WebIntrinsicSizingInfo& sizing_info) {
Albert J. Wong3c93c182018-09-27 17:29:431689 Send(new WidgetHostMsg_IntrinsicSizingInfoChanged(routing_id_, sizing_info));
Chris Harrelsond7ab99b2018-01-24 17:51:361690}
1691
Blink Reformat1c4d759e2017-04-09 16:34:541692void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1693 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
Albert J. Wongfb64e142018-10-16 01:10:451694 QueueMessage(new WidgetHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_));
dglazkovf0e1d6d2015-10-10 02:13:481695 }
dglazkov79c426102015-08-31 21:22:431696
ericwilligers88e69742016-10-17 19:29:551697 for (auto& observer : render_frames_)
1698 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431699}
1700
[email protected]586871b2014-07-22 17:05:111701// static
dchengcedca5612016-04-09 01:40:151702std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111703 IPC::Message* msg,
[email protected]586871b2014-07-22 17:05:111704 FrameSwapMessageQueue* frame_swap_message_queue,
1705 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111706 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111707 bool first_message_for_frame = false;
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:491708 frame_swap_message_queue->QueueMessageForFrame(
1709 source_frame_number, base::WrapUnique(msg), &first_message_for_frame);
danakj2d2889a2019-04-05 21:22:081710 if (!first_message_for_frame)
1711 return nullptr;
1712 return std::make_unique<QueueMessageSwapPromise>(
1713 sync_message_filter, frame_swap_message_queue, source_frame_number);
[email protected]586871b2014-07-22 17:05:111714}
1715
danakj53802692018-07-25 21:46:441716void RenderWidget::SetHandlingInputEvent(bool handling_input_event) {
1717 input_handler_->set_handling_input_event(handling_input_event);
1718}
1719
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:491720void RenderWidget::QueueMessage(IPC::Message* msg) {
danakj125a29e2019-01-24 23:25:291721 if (closing_)
1722 return;
1723
[email protected]586871b2014-07-22 17:05:111724 // RenderThreadImpl::current() is NULL in some tests.
danakj125a29e2019-01-24 23:25:291725 if (!RenderThreadImpl::current()) {
[email protected]586871b2014-07-22 17:05:111726 Send(msg);
1727 return;
1728 }
1729
dchengcedca5612016-04-09 01:40:151730 std::unique_ptr<cc::SwapPromise> swap_promise =
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:491731 QueueMessageImpl(msg, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111732 RenderThreadImpl::current()->sync_message_filter(),
danakja6c10012018-07-06 14:25:361733 layer_tree_view_->GetSourceFrameNumber());
danakj2d2889a2019-04-05 21:22:081734 if (swap_promise) {
1735 layer_tree_view_->layer_tree_host()->QueueSwapPromise(
1736 std::move(swap_promise));
1737 }
[email protected]586871b2014-07-22 17:05:111738}
1739
Blink Reformat1c4d759e2017-04-09 16:34:541740void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301741 // TODO(darin): Eliminate this temporary.
Mike Wassermanf95c2d9d2019-04-17 00:44:211742 WebCursor cursor((CursorInfo(cursor_info)));
initial.commit09911bf2008-07-26 23:55:291743 // Only send a SetCursor message if we need to make a change.
Navid Zolghadr293bb862018-12-12 18:15:411744 if (input_handler_->DidChangeCursor(cursor))
Albert J. Wong3c93c182018-09-27 17:29:431745 Send(new WidgetHostMsg_SetCursor(routing_id_, cursor));
initial.commit09911bf2008-07-26 23:55:291746}
1747
aelias5971e47d2017-06-16 02:39:381748void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
Albert J. Wong3c93c182018-09-27 17:29:431749 Send(new WidgetHostMsg_AutoscrollStart(routing_id_, point));
aelias5971e47d2017-06-16 02:39:381750}
1751
1752void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
Albert J. Wong3c93c182018-09-27 17:29:431753 Send(new WidgetHostMsg_AutoscrollFling(routing_id_, velocity));
aelias5971e47d2017-06-16 02:39:381754}
1755
1756void RenderWidget::AutoscrollEnd() {
Albert J. Wong3c93c182018-09-27 17:29:431757 Send(new WidgetHostMsg_AutoscrollEnd(routing_id_));
aelias5971e47d2017-06-16 02:39:381758}
1759
initial.commit09911bf2008-07-26 23:55:291760// We are supposed to get a single call to Show for a newly created RenderWidget
1761// that was created via RenderWidget::CreateWebView. So, we wait until this
1762// point to dispatch the ShowWidget message.
1763//
1764// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281765// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291766//
Blink Reformat1c4d759e2017-04-09 16:34:541767void RenderWidget::Show(WebNavigationPolicy policy) {
danakj65f423b72018-10-10 17:21:201768 if (!show_callback_) {
Albert J. Wong7bbf22d2018-12-20 00:27:271769 if (delegate()) {
danakja2c9d0a92018-07-25 20:01:181770 // When SupportsMultipleWindows is disabled, popups are reusing
danakj65f423b72018-10-10 17:21:201771 // the view's RenderWidget. In some scenarios, this makes blink to call
1772 // Show() twice. But otherwise, if it is enabled, we should not visit
1773 // Show() more than once.
Albert J. Wong7bbf22d2018-12-20 00:27:271774 DCHECK(!delegate()->SupportsMultipleWindowsForWidget());
danakj65f423b72018-10-10 17:21:201775 return;
danakja2c9d0a92018-07-25 20:01:181776 } else {
danakj65f423b72018-10-10 17:21:201777 NOTREACHED() << "received extraneous Show call";
danakja2c9d0a92018-07-25 20:01:181778 }
danakja2c9d0a92018-07-25 20:01:181779 }
1780
initial.commit09911bf2008-07-26 23:55:291781 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351782
1783 // The opener is responsible for actually showing this widget.
danakjdf1ceb72018-07-18 20:02:251784 std::move(show_callback_).Run(this, policy, initial_rect_);
nickf7b38222016-11-22 21:59:351785
bokanc007c3a2015-02-03 07:15:561786 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441787 // that's okay. It'll be ignored if as_popup is false, or the browser
1788 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561789 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291790}
1791
danakj17216f4d2018-10-16 22:57:321792LayerTreeView* RenderWidget::InitializeLayerTreeView() {
1793 TRACE_EVENT0("blink", "RenderWidget::InitializeLayerTreeView");
danakj17216f4d2018-10-16 22:57:321794
1795 layer_tree_view_ = std::make_unique<LayerTreeView>(
1796 this, compositor_deps_->GetCompositorMainThreadTaskRunner(),
1797 compositor_deps_->GetCompositorImplThreadTaskRunner(),
1798 compositor_deps_->GetTaskGraphRunner(),
1799 compositor_deps_->GetWebMainThreadScheduler());
1800 layer_tree_view_->Initialize(
danakj6dcbc5962018-11-16 16:45:421801 GenerateLayerTreeSettings(compositor_deps_, for_child_local_root_frame_,
danakj17216f4d2018-10-16 22:57:321802 screen_info_.rect.size(),
1803 screen_info_.device_scale_factor),
1804 compositor_deps_->CreateUkmRecorderFactory());
1805
Fady Samuel1c1ad3692018-11-06 23:28:401806 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
danakj0d963bd2019-02-20 18:00:461807 CompositorViewportSize(), screen_info_);
danakj953af052019-02-06 19:13:181808 // If the widget is hidden, delay starting the compositor until the user shows
1809 // it. Also if the RenderWidget is frozen, we delay starting the compositor
1810 // until we expect to use the widget, which will be signaled through
1811 // WarmupCompositor().
1812 if (!is_frozen_ && !is_hidden_)
1813 StartStopCompositor();
danakj17216f4d2018-10-16 22:57:321814
danakj17216f4d2018-10-16 22:57:321815 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
danakj17216f4d2018-10-16 22:57:321816
1817 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1818 if (render_thread) {
1819 input_event_queue_ = base::MakeRefCounted<MainThreadEventQueue>(
1820 this, render_thread->GetWebMainThreadScheduler()->InputTaskRunner(),
danakj953af052019-02-06 19:13:181821 render_thread->GetWebMainThreadScheduler(),
1822 /*allow_raf_aligned_input=*/!compositor_never_visible_);
danakj17216f4d2018-10-16 22:57:321823 }
1824
1825 return layer_tree_view_.get();
1826}
1827
danakj953af052019-02-06 19:13:181828void RenderWidget::StartStopCompositor() {
1829 if (compositor_never_visible_)
1830 return;
danakjde8b7482018-11-15 23:45:021831
danakj22b4e8b2019-08-01 23:14:391832 // TODO(danakj): We should start the compositor before becoming shown for
1833 // *all* provisional frames not just provisional main frames (as they become
1834 // thawed). However we need to also prevent BeginMainFrame from occurring, in
1835 // both cases, until the frame is attached at least. And in the case of main
1836 // frames, until blink requests them through StopDeferringMainFrameUpdate().
danakj953af052019-02-06 19:13:181837 if (is_frozen_) {
1838 layer_tree_view_->SetVisible(false);
1839 // Drop all gpu resources, this makes SetVisible(true) more expensive/slower
1840 // but we don't expect to use this RenderWidget again until some possible
1841 // future navigation. This brings us a bit closer to emulating deleting the
1842 // RenderWidget instead of just stopping the compositor.
1843 layer_tree_view_->ReleaseLayerTreeFrameSink();
1844 } else if (is_hidden_) {
1845 layer_tree_view_->SetVisible(false);
1846 } else {
1847 layer_tree_view_->SetVisible(true);
1848 }
danakjde8b7482018-11-15 23:45:021849}
1850
danakj6dcbc5962018-11-16 16:45:421851void RenderWidget::SetIsFrozen(bool is_frozen) {
1852 DCHECK_NE(is_frozen, is_frozen_);
1853 is_frozen_ = is_frozen;
danakj953af052019-02-06 19:13:181854 // If hidden, then frozen changing doesn't change anything with the
1855 // compositor since when hidden the compositor is always stopped.
1856 if (!is_hidden_)
1857 StartStopCompositor();
danakjde8b7482018-11-15 23:45:021858}
1859
danakjf87460792018-12-04 20:14:221860void RenderWidget::WarmupCompositor() {
1861 DCHECK(is_frozen_);
danakj953af052019-02-06 19:13:181862 if (compositor_never_visible_)
danakjf87460792018-12-04 20:14:221863 return;
1864
1865 // Keeping things simple. This would cancel any outstanding warmup if we
1866 // happened to have one (this should be basically impossible). This avoids any
1867 // extra book keeping about the outstanding reqeust.
1868 warmup_weak_ptr_factory_.InvalidateWeakPtrs();
1869 // And if we already did a warmup then we're done.
1870 if (warmup_frame_sink_)
1871 return;
1872
1873 // Mark us pending the warmup frame sink *before* calling
1874 // DoRequestNewLayerTreeFrameSink() as it may run the reply callback
1875 // synchronously. So we don't want to change any state after the call
1876 // to DoRequestNewLayerTreeFrameSink() here.
1877 warmup_frame_sink_request_pending_ = true;
1878
1879 auto cb = base::BindOnce(&RenderWidget::OnReplyForWarmupCompositor,
1880 warmup_weak_ptr_factory_.GetWeakPtr());
1881 DoRequestNewLayerTreeFrameSink(std::move(cb));
1882}
1883
1884void RenderWidget::OnReplyForWarmupCompositor(
1885 std::unique_ptr<cc::LayerTreeFrameSink> sink) {
1886 warmup_frame_sink_request_pending_ = false;
1887
1888 if (after_warmup_callback_)
1889 std::move(after_warmup_callback_).Run(std::move(sink));
1890 else
1891 warmup_frame_sink_ = std::move(sink);
1892}
1893
1894void RenderWidget::AbortWarmupCompositor() {
1895 warmup_frame_sink_request_pending_ = false;
1896 // Drop any pending warmup.
1897 warmup_weak_ptr_factory_.InvalidateWeakPtrs();
1898 // And drop any completed one.
1899 warmup_frame_sink_.reset();
1900
1901 // If we had saved a callback to run after warmup, just do so now indicating
1902 // failure.
1903 if (after_warmup_callback_)
1904 std::move(after_warmup_callback_).Run(nullptr);
1905}
1906
danakj9e93f322019-08-02 22:56:581907// static
1908void RenderWidget::DoDeferredClose(int widget_routing_id) {
1909 // DoDeferredClose() was a posted task, which means the RenderWidget may have
1910 // become frozen in the meantime. Frozen RenderWidgets do not send messages,
1911 // so break the dependency on RenderWidget here, by making this method static
1912 // and going to RenderThread directly to send.
1913 RenderThread::Get()->Send(new WidgetHostMsg_Close(widget_routing_id));
[email protected]2533ce12009-05-09 00:02:241914}
1915
danakj45e4a4f2019-03-12 22:50:421916void RenderWidget::ClosePopupWidgetSoon() {
1917 // Only should be called for popup widgets.
1918 DCHECK(!for_child_local_root_frame_);
1919 DCHECK(!delegate_);
1920
1921 CloseWidgetSoon();
1922}
1923
Blink Reformat1c4d759e2017-04-09 16:34:541924void RenderWidget::CloseWidgetSoon() {
Avi Drissman07d22452019-03-25 17:56:391925 DCHECK(RenderThread::IsMainThread());
danakj292b63e2018-11-19 20:47:061926 // Prevent compositor from setting up new IPC channels, since we know a
1927 // WidgetMsg_Close is coming. We do this immediately, not in DoDeferredClose,
1928 // as the caller (eg WebPagePopupImpl) may start tearing down things after
1929 // calling this method, including detaching the frame from this RenderWidget.
1930 // Then trying to make a LayerTreeFrameSink would crash.
1931 // https://crbug.com/906340
1932 host_will_close_this_ = true;
1933
initial.commit09911bf2008-07-26 23:55:291934 // If a page calls window.close() twice, we'll end up here twice, but that's
1935 // OK. It is safe to send multiple Close messages.
danakj292b63e2018-11-19 20:47:061936 //
[email protected]2533ce12009-05-09 00:02:241937 // Ask the RenderWidgetHost to initiate close. We could be called from deep
danakj295c43f182019-03-13 16:37:171938 // in Javascript. If we ask the RenderWidgetHost to close now, the window
1939 // could be closed before the JS finishes executing, thanks to nested message
1940 // loops running and handling the resuliting Close IPC. So instead, post a
[email protected]2533ce12009-05-09 00:02:241941 // message back to the message loop, which won't run until the JS is
danakj295c43f182019-03-13 16:37:171942 // complete, and then the Close request can be sent.
Hajime Hoshi315a61f2018-08-14 17:27:281943 GetCleanupTaskRunner()->PostTask(
danakj9e93f322019-08-02 22:56:581944 FROM_HERE, base::BindOnce(&RenderWidget::DoDeferredClose, routing_id_));
initial.commit09911bf2008-07-26 23:55:291945}
1946
Erik Chen3433ee02019-08-05 20:14:261947void RenderWidget::Close(std::unique_ptr<RenderWidget> widget) {
danakja6c10012018-07-06 14:25:361948 layer_tree_view_.reset();
Albert J. Wongd593de532018-09-06 05:42:151949 // Note the ACK is a control message going to the RenderProcessHost.
Albert J. Wong3c93c182018-09-27 17:29:431950 RenderThread::Get()->Send(new WidgetHostMsg_Close_ACK(routing_id()));
danakj6ec39d302019-03-15 22:43:221951 closed_ = true;
Erik Chen3433ee02019-08-05 20:14:261952
1953 // At the end of this method, |widget| which points to this is deleted.
1954 DCHECK_EQ(widget.get(), this);
Ken Buchananed449bb2018-02-01 21:02:051955}
1956
1957void RenderWidget::CloseWebWidget() {
danakj35314ab2018-10-19 16:37:341958 // If the browser has not sent OnDisableDeviceEmulation, we have an emulator
1959 // hanging out still. Destroying it must happen *after* the IPC route is
1960 // removed so that another IPC does not arrive and re-create the emulator
1961 // during closing.
1962 //
1963 // This destruction is normally part of an IPC and expects objects to be alive
1964 // that would be alive while the IPC route is active such as the
1965 // |layer_tree_view_|. So we ensure that it is the first thing to be
1966 // destroyed here before deleting things from the RenderWidget or the
Albert J. Wong7bbf22d2018-12-20 00:27:271967 // delegate().
danakj35314ab2018-10-19 16:37:341968 //
1969 // TODO(danakj): The emulator could reset to non-emulated values in an
1970 // explicit method call (instead of in the destructor) that occurs when
1971 // emulation is disabled, but does not need to occur during RenderWidget
1972 // closing. Then we would not have to destroy this so carefully.
1973 screen_metrics_emulator_.reset();
1974
Erik Chen562ca42b2019-08-22 19:46:061975 // TODO(https://crbug.com/995981): This logic is very confusing and should be
1976 // fixed. When the RenderWidget is associated with a RenderView,
1977 // webwidget_internal_ points to an instance of WebView. This is owned by the
1978 // RenderView, which also owns the RenderWidget and is calling into this
1979 // method. We do nothing here and let RenderView destroy the WebView.
1980 //
1981 // For all other RenderWidgets, webwidget_internal_ points at a 'real'
1982 // instance of a WebWidget which is owned by the RenderWidget. In this case,
1983 // we must close the webwidget.
1984 if (!delegate())
1985 webwidget_internal_->Close();
danakj5c5269b2018-11-06 00:39:111986 webwidget_internal_ = nullptr;
danakj2d2889a2019-04-05 21:22:081987
1988 close_weak_ptr_factory_.InvalidateWeakPtrs();
initial.commit09911bf2008-07-26 23:55:291989}
1990
Mitsuru Oshima3c07b332018-02-06 04:56:501991void RenderWidget::UpdateWebViewWithDeviceScaleFactor() {
1992 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1993 blink::WebFrame* current_frame =
1994 frame_widget ? frame_widget->LocalRoot() : nullptr;
1995 blink::WebView* webview = current_frame ? current_frame->View() : nullptr;
1996 if (webview) {
danakj4b347212018-07-04 17:55:171997 if (compositor_deps_->IsUseZoomForDSFEnabled())
Fady Samuela863f152018-03-09 16:10:031998 webview->SetZoomFactorForDeviceScaleFactor(
1999 GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:502000 else
Fady Samuela863f152018-03-09 16:10:032001 webview->SetDeviceScaleFactor(GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:502002
2003 webview->GetSettings()->SetPreferCompositingToLCDTextEnabled(
Christopher Camerone9a30c12018-03-07 08:23:382004 PreferCompositingToLCDText(compositor_deps_,
Fady Samuela863f152018-03-09 16:10:032005 GetWebScreenInfo().device_scale_factor));
Mitsuru Oshima3c07b332018-02-06 04:56:502006 }
2007}
2008
Ehsan Karamad655d7b8a2018-01-12 18:38:382009blink::WebFrameWidget* RenderWidget::GetFrameWidget() const {
danakj89ae4532018-12-12 22:52:552010 // TODO(danakj): Remove this check and don't call this method for non-frames.
2011 if (!for_frame())
2012 return nullptr;
2013 // TODO(danakj): Is this needed? IPCs stop after closing, but code used to
2014 // check for a null WebWidget.
2015 if (closing_)
Ehsan Karamad655d7b8a2018-01-12 18:38:382016 return nullptr;
2017
Erik Chena2819852019-08-28 01:02:282018 return static_cast<blink::WebFrameWidget*>(webwidget_internal_);
Ehsan Karamad655d7b8a2018-01-12 18:38:382019}
2020
bokan841fdc72016-10-06 00:16:352021void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
2022 DCHECK(window_rect);
2023 float scale = popup_origin_scale_for_emulation_;
2024 if (!scale)
2025 return;
2026 window_rect->x =
2027 popup_view_origin_for_emulation_.x() +
2028 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
2029 window_rect->y =
2030 popup_view_origin_for_emulation_.y() +
2031 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
2032}
2033
2034void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
2035 DCHECK(window_rect);
2036 float scale = popup_origin_scale_for_emulation_;
2037 if (!scale)
2038 return;
2039 window_rect->x =
2040 popup_screen_origin_for_emulation_.x() +
2041 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
2042 window_rect->y =
2043 popup_screen_origin_for_emulation_.y() +
2044 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
2045}
2046
Blink Reformat1c4d759e2017-04-09 16:34:542047WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:352048 WebRect rect;
bokan6b08cd22016-10-05 00:55:212049 if (pending_window_rect_count_) {
2050 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
2051 // the RootWindowRect is probably going to return wrong results since the
2052 // browser may not have processed the Move yet. There isn't really anything
2053 // good to do in this case, and it shouldn't happen - since this size is
2054 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:352055 rect = pending_window_rect_;
2056 } else {
2057 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:212058 }
[email protected]2533ce12009-05-09 00:02:242059
bokan841fdc72016-10-06 00:16:352060 ScreenRectToEmulatedIfNeeded(&rect);
2061 return rect;
bokan6b08cd22016-10-05 00:55:212062}
2063
Blink Reformat1c4d759e2017-04-09 16:34:542064WebRect RenderWidget::ViewRect() {
Albert J. Wong3c93c182018-09-27 17:29:432065 WebRect rect = widget_screen_rect_;
bokan841fdc72016-10-06 00:16:352066 ScreenRectToEmulatedIfNeeded(&rect);
2067 return rect;
initial.commit09911bf2008-07-26 23:55:292068}
2069
Blink Reformat1c4d759e2017-04-09 16:34:542070void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:302071 WebTextDirection hint) {
Albert J. Wong3c93c182018-09-27 17:29:432072 Send(new WidgetHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:302073}
2074
Blink Reformat1c4d759e2017-04-09 16:34:542075void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
danakj81d601e62018-10-09 22:15:052076 // This path is for the renderer to change the on-screen position/size of
2077 // the widget by changing its window rect. This is not possible for
2078 // RenderWidgets whose position/size are controlled by layout from another
danakj6dcbc5962018-11-16 16:45:422079 // frame tree (ie. child local root frames), as the window rect can only be
2080 // set by the browser.
2081 if (for_child_local_root_frame_)
danakj81d601e62018-10-09 22:15:052082 return;
2083
oshima33ec97cd2015-12-14 19:40:242084 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:352085 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:512086
danakj7602f4f2019-01-31 18:03:232087 if (synchronous_resize_mode_for_testing_) {
Kent Tamura21d1de62018-12-10 04:45:202088 // This is a web-test-only path. At one point, it was planned to be
danakj65f423b72018-10-10 17:21:202089 // removed. See https://crbug.com/309760.
bokanc007c3a2015-02-03 07:15:562090 SetWindowRectSynchronously(window_rect);
danakj65f423b72018-10-10 17:21:202091 return;
2092 }
2093
2094 if (show_callback_) {
2095 // The widget is not shown yet. Delay the |window_rect| being sent to the
2096 // browser until Show() is called so it can be sent with that IPC, once the
2097 // browser is ready for the info.
2098 initial_rect_ = window_rect;
2099 } else {
2100 Send(new WidgetHostMsg_RequestSetBounds(routing_id_, window_rect));
2101 SetPendingWindowRect(window_rect);
initial.commit09911bf2008-07-26 23:55:292102 }
2103}
2104
[email protected]2533ce12009-05-09 00:02:242105void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
2106 pending_window_rect_ = rect;
2107 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:242108
bokan6b08cd22016-10-05 00:55:212109 // Popups don't get size updates back from the browser so just store the set
2110 // values.
danakj89ae4532018-12-12 22:52:552111 if (!for_frame()) {
Blink Reformat1c4d759e2017-04-09 16:34:542112 window_screen_rect_ = rect;
Albert J. Wong3c93c182018-09-27 17:29:432113 widget_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:242114 }
[email protected]d4547452008-08-28 18:36:372115}
2116
wjmacleanee244e02017-05-26 21:06:072117void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
2118 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:072119 has_host_context_menu_location_ = true;
2120 host_context_menu_location_ = location;
2121 if (GetWebWidget()) {
2122 GetWebWidget()->ShowContextMenu(
2123 static_cast<blink::WebMenuSourceType>(source_type));
2124 }
2125 has_host_context_menu_location_ = false;
2126}
2127
[email protected]fa7b1dc2010-06-23 17:53:042128void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:262129 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:112130 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:072131 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:112132 int selection_start,
2133 int selection_end) {
ekaramad5aff1942017-01-06 01:26:352134 if (!ShouldHandleImeEvents())
2135 return;
2136
brettw4b461082016-11-19 18:55:162137#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492138 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:112139 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:492140 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:092141 return;
2142 }
2143#endif
[email protected]66fca5bc2013-05-23 06:58:292144 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:012145 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:012146 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:542147 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:112148 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:562149 replacement_range.IsValid()
2150 ? WebRange(replacement_range.start(), replacement_range.length())
2151 : WebRange(),
2152 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:042153 // If we failed to set the composition text, then we need to let the browser
2154 // process to cancel the input method's ongoing composition session, to make
2155 // sure we are in a consistent state.
Dave Tapuska04bc5ee92018-04-17 19:03:312156 if (mojom::WidgetInputHandlerHost* host =
2157 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
2158 host->ImeCancelComposition();
Dave Tapuska139a72f2017-09-06 21:57:032159 }
[email protected]7f00efa2010-04-15 05:01:262160 }
nonafa291792016-08-10 02:36:182161 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:042162}
2163
rlanday7efe2302017-01-11 00:14:282164void RenderWidget::OnImeCommitText(
2165 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:112166 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:282167 const gfx::Range& replacement_range,
2168 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:352169 if (!ShouldHandleImeEvents())
2170 return;
2171
brettw4b461082016-11-19 18:55:162172#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492173 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
2174 plugin->render_frame()->OnImeCommitText(text, replacement_range,
2175 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:092176 return;
2177 }
2178#endif
[email protected]66fca5bc2013-05-23 06:58:292179 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:392180 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:262181 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:542182 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:112183 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:562184 replacement_range.IsValid()
2185 ? WebRange(replacement_range.start(), replacement_range.length())
2186 : WebRange(),
2187 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:262188 }
aelias87b8f7c2016-09-14 03:19:292189 input_handler_->set_handling_input_event(false);
2190 UpdateCompositionInfo(false /* not an immediate request */);
2191}
2192
2193void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:352194 if (!ShouldHandleImeEvents())
2195 return;
2196
brettw4b461082016-11-19 18:55:162197#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492198 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
2199 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:292200 return;
2201 }
2202#endif
2203
changwan38c3eb612016-12-09 01:45:562204 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:292205 return;
2206 ImeEventGuard guard(this);
2207 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:012208 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:542209 controller->FinishComposingText(
2210 keep_selection ? WebInputMethodController::kKeepSelection
2211 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:012212 }
fsamuele8326c742016-01-12 00:49:392213 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:182214 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:292215}
2216
Christopher Camerone9a30c12018-03-07 08:23:382217void RenderWidget::UpdateSurfaceAndScreenInfo(
Fady Samuel1c1ad3692018-11-06 23:28:402218 const viz::LocalSurfaceIdAllocation& new_local_surface_id_allocation,
danakj9c4e7b812019-02-19 22:04:272219 const gfx::Size& compositor_viewport_pixel_size,
Christopher Camerone9a30c12018-03-07 08:23:382220 const ScreenInfo& new_screen_info) {
Christopher Camerone9a30c12018-03-07 08:23:382221 bool orientation_changed =
2222 screen_info_.orientation_angle != new_screen_info.orientation_angle ||
2223 screen_info_.orientation_type != new_screen_info.orientation_type;
2224 bool web_device_scale_factor_changed =
2225 screen_info_.device_scale_factor != new_screen_info.device_scale_factor;
Fady Samuela863f152018-03-09 16:10:032226 ScreenInfo previous_original_screen_info = GetOriginalScreenInfo();
Christopher Cameronbe7ecea2018-02-27 00:47:192227
Fady Samuel1c1ad3692018-11-06 23:28:402228 local_surface_id_allocation_from_parent_ = new_local_surface_id_allocation;
Christopher Camerone9a30c12018-03-07 08:23:382229 screen_info_ = new_screen_info;
Christopher Cameronbe7ecea2018-02-27 00:47:192230
danakj125a29e2019-01-24 23:25:292231 // Note carefully that the DSF specified in |new_screen_info| is not the
2232 // DSF used by the compositor during device emulation!
2233 layer_tree_view_->SetViewportSizeAndScale(
danakj9c4e7b812019-02-19 22:04:272234 compositor_viewport_pixel_size,
danakj125a29e2019-01-24 23:25:292235 GetOriginalScreenInfo().device_scale_factor,
2236 local_surface_id_allocation_from_parent_);
danakj9c4e7b812019-02-19 22:04:272237 // The ViewportVisibleRect derives from the LayerTreeView's viewport size,
2238 // which is set above.
2239 layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect());
danakj04d128a2019-01-25 02:10:202240 layer_tree_view_->SetRasterColorSpace(
2241 screen_info_.color_space.GetRasterColorSpace());
Christopher Cameronbe7ecea2018-02-27 00:47:192242
Christopher Camerone9a30c12018-03-07 08:23:382243 if (orientation_changed)
2244 OnOrientationChange();
Christopher Cameronbe7ecea2018-02-27 00:47:192245
Fady Samuela863f152018-03-09 16:10:032246 if (previous_original_screen_info != GetOriginalScreenInfo()) {
Christopher Camerone9a30c12018-03-07 08:23:382247 for (auto& observer : render_frame_proxies_)
Fady Samuela863f152018-03-09 16:10:032248 observer.OnScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:382249
2250 // Notify all embedded BrowserPlugins of the updated ScreenInfo.
2251 for (auto& observer : browser_plugins_)
Fady Samuela863f152018-03-09 16:10:032252 observer.ScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:382253 }
2254
2255 if (web_device_scale_factor_changed)
Christopher Cameronbe7ecea2018-02-27 00:47:192256 UpdateWebViewWithDeviceScaleFactor();
oshimad5279032015-12-16 18:22:332257}
2258
danakja2c9d0a92018-07-25 20:01:182259void RenderWidget::SetWindowRectSynchronously(
2260 const gfx::Rect& new_window_rect) {
2261 VisualProperties visual_properties;
2262 visual_properties.screen_info = screen_info_;
2263 visual_properties.new_size = new_window_rect.size();
2264 visual_properties.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
2265 new_window_rect.size(), GetWebScreenInfo().device_scale_factor);
2266 visual_properties.visible_viewport_size = new_window_rect.size();
2267 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
2268 visual_properties.display_mode = display_mode_;
Fady Samuel84d8a1f72018-11-08 00:26:172269 visual_properties.local_surface_id_allocation =
2270 local_surface_id_allocation_from_parent_;
danakja2c9d0a92018-07-25 20:01:182271 // We are resizing the window from the renderer, so allocate a new
2272 // viz::LocalSurfaceId to avoid surface invariants violations in tests.
danakj125a29e2019-01-24 23:25:292273 layer_tree_view_->RequestNewLocalSurfaceId();
danakja2c9d0a92018-07-25 20:01:182274 SynchronizeVisualProperties(visual_properties);
2275
Albert J. Wong3c93c182018-09-27 17:29:432276 widget_screen_rect_ = new_window_rect;
danakja2c9d0a92018-07-25 20:01:182277 window_screen_rect_ = new_window_rect;
danakj65f423b72018-10-10 17:21:202278 if (show_callback_) {
2279 // Tests may call here directly to control the window rect. If
2280 // Show() did not happen yet, the rect is stored to be passed to the
2281 // browser when the RenderWidget requests Show().
danakja2c9d0a92018-07-25 20:01:182282 initial_rect_ = new_window_rect;
danakj65f423b72018-10-10 17:21:202283 }
danakja2c9d0a92018-07-25 20:01:182284}
2285
Vladimir Levin98d76dad2018-04-21 00:21:292286void RenderWidget::UpdateCaptureSequenceNumber(
2287 uint32_t capture_sequence_number) {
2288 if (capture_sequence_number == last_capture_sequence_number_)
2289 return;
2290 last_capture_sequence_number_ = capture_sequence_number;
2291
2292 // Notify observers of the new capture sequence number.
2293 for (auto& observer : render_frame_proxies_)
2294 observer.UpdateCaptureSequenceNumber(capture_sequence_number);
2295 for (auto& observer : browser_plugins_)
2296 observer.UpdateCaptureSequenceNumber(capture_sequence_number);
2297}
2298
[email protected]4873c7d2009-07-16 06:36:282299void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
EhsanK955ba582017-11-30 21:14:402300 if (auto* frame = GetFocusedWebLocalFrameInWidget())
2301 frame->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:112302}
2303
Albert J. Wong3c93c182018-09-27 17:29:432304void RenderWidget::OnUpdateScreenRects(const gfx::Rect& widget_screen_rect,
[email protected]80ad8622012-11-07 16:33:032305 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:512306 if (screen_metrics_emulator_) {
Albert J. Wong3c93c182018-09-27 17:29:432307 screen_metrics_emulator_->OnUpdateScreenRects(widget_screen_rect,
mfomitchev2600fd7c2016-02-17 20:53:392308 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:512309 } else {
Albert J. Wong3c93c182018-09-27 17:29:432310 SetScreenRects(widget_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:512311 }
Albert J. Wong3c93c182018-09-27 17:29:432312 Send(new WidgetHostMsg_UpdateScreenRects_ACK(routing_id()));
[email protected]80ad8622012-11-07 16:33:032313}
2314
kenrbea731792017-01-13 15:10:482315void RenderWidget::OnSetViewportIntersection(
Ken Buchananb2c9e262018-03-10 16:53:312316 const gfx::Rect& viewport_intersection,
Stefan Zager54e25832018-08-14 22:15:312317 const gfx::Rect& compositor_visible_rect,
Stefan Zager0926c9c2019-03-12 02:46:092318 blink::FrameOcclusionState occlusion_state) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252319 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchananb2c9e262018-03-10 16:53:312320 compositor_visible_rect_ = compositor_visible_rect;
Stefan Zager54e25832018-08-14 22:15:312321 frame_widget->SetRemoteViewportIntersection(viewport_intersection,
Stefan Zager0926c9c2019-03-12 02:46:092322 occlusion_state);
danakja6c10012018-07-06 14:25:362323 layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect());
kenrbea731792017-01-13 15:10:482324 }
2325}
2326
kenrb04323782017-06-23 01:23:322327void RenderWidget::OnSetIsInert(bool inert) {
danakj89ae4532018-12-12 22:52:552328 if (auto* frame_widget = GetFrameWidget())
Ehsan Karamadf3ca2a82018-01-20 01:05:252329 frame_widget->SetIsInert(inert);
kenrb04323782017-06-23 01:23:322330}
2331
sunxd540a9962018-05-24 22:51:062332void RenderWidget::OnSetInheritedEffectiveTouchAction(
2333 cc::TouchAction touch_action) {
danakj89ae4532018-12-12 22:52:552334 if (auto* frame_widget = GetFrameWidget())
sunxd540a9962018-05-24 22:51:062335 frame_widget->SetInheritedEffectiveTouchAction(touch_action);
sunxd540a9962018-05-24 22:51:062336}
2337
Ken Buchanan8a319fb2017-11-15 18:37:122338void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled,
2339 bool subtree_throttled) {
Vladimir Levinaf8cc0fa2019-07-19 17:54:002340 is_throttled_ = is_throttled;
2341 subtree_throttled_ = subtree_throttled;
2342
danakj89ae4532018-12-12 22:52:552343 if (auto* frame_widget = GetFrameWidget())
Ehsan Karamadf3ca2a82018-01-20 01:05:252344 frame_widget->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled);
Ken Buchanan8a319fb2017-11-15 18:37:122345}
2346
paulmeyer90f6c31d2016-11-12 00:17:592347void RenderWidget::OnDragTargetDragEnter(
2348 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:522349 const gfx::PointF& client_point,
2350 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592351 WebDragOperationsMask ops,
2352 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252353 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2354 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592355 return;
2356
Ehsan Karamadf3ca2a82018-01-20 01:05:252357 WebDragOperation operation = frame_widget->DragTargetDragEnter(
2358 DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point,
2359 ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592360
2361 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2362}
2363
Ella Ge80a52dce2017-11-15 18:01:522364void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point,
2365 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592366 WebDragOperationsMask ops,
2367 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252368 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2369 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592370 return;
2371
Ehsan Karamadf3ca2a82018-01-20 01:05:252372 WebDragOperation operation = frame_widget->DragTargetDragOver(
2373 ConvertWindowPointToViewport(client_point), screen_point, ops,
2374 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592375
2376 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2377}
2378
Ella Ge80a52dce2017-11-15 18:01:522379void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point,
2380 const gfx::PointF& screen_point) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252381 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2382 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592383 return;
Ehsan Karamadf3ca2a82018-01-20 01:05:252384
2385 frame_widget
Blink Reformat1c4d759e2017-04-09 16:34:542386 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:172387 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:592388}
2389
2390void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:522391 const gfx::PointF& client_point,
2392 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592393 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252394 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2395 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592396 return;
2397
Ehsan Karamadf3ca2a82018-01-20 01:05:252398 frame_widget->DragTargetDrop(DropDataToWebDragData(drop_data),
2399 ConvertWindowPointToViewport(client_point),
2400 screen_point, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592401}
2402
Ella Ge80a52dce2017-11-15 18:01:522403void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point,
2404 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:212405 WebDragOperation op) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252406 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2407 if (!frame_widget)
paulmeyer8fc8ea92016-11-15 05:12:212408 return;
2409
Ehsan Karamadf3ca2a82018-01-20 01:05:252410 frame_widget->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
2411 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:212412}
2413
2414void RenderWidget::OnDragSourceSystemDragEnded() {
danakj503545c2019-01-11 19:03:092415 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2416 if (!frame_widget)
paulmeyer8fc8ea92016-11-15 05:12:212417 return;
2418
danakj503545c2019-01-11 19:03:092419 frame_widget->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:212420}
2421
Blink Reformat1c4d759e2017-04-09 16:34:542422void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:262423#if defined(OS_CHROMEOS)
2424 // On ChromeOS, virtual keyboard is triggered only when users leave the
2425 // mouse button or the finger and a text input element is focused at that
2426 // time. Focus event itself shouldn't trigger virtual keyboard.
2427 UpdateTextInputState();
2428#else
changwan75e3b2072017-01-16 02:55:002429 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:262430#endif
boliu7b2be2f2016-11-04 04:58:312431
2432// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
2433// virtual keyboard.
2434#if !defined(OS_ANDROID)
2435 FocusChangeComplete();
2436#endif
[email protected]0d1ebed12013-08-05 22:01:132437}
2438
fsamuel72464894f2015-12-15 06:59:312439ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:162440#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492441 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2442 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:092443#endif
ekaramad5aff1942017-01-06 01:26:352444 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:542445 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:312446 return ui::TEXT_INPUT_TYPE_NONE;
2447}
2448
nonafa291792016-08-10 02:36:182449void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
2450 if (!monitor_composition_info_ && !immediate_request)
2451 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:592452
nonafa291792016-08-10 02:36:182453 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
2454 gfx::Range range;
2455 std::vector<gfx::Rect> character_bounds;
2456
2457 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
2458 // Composition information is only available on editable node.
2459 range = gfx::Range::InvalidRange();
2460 } else {
2461 GetCompositionRange(&range);
2462 GetCompositionCharacterBounds(&character_bounds);
2463 }
2464
2465 if (!immediate_request &&
2466 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:312467 return;
nonafa291792016-08-10 02:36:182468 }
fsamuel72464894f2015-12-15 06:59:312469 composition_character_bounds_ = character_bounds;
2470 composition_range_ = range;
Dave Tapuska04bc5ee92018-04-17 19:03:312471 if (mojom::WidgetInputHandlerHost* host =
2472 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
2473 host->ImeCompositionRangeChanged(composition_range_,
2474 composition_character_bounds_);
Dave Tapuska139a72f2017-09-06 21:57:032475 }
fsamuel72464894f2015-12-15 06:59:312476}
2477
Blink Reformat1c4d759e2017-04-09 16:34:542478void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
danakj4b347212018-07-04 17:55:172479 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:032480 float reverse = 1 / GetOriginalScreenInfo().device_scale_factor;
oshimad5279032015-12-16 18:22:332481 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:542482 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:462483 gfx::Rect window_rect =
2484 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
2485 rect->x = window_rect.x();
2486 rect->y = window_rect.y();
2487 rect->width = window_rect.width();
2488 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:542489 }
2490}
2491
Nicolás Peña Moreno1b3f3f912019-07-16 17:04:132492void RenderWidget::ConvertViewportToWindow(blink::WebFloatRect* rect) {
2493 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
2494 rect->x /= GetOriginalScreenInfo().device_scale_factor;
2495 rect->y /= GetOriginalScreenInfo().device_scale_factor;
2496 rect->width /= GetOriginalScreenInfo().device_scale_factor;
2497 rect->height /= GetOriginalScreenInfo().device_scale_factor;
2498 }
2499}
2500
Blink Reformat1c4d759e2017-04-09 16:34:542501void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
danakj4b347212018-07-04 17:55:172502 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:032503 rect->x *= GetOriginalScreenInfo().device_scale_factor;
2504 rect->y *= GetOriginalScreenInfo().device_scale_factor;
2505 rect->width *= GetOriginalScreenInfo().device_scale_factor;
2506 rect->height *= GetOriginalScreenInfo().device_scale_factor;
oshimaa6985b62016-01-27 08:58:302507 }
2508}
2509
changwan8c342742016-02-26 00:53:392510void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:262511#if defined(OS_ANDROID)
danakj125a29e2019-01-24 23:25:292512 // This task may run between the Close IPC and the task that actually closes
2513 // this class.
2514 if (closing_)
2515 return;
changwan8c342742016-02-26 00:53:392516 DCHECK(!ime_event_guard_);
2517 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:002518 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212519#endif
Dave Tapuska9db80842017-07-24 17:24:262520}
[email protected]105dffb42013-02-20 03:46:212521
ekaramadc9b70a72017-03-23 16:14:232522void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2523 bool monitor_updates) {
2524 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182525 if (!immediate_request)
2526 return;
2527 UpdateCompositionInfo(true /* immediate request */);
2528}
2529
[email protected]fcdc5642014-05-09 14:32:242530void RenderWidget::OnOrientationChange() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382531 if (auto* frame_widget = GetFrameWidget()) {
Alex Moshchuk0b409c42017-09-13 02:09:002532 // LocalRoot() might return null for provisional main frames. In this case,
2533 // the frame hasn't committed a navigation and is not swapped into the tree
2534 // yet, so it doesn't make sense to send orientation change events to it.
2535 //
2536 // TODO(https://crbug.com/578349): This check should be cleaned up
2537 // once provisional frames are gone.
Ehsan Karamad655d7b8a2018-01-12 18:38:382538 if (frame_widget->LocalRoot())
2539 frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302540 }
[email protected]fcdc5642014-05-09 14:32:242541}
2542
[email protected]bee16aab2009-08-26 15:55:032543void RenderWidget::SetHidden(bool hidden) {
danakj14e00a8322019-02-07 17:12:062544 // A frozen main frame widget does not become shown or hidden, since it has
2545 // no frame associated with it. It must be thawed before changing visibility.
2546 DCHECK(!is_frozen_);
2547
[email protected]bee16aab2009-08-26 15:55:032548 if (is_hidden_ == hidden)
2549 return;
2550
jdduke8fac9d102014-12-20 02:40:132551 // The status has changed. Tell the RenderThread about it and ensure
2552 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032553 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132554
Scott Violete3b1a3cb2019-05-02 16:51:522555 if (is_hidden_)
Aditya Keerthic0d45b42019-02-25 18:53:002556 first_update_visual_state_after_hidden_ = true;
alexclarke7fa93942015-10-21 15:37:112557
2558 if (render_widget_scheduling_state_)
2559 render_widget_scheduling_state_->SetHidden(hidden);
danakj1b35e9d2018-11-07 19:09:282560
David Bokanf92eaf22019-03-01 01:54:512561 // If the renderer was hidden, resolve any pending synthetic gestures so they
2562 // aren't blocked waiting for a compositor frame to be generated.
2563 if (is_hidden_)
2564 widget_input_handler_manager_->InvokeInputProcessedCallback();
2565
danakj14e00a8322019-02-07 17:12:062566 StartStopCompositor();
[email protected]bee16aab2009-08-26 15:55:032567}
2568
danakjf9284772019-01-23 18:29:142569void RenderWidget::SetIsFullscreen(bool fullscreen) {
Erik Chen15476cef2019-08-27 17:28:062570 // TODO:(https://crbug.com/995981): If there is no WebWidget, then the
2571 // RenderWidget should also be destroyed, and this conditional should not be
2572 // necessary.
2573 // We intentionally avoid setting internal state so that the next time visual
2574 // properties are synchronized, state will be correctly propagated to the
2575 // WebWidget.
2576 if (!GetWebWidget())
2577 return;
2578
danakjf9284772019-01-23 18:29:142579 if (fullscreen == is_fullscreen_granted_)
[email protected]2b624c562011-10-27 22:58:262580 return;
danakjf9284772019-01-23 18:29:142581 is_fullscreen_granted_ = fullscreen;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122582 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542583 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262584 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542585 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262586 }
[email protected]2b624c562011-10-27 22:58:262587}
2588
changwanf2a707b2015-10-30 08:22:162589void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2590 if (!ime_event_guard_)
2591 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292592}
2593
changwanf2a707b2015-10-30 08:22:162594void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
Jeremy Roman0b261f42018-08-28 15:36:012595 if (ime_event_guard_ != guard)
changwanf2a707b2015-10-30 08:22:162596 return;
changwanf2a707b2015-10-30 08:22:162597 ime_event_guard_ = nullptr;
2598
[email protected]66fca5bc2013-05-23 06:58:292599 // While handling an ime event, text input state and selection bounds updates
2600 // are ignored. These must explicitly be updated once finished handling the
2601 // ime event.
2602 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472603#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002604 if (guard->show_virtual_keyboard())
2605 ShowVirtualKeyboard();
2606 else
2607 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472608#endif
[email protected]66fca5bc2013-05-23 06:58:292609}
2610
[email protected]7c8873e2013-02-05 08:03:012611void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162612#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492613 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092614 // TODO(kinaba) http://crbug.com/101101
2615 // Current Pepper IME API does not handle selection bounds. So we simply
2616 // use the caret position as an empty range for now. It will be updated
2617 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492618 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542619 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092620 *focus = caret;
2621 *anchor = caret;
2622 return;
2623 }
2624#endif
[email protected]7c8873e2013-02-05 08:03:012625 WebRect focus_webrect;
2626 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542627 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2628 ConvertViewportToWindow(&focus_webrect);
2629 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242630 *focus = focus_webrect;
2631 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322632}
2633
[email protected]e99ef6f2011-10-16 01:13:002634void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082635 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212636 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002637 return;
changwanf2a707b2015-10-30 08:22:162638 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292639 return;
[email protected]e99ef6f2011-10-16 01:13:002640
mohsenb0eeba72015-08-09 06:20:082641#if defined(USE_AURA)
2642 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2643 // Aura beucause composited selection updates are not working for webview tags
2644 // which regresses IME inside webview. Remove this when composited selection
2645 // updates are fixed for webviews. See, http://crbug.com/510568.
2646 bool send_ipc = true;
2647#else
jddukeacf809e2014-09-23 20:38:382648 // With composited selection updates, the selection bounds will be reported
2649 // directly by the compositor, in which case explicit IPC selection
2650 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082651 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542652 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082653#endif
2654 if (send_ipc) {
Albert J. Wong3c93c182018-09-27 17:29:432655 WidgetHostMsg_SelectionBounds_Params params;
EhsanK955ba582017-11-30 21:14:402656 params.is_anchor_first = false;
jddukeacf809e2014-09-23 20:38:382657 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2658 if (selection_anchor_rect_ != params.anchor_rect ||
2659 selection_focus_rect_ != params.focus_rect) {
2660 selection_anchor_rect_ = params.anchor_rect;
2661 selection_focus_rect_ = params.focus_rect;
EhsanK955ba582017-11-30 21:14:402662 if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) {
2663 focused_frame->SelectionTextDirection(params.focus_dir,
2664 params.anchor_dir);
2665 params.is_anchor_first = focused_frame->IsSelectionAnchorFirst();
2666 }
Albert J. Wong3c93c182018-09-27 17:29:432667 Send(new WidgetHostMsg_SelectionBoundsChanged(routing_id_, params));
jddukeacf809e2014-09-23 20:38:382668 }
[email protected]58b48a0d2012-06-13 07:01:352669 }
jddukeacf809e2014-09-23 20:38:382670
nonafa291792016-08-10 02:36:182671 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002672}
2673
lfgb00fcad2016-07-14 14:16:332674void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
danakj125a29e2019-01-24 23:25:292675 // Blink can continue running and do a layout/resize between the Close IPC
2676 // and the task that actually closes this class.
2677 if (closing_)
2678 return;
2679
lfgb00fcad2016-07-14 14:16:332680 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542681 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332682 if (size_.width() != new_size_in_window.width ||
2683 size_.height() != new_size_in_window.height) {
2684 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2685
danakj7602f4f2019-01-31 18:03:232686 if (synchronous_resize_mode_for_testing_) {
Blink Reformat1c4d759e2017-04-09 16:34:542687 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2688 size_.height());
Albert J. Wong3c93c182018-09-27 17:29:432689 widget_screen_rect_ = new_pos;
lfgb00fcad2016-07-14 14:16:332690 window_screen_rect_ = new_pos;
2691 }
2692
Christopher Camerone9a30c12018-03-07 08:23:382693 // TODO(ccameron): Note that this destroys any information differentiating
danakj9c4e7b812019-02-19 22:04:272694 // |size_| from the compositor's viewport size. Also note that the
Christopher Cameronaad15a0d2018-03-09 03:47:332695 // calculation of |new_compositor_viewport_pixel_size| does not appear to
2696 // take into account device emulation.
danakj125a29e2019-01-24 23:25:292697 layer_tree_view_->RequestNewLocalSurfaceId();
Christopher Cameronaad15a0d2018-03-09 03:47:332698 gfx::Size new_compositor_viewport_pixel_size =
Fady Samuela863f152018-03-09 16:10:032699 gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor);
Fady Samuel1c1ad3692018-11-06 23:28:402700 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
2701 new_compositor_viewport_pixel_size,
2702 screen_info_);
lfgb00fcad2016-07-14 14:16:332703 }
2704}
2705
[email protected]58b48a0d2012-06-13 07:01:352706void RenderWidget::GetCompositionCharacterBounds(
2707 std::vector<gfx::Rect>* bounds) {
2708 DCHECK(bounds);
2709 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092710
brettw4b461082016-11-19 18:55:162711#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492712 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092713 return;
2714#endif
2715
Ehsan Karamad4975af6d2018-02-09 16:58:162716 blink::WebInputMethodController* controller = GetInputMethodController();
2717 if (!controller)
ekaramad2a46d632016-07-19 13:33:092718 return;
2719 blink::WebVector<blink::WebRect> bounds_from_blink;
Ehsan Karamad4975af6d2018-02-09 16:58:162720 if (!controller->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092721 return;
2722
2723 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542724 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092725 bounds->push_back(bounds_from_blink[i]);
2726 }
[email protected]58b48a0d2012-06-13 07:01:352727}
2728
[email protected]db4fc1e2013-09-06 20:01:512729void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162730#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492731 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092732 return;
2733#endif
EhsanKcdee7b72017-11-08 21:30:092734 blink::WebInputMethodController* controller = GetInputMethodController();
2735 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542736 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212737 *range = gfx::Range::InvalidRange();
2738 return;
[email protected]88dbe32f2013-06-20 23:31:362739 }
Blink Reformat1c4d759e2017-04-09 16:34:542740 range->set_start(web_range.StartOffset());
2741 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362742}
2743
[email protected]501ea13d2013-07-09 17:03:292744bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512745 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292746 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082747 if (!range.IsValid())
2748 return false;
[email protected]501ea13d2013-07-09 17:03:292749 if (composition_range_ != range)
2750 return true;
2751 if (bounds.size() != composition_character_bounds_.size())
2752 return true;
2753 for (size_t i = 0; i < bounds.size(); ++i) {
2754 if (bounds[i] != composition_character_bounds_[i])
2755 return true;
2756 }
2757 return false;
2758}
[email protected]501ea13d2013-07-09 17:03:292759
[email protected]ad26ef42011-06-17 07:59:452760bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162761#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492762 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2763 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092764#endif
[email protected]ad26ef42011-06-17 07:59:452765 return true;
[email protected]56ea1a62011-05-30 07:05:572766}
2767
Blink Reformat1c4d759e2017-04-09 16:34:542768void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2769 bool event_cancelled) {
danakja2c9d0a92018-07-25 20:01:182770 if (event_cancelled) {
Albert J. Wong7bbf22d2018-12-20 00:27:272771 // The delegate() doesn't need to hear about cancelled events.
[email protected]c68c3e4e2013-01-24 00:36:562772 return;
danakja2c9d0a92018-07-25 20:01:182773 }
2774
2775#if defined(OS_ANDROID) || defined(USE_AURA)
Blink Reformat1c4d759e2017-04-09 16:34:542776 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002777 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542778 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212779 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352780 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542781 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002782 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462783 else
changwan75e3b2072017-01-16 02:55:002784 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562785 }
ekaramada110f642016-12-21 19:47:282786// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2787// crbug/420130.
2788#if defined(OS_WIN)
danakja2c9d0a92018-07-25 20:01:182789 if (event.GetType() == blink::WebGestureEvent::kGestureTap) {
2790 // TODO(estade): hit test the event against focused node to make sure
2791 // the tap actually hit the focused node.
2792 blink::WebInputMethodController* controller = GetInputMethodController();
2793 blink::WebTextInputType text_input_type =
2794 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282795
Albert J. Wong3c93c182018-09-27 17:29:432796 Send(new WidgetHostMsg_FocusedNodeTouched(
danakja2c9d0a92018-07-25 20:01:182797 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
2798 }
ekaramada110f642016-12-21 19:47:282799#endif
[email protected]c68c3e4e2013-01-24 00:36:562800#endif
[email protected]c68c3e4e2013-01-24 00:36:562801}
2802
Blink Reformat1c4d759e2017-04-09 16:34:542803void RenderWidget::DidOverscroll(
danakj1b05cf22019-04-12 23:47:052804 const blink::WebFloatSize& overscroll_delta,
2805 const blink::WebFloatSize& accumulated_overscroll,
sataya.m582c9ce2015-06-09 08:03:422806 const blink::WebFloatPoint& position,
danakj1b05cf22019-04-12 23:47:052807 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482808#if defined(OS_MACOSX)
2809 // On OSX the user can disable the elastic overscroll effect. If that's the
2810 // case, don't forward the overscroll notification.
2811 DCHECK(compositor_deps());
2812 if (!compositor_deps()->IsElasticOverscrollEnabled())
2813 return;
2814#endif
danakj1b05cf22019-04-12 23:47:052815 input_handler_->DidOverscrollFromBlink(
2816 overscroll_delta, accumulated_overscroll, position, velocity,
2817 layer_tree_view_->layer_tree_host()->overscroll_behavior());
2818}
2819
Daniel Libby688fcb52019-05-25 01:08:472820void RenderWidget::InjectGestureScrollEvent(
2821 blink::WebGestureDevice device,
2822 const blink::WebFloatSize& delta,
2823 ui::input_types::ScrollGranularity granularity,
2824 cc::ElementId scrollable_area_element_id,
2825 blink::WebInputEvent::Type injected_type) {
2826 input_handler_->InjectGestureScrollEvent(
2827 device, delta, granularity, scrollable_area_element_id, injected_type);
2828}
2829
danakj1b05cf22019-04-12 23:47:052830void RenderWidget::SetOverscrollBehavior(
2831 const cc::OverscrollBehavior& behavior) {
2832 layer_tree_view_->layer_tree_host()->SetOverscrollBehavior(behavior);
sataya.m582c9ce2015-06-09 08:03:422833}
2834
danakj4b347212018-07-04 17:55:172835// static
2836cc::LayerTreeSettings RenderWidget::GenerateLayerTreeSettings(
2837 CompositorDependencies* compositor_deps,
2838 bool is_for_subframe,
2839 const gfx::Size& initial_screen_size,
2840 float initial_device_scale_factor) {
2841 const bool is_threaded =
2842 !!compositor_deps->GetCompositorImplThreadTaskRunner();
2843
2844 const base::CommandLine& cmd = *base::CommandLine::ForCurrentProcess();
2845 cc::LayerTreeSettings settings;
2846
Rahul Arakerie510b8c2019-04-01 21:17:542847 settings.compositor_threaded_scrollbar_scrolling =
2848 base::FeatureList::IsEnabled(
2849 features::kCompositorThreadedScrollbarScrolling);
2850
danakj4b347212018-07-04 17:55:172851 settings.resource_settings.use_r16_texture =
2852 base::FeatureList::IsEnabled(media::kUseR16Texture);
2853
2854 settings.commit_to_active_tree = !is_threaded;
2855 settings.is_layer_tree_for_subframe = is_for_subframe;
2856
danakj4b347212018-07-04 17:55:172857 settings.main_frame_before_activation_enabled =
2858 cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation);
2859
2860 // Checkerimaging is not supported for synchronous single-threaded mode, which
2861 // is what the renderer uses if its not threaded.
2862 settings.enable_checker_imaging =
2863 !cmd.HasSwitch(cc::switches::kDisableCheckerImaging) && is_threaded;
2864
2865#if defined(OS_ANDROID)
2866 // We can use a more aggressive limit on Android since decodes tend to take
2867 // longer on these devices.
2868 settings.min_image_bytes_to_checker = 512 * 1024; // 512kB
2869
2870 // Re-rasterization of checker-imaged content with software raster can be too
2871 // costly on Android.
2872 settings.only_checker_images_with_gpu_raster = true;
2873#endif
2874
2875 auto switch_value_as_int = [](const base::CommandLine& command_line,
2876 const std::string& switch_string, int min_value,
2877 int max_value, int* result) {
2878 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
2879 int int_value;
2880 if (base::StringToInt(string_value, &int_value) && int_value >= min_value &&
2881 int_value <= max_value) {
2882 *result = int_value;
2883 return true;
2884 } else {
danakjda15621e2019-04-05 20:34:432885 DLOG(WARNING) << "Failed to parse switch " << switch_string << ": "
2886 << string_value;
danakj4b347212018-07-04 17:55:172887 return false;
2888 }
2889 };
2890
2891 int default_tile_size = 256;
2892#if defined(OS_ANDROID)
2893 const gfx::Size screen_size =
2894 gfx::ScaleToFlooredSize(initial_screen_size, initial_device_scale_factor);
2895 int display_width = screen_size.width();
2896 int display_height = screen_size.height();
2897 int numTiles = (display_width * display_height) / (256 * 256);
2898 if (numTiles > 16)
2899 default_tile_size = 384;
2900 if (numTiles >= 40)
2901 default_tile_size = 512;
2902
2903 // Adjust for some resolutions that barely straddle an extra
2904 // tile when in portrait mode. This helps worst case scroll/raster
2905 // by not needing a full extra tile for each row.
2906 constexpr int tolerance = 10; // To avoid rounding errors.
2907 int portrait_width = std::min(display_width, display_height);
2908 if (default_tile_size == 256 && std::abs(portrait_width - 768) < tolerance)
2909 default_tile_size += 32;
2910 if (default_tile_size == 384 && std::abs(portrait_width - 1200) < tolerance)
2911 default_tile_size += 32;
2912#elif defined(OS_CHROMEOS) || defined(OS_MACOSX)
2913 // Use 512 for high DPI (dsf=2.0f) devices.
2914 if (initial_device_scale_factor >= 2.0f)
2915 default_tile_size = 512;
2916#endif
2917
2918 // TODO(danakj): This should not be a setting O_O; it should change when the
2919 // device scale factor on LayerTreeHost changes.
2920 settings.default_tile_size = gfx::Size(default_tile_size, default_tile_size);
2921 if (cmd.HasSwitch(switches::kDefaultTileWidth)) {
2922 int tile_width = 0;
2923 switch_value_as_int(cmd, switches::kDefaultTileWidth, 1,
2924 std::numeric_limits<int>::max(), &tile_width);
2925 settings.default_tile_size.set_width(tile_width);
2926 }
2927 if (cmd.HasSwitch(switches::kDefaultTileHeight)) {
2928 int tile_height = 0;
2929 switch_value_as_int(cmd, switches::kDefaultTileHeight, 1,
2930 std::numeric_limits<int>::max(), &tile_height);
2931 settings.default_tile_size.set_height(tile_height);
2932 }
2933
2934 int max_untiled_layer_width = settings.max_untiled_layer_size.width();
2935 if (cmd.HasSwitch(switches::kMaxUntiledLayerWidth)) {
2936 switch_value_as_int(cmd, switches::kMaxUntiledLayerWidth, 1,
2937 std::numeric_limits<int>::max(),
2938 &max_untiled_layer_width);
2939 }
2940 int max_untiled_layer_height = settings.max_untiled_layer_size.height();
2941 if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) {
2942 switch_value_as_int(cmd, switches::kMaxUntiledLayerHeight, 1,
2943 std::numeric_limits<int>::max(),
2944 &max_untiled_layer_height);
2945 }
2946
2947 settings.max_untiled_layer_size =
2948 gfx::Size(max_untiled_layer_width, max_untiled_layer_height);
2949
2950 settings.gpu_rasterization_msaa_sample_count =
2951 compositor_deps->GetGpuRasterizationMSAASampleCount();
2952 settings.gpu_rasterization_forced =
2953 compositor_deps->IsGpuRasterizationForced();
2954
2955 settings.can_use_lcd_text = compositor_deps->IsLcdTextEnabled();
2956 settings.use_zero_copy = compositor_deps->IsZeroCopyEnabled();
2957 settings.use_partial_raster = compositor_deps->IsPartialRasterEnabled();
2958 settings.enable_elastic_overscroll =
2959 compositor_deps->IsElasticOverscrollEnabled();
2960 settings.resource_settings.use_gpu_memory_buffer_resources =
2961 compositor_deps->IsGpuMemoryBufferCompositorResourcesEnabled();
2962 settings.use_painted_device_scale_factor =
2963 compositor_deps->IsUseZoomForDSFEnabled();
2964
2965 // Build LayerTreeSettings from command line args.
2966 if (cmd.HasSwitch(cc::switches::kBrowserControlsShowThreshold)) {
2967 std::string top_threshold_str =
2968 cmd.GetSwitchValueASCII(cc::switches::kBrowserControlsShowThreshold);
2969 double show_threshold;
2970 if (base::StringToDouble(top_threshold_str, &show_threshold) &&
2971 show_threshold >= 0.f && show_threshold <= 1.f)
2972 settings.top_controls_show_threshold = show_threshold;
2973 }
2974
2975 if (cmd.HasSwitch(cc::switches::kBrowserControlsHideThreshold)) {
2976 std::string top_threshold_str =
2977 cmd.GetSwitchValueASCII(cc::switches::kBrowserControlsHideThreshold);
2978 double hide_threshold;
2979 if (base::StringToDouble(top_threshold_str, &hide_threshold) &&
2980 hide_threshold >= 0.f && hide_threshold <= 1.f)
2981 settings.top_controls_hide_threshold = hide_threshold;
2982 }
2983
Philip Rogers848424a2019-08-14 18:19:592984 // Blink sends cc a layer list and property trees.
2985 settings.use_layer_lists = true;
danakj4b347212018-07-04 17:55:172986
David Bokan163b6a72018-10-25 22:03:492987 // Blink currently doesn't support setting fractional scroll offsets so CC
2988 // must send integer values. We plan to eventually make Blink use fractional
2989 // offsets internally: https://crbug.com/414283.
2990 settings.commit_fractional_scroll_deltas =
2991 blink::WebRuntimeFeatures::IsFractionalScrollOffsetsEnabled();
2992
danakj4b347212018-07-04 17:55:172993 // The means the renderer compositor has 2 possible modes:
2994 // - Threaded compositing with a scheduler.
Kent Tamura21d1de62018-12-10 04:45:202995 // - Single threaded compositing without a scheduler (for web tests only).
2996 // Using the scheduler in web tests introduces additional composite steps
danakj4b347212018-07-04 17:55:172997 // that create flakiness.
2998 settings.single_thread_proxy_scheduler = false;
2999
3000 // These flags should be mirrored by UI versions in ui/compositor/.
3001 if (cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders))
3002 settings.initial_debug_state.show_debug_borders.set();
3003 settings.initial_debug_state.show_layer_animation_bounds_rects =
3004 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds);
3005 settings.initial_debug_state.show_paint_rects =
3006 cmd.HasSwitch(switches::kShowPaintRects);
rnasri2e621942019-05-14 21:24:253007 settings.initial_debug_state.show_layout_shift_regions =
3008 cmd.HasSwitch(switches::kShowLayoutShiftRegions);
danakj4b347212018-07-04 17:55:173009 settings.initial_debug_state.show_property_changed_rects =
3010 cmd.HasSwitch(cc::switches::kShowPropertyChangedRects);
3011 settings.initial_debug_state.show_surface_damage_rects =
3012 cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects);
3013 settings.initial_debug_state.show_screen_space_rects =
3014 cmd.HasSwitch(cc::switches::kShowScreenSpaceRects);
3015
3016 settings.initial_debug_state.SetRecordRenderingStats(
3017 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking));
kylechara352d2d12019-08-15 19:11:413018 settings.enable_surface_synchronization = true;
danakj4b347212018-07-04 17:55:173019 settings.build_hit_test_data = features::IsVizHitTestingSurfaceLayerEnabled();
3020
3021 if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) {
3022 const int kMinSlowDownScaleFactor = 0;
3023 const int kMaxSlowDownScaleFactor = INT_MAX;
3024 switch_value_as_int(
3025 cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor,
3026 kMaxSlowDownScaleFactor,
3027 &settings.initial_debug_state.slow_down_raster_scale_factor);
3028 }
3029
3030 // This is default overlay scrollbar settings for Android and DevTools mobile
3031 // emulator. Aura Overlay Scrollbar will override below.
3032 settings.scrollbar_animator = cc::LayerTreeSettings::ANDROID_OVERLAY;
3033 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
3034 settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(300);
3035 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
3036
Daniel Libby43972d82019-02-28 21:35:363037 if (cmd.HasSwitch(cc::switches::kCCScrollAnimationDurationForTesting)) {
3038 const int kMinScrollAnimationDuration = 0;
3039 const int kMaxScrollAnimationDuration = INT_MAX;
3040 int duration;
3041 if (switch_value_as_int(cmd,
3042 cc::switches::kCCScrollAnimationDurationForTesting,
3043 kMinScrollAnimationDuration,
3044 kMaxScrollAnimationDuration, &duration)) {
3045 settings.scroll_animation_duration_for_testing =
3046 base::TimeDelta::FromSeconds(duration);
3047 }
3048 }
3049
danakj4b347212018-07-04 17:55:173050#if defined(OS_ANDROID)
3051 bool using_synchronous_compositor =
3052 compositor_deps->UsingSynchronousCompositing();
Ian Vollick7a847a82019-06-14 19:58:593053 bool using_low_memory_policy =
3054 base::SysInfo::IsLowEndDevice() && !IsSmallScreen(screen_size);
danakj4b347212018-07-04 17:55:173055
3056 settings.use_stream_video_draw_quad = true;
3057 settings.using_synchronous_renderer_compositor = using_synchronous_compositor;
3058 if (using_synchronous_compositor) {
3059 // Android WebView uses system scrollbars, so make ours invisible.
3060 // http://crbug.com/677348: This can't be done using hide_scrollbars
3061 // setting because supporting -webkit custom scrollbars is still desired
3062 // on sublayers.
3063 settings.scrollbar_animator = cc::LayerTreeSettings::NO_ANIMATOR;
3064 settings.solid_color_scrollbar_color = SK_ColorTRANSPARENT;
3065
3066 settings.enable_early_damage_check =
3067 cmd.HasSwitch(cc::switches::kCheckDamageEarly);
3068 }
3069 // Android WebView handles root layer flings itself.
3070 settings.ignore_root_layer_flings = using_synchronous_compositor;
3071 // Memory policy on Android WebView does not depend on whether device is
3072 // low end, so always use default policy.
3073 if (using_low_memory_policy && !using_synchronous_compositor) {
3074 // On low-end we want to be very carefull about killing other
3075 // apps. So initially we use 50% more memory to avoid flickering
3076 // or raster-on-demand.
3077 settings.max_memory_for_prepaint_percentage = 67;
3078 } else {
3079 // On other devices we have increased memory excessively to avoid
3080 // raster-on-demand already, so now we reserve 50% _only_ to avoid
3081 // raster-on-demand, and use 50% of the memory otherwise.
3082 settings.max_memory_for_prepaint_percentage = 50;
3083 }
3084
3085 // TODO(danakj): Only do this on low end devices.
3086 settings.create_low_res_tiling = true;
3087
3088#else // defined(OS_ANDROID)
3089 bool using_synchronous_compositor = false; // Only for Android WebView.
3090 // On desktop, we never use the low memory policy unless we are simulating
3091 // low-end mode via a switch.
3092 bool using_low_memory_policy =
3093 cmd.HasSwitch(switches::kEnableLowEndDeviceMode);
3094
3095 if (ui::IsOverlayScrollbarEnabled()) {
3096 settings.scrollbar_animator = cc::LayerTreeSettings::AURA_OVERLAY;
3097 settings.scrollbar_fade_delay = ui::kOverlayScrollbarFadeDelay;
3098 settings.scrollbar_fade_duration = ui::kOverlayScrollbarFadeDuration;
3099 settings.scrollbar_thinning_duration =
3100 ui::kOverlayScrollbarThinningDuration;
3101 settings.scrollbar_flash_after_any_scroll_update =
3102 ui::OverlayScrollbarFlashAfterAnyScrollUpdate();
3103 settings.scrollbar_flash_when_mouse_enter =
3104 ui::OverlayScrollbarFlashWhenMouseEnter();
3105 }
3106
3107 // On desktop, if there's over 4GB of memory on the machine, increase the
3108 // working set size to 256MB for both gpu and software.
3109 const int kImageDecodeMemoryThresholdMB = 4 * 1024;
3110 if (base::SysInfo::AmountOfPhysicalMemoryMB() >=
3111 kImageDecodeMemoryThresholdMB) {
3112 settings.decoded_image_working_set_budget_bytes = 256 * 1024 * 1024;
3113 } else {
3114 // This is the default, but recorded here as well.
3115 settings.decoded_image_working_set_budget_bytes = 128 * 1024 * 1024;
3116 }
3117#endif // defined(OS_ANDROID)
3118
3119 if (using_low_memory_policy) {
3120 // RGBA_4444 textures are only enabled:
3121 // - If the user hasn't explicitly disabled them
3122 // - If system ram is <= 512MB (1GB devices are sometimes low-end).
3123 // - If we are not running in a WebView, where 4444 isn't supported.
3124 if (!cmd.HasSwitch(switches::kDisableRGBA4444Textures) &&
3125 base::SysInfo::AmountOfPhysicalMemoryMB() <= 512 &&
3126 !using_synchronous_compositor) {
3127 settings.use_rgba_4444 = viz::RGBA_4444;
3128
3129 // If we are going to unpremultiply and dither these tiles, we need to
3130 // allocate an additional RGBA_8888 intermediate for each tile
3131 // rasterization when rastering to RGBA_4444 to allow for dithering.
3132 // Setting a reasonable sized max tile size allows this intermediate to
3133 // be consistently reused.
3134 if (base::FeatureList::IsEnabled(
3135 kUnpremultiplyAndDitherLowBitDepthTiles)) {
3136 settings.max_gpu_raster_tile_size = gfx::Size(512, 256);
3137 settings.unpremultiply_and_dither_low_bit_depth_tiles = true;
3138 }
3139 }
3140 }
3141
3142 if (cmd.HasSwitch(switches::kEnableLowResTiling))
3143 settings.create_low_res_tiling = true;
3144 if (cmd.HasSwitch(switches::kDisableLowResTiling))
3145 settings.create_low_res_tiling = false;
3146
3147 if (cmd.HasSwitch(switches::kEnableRGBA4444Textures) &&
3148 !cmd.HasSwitch(switches::kDisableRGBA4444Textures)) {
3149 settings.use_rgba_4444 = true;
3150 }
3151
3152 settings.max_staging_buffer_usage_in_bytes = 32 * 1024 * 1024; // 32MB
3153 // Use 1/4th of staging buffers on low-end devices.
3154 if (base::SysInfo::IsLowEndDevice())
3155 settings.max_staging_buffer_usage_in_bytes /= 4;
3156
3157 cc::ManagedMemoryPolicy defaults = settings.memory_policy;
3158 settings.memory_policy = GetGpuMemoryPolicy(defaults, initial_screen_size,
3159 initial_device_scale_factor);
3160
3161 settings.disallow_non_exact_resource_reuse =
3162 cmd.HasSwitch(switches::kDisallowNonExactResourceReuse);
3163#if defined(OS_ANDROID)
3164 // TODO(crbug.com/746931): This feature appears to be causing visual
3165 // corruption on certain android devices. Will investigate and re-enable.
3166 settings.disallow_non_exact_resource_reuse = true;
3167#endif
3168
3169 if (cmd.HasSwitch(switches::kRunAllCompositorStagesBeforeDraw)) {
3170 settings.wait_for_all_pipeline_stages_before_draw = true;
3171 settings.enable_latency_recovery = false;
3172 }
Eric Karl1e6ffca2019-02-23 22:08:503173#if defined(OS_ANDROID)
kylechara352d2d12019-08-15 19:11:413174 // TODO(crbug.com/933846): LatencyRecovery is causing jank on Android. Disable
3175 // in viz mode for now, with plan to disable more widely once viz launches.
3176 settings.enable_latency_recovery = false;
Eric Karl1e6ffca2019-02-23 22:08:503177#endif
danakj4b347212018-07-04 17:55:173178
3179 settings.enable_image_animation_resync =
3180 !cmd.HasSwitch(switches::kDisableImageAnimationResync);
3181
Karolina Soltys4d60b402018-10-01 19:28:203182 settings.send_compositor_frame_ack = false;
3183
danakj4b347212018-07-04 17:55:173184 return settings;
3185}
3186
3187// static
3188cc::ManagedMemoryPolicy RenderWidget::GetGpuMemoryPolicy(
3189 const cc::ManagedMemoryPolicy& default_policy,
3190 const gfx::Size& initial_screen_size,
3191 float initial_device_scale_factor) {
3192 cc::ManagedMemoryPolicy actual = default_policy;
3193 actual.bytes_limit_when_visible = 0;
3194
3195 // If the value was overridden on the command line, use the specified value.
3196 static bool client_hard_limit_bytes_overridden =
3197 base::CommandLine::ForCurrentProcess()->HasSwitch(
3198 switches::kForceGpuMemAvailableMb);
3199 if (client_hard_limit_bytes_overridden) {
3200 if (base::StringToSizeT(
3201 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3202 switches::kForceGpuMemAvailableMb),
3203 &actual.bytes_limit_when_visible))
3204 actual.bytes_limit_when_visible *= 1024 * 1024;
3205 return actual;
3206 }
3207
3208#if defined(OS_ANDROID)
3209 // We can't query available GPU memory from the system on Android.
3210 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports
3211 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports
3212 // 128MB java heap size). First we estimate physical memory using both.
3213 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB();
3214 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB();
3215 size_t physical_memory_mb = 0;
3216 if (base::SysInfo::IsLowEndDevice()) {
3217 // TODO(crbug.com/742534): The code below appears to no longer work.
3218 // |dalvik_mb| no longer follows the expected heuristic pattern, causing us
3219 // to over-estimate memory on low-end devices. This entire section probably
3220 // needs to be re-written, but for now we can address the low-end Android
3221 // issues by ignoring |dalvik_mb|.
3222 physical_memory_mb = physical_mb;
3223 } else if (dalvik_mb >= 256) {
3224 physical_memory_mb = dalvik_mb * 4;
3225 } else {
3226 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3);
3227 }
3228
3229 // Now we take a default of 1/8th of memory on high-memory devices,
3230 // and gradually scale that back for low-memory devices (to be nicer
3231 // to other apps so they don't get killed). Examples:
3232 // Nexus 4/10(2GB) 256MB (normally 128MB)
3233 // Droid Razr M(1GB) 114MB (normally 57MB)
3234 // Galaxy Nexus(1GB) 100MB (normally 50MB)
3235 // Xoom(1GB) 100MB (normally 50MB)
3236 // Nexus S(low-end) 8MB (normally 8MB)
3237 // Note that the compositor now uses only some of this memory for
3238 // pre-painting and uses the rest only for 'emergencies'.
3239 if (actual.bytes_limit_when_visible == 0) {
3240 // NOTE: Non-low-end devices use only 50% of these limits,
3241 // except during 'emergencies' where 100% can be used.
3242 if (physical_memory_mb >= 1536)
3243 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB
3244 else if (physical_memory_mb >= 1152)
3245 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB
3246 else if (physical_memory_mb >= 768)
3247 actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB
3248 else if (physical_memory_mb >= 513)
3249 actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB
3250 else
3251 // Devices with this little RAM have very little headroom so we hardcode
3252 // the limit rather than relying on the heuristics above. (They also use
3253 // 4444 textures so we can use a lower limit.)
3254 actual.bytes_limit_when_visible = 8;
3255
3256 actual.bytes_limit_when_visible =
3257 actual.bytes_limit_when_visible * 1024 * 1024;
3258 // Clamp the observed value to a specific range on Android.
3259 actual.bytes_limit_when_visible = std::max(
3260 actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024));
3261 actual.bytes_limit_when_visible =
3262 std::min(actual.bytes_limit_when_visible,
3263 static_cast<size_t>(256 * 1024 * 1024));
3264 }
3265 actual.priority_cutoff_when_visible =
3266 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING;
3267#else
3268 // Ignore what the system said and give all clients the same maximum
3269 // allocation on desktop platforms.
3270 actual.bytes_limit_when_visible = 512 * 1024 * 1024;
3271 actual.priority_cutoff_when_visible =
3272 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
3273
3274 // For large monitors (4k), double the tile memory to avoid frequent out of
3275 // memory problems. 4k could mean a screen width of anywhere from 3840 to 4096
3276 // (see https://en.wikipedia.org/wiki/4K_resolution). We use 3500 as a proxy
3277 // for "large enough".
3278 static const int kLargeDisplayThreshold = 3500;
3279 int display_width =
3280 std::round(initial_screen_size.width() * initial_device_scale_factor);
3281 if (display_width >= kLargeDisplayThreshold)
3282 actual.bytes_limit_when_visible *= 2;
3283#endif
3284 return actual;
3285}
3286
danakj2e87fd82019-07-05 16:42:293287void RenderWidget::SetHasPointerRawUpdateEventHandlers(bool has_handlers) {
Navid Zolghadr8fdb6114e2018-08-29 19:00:543288 if (input_event_queue_)
Navid Zolghadr4ed3ae42019-05-03 17:02:123289 input_event_queue_->HasPointerRawUpdateEventHandlers(has_handlers);
Navid Zolghadr8fdb6114e2018-08-29 19:00:543290}
3291
danakj2e87fd82019-07-05 16:42:293292void RenderWidget::SetHasTouchEventHandlers(bool has_handlers) {
W. James MacLean662d5382018-03-29 18:33:083293 if (has_touch_handlers_ && *has_touch_handlers_ == has_handlers)
3294 return;
3295
3296 has_touch_handlers_ = has_handlers;
alexclarke7fa93942015-10-21 15:37:113297 if (render_widget_scheduling_state_)
3298 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
Albert J. Wongeb28e7e2018-10-12 00:57:433299 Send(new WidgetHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
[email protected]ce6689f2013-03-29 12:52:553300}
3301
danakj4645c022019-07-23 18:15:263302void RenderWidget::SetHaveScrollEventHandlers(bool have_handlers) {
3303 layer_tree_view_->layer_tree_host()->SetHaveScrollEventHandlers(
3304 have_handlers);
3305}
3306
Dave Tapuskadfe486c12017-06-09 16:53:133307void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
3308 if (input_event_queue_)
3309 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
3310}
3311
Pavel Feldman6708eefa2019-01-17 03:14:323312void RenderWidget::SetNeedsUnbufferedInputForDebugger(bool unbuffered) {
3313 if (input_event_queue_)
3314 input_event_queue_->SetNeedsUnbufferedInputForDebugger(unbuffered);
3315}
3316
W. James MacLeand973a55b2018-11-29 21:39:133317void RenderWidget::AnimateDoubleTapZoomInMainFrame(
3318 const blink::WebPoint& point,
3319 const blink::WebRect& rect_to_zoom) {
3320 // Only oopif subframes should be sending this message.
Albert J. Wong7bbf22d2018-12-20 00:27:273321 DCHECK(!delegate());
W. James MacLeand973a55b2018-11-29 21:39:133322 Send(new WidgetHostMsg_AnimateDoubleTapZoomInMainFrame(routing_id(), point,
3323 rect_to_zoom));
3324}
3325
W. James MacLean5372eb72018-12-19 12:56:363326void RenderWidget::ZoomToFindInPageRectInMainFrame(
3327 const blink::WebRect& rect_to_zoom) {
3328 // Only oopif subframes should be sending this message.
Albert J. Wong7bbf22d2018-12-20 00:27:273329 DCHECK(!delegate_);
W. James MacLean5372eb72018-12-19 12:56:363330 Send(new WidgetHostMsg_ZoomToFindInPageRectInMainFrame(routing_id(),
3331 rect_to_zoom));
3332}
3333
danakj4886cad2019-02-26 22:15:563334void RenderWidget::RegisterViewportLayers(const cc::ViewportLayers& layers) {
3335 layer_tree_view_->layer_tree_host()->RegisterViewportLayers(layers);
3336}
3337
3338void RenderWidget::RegisterSelection(const cc::LayerSelection& selection) {
3339 layer_tree_view_->layer_tree_host()->RegisterSelection(selection);
3340}
3341
chaopeng161241b72019-03-21 18:25:173342void RenderWidget::FallbackCursorModeLockCursor(bool left,
3343 bool right,
3344 bool up,
3345 bool down) {
3346 widget_input_handler_manager_->FallbackCursorModeLockCursor(left, right, up,
3347 down);
3348}
3349
3350void RenderWidget::FallbackCursorModeSetCursorVisibility(bool visible) {
3351 widget_input_handler_manager_->FallbackCursorModeSetCursorVisibility(visible);
3352}
3353
danakj35c203a2019-04-16 17:12:393354void RenderWidget::SetAllowGpuRasterization(bool allow_gpu_raster) {
3355 layer_tree_view_->layer_tree_host()->SetHasGpuRasterizationTrigger(
3356 allow_gpu_raster);
3357}
3358
W. James MacLean233a64ff2019-05-18 16:18:493359void RenderWidget::SetPageScaleStateAndLimits(float page_scale_factor,
3360 bool is_pinch_gesture_active,
3361 float minimum,
3362 float maximum) {
danakj77821e252019-03-27 19:58:043363 layer_tree_view_->layer_tree_host()->SetPageScaleFactorAndLimits(
3364 page_scale_factor, minimum, maximum);
W. James MacLean233a64ff2019-05-18 16:18:493365
3366 // Only continue if this is a mainframe, or something's actually changed.
3367 if (!delegate() ||
3368 (page_scale_factor == page_scale_factor_from_mainframe_ &&
3369 is_pinch_gesture_active == is_pinch_gesture_active_from_mainframe_)) {
3370 return;
3371 }
3372
3373 // The page scale is controlled by the WebView for the local main frame of
3374 // the Page. So this is called from blink by for the RenderWidget of that
3375 // local main frame. We forward the value on to each child RenderWidget (each
3376 // of which will be via proxy child frame). These will each in turn forward
3377 // the message to their child RenderWidgets (through their proxy child
3378 // frames).
3379 DCHECK(!is_frozen_);
3380
3381 for (auto& observer : render_frame_proxies_) {
3382 observer.OnPageScaleFactorChanged(page_scale_factor,
3383 is_pinch_gesture_active);
3384 }
3385 // Store the value to give to any new RenderFrameProxy that is registered.
3386 page_scale_factor_from_mainframe_ = page_scale_factor;
3387 is_pinch_gesture_active_from_mainframe_ = is_pinch_gesture_active;
danakj77821e252019-03-27 19:58:043388}
3389
3390void RenderWidget::StartPageScaleAnimation(const gfx::Vector2d& target_offset,
3391 bool use_anchor,
3392 float new_page_scale,
Sergio Villar Senin2127d7b2019-07-31 17:29:583393 base::TimeDelta duration) {
danakj77821e252019-03-27 19:58:043394 layer_tree_view_->layer_tree_host()->StartPageScaleAnimation(
3395 target_offset, use_anchor, new_page_scale, duration);
3396}
3397
danakjd92cf59a42019-07-23 15:22:513398void RenderWidget::ForceRecalculateRasterScales() {
3399 layer_tree_view_->layer_tree_host()->SetNeedsRecalculateRasterScales();
3400}
3401
danakjda15621e2019-04-05 20:34:433402void RenderWidget::RequestDecode(const cc::PaintImage& image,
3403 base::OnceCallback<void(bool)> callback) {
3404 layer_tree_view_->layer_tree_host()->QueueImageDecode(image,
3405 std::move(callback));
3406}
3407
danakj2d2889a2019-04-05 21:22:083408// Enables measuring and reporting both presentation times and swap times in
3409// swap promises.
3410class ReportTimeSwapPromise : public cc::SwapPromise {
3411 using ReportTimeCallback = blink::WebWidgetClient::ReportTimeCallback;
3412
3413 public:
Mohsen Izadid6715832019-06-05 00:32:513414 ReportTimeSwapPromise(ReportTimeCallback swap_time_callback,
3415 ReportTimeCallback presentation_time_callback,
danakj2d2889a2019-04-05 21:22:083416 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
3417 base::WeakPtr<RenderWidget> render_widget)
Mohsen Izadid6715832019-06-05 00:32:513418 : swap_time_callback_(std::move(swap_time_callback)),
3419 presentation_time_callback_(std::move(presentation_time_callback)),
danakj2d2889a2019-04-05 21:22:083420 task_runner_(std::move(task_runner)),
3421 render_widget_(std::move(render_widget)) {}
3422 ~ReportTimeSwapPromise() override = default;
3423
3424 void DidActivate() override {}
3425
3426 void WillSwap(viz::CompositorFrameMetadata* metadata) override {
3427 DCHECK_GT(metadata->frame_token, 0u);
3428 // The interval between the current swap and its presentation time is
3429 // reported in UMA (see corresponding code in DidSwap() below).
3430 frame_token_ = metadata->frame_token;
3431 }
3432 void DidSwap() override {
3433 DCHECK_GT(frame_token_, 0u);
3434 task_runner_->PostTask(
Mohsen Izadid6715832019-06-05 00:32:513435 FROM_HERE, base::BindOnce(&RunCallbackAfterSwap, base::TimeTicks::Now(),
3436 std::move(swap_time_callback_),
3437 std::move(presentation_time_callback_),
3438 std::move(render_widget_), frame_token_));
danakj2d2889a2019-04-05 21:22:083439 }
3440
Bo Liudef993a2019-04-24 20:08:493441 cc::SwapPromise::DidNotSwapAction DidNotSwap(
3442 DidNotSwapReason reason) override {
danakj2d2889a2019-04-05 21:22:083443 blink::WebWidgetClient::SwapResult result;
3444 switch (reason) {
3445 case cc::SwapPromise::DidNotSwapReason::SWAP_FAILS:
3446 result = blink::WebWidgetClient::SwapResult::kDidNotSwapSwapFails;
3447 break;
3448 case cc::SwapPromise::DidNotSwapReason::COMMIT_FAILS:
3449 result = blink::WebWidgetClient::SwapResult::kDidNotSwapCommitFails;
3450 break;
3451 case cc::SwapPromise::DidNotSwapReason::COMMIT_NO_UPDATE:
3452 result = blink::WebWidgetClient::SwapResult::kDidNotSwapCommitNoUpdate;
3453 break;
3454 case cc::SwapPromise::DidNotSwapReason::ACTIVATION_FAILS:
3455 result = blink::WebWidgetClient::SwapResult::kDidNotSwapActivationFails;
3456 break;
3457 }
3458 // During a failed swap, return the current time regardless of whether we're
3459 // using presentation or swap timestamps.
3460 task_runner_->PostTask(
3461 FROM_HERE,
Mohsen Izadid6715832019-06-05 00:32:513462 base::BindOnce(
3463 [](blink::WebWidgetClient::SwapResult result,
3464 base::TimeTicks swap_time, ReportTimeCallback swap_time_callback,
3465 ReportTimeCallback presentation_time_callback) {
3466 ReportTime(std::move(swap_time_callback), result, swap_time);
3467 ReportTime(std::move(presentation_time_callback), result,
3468 swap_time);
3469 },
3470 result, base::TimeTicks::Now(), std::move(swap_time_callback_),
3471 std::move(presentation_time_callback_)));
Bo Liudef993a2019-04-24 20:08:493472 return DidNotSwapAction::BREAK_PROMISE;
danakj2d2889a2019-04-05 21:22:083473 }
3474
3475 int64_t TraceId() const override { return 0; }
3476
3477 private:
Mohsen Izadid6715832019-06-05 00:32:513478 static void RunCallbackAfterSwap(
3479 base::TimeTicks swap_time,
3480 ReportTimeCallback swap_time_callback,
3481 ReportTimeCallback presentation_time_callback,
3482 base::WeakPtr<RenderWidget> render_widget,
3483 int frame_token) {
3484 if (render_widget) {
3485 render_widget->layer_tree_view()->AddPresentationCallback(
3486 frame_token,
3487 base::BindOnce(&RunCallbackAfterPresentation,
3488 std::move(presentation_time_callback), swap_time));
3489 ReportTime(std::move(swap_time_callback),
3490 blink::WebWidgetClient::SwapResult::kDidSwap, swap_time);
3491 } else {
3492 ReportTime(std::move(swap_time_callback),
3493 blink::WebWidgetClient::SwapResult::kDidSwap, swap_time);
3494 ReportTime(std::move(presentation_time_callback),
3495 blink::WebWidgetClient::SwapResult::kDidSwap, swap_time);
3496 }
3497 }
3498
3499 static void RunCallbackAfterPresentation(
3500 ReportTimeCallback presentation_time_callback,
danakj2d2889a2019-04-05 21:22:083501 base::TimeTicks swap_time,
3502 base::TimeTicks presentation_time) {
3503 DCHECK(!swap_time.is_null());
3504 bool presentation_time_is_valid =
3505 !presentation_time.is_null() && (presentation_time > swap_time);
3506 UMA_HISTOGRAM_BOOLEAN("PageLoad.Internal.Renderer.PresentationTime.Valid",
3507 presentation_time_is_valid);
3508 if (presentation_time_is_valid) {
3509 // This measures from 1ms to 10seconds.
3510 UMA_HISTOGRAM_TIMES(
3511 "PageLoad.Internal.Renderer.PresentationTime.DeltaFromSwapTime",
3512 presentation_time - swap_time);
3513 }
Mohsen Izadid6715832019-06-05 00:32:513514 ReportTime(std::move(presentation_time_callback),
3515 blink::WebWidgetClient::SwapResult::kDidSwap,
3516 presentation_time_is_valid ? presentation_time : swap_time);
danakj2d2889a2019-04-05 21:22:083517 }
3518
Mohsen Izadid6715832019-06-05 00:32:513519 static void ReportTime(ReportTimeCallback callback,
3520 blink::WebWidgetClient::SwapResult result,
3521 base::TimeTicks time) {
3522 if (callback)
3523 std::move(callback).Run(result, time);
3524 }
3525
3526 ReportTimeCallback swap_time_callback_;
3527 ReportTimeCallback presentation_time_callback_;
danakj2d2889a2019-04-05 21:22:083528 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
3529 base::WeakPtr<RenderWidget> render_widget_;
3530 uint32_t frame_token_ = 0;
3531
3532 DISALLOW_COPY_AND_ASSIGN(ReportTimeSwapPromise);
3533};
3534
3535void RenderWidget::NotifySwapTime(ReportTimeCallback callback) {
Mohsen Izadid6715832019-06-05 00:32:513536 NotifySwapAndPresentationTime(base::NullCallback(), std::move(callback));
3537}
3538
danakj2e87fd82019-07-05 16:42:293539void RenderWidget::SetEventListenerProperties(
3540 cc::EventListenerClass event_class,
3541 cc::EventListenerProperties properties) {
3542 layer_tree_view_->layer_tree_host()->SetEventListenerProperties(event_class,
3543 properties);
3544}
3545
3546cc::EventListenerProperties RenderWidget::EventListenerProperties(
3547 cc::EventListenerClass event_class) const {
3548 return layer_tree_view_->layer_tree_host()->event_listener_properties(
3549 event_class);
3550}
3551
danakj2001a282019-07-18 19:12:323552std::unique_ptr<cc::ScopedDeferMainFrameUpdate>
3553RenderWidget::DeferMainFrameUpdate() {
3554 return layer_tree_view_->layer_tree_host()->DeferMainFrameUpdate();
3555}
3556
3557void RenderWidget::StartDeferringCommits(base::TimeDelta timeout) {
3558 layer_tree_view_->layer_tree_host()->StartDeferringCommits(timeout);
3559}
3560
3561void RenderWidget::StopDeferringCommits(cc::PaintHoldingCommitTrigger trigger) {
3562 layer_tree_view_->layer_tree_host()->StopDeferringCommits(trigger);
3563}
3564
danakjef7f7fa02019-07-26 22:50:063565void RenderWidget::RequestBeginMainFrameNotExpected(bool request) {
3566 layer_tree_view_->layer_tree_host()->RequestBeginMainFrameNotExpected(
3567 request);
3568}
3569
3570int RenderWidget::GetLayerTreeId() const {
3571 return layer_tree_view_->layer_tree_host()->GetId();
3572}
3573
Erik Chenad7f4a1e2019-08-05 20:38:053574void RenderWidget::SetBrowserControlsShownRatio(float ratio) {
3575 layer_tree_view_->layer_tree_host()->SetBrowserControlsShownRatio(ratio);
3576}
3577
3578void RenderWidget::SetBrowserControlsHeight(float top_height,
3579 float bottom_height,
3580 bool shrink_viewport) {
3581 layer_tree_view_->layer_tree_host()->SetBrowserControlsHeight(
3582 top_height, bottom_height, shrink_viewport);
3583}
3584
Erik Chen4f2f6f0d2019-08-14 23:17:233585viz::FrameSinkId RenderWidget::GetFrameSinkId() {
3586 return viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id());
3587}
3588
Mohsen Izadid6715832019-06-05 00:32:513589void RenderWidget::NotifySwapAndPresentationTime(
3590 ReportTimeCallback swap_time_callback,
3591 ReportTimeCallback presentation_time_callback) {
danakj2d2889a2019-04-05 21:22:083592 cc::LayerTreeHost* layer_tree_host = layer_tree_view_->layer_tree_host();
3593 // When the WebWidget is closed we cancel any pending SwapPromise that would
3594 // call back into blink, so we use |close_weak_ptr_factory_|.
3595 layer_tree_host->QueueSwapPromise(std::make_unique<ReportTimeSwapPromise>(
Mohsen Izadid6715832019-06-05 00:32:513596 std::move(swap_time_callback), std::move(presentation_time_callback),
danakj2d2889a2019-04-05 21:22:083597 layer_tree_host->GetTaskRunnerProvider()->MainThreadTaskRunner(),
3598 close_weak_ptr_factory_.GetWeakPtr()));
3599}
3600
Dave Tapuskabafc2ba32017-11-28 01:54:373601void RenderWidget::RequestUnbufferedInputEvents() {
3602 if (input_event_queue_)
3603 input_event_queue_->RequestUnbufferedInputEvents();
3604}
3605
xidachenfa0199e72017-05-11 11:34:263606void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:263607 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:513608 return;
3609
Dave Tapuska04bc5ee92018-04-17 19:03:313610 widget_input_handler_manager_->ProcessTouchAction(touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:513611}
3612
[email protected]e3244ed2014-06-20 20:04:273613void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
3614 render_frame_proxies_.AddObserver(proxy);
danakj0246bba02019-01-23 23:12:273615 // Page scale factor is propagated down the RenderWidget tree (across
3616 // frame trees). A new RenderFrameProxy means there is a new child
3617 // RenderWidget in another frame tree. In order for it to hear about
3618 // the page scale factor we pass along the last seen value here.
W. James MacLean2cd99b62019-04-08 13:54:433619 proxy->OnPageScaleFactorChanged(page_scale_factor_from_mainframe_,
3620 is_pinch_gesture_active_from_mainframe_);
[email protected]bffc8302014-01-23 20:52:163621}
3622
[email protected]e3244ed2014-06-20 20:04:273623void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
3624 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:163625}
3626
[email protected]de3c5d82014-05-28 22:12:593627void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
3628 render_frames_.AddObserver(frame);
3629}
3630
3631void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
3632 render_frames_.RemoveObserver(frame);
3633}
3634
Saman Samid189e5dfd2017-12-20 22:55:313635void RenderWidget::RegisterBrowserPlugin(BrowserPlugin* browser_plugin) {
3636 browser_plugins_.AddObserver(browser_plugin);
Saman Sami50d1e0c2018-03-13 20:03:493637 browser_plugin->ScreenInfoChanged(GetOriginalScreenInfo());
Saman Samid189e5dfd2017-12-20 22:55:313638}
3639
3640void RenderWidget::UnregisterBrowserPlugin(BrowserPlugin* browser_plugin) {
3641 browser_plugins_.RemoveObserver(browser_plugin);
3642}
3643
Albert J. Wong3c93c182018-09-27 17:29:433644void RenderWidget::OnWaitNextFrameForTests(
3645 int main_frame_thread_observer_routing_id) {
danakj53802692018-07-25 21:46:443646 // Sends an ACK to the browser process during the next compositor frame.
Albert J. Wong3c93c182018-09-27 17:29:433647 QueueMessage(new WidgetHostMsg_WaitForNextFrameForTests_ACK(
3648 main_frame_thread_observer_routing_id));
lfg43e08e62016-02-03 18:51:373649}
3650
Fady Samuela863f152018-03-09 16:10:033651const ScreenInfo& RenderWidget::GetWebScreenInfo() const {
3652 return screen_info_;
Christopher Camerone9a30c12018-03-07 08:23:383653}
3654
Fady Samuela863f152018-03-09 16:10:033655const ScreenInfo& RenderWidget::GetOriginalScreenInfo() const {
Christopher Camerone9a30c12018-03-07 08:23:383656 return screen_metrics_emulator_
3657 ? screen_metrics_emulator_->original_screen_info()
Fady Samuela863f152018-03-09 16:10:033658 : screen_info_;
oshima50872a72016-03-04 13:26:183659}
3660
Ella Ge80a52dce2017-11-15 18:01:523661gfx::PointF RenderWidget::ConvertWindowPointToViewport(
3662 const gfx::PointF& point) {
paulmeyer90f6c31d2016-11-12 00:17:593663 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:543664 ConvertWindowToViewport(&point_in_viewport);
Ella Ge80a52dce2017-11-15 18:01:523665 return gfx::PointF(point_in_viewport.x, point_in_viewport.y);
3666}
3667
3668gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) {
3669 return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point)));
paulmeyer90f6c31d2016-11-12 00:17:593670}
3671
Mustaq Ahmed32a0b152019-08-06 16:01:263672bool RenderWidget::RequestPointerLock(WebLocalFrame* requester_frame) {
3673 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get(),
3674 requester_frame);
lfgbee1e0a2016-06-08 21:24:213675}
3676
Blink Reformat1c4d759e2017-04-09 16:34:543677void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:213678 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
3679}
3680
Blink Reformat1c4d759e2017-04-09 16:34:543681bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:213682 return mouse_lock_dispatcher_->IsMouseLockedTo(
3683 webwidget_mouse_lock_target_.get());
3684}
3685
Richard Li49fe04d2018-10-21 09:07:193686void RenderWidget::StartDragging(network::mojom::ReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:583687 const WebDragData& data,
3688 WebDragOperationsMask mask,
danakj0c75ad82018-07-10 19:50:123689 const SkBitmap& drag_image,
danakjef1735a2018-11-13 19:34:443690 const gfx::Point& web_image_offset) {
3691 blink::WebRect offset_in_window(web_image_offset.x(), web_image_offset.y(), 0,
3692 0);
Blink Reformat1c4d759e2017-04-09 16:34:543693 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:583694 DropData drop_data(DropDataBuilder::Build(data));
3695 drop_data.referrer_policy = policy;
danakj0c75ad82018-07-10 19:50:123696 gfx::Vector2d image_offset(offset_in_window.x, offset_in_window.y);
3697 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask, drag_image,
3698 image_offset, possible_drag_event_info_));
paulmeyer6ef5a792016-11-08 20:33:583699}
3700
Saman Samif7731342018-01-24 22:18:443701void RenderWidget::DidNavigate() {
danakj125a29e2019-01-24 23:25:293702 // Blink may be navigating still between the Close IPC and the task that
3703 // actually closes this class, and for a main frame that would come through
3704 // this method. But since we are closing we can skip it.
3705 if (closing_)
Kinuko Yasudabef2b642019-01-24 04:53:333706 return;
danakj125a29e2019-01-24 23:25:293707
Stephen Chenneyf661f062019-08-02 20:12:423708 // The input handler wants to know about navigation so that it can
Stephen Chenneybccdd0302019-08-15 12:21:283709 // suppress input until the newly navigated page has a committed frame.
3710 // It also resets the state for UMA reporting of input arrival with respect
3711 // to document lifecycle.
Stephen Chenneyf661f062019-08-02 20:12:423712 DCHECK(widget_input_handler_manager_);
3713 widget_input_handler_manager_->DidNavigate();
3714
danakja6c10012018-07-06 14:25:363715 layer_tree_view_->ClearCachesOnNextCommit();
kenrb5d78b842017-03-06 21:06:013716}
3717
lfg8ff33912016-09-13 20:59:213718blink::WebWidget* RenderWidget::GetWebWidget() const {
lfg8ff33912016-09-13 20:59:213719 return webwidget_internal_;
3720}
3721
ekaramad2daaf672016-11-10 20:29:013722blink::WebInputMethodController* RenderWidget::GetInputMethodController()
3723 const {
Ehsan Karamad655d7b8a2018-01-12 18:38:383724 if (auto* frame_widget = GetFrameWidget())
3725 return frame_widget->GetActiveWebInputMethodController();
3726
3727 return nullptr;
ekaramad2daaf672016-11-10 20:29:013728}
3729
Dave Tapuska139a72f2017-09-06 21:57:033730void RenderWidget::SetupWidgetInputHandler(
Dave Tapuskae782bea2019-07-09 16:21:513731 mojo::PendingReceiver<mojom::WidgetInputHandler> receiver,
3732 mojo::PendingRemote<mojom::WidgetInputHandlerHost> host) {
3733 widget_input_handler_manager_->AddInterface(std::move(receiver),
Dave Tapuskab66c28f2017-11-15 17:18:473734 std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:503735}
3736
Dave Tapuska485aca92017-08-08 00:47:583737void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
3738 // Close the old binding if there was one.
3739 // A RenderWidgetHost should not need more than one channel.
3740 widget_binding_.Close();
3741 widget_binding_.Bind(std::move(request));
3742}
3743
Ken Buchanan94c0beb62018-06-22 19:56:243744void RenderWidget::SetMouseCapture(bool capture) {
3745 if (mojom::WidgetInputHandlerHost* host =
3746 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
3747 host->SetMouseCapture(capture);
3748 }
3749}
3750
danakj53802692018-07-25 21:46:443751void RenderWidget::UseSynchronousResizeModeForTesting(bool enable) {
danakj7602f4f2019-01-31 18:03:233752 synchronous_resize_mode_for_testing_ = enable;
danakja2c9d0a92018-07-25 20:01:183753}
3754
3755void RenderWidget::SetDeviceScaleFactorForTesting(float factor) {
danakjb4cec102019-01-30 19:22:133756 DCHECK_GT(factor, 0.f);
danakja2c9d0a92018-07-25 20:01:183757
danakja2c9d0a92018-07-25 20:01:183758 // We are changing the device scale factor from the renderer, so allocate a
3759 // new viz::LocalSurfaceId to avoid surface invariants violations in tests.
danakj125a29e2019-01-24 23:25:293760 layer_tree_view_->RequestNewLocalSurfaceId();
danakjb4cec102019-01-30 19:22:133761
3762 ScreenInfo info = screen_info_;
3763 info.device_scale_factor = factor;
3764 gfx::Size viewport_pixel_size = gfx::ScaleToCeiledSize(size_, factor);
3765 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
3766 viewport_pixel_size, info);
3767
3768 ResizeWebWidget(); // This picks up the new device scale factor in |info|.
3769
3770 gfx::Size visible_viewport_size = visible_viewport_size_;
3771 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
3772 visible_viewport_size =
3773 gfx::ScaleToCeiledSize(visible_viewport_size, factor);
3774 }
W. James MacLean7c8581072019-06-18 18:07:533775
3776 DCHECK(delegate()) << "Resizing the viewport for a cross-process subframe "
3777 "must be done via the RenderView.";
3778 delegate()->ResizeVisualViewportForWidget(visible_viewport_size);
danakjb4cec102019-01-30 19:22:133779
3780 // Make sure the DSF override stays for future VisualProperties updates, and
3781 // that includes overriding the VisualProperties'
3782 // compositor_viewport_pixel_size with size * this for-testing DSF.
3783 device_scale_factor_for_testing_ = factor;
danakja2c9d0a92018-07-25 20:01:183784}
3785
3786void RenderWidget::SetDeviceColorSpaceForTesting(
3787 const gfx::ColorSpace& color_space) {
danakjb4cec102019-01-30 19:22:133788 // We are changing the device color space from the renderer, so allocate a
3789 // new viz::LocalSurfaceId to avoid surface invariants violations in tests.
3790 layer_tree_view_->RequestNewLocalSurfaceId();
3791
danakj04d128a2019-01-25 02:10:203792 ScreenInfo info = screen_info_;
3793 info.color_space = color_space;
3794 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
danakj0d963bd2019-02-20 18:00:463795 CompositorViewportSize(), info);
danakja2c9d0a92018-07-25 20:01:183796}
3797
3798void RenderWidget::SetWindowRectSynchronouslyForTesting(
3799 const gfx::Rect& new_window_rect) {
3800 SetWindowRectSynchronously(new_window_rect);
3801}
3802
3803void RenderWidget::EnableAutoResizeForTesting(const gfx::Size& min_size,
3804 const gfx::Size& max_size) {
3805 VisualProperties visual_properties;
3806 visual_properties.auto_resize_enabled = true;
3807 visual_properties.min_size_for_auto_resize = min_size;
3808 visual_properties.max_size_for_auto_resize = max_size;
Fady Samuel84d8a1f72018-11-08 00:26:173809 visual_properties.local_surface_id_allocation =
3810 base::Optional<viz::LocalSurfaceIdAllocation>(
3811 viz::LocalSurfaceIdAllocation(
3812 viz::LocalSurfaceId(1, 1, base::UnguessableToken::Create()),
3813 base::TimeTicks::Now()));
danakja2c9d0a92018-07-25 20:01:183814 OnSynchronizeVisualProperties(visual_properties);
3815}
3816
3817void RenderWidget::DisableAutoResizeForTesting(const gfx::Size& new_size) {
3818 if (!auto_resize_mode_)
3819 return;
3820
3821 VisualProperties visual_properties;
3822 visual_properties.auto_resize_enabled = false;
3823 visual_properties.screen_info = screen_info_;
3824 visual_properties.new_size = new_size;
danakj0d963bd2019-02-20 18:00:463825 visual_properties.compositor_viewport_pixel_size = CompositorViewportSize();
danakja2c9d0a92018-07-25 20:01:183826 visual_properties.browser_controls_shrink_blink_size =
3827 browser_controls_shrink_blink_size_;
3828 visual_properties.top_controls_height = top_controls_height_;
3829 visual_properties.visible_viewport_size = visible_viewport_size_;
3830 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
3831 visual_properties.display_mode = display_mode_;
3832 OnSynchronizeVisualProperties(visual_properties);
3833}
3834
EhsanK955ba582017-11-30 21:14:403835blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const {
Ehsan Karamad655d7b8a2018-01-12 18:38:383836 if (auto* frame_widget = GetFrameWidget())
3837 return frame_widget->FocusedWebLocalFrameInWidget();
3838 return nullptr;
EhsanK955ba582017-11-30 21:14:403839}
3840
EhsanK22d482e2017-08-10 17:29:493841#if BUILDFLAG(ENABLE_PLUGINS)
3842PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
Ehsan Karamad655d7b8a2018-01-12 18:38:383843 blink::WebFrameWidget* frame_widget = GetFrameWidget();
3844 if (!frame_widget)
EhsanK22d482e2017-08-10 17:29:493845 return nullptr;
3846
3847 // Focused pepper instance might not always be in the focused frame. For
3848 // instance if a pepper instance and its embedder frame are focused an then
3849 // another frame takes focus using javascript, the embedder frame will no
3850 // longer be focused while the pepper instance is (the embedder frame's
3851 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
3852 // is fullscreen, clicking into the pepper will not refocus the embedder
3853 // frame. This is why we have to traverse the whole frame tree to find the
3854 // focused plugin.
Ehsan Karamad655d7b8a2018-01-12 18:38:383855 blink::WebFrame* current_frame = frame_widget->LocalRoot();
EhsanK22d482e2017-08-10 17:29:493856 while (current_frame) {
3857 RenderFrameImpl* render_frame =
3858 current_frame->IsWebLocalFrame()
3859 ? RenderFrameImpl::FromWebFrame(current_frame)
3860 : nullptr;
3861 if (render_frame && render_frame->focused_pepper_plugin())
3862 return render_frame->focused_pepper_plugin();
3863 current_frame = current_frame->TraverseNext();
3864 }
3865 return nullptr;
3866}
3867#endif
3868
Ken Buchananb2c9e262018-03-10 16:53:313869gfx::Rect RenderWidget::ViewportVisibleRect() {
danakj9c4e7b812019-02-19 22:04:273870 if (for_child_local_root_frame_)
3871 return compositor_visible_rect_;
danakj0d963bd2019-02-20 18:00:463872 return gfx::Rect(CompositorViewportSize());
Ken Buchananb2c9e262018-03-10 16:53:313873}
3874
Hajime Hoshi315a61f2018-08-14 17:27:283875// static
3876scoped_refptr<base::SingleThreadTaskRunner>
3877RenderWidget::GetCleanupTaskRunner() {
3878 return RenderThreadImpl::current_blink_platform_impl()
3879 ->main_thread_scheduler()
3880 ->CleanupTaskRunner();
3881}
3882
Saman Sami50d1e0c2018-03-13 20:03:493883base::WeakPtr<RenderWidget> RenderWidget::AsWeakPtr() {
3884 return weak_ptr_factory_.GetWeakPtr();
3885}
3886
Erik Chen7ee377b2019-08-22 23:38:343887void RenderWidget::SetWebWidgetInternal(blink::WebWidget* web_widget) {
Erik Chena2819852019-08-28 01:02:283888 // TODO(https://crbug.com/995981): This method should not need to exist, since
3889 // we should be creating and destroying a RenderWidget along with the
3890 // WebWidget.
3891 if (web_widget)
3892 web_widget->SetAnimationHost(layer_tree_view_->animation_host());
Erik Chen7ee377b2019-08-22 23:38:343893 webwidget_internal_ = web_widget;
3894}
3895
[email protected]e9ff79c2012-10-19 21:31:263896} // namespace content