blob: be18d403e986c053d5e54e2cce2f78253eac7cf0 [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
dchengcedca5612016-04-09 01:40:157#include <memory>
dcheng07945f632015-12-26 07:59:328#include <utility>
9
[email protected]c27dd4f2014-05-22 18:05:1910#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2111#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0012#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1213#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/logging.h"
avi1023d012015-12-25 02:39:1415#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1516#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4017#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3018#include "base/message_loop/message_loop.h"
asvitkine8d51e9d2016-09-02 23:55:4319#include "base/metrics/histogram_macros.h"
[email protected]aa4117f2011-12-09 22:19:2120#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0021#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2722#include "base/sys_info.h"
fdoraya19b7702016-12-23 14:19:3123#include "base/threading/thread_task_runner_handle.h"
primiano9e38d552015-01-28 04:18:0124#include "base/trace_event/trace_event.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "build/build_config.h"
loyso6e6efc42017-01-21 02:23:0326#include "cc/animation/animation_host.h"
xidachenfa0199e72017-05-11 11:34:2627#include "cc/input/touch_action.h"
danakjba65a0912017-09-21 16:38:4228#include "cc/trees/layer_tree_frame_sink.h"
loyso6e6efc42017-01-21 02:23:0329#include "cc/trees/layer_tree_host.h"
Fady Samuelc645ffe2017-07-24 17:28:2030#include "components/viz/common/frame_sinks/begin_frame_source.h"
danakjf20f4502017-09-26 17:13:3131#include "components/viz/common/frame_sinks/copy_output_request.h"
paulmeyer6ef5a792016-11-08 20:33:5832#include "content/common/drag_event_source_info.h"
33#include "content/common/drag_messages.h"
[email protected]c084330e02013-04-27 01:08:1534#include "content/common/input_messages.h"
jonrossa2ff4f82018-02-16 17:27:4635#include "content/common/render_frame_metadata.mojom.h"
jcivelliae1560a2016-11-01 22:40:2336#include "content/common/render_message_filter.mojom.h"
Nasko Oskovf97e8b02017-07-25 02:45:4237#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3838#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5039#include "content/common/view_messages.h"
mlamouriafca06dd2017-01-27 23:35:1840#include "content/public/common/content_client.h"
changwan7ded3752016-03-09 23:25:1241#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2942#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4243#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5944#include "content/public/common/drop_data.h"
Khushal3e96e662017-10-30 23:16:5045#include "content/public/common/service_names.mojom.h"
Jaebaek Seo655110e2017-12-19 23:27:3946#include "content/public/common/use_zoom_for_dsf_policy.h"
mlamouriafca06dd2017-01-27 23:35:1847#include "content/public/renderer/content_renderer_client.h"
Saman Samid189e5dfd2017-12-20 22:55:3148#include "content/renderer/browser_plugin/browser_plugin.h"
[email protected]953bd0062013-08-01 00:58:4049#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3950#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5851#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5152#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1153#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1154#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2855#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2956#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1357#include "content/renderer/input/input_handler_manager.h"
dtapuska9ec1a912017-04-21 15:18:3158#include "content/renderer/input/main_thread_event_queue.h"
Dave Tapuska9db80842017-07-24 17:24:2659#include "content/renderer/input/widget_input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3260#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1661#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2762#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0563#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4464#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5565#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4466#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0967#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0468#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4769#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1870#include "ipc/ipc_sync_message.h"
Antoine Laboure55c9ef82017-11-10 18:51:2371#include "ipc/ipc_sync_message_filter.h"
Scott Violet02e38b92018-03-27 23:42:1472#include "ppapi/buildflags/buildflags.h"
[email protected]661eb9d2009-02-03 02:11:4873#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:0674#include "third_party/blink/public/platform/file_path_conversion.h"
75#include "third_party/blink/public/platform/scheduler/web_main_thread_scheduler.h"
76#include "third_party/blink/public/platform/scheduler/web_render_widget_scheduling_state.h"
77#include "third_party/blink/public/platform/web_cursor_info.h"
78#include "third_party/blink/public/platform/web_drag_data.h"
79#include "third_party/blink/public/platform/web_drag_operation.h"
80#include "third_party/blink/public/platform/web_mouse_event.h"
81#include "third_party/blink/public/platform/web_point.h"
82#include "third_party/blink/public/platform/web_rect.h"
83#include "third_party/blink/public/platform/web_runtime_features.h"
84#include "third_party/blink/public/platform/web_size.h"
85#include "third_party/blink/public/platform/web_string.h"
86#include "third_party/blink/public/web/web_autofill_client.h"
87#include "third_party/blink/public/web/web_device_emulation_params.h"
88#include "third_party/blink/public/web/web_frame_widget.h"
89#include "third_party/blink/public/web/web_input_method_controller.h"
90#include "third_party/blink/public/web/web_local_frame.h"
91#include "third_party/blink/public/web/web_node.h"
92#include "third_party/blink/public/web/web_page_popup.h"
93#include "third_party/blink/public/web/web_popup_menu_info.h"
94#include "third_party/blink/public/web/web_range.h"
95#include "third_party/blink/public/web/web_settings.h"
96#include "third_party/blink/public/web/web_view.h"
97#include "third_party/blink/public/web/web_widget.h"
[email protected]d353541f2012-05-03 22:45:4198#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:5999#include "ui/base/clipboard/clipboard.h"
Scott Violet8ff9c302018-02-22 22:28:35100#include "ui/base/ui_base_features.h"
dtapuska97286c882017-02-24 23:14:43101#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:50102#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:09103#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32104#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48105#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:27106#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:41107#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48108
[email protected]eeb93112013-05-01 19:41:10109#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15110#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24111#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10112#endif
113
[email protected]661eb9d2009-02-03 02:11:48114#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52115#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41116#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48117#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44118
sadrul943e3b32016-08-04 18:22:59119#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10120#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19121#endif
122
ekaramad330ba4232016-09-23 17:57:47123#if defined(OS_MACOSX)
124#include "content/renderer/text_input_client_observer.h"
125#endif
126
Ryan Landay9e42fd742017-08-12 01:59:11127using blink::WebImeTextSpan;
[email protected]180ef242013-11-07 06:50:46128using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43129using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59130using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58131using blink::WebDragOperationsMask;
132using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59133using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46134using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58135using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46136using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49137using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01138using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58139using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46140using blink::WebMouseEvent;
141using blink::WebMouseWheelEvent;
142using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11143using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46144using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11145using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46146using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48147using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46148using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46149using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59150using blink::WebString;
[email protected]180ef242013-11-07 06:50:46151using blink::WebTextDirection;
152using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25153using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46154using blink::WebVector;
155using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26156
paulmeyer90f6c31d2016-11-12 00:17:59157namespace content {
158
[email protected]6a4d7f62013-01-07 21:32:13159namespace {
[email protected]b256eca2013-07-11 10:57:40160
161typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
162
AJITH KUMAR V041c0b02017-08-08 10:39:20163static const int kInvalidNextPreviousFlagsValue = -1;
164
lfgbee1e0a2016-06-08 21:24:21165class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
166 public:
167 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
168 : webwidget_(webwidget) {}
169
170 void OnLockMouseACK(bool succeeded) override {
171 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54172 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21173 else
Blink Reformat1c4d759e2017-04-09 16:34:54174 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21175 }
176
Blink Reformat1c4d759e2017-04-09 16:34:54177 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21178
179 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
180 // The WebWidget handles mouse lock in Blink's handleInputEvent().
181 return false;
182 }
183
184 private:
185 blink::WebWidget* webwidget_;
186};
187
dglazkov97b6c2b2016-10-25 17:35:55188bool IsDateTimeInput(ui::TextInputType type) {
189 return type == ui::TEXT_INPUT_TYPE_DATE ||
190 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
191 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
192 type == ui::TEXT_INPUT_TYPE_MONTH ||
193 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
194}
195
paulmeyer90f6c31d2016-11-12 00:17:59196WebDragData DropMetaDataToWebDragData(
197 const std::vector<DropData::Metadata>& drop_meta_data) {
198 std::vector<WebDragData::Item> item_list;
199 for (const auto& meta_data_item : drop_meta_data) {
200 if (meta_data_item.kind == DropData::Kind::STRING) {
201 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54202 item.storage_type = WebDragData::Item::kStorageTypeString;
203 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59204 // Have to pass a dummy URL here instead of an empty URL because the
205 // DropData received by browser_plugins goes through a round trip:
206 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
207 // will contain an empty URL (which means no URL is dragged) if the URL in
208 // WebDragData is empty.
209 if (base::EqualsASCII(meta_data_item.mime_type,
210 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54211 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59212 }
213 item_list.push_back(item);
214 continue;
215 }
216
217 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
218 // just the mimetype. This is needed to drag files to WebView on Android
219 // platform.
220 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
221 !meta_data_item.filename.empty()) {
222 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54223 item.storage_type = WebDragData::Item::kStorageTypeFilename;
224 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59225 item_list.push_back(item);
226 continue;
227 }
228
229 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
230 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54231 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
232 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59233 item_list.push_back(item);
234 continue;
235 }
236 }
237
238 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54239 result.Initialize();
240 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59241 return result;
242}
243
244WebDragData DropDataToWebDragData(const DropData& drop_data) {
245 std::vector<WebDragData::Item> item_list;
246
247 // These fields are currently unused when dragging into WebKit.
248 DCHECK(drop_data.download_metadata.empty());
249 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23250 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59251
252 if (!drop_data.text.is_null()) {
253 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54254 item.storage_type = WebDragData::Item::kStorageTypeString;
255 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
256 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59257 item_list.push_back(item);
258 }
259
260 if (!drop_data.url.is_empty()) {
261 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54262 item.storage_type = WebDragData::Item::kStorageTypeString;
263 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
264 item.string_data = WebString::FromUTF8(drop_data.url.spec());
265 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59266 item_list.push_back(item);
267 }
268
269 if (!drop_data.html.is_null()) {
270 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54271 item.storage_type = WebDragData::Item::kStorageTypeString;
272 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
273 item.string_data = WebString::FromUTF16(drop_data.html.string());
274 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59275 item_list.push_back(item);
276 }
277
278 for (std::vector<ui::FileInfo>::const_iterator it =
279 drop_data.filenames.begin();
280 it != drop_data.filenames.end();
281 ++it) {
282 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54283 item.storage_type = WebDragData::Item::kStorageTypeFilename;
284 item.filename_data = blink::FilePathToWebString(it->path);
285 item.display_name_data =
kinukoa4293022017-01-27 06:43:25286 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59287 item_list.push_back(item);
288 }
289
290 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
291 drop_data.file_system_files.begin();
292 it != drop_data.file_system_files.end();
293 ++it) {
294 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54295 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
296 item.file_system_url = it->url;
297 item.file_system_file_size = it->size;
298 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59299 item_list.push_back(item);
300 }
301
Stuart Langley48300392017-11-02 03:54:44302 for (const auto& it : drop_data.custom_data) {
paulmeyer90f6c31d2016-11-12 00:17:59303 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54304 item.storage_type = WebDragData::Item::kStorageTypeString;
Stuart Langley48300392017-11-02 03:54:44305 item.string_type = WebString::FromUTF16(it.first);
306 item.string_data = WebString::FromUTF16(it.second);
paulmeyer90f6c31d2016-11-12 00:17:59307 item_list.push_back(item);
308 }
309
310 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54311 result.Initialize();
312 result.SetItems(item_list);
313 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59314 return result;
315}
316
lfg1568d112016-08-30 16:06:29317content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
318 nullptr;
319
320content::RenderWidget::RenderWidgetInitializedCallback
321 g_render_widget_initialized = nullptr;
322
dtapuskac4dd5be2016-10-25 15:11:10323ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
324 // Check the type is in the range representable by ui::TextInputType.
325 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
326 << "blink::WebTextInputType and ui::TextInputType not synchronized";
327 return static_cast<ui::TextInputType>(type);
328}
329
330ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
331 // Check the mode is in the range representable by ui::TextInputMode.
332 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
333 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
334 return static_cast<ui::TextInputMode>(mode);
335}
336
Mitsuru Oshima3c07b332018-02-06 04:56:50337// Returns true if the device scale is high enough that losing subpixel
338// antialiasing won't have a noticeable effect on text quality.
339static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
340#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
341 // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to
342 // composite all scrollers so that we get animated overlay scrollbars.
343 return true;
344#else
345 // 1.5 is a common touchscreen tablet device scale factor. For such
346 // devices main thread antialiasing is a heavy burden.
347 return device_scale_factor >= 1.5f;
348#endif
349}
350
351static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
352 float device_scale_factor) {
353 const base::CommandLine& command_line =
354 *base::CommandLine::ForCurrentProcess();
355 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
356 return false;
357 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
358 return true;
359 if (!compositor_deps->IsLcdTextEnabled())
360 return true;
361 return DeviceScaleEnsuresTextQuality(device_scale_factor);
362}
363
[email protected]b256eca2013-07-11 10:57:40364} // namespace
365
[email protected]b2e4c70132013-10-03 02:07:51366// RenderWidget ---------------------------------------------------------------
367
Hajime Hoshiabb3c8f2017-12-04 18:41:39368RenderWidget::RenderWidget(
369 int32_t widget_routing_id,
370 CompositorDependencies* compositor_deps,
371 blink::WebPopupType popup_type,
372 const ScreenInfo& screen_info,
373 bool swapped_out,
374 bool hidden,
375 bool never_visible,
376 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
377 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45378 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36379 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21380 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44381 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29382 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51383 auto_resize_mode_(false),
Fady Samueld10aadd82017-11-03 18:23:57384 need_resize_ack_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29385 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04386 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39387 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12388 is_fullscreen_granted_(false),
Blink Reformat1c4d759e2017-04-09 16:34:54389 display_mode_(blink::kWebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16390 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48391 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22392 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44393 is_swapped_out_(swapped_out),
dglazkov97b6c2b2016-10-25 17:35:55394 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40395 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20396 text_input_flags_(0),
AJITH KUMAR V041c0b02017-08-08 10:39:20397 next_previous_flags_(kInvalidNextPreviousFlagsValue),
[email protected]86ba5fcb2013-09-04 00:36:53398 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18399 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12400 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48401 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04402 screen_info_(screen_info),
nonafa291792016-08-10 02:36:18403 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51404 popup_origin_scale_for_emulation_(0.f),
samans26510e442017-06-01 22:29:12405 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
[email protected]a09d53ce2014-01-31 00:46:42406 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08407 has_host_context_menu_location_(false),
wjmaclean1d970622017-01-21 22:28:24408 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09409 has_focus_(false),
Nicolas Pena75a35d662018-04-05 20:13:44410 for_oopif_(false),
ekaramad330ba4232016-09-23 17:57:47411#if defined(OS_MACOSX)
412 text_input_client_observer_(new TextInputClientObserver(this)),
413#endif
Takashi SAKAMOTO870f6262017-08-22 04:08:27414 first_update_visual_state_after_hidden_(false),
tasakb95dbb50c2017-02-08 18:07:50415 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01416 current_content_source_id_(0),
Dave Tapuska1bdf1832017-07-07 18:07:19417 widget_binding_(this, std::move(widget_request)),
Hajime Hoshiabb3c8f2017-12-04 18:41:39418 task_runner_(task_runner),
wjmaclean1d970622017-01-21 22:28:24419 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45420 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05421 if (!swapped_out)
422 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27423 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11424
425 // In tests there may not be a RenderThreadImpl.
426 if (RenderThreadImpl::current()) {
427 render_widget_scheduling_state_ = RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:25428 ->GetWebMainThreadScheduler()
dcheng07945f632015-12-26 07:59:32429 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11430 render_widget_scheduling_state_->SetHidden(is_hidden_);
431 }
sadrul602ce1362017-01-26 06:41:10432#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14433 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
Scott Violet8ff9c302018-02-22 22:28:35434 if (features::IsMusEnabled())
Scott Violet1098538e2017-10-05 19:23:33435 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_);
sadrul602ce1362017-01-26 06:41:10436#endif
initial.commit09911bf2008-07-26 23:55:29437}
438
439RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21440 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16441
dtapuska9ec1a912017-04-21 15:18:31442 if (input_event_queue_)
443 input_event_queue_->ClearClient();
444
[email protected]992db4c2011-05-12 15:37:15445 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02446 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15447 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11448#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14449 // It is possible for a RenderWidget to be destroyed before it was embedded
450 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
451 // explicitly delete it here.
452 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11453#endif
initial.commit09911bf2008-07-26 23:55:29454}
455
[email protected]484955942010-08-19 16:13:18456// static
lfg1568d112016-08-30 16:06:29457void RenderWidget::InstallCreateHook(
458 CreateRenderWidgetFunction create_render_widget,
459 RenderWidgetInitializedCallback render_widget_initialized) {
460 CHECK(!g_create_render_widget && !g_render_widget_initialized);
461 g_create_render_widget = create_render_widget;
462 g_render_widget_initialized = render_widget_initialized;
463}
464
465// static
nickf7b38222016-11-22 21:59:35466RenderWidget* RenderWidget::CreateForPopup(
467 RenderViewImpl* opener,
468 CompositorDependencies* compositor_deps,
469 blink::WebPopupType popup_type,
Hajime Hoshiabb3c8f2017-12-04 18:41:39470 const ScreenInfo& screen_info,
471 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Dave Tapuska1bdf1832017-07-07 18:07:19472 mojom::WidgetPtr widget_channel;
473 mojom::WidgetRequest widget_channel_request =
474 mojo::MakeRequest(&widget_channel);
475
nick4df698d82016-11-11 20:39:23476 // Do a synchronous IPC to obtain a routing ID.
477 int32_t routing_id = MSG_ROUTING_NONE;
478 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
Dave Tapuska1bdf1832017-07-07 18:07:19479 opener->GetRoutingID(), popup_type, std::move(widget_channel),
480 &routing_id)) {
nick4df698d82016-11-11 20:39:23481 return nullptr;
482 }
483
Hajime Hoshiabb3c8f2017-12-04 18:41:39484 scoped_refptr<RenderWidget> widget(new RenderWidget(
485 routing_id, compositor_deps, popup_type, screen_info, false, false, false,
486 task_runner, std::move(widget_channel_request)));
nickf7b38222016-11-22 21:59:35487 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24488 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
Tommy Nyquist4b749d02018-03-20 21:46:29489 widget->Init(std::move(opener_callback),
490 RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23491 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
492 return widget.get();
initial.commit09911bf2008-07-26 23:55:29493}
494
[email protected]484955942010-08-19 16:13:18495// static
kenrba7199832015-01-22 23:44:59496RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23497 int widget_routing_id,
kenrba7199832015-01-22 23:44:59498 bool hidden,
ccameron2f451532016-09-07 21:49:27499 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59500 CompositorDependencies* compositor_deps,
501 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23502 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55503 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
504 // same routing ID for both the view routing ID and the main frame widget
505 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23506 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55507 if (view) {
avi8a45c1092016-03-01 16:12:34508 view->AttachWebFrameWidget(
509 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
Lucas Furukawa Gadani6ccadf72018-02-13 10:29:10510 view->GetWidget()->UpdateWebViewWithDeviceScaleFactor();
avi8a45c1092016-03-01 16:12:34511 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55512 }
Hajime Hoshiabb3c8f2017-12-04 18:41:39513 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
514 frame->GetTaskRunner(blink::TaskType::kUnthrottled);
dcheng35d31c112015-07-22 00:17:36515 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29516 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45517 ? g_create_render_widget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54518 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45519 hidden, false)
520 : new RenderWidget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54521 blink::kWebPopupTypeNone, screen_info, false,
Hajime Hoshiabb3c8f2017-12-04 18:41:39522 hidden, false, task_runner));
simonhong628f9812015-04-27 23:13:20523 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23524 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59525 // this function returns.
nickf7b38222016-11-22 21:59:35526 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23527 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
Lucas Furukawa Gadani6ccadf72018-02-13 10:29:10528 widget->UpdateWebViewWithDeviceScaleFactor();
nick4df698d82016-11-11 20:39:23529
530 if (g_render_widget_initialized)
531 g_render_widget_initialized(widget.get());
532 return widget.get();
kenrba7199832015-01-22 23:44:59533}
534
535// static
lfgcaab5142016-02-26 19:06:52536blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08537 RenderWidget* render_widget,
538 blink::WebLocalFrame* frame) {
Blink Reformat1c4d759e2017-04-09 16:34:54539 return blink::WebFrameWidget::Create(render_widget, frame);
dchengda9b4bb2015-07-20 20:58:08540}
541
542// static
kenrba7199832015-01-22 23:44:59543blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18544 switch (render_widget->popup_type_) {
Blink Reformat1c4d759e2017-04-09 16:34:54545 case blink::kWebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18546 break;
Blink Reformat1c4d759e2017-04-09 16:34:54547 case blink::kWebPopupTypePage:
548 return WebPagePopup::Create(render_widget);
[email protected]484955942010-08-19 16:13:18549 default:
550 NOTREACHED();
551 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28552 return nullptr;
[email protected]484955942010-08-19 16:13:18553}
554
dchengda9b4bb2015-07-20 20:58:08555void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32556 OnClose();
kenrba7199832015-01-22 23:44:59557}
558
alexmos78c9c0d2016-10-14 18:57:03559void RenderWidget::SetSwappedOut(bool is_swapped_out) {
560 // We should only toggle between states.
561 DCHECK(is_swapped_out_ != is_swapped_out);
562 is_swapped_out_ = is_swapped_out;
563
564 // If we are swapping out, we will call ReleaseProcess, allowing the process
565 // to exit if all of its RenderViews are swapped out. We wait until the
566 // WasSwappedOut call to do this, to allow the unload handler to finish.
567 // If we are swapping in, we call AddRefProcess to prevent the process from
568 // exiting.
569 if (!is_swapped_out_)
570 RenderProcess::current()->AddRefProcess();
571}
572
nickf7b38222016-11-22 21:59:35573void RenderWidget::Init(const ShowCallback& show_callback,
574 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21575 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23576 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29577
Jeremy Roman04f27c372017-10-27 15:20:55578 input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45579
Dave Tapuska9db80842017-07-24 17:24:26580 if (base::FeatureList::IsEnabled(features::kMojoInputMessages)) {
581 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
582
Dave Tapuska525eb15e2017-08-17 21:05:50583 widget_input_handler_manager_ = WidgetInputHandlerManager::Create(
Dave Tapuska139a72f2017-09-06 21:57:03584 weak_ptr_factory_.GetWeakPtr(),
Dave Tapuska9db80842017-07-24 17:24:26585 render_thread_impl && compositor_
586 ? render_thread_impl->compositor_task_runner()
587 : nullptr,
Yuta Kitamura3331f5c2018-04-05 11:12:25588 render_thread_impl ? render_thread_impl->GetWebMainThreadScheduler()
Dave Tapuska9db80842017-07-24 17:24:26589 : nullptr);
590 }
591
nickf7b38222016-11-22 21:59:35592 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29593
lfg8ff33912016-09-13 20:59:21594 webwidget_internal_ = web_widget;
595 webwidget_mouse_lock_target_.reset(
596 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21597 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29598
nick4df698d82016-11-11 20:39:23599 RenderThread::Get()->AddRoute(routing_id_, this);
600 // Take a reference on behalf of the RenderThread. This will be balanced
601 // when we receive ViewMsg_Close.
602 AddRef();
603 if (RenderThreadImpl::current()) {
604 RenderThreadImpl::current()->WidgetCreated();
605 if (is_hidden_)
606 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29607 }
608}
609
[email protected]949b6592014-08-20 13:17:52610void RenderWidget::WasSwappedOut() {
611 // If we have been swapped out and no one else is using this process,
612 // it's safe to exit now.
613 CHECK(is_swapped_out_);
614 RenderProcess::current()->ReleaseProcess();
615}
616
[email protected]b2e4c70132013-10-03 02:07:51617void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39618 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51619 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43620 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00621 popup_screen_origin_for_emulation_ =
Lei Zhang9b359d32017-11-28 00:57:02622 emulator->original_screen_rect().origin();
Christopher Cameronaad15a0d2018-03-09 03:47:33623 UpdateSurfaceAndScreenInfo(local_surface_id_, compositor_viewport_pixel_size_,
Christopher Camerone9a30c12018-03-07 08:23:38624 emulator->original_screen_info());
[email protected]b2e4c70132013-10-03 02:07:51625}
626
[email protected]2d6836f42014-07-02 17:25:31627gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
628 if (screen_metrics_emulator_)
629 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
630 return anchor;
631}
632
thakis18e426412017-03-15 12:06:37633#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51634void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39635 ExternalPopupMenu* popup,
636 RenderWidgetScreenMetricsEmulator* emulator) {
Pavel Feldmancc099f72017-07-20 23:09:00637 popup->SetOriginScaleForEmulation(emulator->scale());
[email protected]b2e4c70132013-10-03 02:07:51638}
[email protected]53907862014-03-25 15:42:40639#endif
[email protected]b2e4c70132013-10-03 02:07:51640
[email protected]b2e4c70132013-10-03 02:07:51641void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
642 if (screen_metrics_emulator_)
643 screen_metrics_emulator_->OnShowContextMenu(params);
644}
645
[email protected]a95986a82010-12-24 06:19:28646bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47647#if defined(OS_MACOSX)
648 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
649 return text_input_client_observer_->OnMessageReceived(message);
650#endif
lfgbee1e0a2016-06-08 21:24:21651 if (mouse_lock_dispatcher_ &&
652 mouse_lock_dispatcher_->OnMessageReceived(message))
653 return true;
654
[email protected]a95986a82010-12-24 06:19:28655 bool handled = true;
656 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15657 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22658 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
659 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22660 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29661 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
662 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
663 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15664 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46665 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
666 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15667 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
wjmacleanee244e02017-05-26 21:06:07668 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]a95986a82010-12-24 06:19:28669 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28670 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20671 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
672 OnEnableDeviceEmulation)
673 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
674 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28675 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41676 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25677 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28678 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
679 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03680 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48681 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
682 OnSetViewportIntersection)
kenrb04323782017-06-23 01:23:32683 IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert)
Ken Buchanan8a319fb2017-11-15 18:37:12684 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRenderThrottlingStatus,
685 OnUpdateRenderThrottlingStatus)
lfg43e08e62016-02-03 18:51:37686 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
687 OnWaitNextFrameForTests)
ekaramadc9b70a72017-03-23 16:14:23688 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdates,
689 OnRequestCompositionUpdates)
paulmeyer90f6c31d2016-11-12 00:17:59690 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
691 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
692 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
693 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21694 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
695 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
696 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21697#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39698 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
699 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21700#endif
[email protected]a95986a82010-12-24 06:19:28701 IPC_MESSAGE_UNHANDLED(handled = false)
702 IPC_END_MESSAGE_MAP()
703 return handled;
704}
initial.commit09911bf2008-07-26 23:55:29705
706bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42707 // Don't send any messages after the browser has told us to close, and filter
708 // most outgoing messages while swapped out.
709 if ((is_swapped_out_ &&
710 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
711 closing_) {
initial.commit09911bf2008-07-26 23:55:29712 delete message;
713 return false;
714 }
715
716 // If given a messsage without a routing ID, then assign our routing ID.
717 if (message->routing_id() == MSG_ROUTING_NONE)
718 message->set_routing_id(routing_id_);
719
[email protected]380244092011-10-07 17:26:27720 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44721}
722
dtapuska014ed082016-11-11 21:58:48723void RenderWidget::SendOrCrash(IPC::Message* message) {
724 bool result = Send(message);
725 CHECK(closing_ || result) << "Failed to send message";
726}
727
ekaramad5aff1942017-01-06 01:26:35728bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26729 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
730 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
731 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
732 // will be processed regardless of page focus. We should revisit this after
733 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
Blink Reformat1c4d759e2017-04-09 16:34:54734 return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
ekaramadb6483a052017-02-10 02:23:26735 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35736}
737
bokanc007c3a2015-02-03 07:15:56738void RenderWidget::SetWindowRectSynchronously(
739 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39740 ResizeParams params;
741 params.screen_info = screen_info_;
742 params.new_size = new_window_rect.size();
Fady Samuela863f152018-03-09 16:10:03743 params.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
744 new_window_rect.size(), GetWebScreenInfo().device_scale_factor);
mfomitchev2600fd7c2016-02-17 20:53:39745 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39746 params.is_fullscreen_granted = is_fullscreen_granted_;
747 params.display_mode = display_mode_;
748 params.needs_resize_ack = false;
749 Resize(params);
750
bokanc007c3a2015-02-03 07:15:56751 view_screen_rect_ = new_window_rect;
752 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02753 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56754 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02755}
756
initial.commit09911bf2008-07-26 23:55:29757void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32758 DCHECK(content::RenderThread::Get());
759 if (closing_)
760 return;
761 NotifyOnClose();
762 closing_ = true;
763
764 // Browser correspondence is no longer needed at this point.
765 if (routing_id_ != MSG_ROUTING_NONE) {
766 RenderThread::Get()->RemoveRoute(routing_id_);
767 SetHidden(false);
768 if (RenderThreadImpl::current())
769 RenderThreadImpl::current()->WidgetDestroyed();
770 }
771
772 if (for_oopif_) {
773 // Widgets for frames may be created and closed at any time while the frame
Ken Buchananed449bb2018-02-01 21:02:05774 // is alive. However, WebWidget must be closed synchronously because frame
775 // widgets and frames hold pointers to each other. The deferred call to
776 // Close() will complete cleanup and release |this|, but CloseWebWidget()
777 // prevents Close() from attempting to access members of an
778 // already-deleted frame.
779 CloseWebWidget();
dchengd96a27a2015-07-24 20:17:32780 }
Ken Buchananed449bb2018-02-01 21:02:05781 // If there is a Send call on the stack, then it could be dangerous to close
782 // now. Post a task that only gets invoked when there are no nested message
783 // loops.
784 task_runner_->PostNonNestableTask(FROM_HERE,
785 base::BindOnce(&RenderWidget::Close, this));
dchengd96a27a2015-07-24 20:17:32786
787 // Balances the AddRef taken when we called AddRoute.
788 Release();
initial.commit09911bf2008-07-26 23:55:29789}
790
fsamuel664e8b62016-01-20 19:54:01791void RenderWidget::OnResize(const ResizeParams& params) {
EhsanKbd2cea992017-11-23 18:49:08792 gfx::Size old_visible_viewport_size = visible_viewport_size_;
793
[email protected]5b45ad42013-10-25 00:42:04794 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32795 return;
796
[email protected]b2e4c70132013-10-03 02:07:51797 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39798 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51799 return;
800 }
801
mfomitchev2600fd7c2016-02-17 20:53:39802 Resize(params);
EhsanKbd2cea992017-11-23 18:49:08803
804 if (old_visible_viewport_size != visible_viewport_size_) {
805 for (auto& render_frame : render_frames_)
806 render_frame.DidChangeVisibleViewport();
807 }
initial.commit09911bf2008-07-26 23:55:29808}
809
dgozman9260b0a12015-03-16 13:45:20810void RenderWidget::OnEnableDeviceEmulation(
Lei Zhang9b359d32017-11-28 00:57:02811 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39812 if (!screen_metrics_emulator_) {
813 ResizeParams resize_params;
814 resize_params.screen_info = screen_info_;
815 resize_params.new_size = size_;
Christopher Cameronaad15a0d2018-03-09 03:47:33816 resize_params.compositor_viewport_pixel_size =
817 compositor_viewport_pixel_size_;
Fady Samuela41e9d42018-03-01 21:31:58818 resize_params.local_surface_id = local_surface_id_;
819 resize_params.content_source_id = current_content_source_id_;
mfomitchev2600fd7c2016-02-17 20:53:39820 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39821 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
822 resize_params.display_mode = display_mode_;
823 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
824 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18825 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39826 } else {
dgozman9260b0a12015-03-16 13:45:20827 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39828 }
dgozman9260b0a12015-03-16 13:45:20829}
830
831void RenderWidget::OnDisableDeviceEmulation() {
832 screen_metrics_emulator_.reset();
833}
834
initial.commit09911bf2008-07-26 23:55:29835void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31836 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29837 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03838 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55839 for (auto& observer : render_frames_)
840 observer.WasHidden();
Saman Sami58ed4392018-01-31 20:54:19841
842 // Ack the resize if we have to, so that the next time we're visible we get a
843 // fresh ResizeParams right away; otherwise we'll start painting based on a
844 // stale ResizeParams.
845 DidResizeOrRepaintAck();
initial.commit09911bf2008-07-26 23:55:29846}
847
Saman Samid709592b2018-02-03 00:38:10848void RenderWidget::OnWasShown(bool needs_repainting,
849 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41850 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29851 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21852 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29853 return;
854
tasakb95dbb50c2017-02-08 18:07:50855 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29856 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03857 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55858 for (auto& observer : render_frames_)
859 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29860
[email protected]8a23afb32014-04-30 22:40:23861 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29862 return;
initial.commit09911bf2008-07-26 23:55:29863
[email protected]3399dd822014-08-09 11:14:24864 if (compositor_) {
865 ui::LatencyInfo swap_latency_info(latency_info);
danakj87fbafb2017-04-04 16:54:11866 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
867 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info);
868 // Force this SwapPromiseMonitor to trigger and insert a SwapPromise.
Blink Reformat1c4d759e2017-04-09 16:34:54869 compositor_->SetNeedsBeginFrame();
[email protected]3399dd822014-08-09 11:14:24870 }
initial.commit09911bf2008-07-26 23:55:29871}
872
[email protected]53d3f302009-12-21 04:42:05873void RenderWidget::OnRequestMoveAck() {
874 DCHECK(pending_window_rect_count_);
875 pending_window_rect_count_--;
876}
877
[email protected]ed7defa2013-03-12 21:29:59878GURL RenderWidget::GetURLForGraphicsContext3D() {
879 return GURL();
[email protected]65225772011-05-12 21:10:24880}
881
nzolghadr5d8596502017-01-23 22:59:35882void RenderWidget::OnHandleInputEvent(
883 const blink::WebInputEvent* input_event,
884 const std::vector<const blink::WebInputEvent*>& coalesced_events,
885 const ui::LatencyInfo& latency_info,
886 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23887 if (!input_event)
888 return;
nzolghadr5d8596502017-01-23 22:59:35889
Dave Tapuskaea83d3bd2017-06-13 16:14:55890 HandledEventCallback callback;
891 if (dispatch_type == DISPATCH_TYPE_BLOCKING) {
892 callback = base::Bind(
893 &RenderWidget::SendInputEventAck, this, input_event->GetType(),
894 ui::WebInputEventTraits::GetUniqueTouchEventId(*input_event));
895 }
nzolghadr5d8596502017-01-23 22:59:35896 input_handler_->HandleInputEvent(
897 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
Dave Tapuskaea83d3bd2017-06-13 16:14:55898 latency_info, std::move(callback));
fsamuel78f86e42016-01-20 04:10:23899}
900
Sadrul Habib Chowdhury6539b732018-01-05 21:53:27901viz::FrameSinkId RenderWidget::GetFrameSinkIdAtPoint(const gfx::Point& point) {
902 return input_handler_->GetFrameSinkIdAtPoint(point);
Navid Zolghadr0d86e5f2017-10-23 18:09:22903}
904
Dave Tapuskaea83d3bd2017-06-13 16:14:55905void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31906 const blink::WebCoalescedInputEvent& input_event,
907 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55908 HandledEventCallback callback) {
909 input_handler_->HandleInputEvent(input_event, latency_info,
910 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31911}
912
Dave Tapuskaea83d3bd2017-06-13 16:14:55913void RenderWidget::SendInputEventAck(
914 blink::WebInputEvent::Type type,
915 uint32_t touch_event_id,
916 InputEventAckState ack_state,
917 const ui::LatencyInfo& latency_info,
Dave Tapuskab28a1082017-08-30 15:37:26918 std::unique_ptr<ui::DidOverscrollParams> overscroll_params,
919 base::Optional<cc::TouchAction> touch_action) {
Dave Tapuskaea83d3bd2017-06-13 16:14:55920 InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_state,
Dave Tapuskab28a1082017-08-30 15:37:26921 latency_info, std::move(overscroll_params), touch_event_id,
922 touch_action);
dtapuska9ec1a912017-04-21 15:18:31923 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
924}
925
dtapuska9d46ef7d2017-05-26 19:06:06926scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
927 return input_event_queue_;
928}
929
fsamuel78f86e42016-01-20 04:10:23930void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21931 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54932 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23933}
934
935void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21936 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54937 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23938}
939
alexmos56567492016-09-13 00:52:46940void RenderWidget::OnSetEditCommandsForNextKeyEvent(
941 const EditCommands& edit_commands) {
942 edit_commands_ = edit_commands;
943}
944
fsamuel78f86e42016-01-20 04:10:23945void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08946 has_focus_ = enable;
947
lfg8ff33912016-09-13 20:59:21948 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54949 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08950
ericwilligers88e69742016-10-17 19:29:55951 for (auto& observer : render_frames_)
952 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23953}
954
dtapuska3d5624d32016-08-30 04:34:00955void RenderWidget::SetNeedsMainFrame() {
956 RenderWidgetCompositor* rwc = compositor();
957 if (!rwc)
958 return;
Blink Reformat1c4d759e2017-04-09 16:34:54959 rwc->SetNeedsBeginFrame();
dtapuska3d5624d32016-08-30 04:34:00960}
961
fsamuel78f86e42016-01-20 04:10:23962///////////////////////////////////////////////////////////////////////////////
963// RenderWidgetCompositorDelegate
964
965void RenderWidget::ApplyViewportDeltas(
966 const gfx::Vector2dF& inner_delta,
967 const gfx::Vector2dF& outer_delta,
968 const gfx::Vector2dF& elastic_overscroll_delta,
969 float page_scale,
970 float top_controls_delta) {
Ken Buchananed449bb2018-02-01 21:02:05971 if (!GetWebWidget())
972 return;
Blink Reformat1c4d759e2017-04-09 16:34:54973 GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta,
lfg8ff33912016-09-13 20:59:21974 elastic_overscroll_delta, page_scale,
975 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23976}
977
sahel1b47fda72017-03-28 17:03:07978void RenderWidget::RecordWheelAndTouchScrollingCount(
979 bool has_scrolled_by_wheel,
980 bool has_scrolled_by_touch) {
Ken Buchananed449bb2018-02-01 21:02:05981 if (!GetWebWidget())
982 return;
Blink Reformat1c4d759e2017-04-09 16:34:54983 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07984 has_scrolled_by_touch);
985}
986
fsamuel78f86e42016-01-20 04:10:23987void RenderWidget::BeginMainFrame(double frame_time_sec) {
Ken Buchananed449bb2018-02-01 21:02:05988 if (!GetWebWidget())
989 return;
dtapuska9ec1a912017-04-21 15:18:31990 if (input_event_queue_) {
991 input_event_queue_->DispatchRafAlignedInput(
992 ui::EventTimeStampFromSeconds(frame_time_sec));
993 }
dtapuska3d5624d32016-08-30 04:34:00994
Blink Reformat1c4d759e2017-04-09 16:34:54995 GetWebWidget()->BeginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23996}
997
danakjc7afae52017-06-20 21:12:41998void RenderWidget::RequestNewLayerTreeFrameSink(
danakjc7afae52017-06-20 21:12:41999 const LayerTreeFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:211000 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:031001 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:411002 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:391003 DCHECK(!compositor_never_visible_);
jonrossa2ff4f82018-02-16 17:27:461004
1005 // TODO(jonross): have this generated by the LayerTreeFrameSink itself, which
1006 // would then handle binding.
1007 mojom::RenderFrameMetadataObserverPtr ptr;
1008 mojom::RenderFrameMetadataObserverRequest request = mojo::MakeRequest(&ptr);
1009 mojom::RenderFrameMetadataObserverClientPtrInfo client_info;
1010 mojom::RenderFrameMetadataObserverClientRequest client_request =
1011 mojo::MakeRequest(&client_info);
1012 compositor_->CreateRenderFrameObserver(std::move(request),
1013 std::move(client_info));
danakjc7afae52017-06-20 21:12:411014 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
danakjab9ef4d2017-10-31 23:38:331015 routing_id_, frame_swap_message_queue_, GetURLForGraphicsContext3D(),
jonrossa2ff4f82018-02-16 17:27:461016 callback, std::move(client_request), std::move(ptr));
[email protected]ba91a792013-02-06 09:48:281017}
1018
fsamuel78f86e42016-01-20 04:10:231019void RenderWidget::DidCommitAndDrawCompositorFrame() {
1020 // NOTE: Tests may break if this event is renamed or moved. See
1021 // tab_capture_performancetest.cc.
1022 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:081023
ericwilligers88e69742016-10-17 19:29:551024 for (auto& observer : render_frames_)
1025 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:081026
fsamuel78f86e42016-01-20 04:10:231027 // Notify subclasses that we initiated the paint operation.
1028 DidInitiatePaint();
1029}
1030
Saman Sami766e0b02018-01-31 17:19:201031void RenderWidget::DidCommitCompositorFrame() {
Saman Samif9b3f6192018-03-29 02:59:291032 DidResizeOrRepaintAck();
Saman Sami766e0b02018-01-31 17:19:201033}
fsamuel78f86e42016-01-20 04:10:231034
1035void RenderWidget::DidCompletePageScaleAnimation() {}
1036
danakj6c872fc02016-10-22 04:29:491037void RenderWidget::DidReceiveCompositorFrameAck() {
fsamuel78f86e42016-01-20 04:10:231038}
1039
fsamuel78f86e42016-01-20 04:10:231040bool RenderWidget::IsClosing() const {
1041 return host_closing_;
1042}
1043
danakj53eccbc2016-03-02 22:51:071044void RenderWidget::RequestScheduleAnimation() {
Blink Reformat1c4d759e2017-04-09 16:34:541045 ScheduleAnimation();
initial.commit09911bf2008-07-26 23:55:291046}
1047
Eric Seckler8af8c0e52018-01-17 23:45:531048void RenderWidget::UpdateVisualState(VisualStateUpdate requested_update) {
Ken Buchananed449bb2018-02-01 21:02:051049 if (!GetWebWidget())
1050 return;
1051
Eric Seckler8af8c0e52018-01-17 23:45:531052 bool pre_paint_only = requested_update == VisualStateUpdate::kPrePaint;
1053 WebWidget::LifecycleUpdate lifecycle_update =
1054 pre_paint_only ? WebWidget::LifecycleUpdate::kPrePaint
1055 : WebWidget::LifecycleUpdate::kAll;
1056
1057 GetWebWidget()->UpdateLifecycle(lifecycle_update);
Blink Reformat1c4d759e2017-04-09 16:34:541058 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:501059
Eric Seckler8af8c0e52018-01-17 23:45:531060 if (first_update_visual_state_after_hidden_ && !pre_paint_only) {
Takashi SAKAMOTO870f6262017-08-22 04:08:271061 RecordTimeToFirstActivePaint();
1062 first_update_visual_state_after_hidden_ = false;
1063 }
1064}
tasakb95dbb50c2017-02-08 18:07:501065
Takashi SAKAMOTO870f6262017-08-22 04:08:271066void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501067 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501068 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271069 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1070 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1071 sample);
1072 }
1073 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1074 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1075 UMA_HISTOGRAM_TIMES(
1076 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1077 "AfterBackgrounded.5min",
1078 sample);
1079 }
fsamuel78f86e42016-01-20 04:10:231080}
1081
1082void RenderWidget::WillBeginCompositorFrame() {
1083 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1084
Ken Buchananed449bb2018-02-01 21:02:051085 if (!GetWebWidget())
1086 return;
1087
Blink Reformat1c4d759e2017-04-09 16:34:541088 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291089
dglazkov06854c5c2016-08-31 00:19:591090 // The UpdateTextInputState can result in further layout and possibly
1091 // enable GPU acceleration so they need to be called before any painting
1092 // is done.
changwan75e3b2072017-01-16 02:55:001093 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591094 UpdateSelectionBounds();
1095
ericwilligers88e69742016-10-17 19:29:551096 for (auto& observer : render_frame_proxies_)
1097 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291098}
1099
jbroman6ccbc7d472016-07-27 04:45:411100std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:041101 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:411102 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
1103 routing_id_, std::move(request));
1104}
1105
fsamuel72464894f2015-12-15 06:59:311106///////////////////////////////////////////////////////////////////////////////
1107// RenderWidgetInputHandlerDelegate
1108
avid7d6b2e2016-03-04 19:41:171109void RenderWidget::FocusChangeComplete() {
Ehsan Karamad655d7b8a2018-01-12 18:38:381110 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1111 if (!frame_widget)
ekaramad27ca69b12017-04-20 18:34:291112 return;
Ehsan Karamad655d7b8a2018-01-12 18:38:381113
ekaramad27ca69b12017-04-20 18:34:291114 blink::WebLocalFrame* focused =
Ehsan Karamad655d7b8a2018-01-12 18:38:381115 frame_widget->LocalRoot()->View()->FocusedFrame();
1116
ekaramad27ca69b12017-04-20 18:34:291117 if (focused && focused->AutofillClient())
1118 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171119}
fsamuel72464894f2015-12-15 06:59:311120
dtapuska1827dd22016-03-11 15:24:591121void RenderWidget::ObserveGestureEventAndResult(
1122 const blink::WebGestureEvent& gesture_event,
1123 const gfx::Vector2dF& unused_delta,
Sandra Sunac5cdd832017-12-11 03:27:131124 const cc::OverscrollBehavior& overscroll_behavior,
dtapuska1827dd22016-03-11 15:24:591125 bool event_processed) {
1126 if (!compositor_deps_->IsElasticOverscrollEnabled())
1127 return;
1128
1129 cc::InputHandlerScrollResult scroll_result;
1130 scroll_result.did_scroll = event_processed;
1131 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1132 scroll_result.unused_scroll_delta = unused_delta;
Sandra Sunac5cdd832017-12-11 03:27:131133 scroll_result.overscroll_behavior = overscroll_behavior;
dtapuska1827dd22016-03-11 15:24:591134
1135 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1136 InputHandlerManager* input_handler_manager =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281137 render_thread ? render_thread->input_handler_manager() : nullptr;
dtapuska1827dd22016-03-11 15:24:591138 if (input_handler_manager) {
1139 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1140 routing_id_, gesture_event, scroll_result);
Dave Tapuska9db80842017-07-24 17:24:261141 } else if (widget_input_handler_manager_) {
1142 widget_input_handler_manager_->ObserveGestureEventOnMainThread(
1143 gesture_event, scroll_result);
dtapuska1827dd22016-03-11 15:24:591144 }
1145}
1146
avid7d6b2e2016-03-04 19:41:171147void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461148 ClearEditCommands();
1149}
1150
1151void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1152 const std::string& value) {
1153 ClearEditCommands();
1154 edit_commands_.emplace_back(name, value);
1155}
1156
1157void RenderWidget::ClearEditCommands() {
1158 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171159}
fsamuel72464894f2015-12-15 06:59:311160
chongza8ba91fc2016-08-16 21:39:171161void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska139a72f2017-09-06 21:57:031162 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:051163 if (mojom::WidgetInputHandlerHost* host =
1164 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1165 host->DidOverscroll(params);
1166 }
Dave Tapuska139a72f2017-09-06 21:57:031167 } else {
1168 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1169 }
fsamuel72464894f2015-12-15 06:59:311170}
1171
fsamuele8326c742016-01-12 00:49:391172void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1173 // Nothing to do here. RenderWidget created the |input_handler| and will take
1174 // ownership of it. We just verify here that we don't already have an input
1175 // handler.
1176 DCHECK(!input_handler_);
1177}
1178
changwan75e3b2072017-01-16 02:55:001179void RenderWidget::ShowVirtualKeyboard() {
1180 UpdateTextInputStateInternal(true, false);
1181}
1182
changwan62f57292017-02-17 08:28:251183void RenderWidget::ClearTextInputState() {
1184 text_input_info_ = blink::WebTextInputInfo();
1185 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1186 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1187 can_compose_inline_ = false;
1188 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201189 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251190}
1191
changwan75e3b2072017-01-16 02:55:001192void RenderWidget::UpdateTextInputState() {
1193 UpdateTextInputStateInternal(false, false);
1194}
1195
1196void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1197 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311198 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001199
fsamuel72464894f2015-12-15 06:59:311200 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001201 DCHECK(!reply_to_request);
1202 // show_virtual_keyboard should still be effective even if it was set inside
1203 // the IME
fsamuel72464894f2015-12-15 06:59:311204 // event guard.
changwan75e3b2072017-01-16 02:55:001205 if (show_virtual_keyboard)
1206 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311207 return;
1208 }
1209
dglazkov97b6c2b2016-10-25 17:35:551210 ui::TextInputType new_type = GetTextInputType();
1211 if (IsDateTimeInput(new_type))
1212 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311213
dglazkov97b6c2b2016-10-25 17:35:551214 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351215 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541216 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101217 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541218 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311219
1220 bool new_can_compose_inline = CanComposeInline();
1221
1222 // Only sends text input params if they are changed or if the ime should be
1223 // shown.
changwan75e3b2072017-01-16 02:55:001224 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561225 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1226 text_input_info_ != new_info ||
1227 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381228 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551229 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311230 params.mode = new_mode;
1231 params.flags = new_info.flags;
AJITH KUMAR V9e7b5572017-11-14 00:54:211232#if defined(OS_ANDROID)
AJITH KUMAR V041c0b02017-08-08 10:39:201233 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1234 // Due to a focus change, values will be reset by the frame.
1235 // That case we only need fresh NEXT/PREVIOUS information.
1236 // Also we won't send ViewHostMsg_TextInputStateChanged if next/previous
1237 // focusable status is changed.
1238 if (auto* controller = GetInputMethodController()) {
1239 next_previous_flags_ =
1240 controller->ComputeWebTextInputNextPreviousFlags();
1241 } else {
1242 // For safety in case GetInputMethodController() is null, because -1 is
1243 // invalid value to send to browser process.
1244 next_previous_flags_ = 0;
1245 }
1246 }
AJITH KUMAR V9e7b5572017-11-14 00:54:211247#else
1248 next_previous_flags_ = 0;
1249#endif
AJITH KUMAR V041c0b02017-08-08 10:39:201250 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541251 params.value = new_info.value.Utf8();
1252 params.selection_start = new_info.selection_start;
1253 params.selection_end = new_info.selection_end;
1254 params.composition_start = new_info.composition_start;
1255 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311256 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001257 // TODO(changwan): change instances of show_ime_if_needed to
1258 // show_virtual_keyboard.
1259 params.show_ime_if_needed = show_virtual_keyboard;
1260 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311261 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1262
1263 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551264 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311265 text_input_mode_ = new_mode;
1266 can_compose_inline_ = new_can_compose_inline;
1267 text_input_flags_ = new_info.flags;
1268 }
1269}
1270
1271bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581272 possible_drag_event_info_.event_source =
1273 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1274 possible_drag_event_info_.event_location =
Ella Ge1116059d2018-03-21 02:06:131275 gfx::ToFlooredPoint(event.PositionInScreen());
avid7d6b2e2016-03-04 19:41:171276
fsamuel72464894f2015-12-15 06:59:311277 return false;
1278}
1279
1280bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551281 for (auto& observer : render_frames_)
1282 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081283
paulmeyer6ef5a792016-11-08 20:33:581284 possible_drag_event_info_.event_source =
1285 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1286 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541287 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581288
avid7d6b2e2016-03-04 19:41:171289 if (owner_delegate_)
1290 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1291
fsamuel72464894f2015-12-15 06:59:311292 return false;
[email protected]fd847792013-10-24 17:12:351293}
1294
initial.commit09911bf2008-07-26 23:55:291295///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391296// RenderWidgetScreenMetricsDelegate
1297
1298void RenderWidget::Redraw() {
1299 set_next_paint_is_resize_ack();
1300 if (compositor_)
1301 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1302}
1303
bokanc63441c2016-04-27 15:49:121304void RenderWidget::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:541305 GetWebWidget()->Resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121306}
1307
1308gfx::Size RenderWidget::GetSizeForWebWidget() const {
Fady Samuela863f152018-03-09 16:10:031309 if (IsUseZoomForDSFEnabled()) {
1310 return gfx::ScaleToCeiledSize(size_,
1311 GetOriginalScreenInfo().device_scale_factor);
1312 }
bokanc63441c2016-04-27 15:49:121313
1314 return size_;
1315}
1316
mfomitchev2600fd7c2016-02-17 20:53:391317void RenderWidget::Resize(const ResizeParams& params) {
Chris Blume760b9462018-04-12 21:45:331318 viz::LocalSurfaceId new_local_surface_id;
1319 // If the content_source_id of ResizeParams doesn't match
1320 // |current_content_source_id_|, then the given LocalSurfaceId was generated
1321 // before the navigation. Continue with the resize but don't use the
1322 // LocalSurfaceId until the right one comes.
1323 if (params.local_surface_id &&
1324 params.content_source_id == current_content_source_id_) {
1325 new_local_surface_id = child_local_surface_id_allocator_.UpdateFromParent(
1326 params.local_surface_id.value());
1327 }
1328
Fady Samuele62be402018-03-29 03:19:531329 if (params.auto_resize_enabled && auto_resize_mode_ &&
1330 (!params.auto_resize_sequence_number ||
1331 auto_resize_sequence_number_ != params.auto_resize_sequence_number)) {
1332 DidResizeOrRepaintAck();
1333 return;
1334 }
1335
Saman Samif7731342018-01-24 22:18:441336 // The content_source_id that the browser sends us should never be larger than
1337 // |current_content_source_id_|.
1338 DCHECK_GE(1u << 30, current_content_source_id_ - params.content_source_id);
1339
Christopher Cameronbe7ecea2018-02-27 00:47:191340 // Inform the rendering thread of the color space indicate the presence of HDR
1341 // capabilities.
Miguel Casas5e1018052018-01-09 19:17:361342 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1343 if (render_thread)
Christopher Camerone9a30c12018-03-07 08:23:381344 render_thread->SetRenderingColorSpace(params.screen_info.color_space);
Miguel Casas5e1018052018-01-09 19:17:361345
mfomitchev2600fd7c2016-02-17 20:53:391346 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1347 // A resize ack shouldn't be requested if we have not ACK'd the previous
1348 // one.
Saman Samif7731342018-01-24 22:18:441349 DCHECK(!compositor_ || !params.needs_resize_ack ||
1350 !next_paint_is_resize_ack());
mfomitchev2600fd7c2016-02-17 20:53:391351 }
1352
1353 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211354 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391355 return;
1356
Fady Samuele62be402018-03-29 03:19:531357 gfx::Size new_compositor_viewport_pixel_size =
1358 params.auto_resize_enabled
1359 ? gfx::ScaleToCeiledSize(size_,
1360 params.screen_info.device_scale_factor)
1361 : params.compositor_viewport_pixel_size;
Christopher Cameronaad15a0d2018-03-09 03:47:331362 UpdateSurfaceAndScreenInfo(new_local_surface_id,
Fady Samuele62be402018-03-29 03:19:531363 new_compositor_viewport_pixel_size,
Christopher Camerone9a30c12018-03-07 08:23:381364 params.screen_info);
ianwene5fc5782016-08-18 04:05:151365 if (compositor_) {
Fady Samuel319e429c2017-10-02 18:31:551366 // If surface synchronization is enabled, then this will use the provided
fsamuelca02c4e2017-05-09 13:34:141367 // |local_surface_id_| to submit the next generated CompositorFrame.
1368 // If the ID is not valid, then the compositor will defer commits until
1369 // it receives a valid surface ID. This is a no-op if surface
1370 // synchronization is disabled.
Fady Samuel2bb02292017-10-17 23:59:151371 DCHECK(!compositor_->IsSurfaceSynchronizationEnabled() ||
Fady Samuela41e9d42018-03-01 21:31:581372 !params.needs_resize_ack || !params.local_surface_id ||
1373 params.local_surface_id->is_valid());
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271374 compositor_->SetBrowserControlsHeight(
1375 params.top_controls_height, params.bottom_controls_height,
1376 params.browser_controls_shrink_blink_size);
1377 compositor_->SetRasterColorSpace(
1378 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151379 }
mfomitchev2600fd7c2016-02-17 20:53:391380
Fady Samuele62be402018-03-29 03:19:531381 if (params.auto_resize_enabled)
1382 return;
1383
mfomitchev2600fd7c2016-02-17 20:53:391384 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391385
1386 // NOTE: We may have entered fullscreen mode without changing our size.
1387 bool fullscreen_change =
1388 is_fullscreen_granted_ != params.is_fullscreen_granted;
1389 is_fullscreen_granted_ = params.is_fullscreen_granted;
1390 display_mode_ = params.display_mode;
1391
bokanc63441c2016-04-27 15:49:121392 size_ = params.new_size;
mfomitchev2600fd7c2016-02-17 20:53:391393
bokanc63441c2016-04-27 15:49:121394 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221395
mfomitchev2600fd7c2016-02-17 20:53:391396 WebSize visual_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391397 if (IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:031398 visual_viewport_size =
1399 gfx::ScaleToCeiledSize(params.visible_viewport_size,
1400 GetOriginalScreenInfo().device_scale_factor);
mfomitchev2600fd7c2016-02-17 20:53:391401 } else {
1402 visual_viewport_size = visible_viewport_size_;
1403 }
Blink Reformat1c4d759e2017-04-09 16:34:541404 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391405
bokanc63441c2016-04-27 15:49:121406 // When resizing, we want to wait to paint before ACK'ing the resize. This
1407 // ensures that we only resize as fast as we can paint. We only need to
1408 // send an ACK if we are resized to a non-empty rect.
Christopher Cameronaad15a0d2018-03-09 03:47:331409 if (params.new_size.IsEmpty() ||
1410 params.compositor_viewport_pixel_size.IsEmpty()) {
mfomitchev2600fd7c2016-02-17 20:53:391411 // In this case there is no paint/composite and therefore no
Fady Samuelcc3e3b4a2017-10-03 02:09:211412 // ViewHostMsg_ResizeOrRepaint_ACK to send the resize ack with. We'd need to
1413 // send the ack through a fake ViewHostMsg_ResizeOrRepaint_ACK or a
1414 // different message.
mfomitchev2600fd7c2016-02-17 20:53:391415 DCHECK(!params.needs_resize_ack);
1416 }
1417
1418 // Send the Resize_ACK flag once we paint again if requested.
1419 if (params.needs_resize_ack)
1420 set_next_paint_is_resize_ack();
1421
1422 if (fullscreen_change)
1423 DidToggleFullscreen();
1424
1425 // If a resize ack is requested and it isn't set-up, then no more resizes will
1426 // come in and in general things will go wrong.
1427 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
Saman Samif7731342018-01-24 22:18:441428
1429 // If this resize was initiated before navigation and surface synchronization
1430 // is on, it is not expected to be acked.
1431 if (compositor_ && compositor_->IsSurfaceSynchronizationEnabled() &&
1432 params.needs_resize_ack && !local_surface_id_.is_valid()) {
1433 DCHECK_NE(params.content_source_id, current_content_source_id_);
1434 reset_next_paint_is_resize_ack();
1435 }
mfomitchev2600fd7c2016-02-17 20:53:391436}
1437
1438void RenderWidget::SetScreenMetricsEmulationParameters(
1439 bool enabled,
1440 const blink::WebDeviceEmulationParams& params) {
1441 // This is only supported in RenderView.
1442 NOTREACHED();
1443}
1444
1445void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1446 const gfx::Rect& window_screen_rect) {
1447 view_screen_rect_ = view_screen_rect;
1448 window_screen_rect_ = window_screen_rect;
1449}
1450
1451///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461452// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291453
Blink Reformat1c4d759e2017-04-09 16:34:541454blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221455 DCHECK(!host_closing_);
1456
loyso6e6efc42017-01-21 02:23:031457 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1458 auto animation_host = cc::AnimationHost::CreateMainInstance();
1459
wjmacleana755e302017-04-20 00:43:161460 // Oopif status must be set before the LayerTreeHost is created.
1461 compositor_->SetIsForOopif(for_oopif_);
loyso6e6efc42017-01-21 02:23:031462 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1463 compositor_.get(), compositor_.get(), animation_host.get(),
Christopher Camerone9a30c12018-03-07 08:23:381464 compositor_deps_, screen_info_);
loyso6e6efc42017-01-21 02:23:031465 compositor_->Initialize(std::move(layer_tree_host),
1466 std::move(animation_host));
1467
Saman Samif7731342018-01-24 22:18:441468 // We can get into this state if surface synchronization is on and the last
1469 // resize was initiated before navigation, in which case we don't have to ack
1470 // it.
1471 if (compositor_->IsSurfaceSynchronizationEnabled() && !auto_resize_mode_ &&
1472 next_paint_is_resize_ack() && !local_surface_id_.is_valid()) {
1473 reset_next_paint_is_resize_ack();
1474 }
1475
Christopher Cameronaad15a0d2018-03-09 03:47:331476 UpdateSurfaceAndScreenInfo(local_surface_id_, compositor_viewport_pixel_size_,
Christopher Camerone9a30c12018-03-07 08:23:381477 screen_info_);
ccameron01912992017-05-23 07:34:031478 compositor_->SetRasterColorSpace(
Christopher Camerona1ea2b72017-08-02 01:59:091479 screen_info_.color_space.GetRasterColorSpace());
kenrb5d78b842017-03-06 21:06:011480 compositor_->SetContentSourceId(current_content_source_id_);
sievers71c62dd52015-10-07 01:44:391481 // For background pages and certain tests, we don't want to trigger
danakjc7afae52017-06-20 21:12:411482 // LayerTreeFrameSink creation.
dtapuskab08611f2017-04-24 16:10:221483 bool should_generate_frame_sink =
1484 !compositor_never_visible_ && RenderThreadImpl::current();
1485 if (!should_generate_frame_sink)
sievers71c62dd52015-10-07 01:44:391486 compositor_->SetNeverVisible();
1487
pimanc4af3072015-10-02 03:45:591488 StartCompositor();
staraz067f58242016-11-07 21:06:411489 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1490 compositor_->SetFrameSinkId(
Fady Samueld5c26182017-07-12 02:43:331491 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371492
wjmaclean1d970622017-01-21 22:28:241493 RenderThreadImpl* render_thread = RenderThreadImpl::current();
Dave Tapuska9db80842017-07-24 17:24:261494 if (render_thread) {
dtapuska9ec1a912017-04-21 15:18:311495 input_event_queue_ = new MainThreadEventQueue(
Yuta Kitamura3331f5c2018-04-05 11:12:251496 this, render_thread->GetWebMainThreadScheduler()->InputTaskRunner(),
1497 render_thread->GetWebMainThreadScheduler(), should_generate_frame_sink);
Dave Tapuska9db80842017-07-24 17:24:261498
1499 InputHandlerManager* input_handler_manager =
1500 render_thread->input_handler_manager();
1501 if (input_handler_manager) {
1502 input_handler_manager->AddInputHandler(
1503 routing_id_, compositor()->GetInputHandler(), input_event_queue_,
1504 weak_ptr_factory_.GetWeakPtr(),
1505 compositor_deps_->IsScrollAnimatorEnabled());
1506 has_added_input_handler_ = true;
1507 }
wjmaclean1d970622017-01-21 22:28:241508 }
1509
Khushal3e96e662017-10-30 23:16:501510 UpdateURLForCompositorUkm();
1511
loyso50b51c22017-01-10 07:18:371512 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591513}
1514
Chris Harrelsond7ab99b2018-01-24 17:51:361515void RenderWidget::IntrinsicSizingInfoChanged(
1516 const blink::WebIntrinsicSizingInfo& sizing_info) {
1517 Send(new ViewHostMsg_IntrinsicSizingInfoChanged(routing_id_, sizing_info));
1518}
1519
ennef3c58142014-12-09 21:44:381520void RenderWidget::WillCloseLayerTreeView() {
1521 if (host_closing_)
1522 return;
1523
1524 // Prevent new compositors or output surfaces from being created.
1525 host_closing_ = true;
1526
[email protected]aeeedad2014-08-22 18:16:221527 // Always send this notification to prevent new layer tree views from
1528 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211529 if (blink::WebWidget* widget = GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541530 widget->WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221531}
1532
Blink Reformat1c4d759e2017-04-09 16:34:541533void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1534 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
dglazkovf0e1d6d2015-10-10 02:13:481535 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1536 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1537 }
dglazkov79c426102015-08-31 21:22:431538
ericwilligers88e69742016-10-17 19:29:551539 for (auto& observer : render_frames_)
1540 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431541}
1542
[email protected]586871b2014-07-22 17:05:111543// static
dchengcedca5612016-04-09 01:40:151544std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111545 IPC::Message* msg,
1546 MessageDeliveryPolicy policy,
1547 FrameSwapMessageQueue* frame_swap_message_queue,
1548 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111549 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111550 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151551 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1552 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111553 &first_message_for_frame);
1554 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151555 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111556 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061557 return promise;
[email protected]586871b2014-07-22 17:05:111558 }
dcheng4b6b5ff2014-10-16 00:42:061559 return nullptr;
[email protected]586871b2014-07-22 17:05:111560}
1561
1562void RenderWidget::QueueMessage(IPC::Message* msg,
1563 MessageDeliveryPolicy policy) {
1564 // RenderThreadImpl::current() is NULL in some tests.
1565 if (!compositor_ || !RenderThreadImpl::current()) {
1566 Send(msg);
1567 return;
1568 }
1569
dchengcedca5612016-04-09 01:40:151570 std::unique_ptr<cc::SwapPromise> swap_promise =
1571 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111572 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111573 compositor_->GetSourceFrameNumber());
1574
Ken Buchanance710eb2017-08-30 23:46:521575 if (swap_promise)
dcheng07945f632015-12-26 07:59:321576 compositor_->QueueSwapPromise(std::move(swap_promise));
[email protected]586871b2014-07-22 17:05:111577}
1578
Blink Reformat1c4d759e2017-04-09 16:34:541579void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301580 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521581 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181582 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291583 // Only send a SetCursor message if we need to make a change.
1584 if (!current_cursor_.IsEqual(cursor)) {
1585 current_cursor_ = cursor;
1586 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1587 }
1588}
1589
aelias5971e47d2017-06-16 02:39:381590void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
1591 Send(new ViewHostMsg_AutoscrollStart(routing_id_, point));
1592}
1593
1594void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
1595 Send(new ViewHostMsg_AutoscrollFling(routing_id_, velocity));
1596}
1597
1598void RenderWidget::AutoscrollEnd() {
1599 Send(new ViewHostMsg_AutoscrollEnd(routing_id_));
1600}
1601
initial.commit09911bf2008-07-26 23:55:291602// We are supposed to get a single call to Show for a newly created RenderWidget
1603// that was created via RenderWidget::CreateWebView. So, we wait until this
1604// point to dispatch the ShowWidget message.
1605//
1606// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281607// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291608//
Blink Reformat1c4d759e2017-04-09 16:34:541609void RenderWidget::Show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291610 DCHECK(!did_show_) << "received extraneous Show call";
1611 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351612 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291613
[email protected]8de12d942010-11-17 20:42:441614 if (did_show_)
1615 return;
1616
1617 did_show_ = true;
nickf7b38222016-11-22 21:59:351618
1619 // The opener is responsible for actually showing this widget.
1620 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351621 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351622
bokanc007c3a2015-02-03 07:15:561623 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441624 // that's okay. It'll be ignored if as_popup is false, or the browser
1625 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561626 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291627}
1628
[email protected]2533ce12009-05-09 00:02:241629void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381630 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241631 Send(new ViewHostMsg_Close(routing_id_));
1632}
1633
dgozmancf9039cd2015-04-06 12:01:311634void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551635 for (auto& observer : render_frames_)
1636 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311637}
1638
Blink Reformat1c4d759e2017-04-09 16:34:541639void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081640 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321641 if (is_swapped_out_) {
1642 // This widget is currently swapped out, and the active widget is in a
1643 // different process. Have the browser route the close request to the
1644 // active widget instead, so that the correct unload handlers are run.
1645 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1646 return;
1647 }
1648
initial.commit09911bf2008-07-26 23:55:291649 // If a page calls window.close() twice, we'll end up here twice, but that's
1650 // OK. It is safe to send multiple Close messages.
1651
[email protected]2533ce12009-05-09 00:02:241652 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1653 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1654 // could be closed before the JS finishes executing. So instead, post a
1655 // message back to the message loop, which won't run until the JS is
1656 // complete, and then the Close message can be sent.
Hajime Hoshiabb3c8f2017-12-04 18:41:391657 task_runner_->PostTask(FROM_HERE,
1658 base::BindOnce(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291659}
1660
1661void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031662 screen_metrics_emulator_.reset();
Ken Buchananed449bb2018-02-01 21:02:051663 CloseWebWidget();
ennef3c58142014-12-09 21:44:381664 compositor_.reset();
Ken Buchananed449bb2018-02-01 21:02:051665}
1666
1667void RenderWidget::CloseWebWidget() {
1668 WillCloseLayerTreeView();
lfg8ff33912016-09-13 20:59:211669 if (webwidget_internal_) {
Blink Reformat1c4d759e2017-04-09 16:34:541670 webwidget_internal_->Close();
lfg8ff33912016-09-13 20:59:211671 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291672 }
1673}
1674
Mitsuru Oshima3c07b332018-02-06 04:56:501675void RenderWidget::UpdateWebViewWithDeviceScaleFactor() {
1676 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1677 blink::WebFrame* current_frame =
1678 frame_widget ? frame_widget->LocalRoot() : nullptr;
1679 blink::WebView* webview = current_frame ? current_frame->View() : nullptr;
1680 if (webview) {
1681 if (IsUseZoomForDSFEnabled())
Fady Samuela863f152018-03-09 16:10:031682 webview->SetZoomFactorForDeviceScaleFactor(
1683 GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:501684 else
Fady Samuela863f152018-03-09 16:10:031685 webview->SetDeviceScaleFactor(GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:501686
1687 webview->GetSettings()->SetPreferCompositingToLCDTextEnabled(
Christopher Camerone9a30c12018-03-07 08:23:381688 PreferCompositingToLCDText(compositor_deps_,
Fady Samuela863f152018-03-09 16:10:031689 GetWebScreenInfo().device_scale_factor));
Mitsuru Oshima3c07b332018-02-06 04:56:501690 }
1691}
1692
Ehsan Karamad655d7b8a2018-01-12 18:38:381693blink::WebFrameWidget* RenderWidget::GetFrameWidget() const {
1694 blink::WebWidget* web_widget = GetWebWidget();
1695 if (!web_widget)
1696 return nullptr;
1697
1698 if (!web_widget->IsWebFrameWidget()) {
1699 // TODO(ekaramad): This should not happen. If we have a WebWidget and we
1700 // need a WebFrameWidget then we should be getting a WebFrameWidget. But
1701 // unfortunately this does not seem to be the case in some scenarios --
1702 // specifically when a RenderViewImpl swaps out during navigation the
1703 // WebViewImpl loses its WebViewFrameWidget but sometimes we receive IPCs
1704 // which are destined for WebFrameWidget (https://crbug.com/669219).
1705 return nullptr;
1706 }
1707
1708 return static_cast<blink::WebFrameWidget*>(web_widget);
1709}
1710
bokan841fdc72016-10-06 00:16:351711void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1712 DCHECK(window_rect);
1713 float scale = popup_origin_scale_for_emulation_;
1714 if (!scale)
1715 return;
1716 window_rect->x =
1717 popup_view_origin_for_emulation_.x() +
1718 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1719 window_rect->y =
1720 popup_view_origin_for_emulation_.y() +
1721 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1722}
1723
1724void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1725 DCHECK(window_rect);
1726 float scale = popup_origin_scale_for_emulation_;
1727 if (!scale)
1728 return;
1729 window_rect->x =
1730 popup_screen_origin_for_emulation_.x() +
1731 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1732 window_rect->y =
1733 popup_screen_origin_for_emulation_.y() +
1734 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1735}
1736
Blink Reformat1c4d759e2017-04-09 16:34:541737WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351738 WebRect rect;
bokan6b08cd22016-10-05 00:55:211739 if (pending_window_rect_count_) {
1740 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1741 // the RootWindowRect is probably going to return wrong results since the
1742 // browser may not have processed the Move yet. There isn't really anything
1743 // good to do in this case, and it shouldn't happen - since this size is
1744 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351745 rect = pending_window_rect_;
1746 } else {
1747 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211748 }
[email protected]2533ce12009-05-09 00:02:241749
bokan841fdc72016-10-06 00:16:351750 ScreenRectToEmulatedIfNeeded(&rect);
1751 return rect;
bokan6b08cd22016-10-05 00:55:211752}
1753
Blink Reformat1c4d759e2017-04-09 16:34:541754WebRect RenderWidget::ViewRect() {
bokan841fdc72016-10-06 00:16:351755 WebRect rect = view_screen_rect_;
1756 ScreenRectToEmulatedIfNeeded(&rect);
1757 return rect;
initial.commit09911bf2008-07-26 23:55:291758}
1759
Blink Reformat1c4d759e2017-04-09 16:34:541760void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301761 WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541762 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301763}
1764
Blink Reformat1c4d759e2017-04-09 16:34:541765void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
oshima33ec97cd2015-12-14 19:40:241766 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351767 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511768
[email protected]5b45ad42013-10-25 00:42:041769 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201770 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561771 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1772 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031773 } else {
bokanc007c3a2015-02-03 07:15:561774 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031775 }
initial.commit09911bf2008-07-26 23:55:291776 } else {
bokanc007c3a2015-02-03 07:15:561777 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291778 }
1779}
1780
[email protected]2533ce12009-05-09 00:02:241781void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1782 pending_window_rect_ = rect;
1783 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241784
bokan6b08cd22016-10-05 00:55:211785 // Popups don't get size updates back from the browser so just store the set
1786 // values.
Blink Reformat1c4d759e2017-04-09 16:34:541787 if (popup_type_ != blink::kWebPopupTypeNone) {
1788 window_screen_rect_ = rect;
1789 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241790 }
[email protected]d4547452008-08-28 18:36:371791}
1792
wjmacleanee244e02017-05-26 21:06:071793void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1794 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071795 has_host_context_menu_location_ = true;
1796 host_context_menu_location_ = location;
1797 if (GetWebWidget()) {
1798 GetWebWidget()->ShowContextMenu(
1799 static_cast<blink::WebMenuSourceType>(source_type));
1800 }
1801 has_host_context_menu_location_ = false;
1802}
1803
[email protected]fa7b1dc2010-06-23 17:53:041804void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261805 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111806 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:071807 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:111808 int selection_start,
1809 int selection_end) {
ekaramad5aff1942017-01-06 01:26:351810 if (!ShouldHandleImeEvents())
1811 return;
1812
brettw4b461082016-11-19 18:55:161813#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491814 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:111815 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:491816 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091817 return;
1818 }
1819#endif
[email protected]66fca5bc2013-05-23 06:58:291820 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011821 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011822 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541823 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:111824 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561825 replacement_range.IsValid()
1826 ? WebRange(replacement_range.start(), replacement_range.length())
1827 : WebRange(),
1828 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041829 // If we failed to set the composition text, then we need to let the browser
1830 // process to cancel the input method's ongoing composition session, to make
1831 // sure we are in a consistent state.
Dave Tapuska139a72f2017-09-06 21:57:031832 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:051833 if (mojom::WidgetInputHandlerHost* host =
1834 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1835 host->ImeCancelComposition();
1836 }
Dave Tapuska139a72f2017-09-06 21:57:031837 } else {
1838 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1839 }
[email protected]7f00efa2010-04-15 05:01:261840 }
nonafa291792016-08-10 02:36:181841 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041842}
1843
rlanday7efe2302017-01-11 00:14:281844void RenderWidget::OnImeCommitText(
1845 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111846 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:281847 const gfx::Range& replacement_range,
1848 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351849 if (!ShouldHandleImeEvents())
1850 return;
1851
brettw4b461082016-11-19 18:55:161852#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491853 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1854 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1855 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091856 return;
1857 }
1858#endif
[email protected]66fca5bc2013-05-23 06:58:291859 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391860 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261861 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541862 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:111863 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561864 replacement_range.IsValid()
1865 ? WebRange(replacement_range.start(), replacement_range.length())
1866 : WebRange(),
1867 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261868 }
aelias87b8f7c2016-09-14 03:19:291869 input_handler_->set_handling_input_event(false);
1870 UpdateCompositionInfo(false /* not an immediate request */);
1871}
1872
1873void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351874 if (!ShouldHandleImeEvents())
1875 return;
1876
brettw4b461082016-11-19 18:55:161877#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491878 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1879 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291880 return;
1881 }
1882#endif
1883
changwan38c3eb612016-12-09 01:45:561884 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291885 return;
1886 ImeEventGuard guard(this);
1887 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011888 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541889 controller->FinishComposingText(
1890 keep_selection ? WebInputMethodController::kKeepSelection
1891 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011892 }
fsamuele8326c742016-01-12 00:49:391893 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181894 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291895}
1896
Christopher Camerone9a30c12018-03-07 08:23:381897void RenderWidget::UpdateSurfaceAndScreenInfo(
Christopher Cameronbe7ecea2018-02-27 00:47:191898 viz::LocalSurfaceId new_local_surface_id,
Christopher Cameronaad15a0d2018-03-09 03:47:331899 const gfx::Size& new_compositor_viewport_pixel_size,
Christopher Camerone9a30c12018-03-07 08:23:381900 const ScreenInfo& new_screen_info) {
Christopher Camerone9a30c12018-03-07 08:23:381901 bool orientation_changed =
1902 screen_info_.orientation_angle != new_screen_info.orientation_angle ||
1903 screen_info_.orientation_type != new_screen_info.orientation_type;
1904 bool web_device_scale_factor_changed =
1905 screen_info_.device_scale_factor != new_screen_info.device_scale_factor;
Fady Samuela863f152018-03-09 16:10:031906 ScreenInfo previous_original_screen_info = GetOriginalScreenInfo();
Christopher Cameronbe7ecea2018-02-27 00:47:191907
1908 local_surface_id_ = new_local_surface_id;
Christopher Cameronaad15a0d2018-03-09 03:47:331909 compositor_viewport_pixel_size_ = new_compositor_viewport_pixel_size;
Christopher Camerone9a30c12018-03-07 08:23:381910 screen_info_ = new_screen_info;
Christopher Cameronbe7ecea2018-02-27 00:47:191911
Christopher Camerone9a30c12018-03-07 08:23:381912 if (compositor_) {
Ken Buchananb2c9e262018-03-10 16:53:311913 compositor_->SetViewportVisibleRect(ViewportVisibleRect());
Christopher Camerone9a30c12018-03-07 08:23:381914 // Note carefully that the DSF specified in |new_screen_info| is not the
1915 // DSF used by the compositor during device emulation!
Fady Samuela863f152018-03-09 16:10:031916 compositor_->SetViewportSizeAndScale(
1917 compositor_viewport_pixel_size_,
1918 GetOriginalScreenInfo().device_scale_factor, local_surface_id_);
Christopher Camerone9a30c12018-03-07 08:23:381919 }
Christopher Cameronbe7ecea2018-02-27 00:47:191920
Christopher Camerone9a30c12018-03-07 08:23:381921 if (orientation_changed)
1922 OnOrientationChange();
Christopher Cameronbe7ecea2018-02-27 00:47:191923
Fady Samuela863f152018-03-09 16:10:031924 if (previous_original_screen_info != GetOriginalScreenInfo()) {
Christopher Camerone9a30c12018-03-07 08:23:381925 for (auto& observer : render_frame_proxies_)
Fady Samuela863f152018-03-09 16:10:031926 observer.OnScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:381927
1928 // Notify all embedded BrowserPlugins of the updated ScreenInfo.
1929 for (auto& observer : browser_plugins_)
Fady Samuela863f152018-03-09 16:10:031930 observer.ScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:381931 }
1932
1933 if (web_device_scale_factor_changed)
Christopher Cameronbe7ecea2018-02-27 00:47:191934 UpdateWebViewWithDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331935}
1936
[email protected]0bc1f572013-04-17 01:46:311937void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121938 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211939 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121940 return;
1941
[email protected]0bc1f572013-04-17 01:46:311942 // Even if the browser provides an empty damage rect, it's still expecting to
1943 // receive a repaint ack so just damage the entire widget bounds.
1944 if (size_to_paint.IsEmpty()) {
1945 size_to_paint = size_;
1946 }
1947
[email protected]ec7dc112008-08-06 05:30:121948 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051949 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311950 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121951}
1952
[email protected]4873c7d2009-07-16 06:36:281953void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
EhsanK955ba582017-11-30 21:14:401954 if (auto* frame = GetFocusedWebLocalFrameInWidget())
1955 frame->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111956}
1957
[email protected]80ad8622012-11-07 16:33:031958void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1959 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511960 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391961 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1962 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511963 } else {
mfomitchev2600fd7c2016-02-17 20:53:391964 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511965 }
[email protected]80ad8622012-11-07 16:33:031966 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1967}
1968
lfgdb5c4ed2016-03-04 23:09:071969void RenderWidget::OnUpdateWindowScreenRect(
1970 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211971 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071972 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211973 else
lfgdb5c4ed2016-03-04 23:09:071974 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071975}
1976
kenrbea731792017-01-13 15:10:481977void RenderWidget::OnSetViewportIntersection(
Ken Buchananb2c9e262018-03-10 16:53:311978 const gfx::Rect& viewport_intersection,
1979 const gfx::Rect& compositor_visible_rect) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251980 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:121981 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ken Buchananb2c9e262018-03-10 16:53:311982 viewport_intersection_ = viewport_intersection;
1983 compositor_visible_rect_ = compositor_visible_rect;
Ehsan Karamadf3ca2a82018-01-20 01:05:251984 frame_widget->SetRemoteViewportIntersection(viewport_intersection);
Ken Buchananb2c9e262018-03-10 16:53:311985 compositor_->SetViewportVisibleRect(ViewportVisibleRect());
kenrbea731792017-01-13 15:10:481986 }
1987}
1988
kenrb04323782017-06-23 01:23:321989void RenderWidget::OnSetIsInert(bool inert) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251990 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:121991 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:251992 frame_widget->SetIsInert(inert);
kenrb04323782017-06-23 01:23:321993 }
1994}
1995
Ken Buchanan8a319fb2017-11-15 18:37:121996void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled,
1997 bool subtree_throttled) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251998 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:121999 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:252000 frame_widget->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled);
Ken Buchanan8a319fb2017-11-15 18:37:122001 }
2002}
2003
paulmeyer90f6c31d2016-11-12 00:17:592004void RenderWidget::OnDragTargetDragEnter(
2005 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:522006 const gfx::PointF& client_point,
2007 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592008 WebDragOperationsMask ops,
2009 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252010 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2011 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592012 return;
2013
Ehsan Karamadf3ca2a82018-01-20 01:05:252014 WebDragOperation operation = frame_widget->DragTargetDragEnter(
2015 DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point,
2016 ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592017
2018 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2019}
2020
Ella Ge80a52dce2017-11-15 18:01:522021void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point,
2022 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592023 WebDragOperationsMask ops,
2024 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252025 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2026 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592027 return;
2028
Ehsan Karamadf3ca2a82018-01-20 01:05:252029 WebDragOperation operation = frame_widget->DragTargetDragOver(
2030 ConvertWindowPointToViewport(client_point), screen_point, ops,
2031 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592032
2033 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2034}
2035
Ella Ge80a52dce2017-11-15 18:01:522036void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point,
2037 const gfx::PointF& screen_point) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252038 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2039 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592040 return;
Ehsan Karamadf3ca2a82018-01-20 01:05:252041
2042 frame_widget
2043
Blink Reformat1c4d759e2017-04-09 16:34:542044 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:172045 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:592046}
2047
2048void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:522049 const gfx::PointF& client_point,
2050 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592051 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252052 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2053 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592054 return;
2055
Ehsan Karamadf3ca2a82018-01-20 01:05:252056 frame_widget->DragTargetDrop(DropDataToWebDragData(drop_data),
2057 ConvertWindowPointToViewport(client_point),
2058 screen_point, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592059}
2060
Ella Ge80a52dce2017-11-15 18:01:522061void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point,
2062 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:212063 WebDragOperation op) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252064 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2065 if (!frame_widget)
paulmeyer8fc8ea92016-11-15 05:12:212066 return;
2067
Ehsan Karamadf3ca2a82018-01-20 01:05:252068 frame_widget->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
2069 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:212070}
2071
2072void RenderWidget::OnDragSourceSystemDragEnded() {
2073 if (!GetWebWidget())
2074 return;
2075
Blink Reformat1c4d759e2017-04-09 16:34:542076 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:212077}
2078
Blink Reformat1c4d759e2017-04-09 16:34:542079void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:262080#if defined(OS_CHROMEOS)
2081 // On ChromeOS, virtual keyboard is triggered only when users leave the
2082 // mouse button or the finger and a text input element is focused at that
2083 // time. Focus event itself shouldn't trigger virtual keyboard.
2084 UpdateTextInputState();
2085#else
changwan75e3b2072017-01-16 02:55:002086 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:262087#endif
boliu7b2be2f2016-11-04 04:58:312088
2089// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
2090// virtual keyboard.
2091#if !defined(OS_ANDROID)
2092 FocusChangeComplete();
2093#endif
[email protected]0d1ebed12013-08-05 22:01:132094}
2095
fsamuel72464894f2015-12-15 06:59:312096ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:162097#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492098 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2099 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:092100#endif
ekaramad5aff1942017-01-06 01:26:352101 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:542102 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:312103 return ui::TEXT_INPUT_TYPE_NONE;
2104}
2105
nonafa291792016-08-10 02:36:182106void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
2107 if (!monitor_composition_info_ && !immediate_request)
2108 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:592109
nonafa291792016-08-10 02:36:182110 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
2111 gfx::Range range;
2112 std::vector<gfx::Rect> character_bounds;
2113
2114 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
2115 // Composition information is only available on editable node.
2116 range = gfx::Range::InvalidRange();
2117 } else {
2118 GetCompositionRange(&range);
2119 GetCompositionCharacterBounds(&character_bounds);
2120 }
2121
2122 if (!immediate_request &&
2123 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:312124 return;
nonafa291792016-08-10 02:36:182125 }
fsamuel72464894f2015-12-15 06:59:312126 composition_character_bounds_ = character_bounds;
2127 composition_range_ = range;
Dave Tapuska139a72f2017-09-06 21:57:032128 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:052129 if (mojom::WidgetInputHandlerHost* host =
2130 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
2131 host->ImeCompositionRangeChanged(composition_range_,
2132 composition_character_bounds_);
2133 }
Dave Tapuska139a72f2017-09-06 21:57:032134 } else {
2135 Send(new InputHostMsg_ImeCompositionRangeChanged(
2136 routing_id(), composition_range_, composition_character_bounds_));
2137 }
fsamuel72464894f2015-12-15 06:59:312138}
2139
Blink Reformat1c4d759e2017-04-09 16:34:542140void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:542141 if (IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:032142 float reverse = 1 / GetOriginalScreenInfo().device_scale_factor;
oshimad5279032015-12-16 18:22:332143 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:542144 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:462145 gfx::Rect window_rect =
2146 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
2147 rect->x = window_rect.x();
2148 rect->y = window_rect.y();
2149 rect->width = window_rect.width();
2150 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:542151 }
2152}
2153
Blink Reformat1c4d759e2017-04-09 16:34:542154void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
oshimaa6985b62016-01-27 08:58:302155 if (IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:032156 rect->x *= GetOriginalScreenInfo().device_scale_factor;
2157 rect->y *= GetOriginalScreenInfo().device_scale_factor;
2158 rect->width *= GetOriginalScreenInfo().device_scale_factor;
2159 rect->height *= GetOriginalScreenInfo().device_scale_factor;
oshimaa6985b62016-01-27 08:58:302160 }
2161}
2162
changwan8c342742016-02-26 00:53:392163void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:262164#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392165 DCHECK(!ime_event_guard_);
2166 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:002167 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212168#endif
Dave Tapuska9db80842017-07-24 17:24:262169}
[email protected]105dffb42013-02-20 03:46:212170
ekaramadc9b70a72017-03-23 16:14:232171void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2172 bool monitor_updates) {
2173 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182174 if (!immediate_request)
2175 return;
2176 UpdateCompositionInfo(true /* immediate request */);
2177}
2178
[email protected]fcdc5642014-05-09 14:32:242179void RenderWidget::OnOrientationChange() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382180 if (auto* frame_widget = GetFrameWidget()) {
Alex Moshchuk0b409c42017-09-13 02:09:002181 // LocalRoot() might return null for provisional main frames. In this case,
2182 // the frame hasn't committed a navigation and is not swapped into the tree
2183 // yet, so it doesn't make sense to send orientation change events to it.
2184 //
2185 // TODO(https://crbug.com/578349): This check should be cleaned up
2186 // once provisional frames are gone.
Ehsan Karamad655d7b8a2018-01-12 18:38:382187 if (frame_widget->LocalRoot())
2188 frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302189 }
[email protected]fcdc5642014-05-09 14:32:242190}
2191
[email protected]bee16aab2009-08-26 15:55:032192void RenderWidget::SetHidden(bool hidden) {
2193 if (is_hidden_ == hidden)
2194 return;
2195
jdduke8fac9d102014-12-20 02:40:132196 // The status has changed. Tell the RenderThread about it and ensure
2197 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032198 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132199
Scott Violet1098538e2017-10-05 19:23:332200#if defined(USE_AURA)
Scott Violet8ff9c302018-02-22 22:28:352201 if (features::IsMusEnabled())
Scott Violet1098538e2017-10-05 19:23:332202 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden);
2203#endif
2204
Saman Sami58ed4392018-01-31 20:54:192205 // RenderThreadImpl::current() could be null in tests.
2206 if (RenderThreadImpl::current()) {
2207 if (is_hidden_) {
2208 RenderThreadImpl::current()->WidgetHidden();
2209 first_update_visual_state_after_hidden_ = true;
2210 } else {
2211 RenderThreadImpl::current()->WidgetRestored();
2212 }
Lei Zhang9b359d32017-11-28 00:57:022213 }
alexclarke7fa93942015-10-21 15:37:112214
2215 if (render_widget_scheduling_state_)
2216 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:032217}
2218
[email protected]2b624c562011-10-27 22:58:262219void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212220 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262221 return;
2222
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122223 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542224 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262225 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542226 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262227 }
[email protected]2b624c562011-10-27 22:58:262228}
2229
[email protected]674741932009-02-04 23:44:462230bool RenderWidget::next_paint_is_resize_ack() const {
Fady Samuelcc3e3b4a2017-10-03 02:09:212231 return ViewHostMsg_ResizeOrRepaint_ACK_Flags::is_resize_ack(
2232 next_paint_flags_);
[email protected]674741932009-02-04 23:44:462233}
2234
[email protected]674741932009-02-04 23:44:462235void RenderWidget::set_next_paint_is_resize_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212236 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462237}
2238
[email protected]674741932009-02-04 23:44:462239void RenderWidget::set_next_paint_is_repaint_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212240 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462241}
2242
Saman Samif7731342018-01-24 22:18:442243void RenderWidget::reset_next_paint_is_resize_ack() {
2244 DCHECK(next_paint_is_resize_ack());
2245 next_paint_flags_ ^= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK;
2246}
2247
changwanf2a707b2015-10-30 08:22:162248void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2249 if (!ime_event_guard_)
2250 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292251}
2252
changwanf2a707b2015-10-30 08:22:162253void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
2254 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:002255 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:162256 return;
2257 }
2258 ime_event_guard_ = nullptr;
2259
[email protected]66fca5bc2013-05-23 06:58:292260 // While handling an ime event, text input state and selection bounds updates
2261 // are ignored. These must explicitly be updated once finished handling the
2262 // ime event.
2263 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472264#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002265 if (guard->show_virtual_keyboard())
2266 ShowVirtualKeyboard();
2267 else
2268 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472269#endif
[email protected]66fca5bc2013-05-23 06:58:292270}
2271
[email protected]7c8873e2013-02-05 08:03:012272void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162273#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492274 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092275 // TODO(kinaba) http://crbug.com/101101
2276 // Current Pepper IME API does not handle selection bounds. So we simply
2277 // use the caret position as an empty range for now. It will be updated
2278 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492279 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542280 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092281 *focus = caret;
2282 *anchor = caret;
2283 return;
2284 }
2285#endif
[email protected]7c8873e2013-02-05 08:03:012286 WebRect focus_webrect;
2287 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542288 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2289 ConvertViewportToWindow(&focus_webrect);
2290 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242291 *focus = focus_webrect;
2292 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322293}
2294
[email protected]e99ef6f2011-10-16 01:13:002295void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082296 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212297 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002298 return;
changwanf2a707b2015-10-30 08:22:162299 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292300 return;
[email protected]e99ef6f2011-10-16 01:13:002301
mohsenb0eeba72015-08-09 06:20:082302#if defined(USE_AURA)
2303 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2304 // Aura beucause composited selection updates are not working for webview tags
2305 // which regresses IME inside webview. Remove this when composited selection
2306 // updates are fixed for webviews. See, http://crbug.com/510568.
2307 bool send_ipc = true;
2308#else
jddukeacf809e2014-09-23 20:38:382309 // With composited selection updates, the selection bounds will be reported
2310 // directly by the compositor, in which case explicit IPC selection
2311 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082312 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542313 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082314#endif
2315 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382316 ViewHostMsg_SelectionBounds_Params params;
EhsanK955ba582017-11-30 21:14:402317 params.is_anchor_first = false;
jddukeacf809e2014-09-23 20:38:382318 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2319 if (selection_anchor_rect_ != params.anchor_rect ||
2320 selection_focus_rect_ != params.focus_rect) {
2321 selection_anchor_rect_ = params.anchor_rect;
2322 selection_focus_rect_ = params.focus_rect;
EhsanK955ba582017-11-30 21:14:402323 if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) {
2324 focused_frame->SelectionTextDirection(params.focus_dir,
2325 params.anchor_dir);
2326 params.is_anchor_first = focused_frame->IsSelectionAnchorFirst();
2327 }
jddukeacf809e2014-09-23 20:38:382328 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2329 }
[email protected]58b48a0d2012-06-13 07:01:352330 }
jddukeacf809e2014-09-23 20:38:382331
nonafa291792016-08-10 02:36:182332 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002333}
2334
lfgb00fcad2016-07-14 14:16:332335void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2336 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542337 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332338 if (size_.width() != new_size_in_window.width ||
2339 size_.height() != new_size_in_window.height) {
2340 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2341
2342 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542343 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2344 size_.height());
lfgb00fcad2016-07-14 14:16:332345 view_screen_rect_ = new_pos;
2346 window_screen_rect_ = new_pos;
2347 }
2348
Christopher Camerone9a30c12018-03-07 08:23:382349 // TODO(ccameron): Note that this destroys any information differentiating
Christopher Cameronaad15a0d2018-03-09 03:47:332350 // |size_| from |compositor_viewport_pixel_size_|. Also note that the
2351 // calculation of |new_compositor_viewport_pixel_size| does not appear to
2352 // take into account device emulation.
Fady Samuelda839bb2018-03-26 17:34:482353 ++auto_resize_sequence_number_;
Christopher Cameronaad15a0d2018-03-09 03:47:332354 gfx::Size new_compositor_viewport_pixel_size =
Fady Samuela863f152018-03-09 16:10:032355 gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor);
Chris Blume760b9462018-04-12 21:45:332356 viz::LocalSurfaceId local_surface_id;
2357 if (!compositor_viewport_pixel_size_.IsEmpty())
2358 local_surface_id = child_local_surface_id_allocator_.GenerateId();
2359 UpdateSurfaceAndScreenInfo(
2360 local_surface_id, new_compositor_viewport_pixel_size, screen_info_);
lfgb00fcad2016-07-14 14:16:332361
Fady Samuel319e429c2017-10-02 18:31:552362 if (!resizing_mode_selector_->is_synchronous_mode()) {
Fady Samueld10aadd82017-11-03 18:23:572363 need_resize_ack_for_auto_resize_ = true;
Fady Samuel319e429c2017-10-02 18:31:552364 // If surface synchronization is off, then ResizeAcks go to the browser in
2365 // response to a DidReceiveCompositorFrame. With surface synchronization
2366 // on, that notification will not arrive here because the compositor is
2367 // deferring commits and thus submission of CompositorFrames.
2368 if (!size_.IsEmpty() && compositor_ &&
Fady Samuel1ee6fb5c2018-02-16 03:27:462369 compositor_->IsSurfaceSynchronizationEnabled() &&
2370 !auto_resize_ack_callback_.callback()) {
2371 auto_resize_ack_callback_.Reset(
2372 base::BindOnce(&RenderWidget::DidResizeOrRepaintAck,
2373 weak_ptr_factory_.GetWeakPtr()));
2374 base::ThreadTaskRunnerHandle::Get()->PostTask(
2375 FROM_HERE, auto_resize_ack_callback_.callback());
Fady Samuel319e429c2017-10-02 18:31:552376 }
2377 }
lfgb00fcad2016-07-14 14:16:332378 }
2379}
2380
[email protected]58b48a0d2012-06-13 07:01:352381void RenderWidget::GetCompositionCharacterBounds(
2382 std::vector<gfx::Rect>* bounds) {
2383 DCHECK(bounds);
2384 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092385
brettw4b461082016-11-19 18:55:162386#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492387 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092388 return;
2389#endif
2390
Ehsan Karamad4975af6d2018-02-09 16:58:162391 blink::WebInputMethodController* controller = GetInputMethodController();
2392 if (!controller)
ekaramad2a46d632016-07-19 13:33:092393 return;
2394 blink::WebVector<blink::WebRect> bounds_from_blink;
Ehsan Karamad4975af6d2018-02-09 16:58:162395 if (!controller->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092396 return;
2397
2398 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542399 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092400 bounds->push_back(bounds_from_blink[i]);
2401 }
[email protected]58b48a0d2012-06-13 07:01:352402}
2403
[email protected]db4fc1e2013-09-06 20:01:512404void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162405#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492406 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092407 return;
2408#endif
EhsanKcdee7b72017-11-08 21:30:092409 blink::WebInputMethodController* controller = GetInputMethodController();
2410 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542411 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212412 *range = gfx::Range::InvalidRange();
2413 return;
[email protected]88dbe32f2013-06-20 23:31:362414 }
Blink Reformat1c4d759e2017-04-09 16:34:542415 range->set_start(web_range.StartOffset());
2416 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362417}
2418
[email protected]501ea13d2013-07-09 17:03:292419bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512420 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292421 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082422 if (!range.IsValid())
2423 return false;
[email protected]501ea13d2013-07-09 17:03:292424 if (composition_range_ != range)
2425 return true;
2426 if (bounds.size() != composition_character_bounds_.size())
2427 return true;
2428 for (size_t i = 0; i < bounds.size(); ++i) {
2429 if (bounds[i] != composition_character_bounds_[i])
2430 return true;
2431 }
2432 return false;
2433}
[email protected]501ea13d2013-07-09 17:03:292434
[email protected]ad26ef42011-06-17 07:59:452435bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162436#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492437 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2438 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092439#endif
[email protected]ad26ef42011-06-17 07:59:452440 return true;
[email protected]56ea1a62011-05-30 07:05:572441}
2442
Blink Reformat1c4d759e2017-04-09 16:34:542443blink::WebScreenInfo RenderWidget::GetScreenInfo() {
ccameron2f451532016-09-07 21:49:272444 blink::WebScreenInfo web_screen_info;
Blink Reformat1c4d759e2017-04-09 16:34:542445 web_screen_info.device_scale_factor = screen_info_.device_scale_factor;
ccameronab0aab82017-06-24 17:21:542446 web_screen_info.color_space = screen_info_.color_space;
ccameron2f451532016-09-07 21:49:272447 web_screen_info.depth = screen_info_.depth;
Blink Reformat1c4d759e2017-04-09 16:34:542448 web_screen_info.depth_per_component = screen_info_.depth_per_component;
2449 web_screen_info.is_monochrome = screen_info_.is_monochrome;
ccameron2f451532016-09-07 21:49:272450 web_screen_info.rect = blink::WebRect(screen_info_.rect);
Blink Reformat1c4d759e2017-04-09 16:34:542451 web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect);
ccameron2f451532016-09-07 21:49:272452 switch (screen_info_.orientation_type) {
2453 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542454 web_screen_info.orientation_type =
2455 blink::kWebScreenOrientationPortraitPrimary;
ccameron2f451532016-09-07 21:49:272456 break;
2457 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542458 web_screen_info.orientation_type =
2459 blink::kWebScreenOrientationPortraitSecondary;
ccameron2f451532016-09-07 21:49:272460 break;
2461 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542462 web_screen_info.orientation_type =
2463 blink::kWebScreenOrientationLandscapePrimary;
ccameron2f451532016-09-07 21:49:272464 break;
2465 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542466 web_screen_info.orientation_type =
2467 blink::kWebScreenOrientationLandscapeSecondary;
ccameron2f451532016-09-07 21:49:272468 break;
2469 default:
Blink Reformat1c4d759e2017-04-09 16:34:542470 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
ccameron2f451532016-09-07 21:49:272471 break;
2472 }
Blink Reformat1c4d759e2017-04-09 16:34:542473 web_screen_info.orientation_angle = screen_info_.orientation_angle;
Fady Samuel85a1bf72017-10-27 14:30:202474
ccameron2f451532016-09-07 21:49:272475 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282476}
2477
Blink Reformat1c4d759e2017-04-09 16:34:542478void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2479 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022480#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562481 if (event_cancelled)
2482 return;
Blink Reformat1c4d759e2017-04-09 16:34:542483 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002484 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542485 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212486 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352487 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542488 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002489 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462490 else
changwan75e3b2072017-01-16 02:55:002491 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562492 }
ekaramada110f642016-12-21 19:47:282493// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2494// crbug/420130.
2495#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:542496 if (event.GetType() != blink::WebGestureEvent::kGestureTap)
ekaramada110f642016-12-21 19:47:282497 return;
2498
2499 // TODO(estade): hit test the event against focused node to make sure
2500 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352501 blink::WebInputMethodController* controller = GetInputMethodController();
2502 blink::WebTextInputType text_input_type =
Blink Reformat1c4d759e2017-04-09 16:34:542503 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282504
2505 Send(new ViewHostMsg_FocusedNodeTouched(
Blink Reformat1c4d759e2017-04-09 16:34:542506 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
ekaramada110f642016-12-21 19:47:282507#endif
[email protected]c68c3e4e2013-01-24 00:36:562508#endif
2509}
2510
Blink Reformat1c4d759e2017-04-09 16:34:542511void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312512 const blink::WebFloatSize& overscrollDelta,
2513 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422514 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:542515 const blink::WebFloatSize& velocity,
Sandra Sun2288e8532017-11-30 22:50:162516 const blink::WebOverscrollBehavior& behavior) {
bokan731ec382016-04-07 03:16:482517#if defined(OS_MACOSX)
2518 // On OSX the user can disable the elastic overscroll effect. If that's the
2519 // case, don't forward the overscroll notification.
2520 DCHECK(compositor_deps());
2521 if (!compositor_deps()->IsElasticOverscrollEnabled())
2522 return;
2523#endif
bokane53a10f2016-04-13 23:48:312524 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:542525 position, velocity, behavior);
sataya.m582c9ce2015-06-09 08:03:422526}
2527
[email protected]7912e822014-04-16 02:37:032528void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392529 if (!is_hidden())
Blink Reformat1c4d759e2017-04-09 16:34:542530 compositor_->SetVisible(true);
[email protected]7912e822014-04-16 02:37:032531}
2532
[email protected]24ed0432013-04-24 07:50:312533RenderWidgetCompositor* RenderWidget::compositor() const {
2534 return compositor_.get();
2535}
2536
fsamuel72464894f2015-12-15 06:59:312537void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392538 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372539}
[email protected]c3d45532011-10-07 19:20:402540
Blink Reformat1c4d759e2017-04-09 16:34:542541void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
W. James MacLean662d5382018-03-29 18:33:082542 if (has_touch_handlers_ && *has_touch_handlers_ == has_handlers)
2543 return;
2544
2545 has_touch_handlers_ = has_handlers;
alexclarke7fa93942015-10-21 15:37:112546 if (render_widget_scheduling_state_)
2547 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552548 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2549}
2550
Dave Tapuskadfe486c12017-06-09 16:53:132551void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
2552 if (input_event_queue_)
2553 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
2554}
2555
Dave Tapuskabafc2ba32017-11-28 01:54:372556void RenderWidget::RequestUnbufferedInputEvents() {
2557 if (input_event_queue_)
2558 input_event_queue_->RequestUnbufferedInputEvents();
2559}
2560
xidachenfa0199e72017-05-11 11:34:262561void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:262562 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:512563 return;
2564
Dave Tapuska139a72f2017-09-06 21:57:032565 if (widget_input_handler_manager_) {
2566 widget_input_handler_manager_->ProcessTouchAction(touch_action);
2567 } else {
2568 Send(new InputHostMsg_SetTouchAction(routing_id_, touch_action));
2569 }
[email protected]5d0bbdfa92013-12-10 00:35:512570}
2571
[email protected]e3244ed2014-06-20 20:04:272572void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2573 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162574}
2575
[email protected]e3244ed2014-06-20 20:04:272576void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2577 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162578}
2579
[email protected]de3c5d82014-05-28 22:12:592580void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2581 render_frames_.AddObserver(frame);
2582}
2583
2584void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2585 render_frames_.RemoveObserver(frame);
2586}
2587
Saman Samid189e5dfd2017-12-20 22:55:312588void RenderWidget::RegisterBrowserPlugin(BrowserPlugin* browser_plugin) {
2589 browser_plugins_.AddObserver(browser_plugin);
Saman Sami50d1e0c2018-03-13 20:03:492590 browser_plugin->ScreenInfoChanged(GetOriginalScreenInfo());
Saman Samid189e5dfd2017-12-20 22:55:312591}
2592
2593void RenderWidget::UnregisterBrowserPlugin(BrowserPlugin* browser_plugin) {
2594 browser_plugins_.RemoveObserver(browser_plugin);
2595}
2596
lfg43e08e62016-02-03 18:51:372597void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2598 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2599 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2600}
2601
Fady Samuela863f152018-03-09 16:10:032602const ScreenInfo& RenderWidget::GetWebScreenInfo() const {
2603 return screen_info_;
Christopher Camerone9a30c12018-03-07 08:23:382604}
2605
Fady Samuela863f152018-03-09 16:10:032606const ScreenInfo& RenderWidget::GetOriginalScreenInfo() const {
Christopher Camerone9a30c12018-03-07 08:23:382607 return screen_metrics_emulator_
2608 ? screen_metrics_emulator_->original_screen_info()
Fady Samuela863f152018-03-09 16:10:032609 : screen_info_;
oshima50872a72016-03-04 13:26:182610}
2611
Ella Ge80a52dce2017-11-15 18:01:522612gfx::PointF RenderWidget::ConvertWindowPointToViewport(
2613 const gfx::PointF& point) {
paulmeyer90f6c31d2016-11-12 00:17:592614 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542615 ConvertWindowToViewport(&point_in_viewport);
Ella Ge80a52dce2017-11-15 18:01:522616 return gfx::PointF(point_in_viewport.x, point_in_viewport.y);
2617}
2618
2619gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) {
2620 return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point)));
paulmeyer90f6c31d2016-11-12 00:17:592621}
2622
Blink Reformat1c4d759e2017-04-09 16:34:542623bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:212624 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2625}
2626
Blink Reformat1c4d759e2017-04-09 16:34:542627void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:212628 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2629}
2630
Blink Reformat1c4d759e2017-04-09 16:34:542631bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:212632 return mouse_lock_dispatcher_->IsMouseLockedTo(
2633 webwidget_mouse_lock_target_.get());
2634}
2635
Blink Reformat1c4d759e2017-04-09 16:34:542636void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:582637 const WebDragData& data,
2638 WebDragOperationsMask mask,
2639 const WebImage& image,
2640 const WebPoint& webImageOffset) {
2641 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542642 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:582643 DropData drop_data(DropDataBuilder::Build(data));
2644 drop_data.referrer_policy = policy;
2645 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592646 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
Blink Reformat1c4d759e2017-04-09 16:34:542647 image.GetSkBitmap(), imageOffset,
paulmeyer6ef5a792016-11-08 20:33:582648 possible_drag_event_info_));
2649}
2650
kenrb5d78b842017-03-06 21:06:012651uint32_t RenderWidget::GetContentSourceId() {
2652 return current_content_source_id_;
2653}
2654
Saman Samif7731342018-01-24 22:18:442655void RenderWidget::DidNavigate() {
Saman Sami26a1fcd2018-04-10 17:12:212656 ++current_content_source_id_;
Saman Samif7731342018-01-24 22:18:442657 if (!compositor_)
2658 return;
Saman Sami26a1fcd2018-04-10 17:12:212659 compositor_->SetContentSourceId(current_content_source_id_);
Christopher Cameronbe7ecea2018-02-27 00:47:192660
Christopher Cameronaad15a0d2018-03-09 03:47:332661 UpdateSurfaceAndScreenInfo(viz::LocalSurfaceId(),
2662 compositor_viewport_pixel_size_, screen_info_);
Christopher Cameronbe7ecea2018-02-27 00:47:192663
Saman Samif7731342018-01-24 22:18:442664 // If surface synchronization is on, navigation implicitly acks any resize
2665 // that has happened so far so we can get the next ResizeParams containing the
2666 // LocalSurfaceId that should be used after navigation.
2667 if (compositor_->IsSurfaceSynchronizationEnabled() && !auto_resize_mode_ &&
2668 next_paint_is_resize_ack()) {
2669 reset_next_paint_is_resize_ack();
2670 }
kenrb5d78b842017-03-06 21:06:012671}
2672
lfg8ff33912016-09-13 20:59:212673blink::WebWidget* RenderWidget::GetWebWidget() const {
2674 return webwidget_internal_;
2675}
2676
ekaramad2daaf672016-11-10 20:29:012677blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2678 const {
Ehsan Karamad655d7b8a2018-01-12 18:38:382679 if (auto* frame_widget = GetFrameWidget())
2680 return frame_widget->GetActiveWebInputMethodController();
2681
2682 return nullptr;
ekaramad2daaf672016-11-10 20:29:012683}
2684
Dave Tapuska139a72f2017-09-06 21:57:032685void RenderWidget::SetupWidgetInputHandler(
2686 mojom::WidgetInputHandlerRequest request,
2687 mojom::WidgetInputHandlerHostPtr host) {
Dave Tapuskab66c28f2017-11-15 17:18:472688 widget_input_handler_manager_->AddInterface(std::move(request),
2689 std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:502690}
2691
Dave Tapuska485aca92017-08-08 00:47:582692void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
2693 // Close the old binding if there was one.
2694 // A RenderWidgetHost should not need more than one channel.
2695 widget_binding_.Close();
2696 widget_binding_.Bind(std::move(request));
2697}
2698
Fady Samuelcc3e3b4a2017-10-03 02:09:212699void RenderWidget::DidResizeOrRepaintAck() {
Fady Samueld10aadd82017-11-03 18:23:572700 if (!next_paint_flags_ && !need_resize_ack_for_auto_resize_)
Fady Samuel319e429c2017-10-02 18:31:552701 return;
2702
Fady Samuelcc3e3b4a2017-10-03 02:09:212703 ViewHostMsg_ResizeOrRepaint_ACK_Params params;
Fady Samuel319e429c2017-10-02 18:31:552704 params.view_size = size_;
2705 params.flags = next_paint_flags_;
Fady Samuelda839bb2018-03-26 17:34:482706 params.sequence_number = auto_resize_sequence_number_;
Chris Blume760b9462018-04-12 21:45:332707 if (child_local_surface_id_allocator_.GetCurrentLocalSurfaceId().is_valid()) {
2708 params.child_allocated_local_surface_id =
2709 child_local_surface_id_allocator_.GetCurrentLocalSurfaceId();
2710 DCHECK(params.child_allocated_local_surface_id.value().is_valid());
2711 }
Fady Samuel319e429c2017-10-02 18:31:552712
Fady Samuelcc3e3b4a2017-10-03 02:09:212713 Send(new ViewHostMsg_ResizeOrRepaint_ACK(routing_id_, params));
Fady Samuel319e429c2017-10-02 18:31:552714 next_paint_flags_ = 0;
Fady Samueld10aadd82017-11-03 18:23:572715 need_resize_ack_for_auto_resize_ = false;
Fady Samuel319e429c2017-10-02 18:31:552716}
2717
Khushal3e96e662017-10-30 23:16:502718void RenderWidget::UpdateURLForCompositorUkm() {
2719 DCHECK(compositor_);
Ehsan Karamad655d7b8a2018-01-12 18:38:382720 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2721 if (!frame_widget)
Khushal3e96e662017-10-30 23:16:502722 return;
2723
Ehsan Karamad655d7b8a2018-01-12 18:38:382724 auto* render_frame = RenderFrameImpl::FromWebFrame(frame_widget->LocalRoot());
Khushal3e96e662017-10-30 23:16:502725 if (!render_frame->IsMainFrame())
2726 return;
2727
2728 compositor_->SetURLForUkm(render_frame->GetWebFrame()->GetDocument().Url());
2729}
2730
EhsanK955ba582017-11-30 21:14:402731blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const {
Ehsan Karamad655d7b8a2018-01-12 18:38:382732 if (auto* frame_widget = GetFrameWidget())
2733 return frame_widget->FocusedWebLocalFrameInWidget();
2734 return nullptr;
EhsanK955ba582017-11-30 21:14:402735}
2736
EhsanK22d482e2017-08-10 17:29:492737#if BUILDFLAG(ENABLE_PLUGINS)
2738PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382739 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2740 if (!frame_widget)
EhsanK22d482e2017-08-10 17:29:492741 return nullptr;
2742
2743 // Focused pepper instance might not always be in the focused frame. For
2744 // instance if a pepper instance and its embedder frame are focused an then
2745 // another frame takes focus using javascript, the embedder frame will no
2746 // longer be focused while the pepper instance is (the embedder frame's
2747 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
2748 // is fullscreen, clicking into the pepper will not refocus the embedder
2749 // frame. This is why we have to traverse the whole frame tree to find the
2750 // focused plugin.
Ehsan Karamad655d7b8a2018-01-12 18:38:382751 blink::WebFrame* current_frame = frame_widget->LocalRoot();
EhsanK22d482e2017-08-10 17:29:492752 while (current_frame) {
2753 RenderFrameImpl* render_frame =
2754 current_frame->IsWebLocalFrame()
2755 ? RenderFrameImpl::FromWebFrame(current_frame)
2756 : nullptr;
2757 if (render_frame && render_frame->focused_pepper_plugin())
2758 return render_frame->focused_pepper_plugin();
2759 current_frame = current_frame->TraverseNext();
2760 }
2761 return nullptr;
2762}
2763#endif
2764
Ken Buchananb2c9e262018-03-10 16:53:312765gfx::Rect RenderWidget::ViewportVisibleRect() {
2766 return for_oopif_ ? compositor_visible_rect_
2767 : gfx::Rect(compositor_viewport_pixel_size_);
2768}
2769
Saman Sami50d1e0c2018-03-13 20:03:492770base::WeakPtr<RenderWidget> RenderWidget::AsWeakPtr() {
2771 return weak_ptr_factory_.GetWeakPtr();
2772}
2773
[email protected]e9ff79c2012-10-19 21:31:262774} // namespace content