blob: c7b4cc1811b71de918bd63ccc2232e63d6113e6a [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"
jcivelliae1560a2016-11-01 22:40:2335#include "content/common/render_message_filter.mojom.h"
Nasko Oskovf97e8b02017-07-25 02:45:4236#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3837#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5038#include "content/common/view_messages.h"
mlamouriafca06dd2017-01-27 23:35:1839#include "content/public/common/content_client.h"
changwan7ded3752016-03-09 23:25:1240#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2941#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4242#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5943#include "content/public/common/drop_data.h"
Khushal3e96e662017-10-30 23:16:5044#include "content/public/common/service_names.mojom.h"
Jaebaek Seo655110e2017-12-19 23:27:3945#include "content/public/common/use_zoom_for_dsf_policy.h"
mlamouriafca06dd2017-01-27 23:35:1846#include "content/public/renderer/content_renderer_client.h"
Saman Samid189e5dfd2017-12-20 22:55:3147#include "content/renderer/browser_plugin/browser_plugin.h"
[email protected]953bd0062013-08-01 00:58:4048#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3949#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5850#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5151#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1152#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1153#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2854#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2955#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1356#include "content/renderer/input/input_handler_manager.h"
dtapuska9ec1a912017-04-21 15:18:3157#include "content/renderer/input/main_thread_event_queue.h"
Dave Tapuska9db80842017-07-24 17:24:2658#include "content/renderer/input/widget_input_handler_manager.h"
Scott Violet1098538e2017-10-05 19:23:3359#include "content/renderer/mash_util.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"
brettw4b461082016-11-19 18:55:1672#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4873#include "skia/ext/platform_canvas.h"
kinukoa4293022017-01-27 06:43:2574#include "third_party/WebKit/public/platform/FilePathConversion.h"
[email protected]ec173b522013-11-14 11:01:1875#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5976#include "third_party/WebKit/public/platform/WebDragData.h"
77#include "third_party/WebKit/public/platform/WebDragOperation.h"
dtapuskaa794bd0812017-01-06 15:22:5578#include "third_party/WebKit/public/platform/WebMouseEvent.h"
donnda070f3c2015-01-16 19:54:1179#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3080#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:3081#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]aaf68892013-07-18 00:11:3082#include "third_party/WebKit/public/platform/WebSize.h"
83#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5184#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
85#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
ekaramad27ca69b12017-04-20 18:34:2986#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]19193682014-04-03 15:01:4387#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5988#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0189#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5990#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1191#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3192#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3193#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
94#include "third_party/WebKit/public/web/WebRange.h"
Donn Denman43a439e2017-08-29 04:20:4595#include "third_party/WebKit/public/web/WebTappedInfo.h"
kenrba7199832015-01-22 23:44:5996#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0897#include "third_party/WebKit/public/web/WebWidget.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"
[email protected]faec7b12012-06-19 14:42:13100#include "ui/base/ui_base_switches.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;
Donn Denman43a439e2017-08-29 04:20:45151using blink::WebTappedInfo;
[email protected]180ef242013-11-07 06:50:46152using blink::WebTextDirection;
153using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25154using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46155using blink::WebVector;
156using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26157
paulmeyer90f6c31d2016-11-12 00:17:59158namespace content {
159
[email protected]6a4d7f62013-01-07 21:32:13160namespace {
[email protected]b256eca2013-07-11 10:57:40161
162typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
163
AJITH KUMAR V041c0b02017-08-08 10:39:20164static const int kInvalidNextPreviousFlagsValue = -1;
165
lfgbee1e0a2016-06-08 21:24:21166class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
167 public:
168 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
169 : webwidget_(webwidget) {}
170
171 void OnLockMouseACK(bool succeeded) override {
172 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54173 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21174 else
Blink Reformat1c4d759e2017-04-09 16:34:54175 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21176 }
177
Blink Reformat1c4d759e2017-04-09 16:34:54178 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21179
180 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
181 // The WebWidget handles mouse lock in Blink's handleInputEvent().
182 return false;
183 }
184
185 private:
186 blink::WebWidget* webwidget_;
187};
188
dglazkov97b6c2b2016-10-25 17:35:55189bool IsDateTimeInput(ui::TextInputType type) {
190 return type == ui::TEXT_INPUT_TYPE_DATE ||
191 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
192 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
193 type == ui::TEXT_INPUT_TYPE_MONTH ||
194 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
195}
196
paulmeyer90f6c31d2016-11-12 00:17:59197WebDragData DropMetaDataToWebDragData(
198 const std::vector<DropData::Metadata>& drop_meta_data) {
199 std::vector<WebDragData::Item> item_list;
200 for (const auto& meta_data_item : drop_meta_data) {
201 if (meta_data_item.kind == DropData::Kind::STRING) {
202 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54203 item.storage_type = WebDragData::Item::kStorageTypeString;
204 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59205 // Have to pass a dummy URL here instead of an empty URL because the
206 // DropData received by browser_plugins goes through a round trip:
207 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
208 // will contain an empty URL (which means no URL is dragged) if the URL in
209 // WebDragData is empty.
210 if (base::EqualsASCII(meta_data_item.mime_type,
211 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54212 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59213 }
214 item_list.push_back(item);
215 continue;
216 }
217
218 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
219 // just the mimetype. This is needed to drag files to WebView on Android
220 // platform.
221 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
222 !meta_data_item.filename.empty()) {
223 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54224 item.storage_type = WebDragData::Item::kStorageTypeFilename;
225 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59226 item_list.push_back(item);
227 continue;
228 }
229
230 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
231 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54232 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
233 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59234 item_list.push_back(item);
235 continue;
236 }
237 }
238
239 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54240 result.Initialize();
241 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59242 return result;
243}
244
245WebDragData DropDataToWebDragData(const DropData& drop_data) {
246 std::vector<WebDragData::Item> item_list;
247
248 // These fields are currently unused when dragging into WebKit.
249 DCHECK(drop_data.download_metadata.empty());
250 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23251 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59252
253 if (!drop_data.text.is_null()) {
254 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54255 item.storage_type = WebDragData::Item::kStorageTypeString;
256 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
257 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59258 item_list.push_back(item);
259 }
260
261 if (!drop_data.url.is_empty()) {
262 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54263 item.storage_type = WebDragData::Item::kStorageTypeString;
264 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
265 item.string_data = WebString::FromUTF8(drop_data.url.spec());
266 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59267 item_list.push_back(item);
268 }
269
270 if (!drop_data.html.is_null()) {
271 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54272 item.storage_type = WebDragData::Item::kStorageTypeString;
273 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
274 item.string_data = WebString::FromUTF16(drop_data.html.string());
275 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59276 item_list.push_back(item);
277 }
278
279 for (std::vector<ui::FileInfo>::const_iterator it =
280 drop_data.filenames.begin();
281 it != drop_data.filenames.end();
282 ++it) {
283 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54284 item.storage_type = WebDragData::Item::kStorageTypeFilename;
285 item.filename_data = blink::FilePathToWebString(it->path);
286 item.display_name_data =
kinukoa4293022017-01-27 06:43:25287 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59288 item_list.push_back(item);
289 }
290
291 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
292 drop_data.file_system_files.begin();
293 it != drop_data.file_system_files.end();
294 ++it) {
295 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54296 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
297 item.file_system_url = it->url;
298 item.file_system_file_size = it->size;
299 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59300 item_list.push_back(item);
301 }
302
Stuart Langley48300392017-11-02 03:54:44303 for (const auto& it : drop_data.custom_data) {
paulmeyer90f6c31d2016-11-12 00:17:59304 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54305 item.storage_type = WebDragData::Item::kStorageTypeString;
Stuart Langley48300392017-11-02 03:54:44306 item.string_type = WebString::FromUTF16(it.first);
307 item.string_data = WebString::FromUTF16(it.second);
paulmeyer90f6c31d2016-11-12 00:17:59308 item_list.push_back(item);
309 }
310
311 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54312 result.Initialize();
313 result.SetItems(item_list);
314 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59315 return result;
316}
317
lfg1568d112016-08-30 16:06:29318content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
319 nullptr;
320
321content::RenderWidget::RenderWidgetInitializedCallback
322 g_render_widget_initialized = nullptr;
323
dtapuskac4dd5be2016-10-25 15:11:10324ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
325 // Check the type is in the range representable by ui::TextInputType.
326 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
327 << "blink::WebTextInputType and ui::TextInputType not synchronized";
328 return static_cast<ui::TextInputType>(type);
329}
330
331ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
332 // Check the mode is in the range representable by ui::TextInputMode.
333 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
334 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
335 return static_cast<ui::TextInputMode>(mode);
336}
337
[email protected]b256eca2013-07-11 10:57:40338} // namespace
339
[email protected]b2e4c70132013-10-03 02:07:51340// RenderWidget ---------------------------------------------------------------
341
Hajime Hoshiabb3c8f2017-12-04 18:41:39342RenderWidget::RenderWidget(
343 int32_t widget_routing_id,
344 CompositorDependencies* compositor_deps,
345 blink::WebPopupType popup_type,
346 const ScreenInfo& screen_info,
347 bool swapped_out,
348 bool hidden,
349 bool never_visible,
350 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
351 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45352 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36353 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21354 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44355 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29356 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51357 auto_resize_mode_(false),
Fady Samueld10aadd82017-11-03 18:23:57358 need_resize_ack_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29359 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04360 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39361 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12362 is_fullscreen_granted_(false),
Blink Reformat1c4d759e2017-04-09 16:34:54363 display_mode_(blink::kWebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16364 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48365 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22366 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44367 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20368 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55369 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40370 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20371 text_input_flags_(0),
AJITH KUMAR V041c0b02017-08-08 10:39:20372 next_previous_flags_(kInvalidNextPreviousFlagsValue),
[email protected]86ba5fcb2013-09-04 00:36:53373 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18374 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12375 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48376 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04377 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27378 device_scale_factor_(screen_info_.device_scale_factor),
nonafa291792016-08-10 02:36:18379 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51380 popup_origin_scale_for_emulation_(0.f),
samans26510e442017-06-01 22:29:12381 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
[email protected]a09d53ce2014-01-31 00:46:42382 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08383 has_host_context_menu_location_(false),
wjmaclean1d970622017-01-21 22:28:24384 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09385 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47386#if defined(OS_MACOSX)
387 text_input_client_observer_(new TextInputClientObserver(this)),
388#endif
Takashi SAKAMOTO870f6262017-08-22 04:08:27389 first_update_visual_state_after_hidden_(false),
tasakb95dbb50c2017-02-08 18:07:50390 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01391 current_content_source_id_(0),
Dave Tapuska1bdf1832017-07-07 18:07:19392 widget_binding_(this, std::move(widget_request)),
Hajime Hoshiabb3c8f2017-12-04 18:41:39393 task_runner_(task_runner),
wjmaclean1d970622017-01-21 22:28:24394 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45395 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05396 if (!swapped_out)
397 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27398 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11399
400 // In tests there may not be a RenderThreadImpl.
401 if (RenderThreadImpl::current()) {
402 render_widget_scheduling_state_ = RenderThreadImpl::current()
403 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32404 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11405 render_widget_scheduling_state_->SetHidden(is_hidden_);
406 }
sadrul602ce1362017-01-26 06:41:10407#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14408 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
Sadrul Habib Chowdhury1dbe3b42017-11-18 02:27:43409 if (IsRunningWithMus())
Scott Violet1098538e2017-10-05 19:23:33410 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_);
sadrul602ce1362017-01-26 06:41:10411#endif
initial.commit09911bf2008-07-26 23:55:29412}
413
414RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21415 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16416
dtapuska9ec1a912017-04-21 15:18:31417 if (input_event_queue_)
418 input_event_queue_->ClearClient();
419
[email protected]992db4c2011-05-12 15:37:15420 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02421 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15422 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11423#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14424 // It is possible for a RenderWidget to be destroyed before it was embedded
425 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
426 // explicitly delete it here.
427 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11428#endif
initial.commit09911bf2008-07-26 23:55:29429}
430
[email protected]484955942010-08-19 16:13:18431// static
lfg1568d112016-08-30 16:06:29432void RenderWidget::InstallCreateHook(
433 CreateRenderWidgetFunction create_render_widget,
434 RenderWidgetInitializedCallback render_widget_initialized) {
435 CHECK(!g_create_render_widget && !g_render_widget_initialized);
436 g_create_render_widget = create_render_widget;
437 g_render_widget_initialized = render_widget_initialized;
438}
439
440// static
nickf7b38222016-11-22 21:59:35441RenderWidget* RenderWidget::CreateForPopup(
442 RenderViewImpl* opener,
443 CompositorDependencies* compositor_deps,
444 blink::WebPopupType popup_type,
Hajime Hoshiabb3c8f2017-12-04 18:41:39445 const ScreenInfo& screen_info,
446 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Dave Tapuska1bdf1832017-07-07 18:07:19447 mojom::WidgetPtr widget_channel;
448 mojom::WidgetRequest widget_channel_request =
449 mojo::MakeRequest(&widget_channel);
450
nick4df698d82016-11-11 20:39:23451 // Do a synchronous IPC to obtain a routing ID.
452 int32_t routing_id = MSG_ROUTING_NONE;
453 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
Dave Tapuska1bdf1832017-07-07 18:07:19454 opener->GetRoutingID(), popup_type, std::move(widget_channel),
455 &routing_id)) {
nick4df698d82016-11-11 20:39:23456 return nullptr;
457 }
458
Hajime Hoshiabb3c8f2017-12-04 18:41:39459 scoped_refptr<RenderWidget> widget(new RenderWidget(
460 routing_id, compositor_deps, popup_type, screen_info, false, false, false,
461 task_runner, std::move(widget_channel_request)));
nickf7b38222016-11-22 21:59:35462 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24463 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
nickf7b38222016-11-22 21:59:35464 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23465 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
466 return widget.get();
initial.commit09911bf2008-07-26 23:55:29467}
468
[email protected]484955942010-08-19 16:13:18469// static
kenrba7199832015-01-22 23:44:59470RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23471 int widget_routing_id,
kenrba7199832015-01-22 23:44:59472 bool hidden,
ccameron2f451532016-09-07 21:49:27473 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59474 CompositorDependencies* compositor_deps,
475 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23476 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55477 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
478 // same routing ID for both the view routing ID and the main frame widget
479 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23480 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55481 if (view) {
avi8a45c1092016-03-01 16:12:34482 view->AttachWebFrameWidget(
483 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
484 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55485 }
Hajime Hoshiabb3c8f2017-12-04 18:41:39486 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
487 frame->GetTaskRunner(blink::TaskType::kUnthrottled);
dcheng35d31c112015-07-22 00:17:36488 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29489 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45490 ? g_create_render_widget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54491 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45492 hidden, false)
493 : new RenderWidget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54494 blink::kWebPopupTypeNone, screen_info, false,
Hajime Hoshiabb3c8f2017-12-04 18:41:39495 hidden, false, task_runner));
simonhong628f9812015-04-27 23:13:20496 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23497 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59498 // this function returns.
nickf7b38222016-11-22 21:59:35499 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23500 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
501
502 if (g_render_widget_initialized)
503 g_render_widget_initialized(widget.get());
504 return widget.get();
kenrba7199832015-01-22 23:44:59505}
506
507// static
lfgcaab5142016-02-26 19:06:52508blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08509 RenderWidget* render_widget,
510 blink::WebLocalFrame* frame) {
Blink Reformat1c4d759e2017-04-09 16:34:54511 return blink::WebFrameWidget::Create(render_widget, frame);
dchengda9b4bb2015-07-20 20:58:08512}
513
514// static
kenrba7199832015-01-22 23:44:59515blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18516 switch (render_widget->popup_type_) {
Blink Reformat1c4d759e2017-04-09 16:34:54517 case blink::kWebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18518 break;
Blink Reformat1c4d759e2017-04-09 16:34:54519 case blink::kWebPopupTypePage:
520 return WebPagePopup::Create(render_widget);
[email protected]484955942010-08-19 16:13:18521 default:
522 NOTREACHED();
523 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28524 return nullptr;
[email protected]484955942010-08-19 16:13:18525}
526
dchengda9b4bb2015-07-20 20:58:08527void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32528 OnClose();
kenrba7199832015-01-22 23:44:59529}
530
alexmos78c9c0d2016-10-14 18:57:03531void RenderWidget::SetSwappedOut(bool is_swapped_out) {
532 // We should only toggle between states.
533 DCHECK(is_swapped_out_ != is_swapped_out);
534 is_swapped_out_ = is_swapped_out;
535
536 // If we are swapping out, we will call ReleaseProcess, allowing the process
537 // to exit if all of its RenderViews are swapped out. We wait until the
538 // WasSwappedOut call to do this, to allow the unload handler to finish.
539 // If we are swapping in, we call AddRefProcess to prevent the process from
540 // exiting.
541 if (!is_swapped_out_)
542 RenderProcess::current()->AddRefProcess();
543}
544
nickf7b38222016-11-22 21:59:35545void RenderWidget::Init(const ShowCallback& show_callback,
546 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21547 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23548 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29549
Jeremy Roman04f27c372017-10-27 15:20:55550 input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45551
Dave Tapuska9db80842017-07-24 17:24:26552 if (base::FeatureList::IsEnabled(features::kMojoInputMessages)) {
553 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
554
Dave Tapuska525eb15e2017-08-17 21:05:50555 widget_input_handler_manager_ = WidgetInputHandlerManager::Create(
Dave Tapuska139a72f2017-09-06 21:57:03556 weak_ptr_factory_.GetWeakPtr(),
Dave Tapuska9db80842017-07-24 17:24:26557 render_thread_impl && compositor_
558 ? render_thread_impl->compositor_task_runner()
559 : nullptr,
560 render_thread_impl ? render_thread_impl->GetRendererScheduler()
561 : nullptr);
562 }
563
nickf7b38222016-11-22 21:59:35564 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29565
lfg8ff33912016-09-13 20:59:21566 webwidget_internal_ = web_widget;
567 webwidget_mouse_lock_target_.reset(
568 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21569 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29570
nick4df698d82016-11-11 20:39:23571 RenderThread::Get()->AddRoute(routing_id_, this);
572 // Take a reference on behalf of the RenderThread. This will be balanced
573 // when we receive ViewMsg_Close.
574 AddRef();
575 if (RenderThreadImpl::current()) {
576 RenderThreadImpl::current()->WidgetCreated();
577 if (is_hidden_)
578 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29579 }
580}
581
[email protected]949b6592014-08-20 13:17:52582void RenderWidget::WasSwappedOut() {
583 // If we have been swapped out and no one else is using this process,
584 // it's safe to exit now.
585 CHECK(is_swapped_out_);
586 RenderProcess::current()->ReleaseProcess();
587}
588
[email protected]b2e4c70132013-10-03 02:07:51589void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39590 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51591 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43592 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00593 popup_screen_origin_for_emulation_ =
Lei Zhang9b359d32017-11-28 00:57:02594 emulator->original_screen_rect().origin();
[email protected]5f75aa42014-04-01 23:00:56595 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27596 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51597}
598
[email protected]2d6836f42014-07-02 17:25:31599gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
600 if (screen_metrics_emulator_)
601 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
602 return anchor;
603}
604
thakis18e426412017-03-15 12:06:37605#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51606void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39607 ExternalPopupMenu* popup,
608 RenderWidgetScreenMetricsEmulator* emulator) {
Pavel Feldmancc099f72017-07-20 23:09:00609 popup->SetOriginScaleForEmulation(emulator->scale());
[email protected]b2e4c70132013-10-03 02:07:51610}
[email protected]53907862014-03-25 15:42:40611#endif
[email protected]b2e4c70132013-10-03 02:07:51612
Fady Samuel69b33b52017-11-08 22:01:52613void RenderWidget::SetLocalSurfaceIdForAutoResize(
614 uint64_t sequence_number,
615 const content::ScreenInfo& screen_info,
Saman Samif7731342018-01-24 22:18:44616 uint32_t content_source_id,
Fady Samuel69b33b52017-11-08 22:01:52617 const viz::LocalSurfaceId& local_surface_id) {
618 bool screen_info_changed = screen_info_ != screen_info;
619
620 screen_info_ = screen_info;
621 if (device_scale_factor_ != screen_info_.device_scale_factor) {
622 device_scale_factor_ = screen_info_.device_scale_factor;
623 OnDeviceScaleFactorChanged();
624 }
625
626 if (screen_info_changed) {
627 for (auto& observer : render_frame_proxies_)
628 observer.OnScreenInfoChanged(screen_info);
629
Saman Samid189e5dfd2017-12-20 22:55:31630 // Notify all embedded BrowserPlugins of the updated ScreenInfo.
631 for (auto& observer : browser_plugins_)
632 observer.ScreenInfoChanged(screen_info);
Fady Samuel69b33b52017-11-08 22:01:52633 }
634
Saman Samif7731342018-01-24 22:18:44635 // If the given LocalSurfaceId was generated before navigation, don't use it.
636 // We should receive a new LocalSurfaceId later.
637 if (content_source_id != current_content_source_id_)
638 AutoResizeCompositor(viz::LocalSurfaceId());
639 else
640 AutoResizeCompositor(local_surface_id);
Fady Samuel69b33b52017-11-08 22:01:52641}
642
[email protected]b2e4c70132013-10-03 02:07:51643void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
644 if (screen_metrics_emulator_)
645 screen_metrics_emulator_->OnShowContextMenu(params);
646}
647
[email protected]a95986a82010-12-24 06:19:28648bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47649#if defined(OS_MACOSX)
650 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
651 return text_input_client_observer_->OnMessageReceived(message);
652#endif
lfgbee1e0a2016-06-08 21:24:21653 if (mouse_lock_dispatcher_ &&
654 mouse_lock_dispatcher_->OnMessageReceived(message))
655 return true;
656
[email protected]a95986a82010-12-24 06:19:28657 bool handled = true;
658 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15659 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22660 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
661 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22662 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29663 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
664 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
665 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15666 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46667 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
668 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15669 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
wjmacleanee244e02017-05-26 21:06:07670 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]a95986a82010-12-24 06:19:28671 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28672 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
Fady Samuel319e429c2017-10-02 18:31:55673 IPC_MESSAGE_HANDLER(ViewMsg_SetLocalSurfaceIdForAutoResize,
674 OnSetLocalSurfaceIdForAutoResize)
dgozman9260b0a12015-03-16 13:45:20675 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
676 OnEnableDeviceEmulation)
677 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
678 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28679 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41680 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25681 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28682 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
683 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03684 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48685 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
686 OnSetViewportIntersection)
kenrb04323782017-06-23 01:23:32687 IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert)
Ken Buchanan8a319fb2017-11-15 18:37:12688 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRenderThrottlingStatus,
689 OnUpdateRenderThrottlingStatus)
lfg43e08e62016-02-03 18:51:37690 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
691 OnWaitNextFrameForTests)
ekaramadc9b70a72017-03-23 16:14:23692 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdates,
693 OnRequestCompositionUpdates)
paulmeyer90f6c31d2016-11-12 00:17:59694 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
695 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
696 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
697 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21698 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
699 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
700 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21701#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39702 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
703 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21704#endif
[email protected]a95986a82010-12-24 06:19:28705 IPC_MESSAGE_UNHANDLED(handled = false)
706 IPC_END_MESSAGE_MAP()
707 return handled;
708}
initial.commit09911bf2008-07-26 23:55:29709
710bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42711 // Don't send any messages after the browser has told us to close, and filter
712 // most outgoing messages while swapped out.
713 if ((is_swapped_out_ &&
714 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
715 closing_) {
initial.commit09911bf2008-07-26 23:55:29716 delete message;
717 return false;
718 }
719
720 // If given a messsage without a routing ID, then assign our routing ID.
721 if (message->routing_id() == MSG_ROUTING_NONE)
722 message->set_routing_id(routing_id_);
723
[email protected]380244092011-10-07 17:26:27724 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44725}
726
dtapuska014ed082016-11-11 21:58:48727void RenderWidget::SendOrCrash(IPC::Message* message) {
728 bool result = Send(message);
729 CHECK(closing_ || result) << "Failed to send message";
730}
731
ekaramad5aff1942017-01-06 01:26:35732bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26733 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
734 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
735 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
736 // will be processed regardless of page focus. We should revisit this after
737 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
Blink Reformat1c4d759e2017-04-09 16:34:54738 return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
ekaramadb6483a052017-02-10 02:23:26739 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35740}
741
bokanc007c3a2015-02-03 07:15:56742void RenderWidget::SetWindowRectSynchronously(
743 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39744 ResizeParams params;
745 params.screen_info = screen_info_;
746 params.new_size = new_window_rect.size();
747 params.physical_backing_size =
748 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39749 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39750 params.is_fullscreen_granted = is_fullscreen_granted_;
751 params.display_mode = display_mode_;
752 params.needs_resize_ack = false;
753 Resize(params);
754
bokanc007c3a2015-02-03 07:15:56755 view_screen_rect_ = new_window_rect;
756 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02757 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56758 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02759}
760
initial.commit09911bf2008-07-26 23:55:29761void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32762 DCHECK(content::RenderThread::Get());
763 if (closing_)
764 return;
765 NotifyOnClose();
766 closing_ = true;
767
768 // Browser correspondence is no longer needed at this point.
769 if (routing_id_ != MSG_ROUTING_NONE) {
770 RenderThread::Get()->RemoveRoute(routing_id_);
771 SetHidden(false);
772 if (RenderThreadImpl::current())
773 RenderThreadImpl::current()->WidgetDestroyed();
774 }
775
776 if (for_oopif_) {
777 // Widgets for frames may be created and closed at any time while the frame
778 // is alive. However, the closing process must happen synchronously. Frame
779 // widget and frames hold pointers to each other. If Close() is deferred to
780 // the message loop like in the non-frame widget case, WebWidget::close()
781 // can end up accessing members of an already-deleted frame.
782 Close();
783 } else {
784 // If there is a Send call on the stack, then it could be dangerous to close
785 // now. Post a task that only gets invoked when there are no nested message
786 // loops.
Hajime Hoshiabb3c8f2017-12-04 18:41:39787 task_runner_->PostNonNestableTask(
tzikff2a81a2017-09-15 05:10:06788 FROM_HERE, base::BindOnce(&RenderWidget::Close, this));
dchengd96a27a2015-07-24 20:17:32789 }
790
791 // Balances the AddRef taken when we called AddRoute.
792 Release();
initial.commit09911bf2008-07-26 23:55:29793}
794
fsamuel664e8b62016-01-20 19:54:01795void RenderWidget::OnResize(const ResizeParams& params) {
EhsanKbd2cea992017-11-23 18:49:08796 gfx::Size old_visible_viewport_size = visible_viewport_size_;
797
[email protected]5b45ad42013-10-25 00:42:04798 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32799 return;
800
[email protected]b2e4c70132013-10-03 02:07:51801 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39802 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51803 return;
804 }
805
mfomitchev2600fd7c2016-02-17 20:53:39806 Resize(params);
EhsanKbd2cea992017-11-23 18:49:08807
808 if (old_visible_viewport_size != visible_viewport_size_) {
809 for (auto& render_frame : render_frames_)
810 render_frame.DidChangeVisibleViewport();
811 }
initial.commit09911bf2008-07-26 23:55:29812}
813
Fady Samuel319e429c2017-10-02 18:31:55814void RenderWidget::OnSetLocalSurfaceIdForAutoResize(
815 uint64_t sequence_number,
Fady Samuel69b33b52017-11-08 22:01:52816 const gfx::Size& min_size,
817 const gfx::Size& max_size,
818 const content::ScreenInfo& screen_info,
Saman Samif7731342018-01-24 22:18:44819 uint32_t content_source_id,
Fady Samuel319e429c2017-10-02 18:31:55820 const viz::LocalSurfaceId& local_surface_id) {
821 if (!auto_resize_mode_ || resize_or_repaint_ack_num_ != sequence_number)
822 return;
Fady Samuel69b33b52017-11-08 22:01:52823
824 SetLocalSurfaceIdForAutoResize(sequence_number, screen_info,
Saman Samif7731342018-01-24 22:18:44825 content_source_id, local_surface_id);
Fady Samuel319e429c2017-10-02 18:31:55826}
827
dgozman9260b0a12015-03-16 13:45:20828void RenderWidget::OnEnableDeviceEmulation(
Lei Zhang9b359d32017-11-28 00:57:02829 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39830 if (!screen_metrics_emulator_) {
831 ResizeParams resize_params;
832 resize_params.screen_info = screen_info_;
833 resize_params.new_size = size_;
834 resize_params.physical_backing_size = physical_backing_size_;
835 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39836 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
837 resize_params.display_mode = display_mode_;
838 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
839 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18840 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39841 } else {
dgozman9260b0a12015-03-16 13:45:20842 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39843 }
dgozman9260b0a12015-03-16 13:45:20844}
845
846void RenderWidget::OnDisableDeviceEmulation() {
847 screen_metrics_emulator_.reset();
848}
849
initial.commit09911bf2008-07-26 23:55:29850void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31851 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29852 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03853 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55854 for (auto& observer : render_frames_)
855 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29856}
857
[email protected]3399dd822014-08-09 11:14:24858void RenderWidget::OnWasShown(bool needs_repainting,
859 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41860 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29861 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21862 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29863 return;
864
tasakb95dbb50c2017-02-08 18:07:50865 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29866 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03867 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55868 for (auto& observer : render_frames_)
869 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29870
[email protected]8a23afb32014-04-30 22:40:23871 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29872 return;
initial.commit09911bf2008-07-26 23:55:29873
[email protected]3399dd822014-08-09 11:14:24874 if (compositor_) {
875 ui::LatencyInfo swap_latency_info(latency_info);
danakj87fbafb2017-04-04 16:54:11876 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
877 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info);
878 // Force this SwapPromiseMonitor to trigger and insert a SwapPromise.
Blink Reformat1c4d759e2017-04-09 16:34:54879 compositor_->SetNeedsBeginFrame();
[email protected]3399dd822014-08-09 11:14:24880 }
initial.commit09911bf2008-07-26 23:55:29881}
882
[email protected]53d3f302009-12-21 04:42:05883void RenderWidget::OnRequestMoveAck() {
884 DCHECK(pending_window_rect_count_);
885 pending_window_rect_count_--;
886}
887
[email protected]ed7defa2013-03-12 21:29:59888GURL RenderWidget::GetURLForGraphicsContext3D() {
889 return GURL();
[email protected]65225772011-05-12 21:10:24890}
891
nzolghadr5d8596502017-01-23 22:59:35892void RenderWidget::OnHandleInputEvent(
893 const blink::WebInputEvent* input_event,
894 const std::vector<const blink::WebInputEvent*>& coalesced_events,
895 const ui::LatencyInfo& latency_info,
896 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23897 if (!input_event)
898 return;
nzolghadr5d8596502017-01-23 22:59:35899
Dave Tapuskaea83d3bd2017-06-13 16:14:55900 HandledEventCallback callback;
901 if (dispatch_type == DISPATCH_TYPE_BLOCKING) {
902 callback = base::Bind(
903 &RenderWidget::SendInputEventAck, this, input_event->GetType(),
904 ui::WebInputEventTraits::GetUniqueTouchEventId(*input_event));
905 }
nzolghadr5d8596502017-01-23 22:59:35906 input_handler_->HandleInputEvent(
907 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
Dave Tapuskaea83d3bd2017-06-13 16:14:55908 latency_info, std::move(callback));
fsamuel78f86e42016-01-20 04:10:23909}
910
Sadrul Habib Chowdhury6539b732018-01-05 21:53:27911viz::FrameSinkId RenderWidget::GetFrameSinkIdAtPoint(const gfx::Point& point) {
912 return input_handler_->GetFrameSinkIdAtPoint(point);
Navid Zolghadr0d86e5f2017-10-23 18:09:22913}
914
Dave Tapuskaea83d3bd2017-06-13 16:14:55915void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31916 const blink::WebCoalescedInputEvent& input_event,
917 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55918 HandledEventCallback callback) {
919 input_handler_->HandleInputEvent(input_event, latency_info,
920 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31921}
922
Dave Tapuskaea83d3bd2017-06-13 16:14:55923void RenderWidget::SendInputEventAck(
924 blink::WebInputEvent::Type type,
925 uint32_t touch_event_id,
926 InputEventAckState ack_state,
927 const ui::LatencyInfo& latency_info,
Dave Tapuskab28a1082017-08-30 15:37:26928 std::unique_ptr<ui::DidOverscrollParams> overscroll_params,
929 base::Optional<cc::TouchAction> touch_action) {
Dave Tapuskaea83d3bd2017-06-13 16:14:55930 InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_state,
Dave Tapuskab28a1082017-08-30 15:37:26931 latency_info, std::move(overscroll_params), touch_event_id,
932 touch_action);
dtapuska9ec1a912017-04-21 15:18:31933 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
934}
935
dtapuska9d46ef7d2017-05-26 19:06:06936scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
937 return input_event_queue_;
938}
939
fsamuel78f86e42016-01-20 04:10:23940void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21941 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54942 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23943}
944
945void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21946 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54947 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23948}
949
alexmos56567492016-09-13 00:52:46950void RenderWidget::OnSetEditCommandsForNextKeyEvent(
951 const EditCommands& edit_commands) {
952 edit_commands_ = edit_commands;
953}
954
fsamuel78f86e42016-01-20 04:10:23955void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08956 has_focus_ = enable;
957
lfg8ff33912016-09-13 20:59:21958 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54959 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08960
ericwilligers88e69742016-10-17 19:29:55961 for (auto& observer : render_frames_)
962 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23963}
964
dtapuska3d5624d32016-08-30 04:34:00965void RenderWidget::SetNeedsMainFrame() {
966 RenderWidgetCompositor* rwc = compositor();
967 if (!rwc)
968 return;
Blink Reformat1c4d759e2017-04-09 16:34:54969 rwc->SetNeedsBeginFrame();
dtapuska3d5624d32016-08-30 04:34:00970}
971
fsamuel78f86e42016-01-20 04:10:23972///////////////////////////////////////////////////////////////////////////////
973// RenderWidgetCompositorDelegate
974
975void RenderWidget::ApplyViewportDeltas(
976 const gfx::Vector2dF& inner_delta,
977 const gfx::Vector2dF& outer_delta,
978 const gfx::Vector2dF& elastic_overscroll_delta,
979 float page_scale,
980 float top_controls_delta) {
Blink Reformat1c4d759e2017-04-09 16:34:54981 GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta,
lfg8ff33912016-09-13 20:59:21982 elastic_overscroll_delta, page_scale,
983 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23984}
985
sahel1b47fda72017-03-28 17:03:07986void RenderWidget::RecordWheelAndTouchScrollingCount(
987 bool has_scrolled_by_wheel,
988 bool has_scrolled_by_touch) {
Blink Reformat1c4d759e2017-04-09 16:34:54989 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07990 has_scrolled_by_touch);
991}
992
fsamuel78f86e42016-01-20 04:10:23993void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska9ec1a912017-04-21 15:18:31994 if (input_event_queue_) {
995 input_event_queue_->DispatchRafAlignedInput(
996 ui::EventTimeStampFromSeconds(frame_time_sec));
997 }
dtapuska3d5624d32016-08-30 04:34:00998
Blink Reformat1c4d759e2017-04-09 16:34:54999 GetWebWidget()->BeginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:231000}
1001
danakjc7afae52017-06-20 21:12:411002void RenderWidget::RequestNewLayerTreeFrameSink(
danakjc7afae52017-06-20 21:12:411003 const LayerTreeFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:211004 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:031005 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:411006 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:391007 DCHECK(!compositor_never_visible_);
danakjc7afae52017-06-20 21:12:411008 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
danakjab9ef4d2017-10-31 23:38:331009 routing_id_, frame_swap_message_queue_, GetURLForGraphicsContext3D(),
1010 callback);
[email protected]ba91a792013-02-06 09:48:281011}
1012
fsamuel78f86e42016-01-20 04:10:231013void RenderWidget::DidCommitAndDrawCompositorFrame() {
1014 // NOTE: Tests may break if this event is renamed or moved. See
1015 // tab_capture_performancetest.cc.
1016 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:081017
Saman Sami766e0b02018-01-31 17:19:201018 // If we haven't commited yet, then this method was called as a response to a
1019 // previous commit and should not be used to ack the resize.
1020 if (did_commit_after_resize_)
1021 DidResizeOrRepaintAck();
Saman Sami9ee04be2018-01-25 01:31:251022
ericwilligers88e69742016-10-17 19:29:551023 for (auto& observer : render_frames_)
1024 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:081025
fsamuel78f86e42016-01-20 04:10:231026 // Notify subclasses that we initiated the paint operation.
1027 DidInitiatePaint();
1028}
1029
Saman Sami766e0b02018-01-31 17:19:201030void RenderWidget::DidCommitCompositorFrame() {
1031 did_commit_after_resize_ = true;
1032}
fsamuel78f86e42016-01-20 04:10:231033
1034void RenderWidget::DidCompletePageScaleAnimation() {}
1035
danakj6c872fc02016-10-22 04:29:491036void RenderWidget::DidReceiveCompositorFrameAck() {
fsamuel78f86e42016-01-20 04:10:231037}
1038
fsamuel78f86e42016-01-20 04:10:231039bool RenderWidget::IsClosing() const {
1040 return host_closing_;
1041}
1042
danakj53eccbc2016-03-02 22:51:071043void RenderWidget::RequestScheduleAnimation() {
Blink Reformat1c4d759e2017-04-09 16:34:541044 ScheduleAnimation();
initial.commit09911bf2008-07-26 23:55:291045}
1046
Eric Seckler8af8c0e52018-01-17 23:45:531047void RenderWidget::UpdateVisualState(VisualStateUpdate requested_update) {
1048 bool pre_paint_only = requested_update == VisualStateUpdate::kPrePaint;
1049 WebWidget::LifecycleUpdate lifecycle_update =
1050 pre_paint_only ? WebWidget::LifecycleUpdate::kPrePaint
1051 : WebWidget::LifecycleUpdate::kAll;
1052
1053 GetWebWidget()->UpdateLifecycle(lifecycle_update);
Blink Reformat1c4d759e2017-04-09 16:34:541054 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:501055
Eric Seckler8af8c0e52018-01-17 23:45:531056 if (first_update_visual_state_after_hidden_ && !pre_paint_only) {
Takashi SAKAMOTO870f6262017-08-22 04:08:271057 RecordTimeToFirstActivePaint();
1058 first_update_visual_state_after_hidden_ = false;
1059 }
1060}
tasakb95dbb50c2017-02-08 18:07:501061
Takashi SAKAMOTO870f6262017-08-22 04:08:271062void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501063 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501064 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271065 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1066 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1067 sample);
1068 }
1069 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1070 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1071 UMA_HISTOGRAM_TIMES(
1072 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1073 "AfterBackgrounded.5min",
1074 sample);
1075 }
fsamuel78f86e42016-01-20 04:10:231076}
1077
1078void RenderWidget::WillBeginCompositorFrame() {
1079 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1080
Blink Reformat1c4d759e2017-04-09 16:34:541081 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291082
dglazkov06854c5c2016-08-31 00:19:591083 // The UpdateTextInputState can result in further layout and possibly
1084 // enable GPU acceleration so they need to be called before any painting
1085 // is done.
changwan75e3b2072017-01-16 02:55:001086 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591087 UpdateSelectionBounds();
1088
ericwilligers88e69742016-10-17 19:29:551089 for (auto& observer : render_frame_proxies_)
1090 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291091}
1092
jbroman6ccbc7d472016-07-27 04:45:411093std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:041094 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:411095 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
1096 routing_id_, std::move(request));
1097}
1098
fsamuel72464894f2015-12-15 06:59:311099///////////////////////////////////////////////////////////////////////////////
1100// RenderWidgetInputHandlerDelegate
1101
avid7d6b2e2016-03-04 19:41:171102void RenderWidget::FocusChangeComplete() {
Ehsan Karamad655d7b8a2018-01-12 18:38:381103 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1104 if (!frame_widget)
ekaramad27ca69b12017-04-20 18:34:291105 return;
Ehsan Karamad655d7b8a2018-01-12 18:38:381106
ekaramad27ca69b12017-04-20 18:34:291107 blink::WebLocalFrame* focused =
Ehsan Karamad655d7b8a2018-01-12 18:38:381108 frame_widget->LocalRoot()->View()->FocusedFrame();
1109
ekaramad27ca69b12017-04-20 18:34:291110 if (focused && focused->AutofillClient())
1111 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171112}
fsamuel72464894f2015-12-15 06:59:311113
dtapuska1827dd22016-03-11 15:24:591114void RenderWidget::ObserveGestureEventAndResult(
1115 const blink::WebGestureEvent& gesture_event,
1116 const gfx::Vector2dF& unused_delta,
Sandra Sunac5cdd832017-12-11 03:27:131117 const cc::OverscrollBehavior& overscroll_behavior,
dtapuska1827dd22016-03-11 15:24:591118 bool event_processed) {
1119 if (!compositor_deps_->IsElasticOverscrollEnabled())
1120 return;
1121
1122 cc::InputHandlerScrollResult scroll_result;
1123 scroll_result.did_scroll = event_processed;
1124 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1125 scroll_result.unused_scroll_delta = unused_delta;
Sandra Sunac5cdd832017-12-11 03:27:131126 scroll_result.overscroll_behavior = overscroll_behavior;
dtapuska1827dd22016-03-11 15:24:591127
1128 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1129 InputHandlerManager* input_handler_manager =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281130 render_thread ? render_thread->input_handler_manager() : nullptr;
dtapuska1827dd22016-03-11 15:24:591131 if (input_handler_manager) {
1132 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1133 routing_id_, gesture_event, scroll_result);
Dave Tapuska9db80842017-07-24 17:24:261134 } else if (widget_input_handler_manager_) {
1135 widget_input_handler_manager_->ObserveGestureEventOnMainThread(
1136 gesture_event, scroll_result);
dtapuska1827dd22016-03-11 15:24:591137 }
1138}
1139
avid7d6b2e2016-03-04 19:41:171140void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461141 ClearEditCommands();
1142}
1143
1144void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1145 const std::string& value) {
1146 ClearEditCommands();
1147 edit_commands_.emplace_back(name, value);
1148}
1149
1150void RenderWidget::ClearEditCommands() {
1151 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171152}
fsamuel72464894f2015-12-15 06:59:311153
chongza8ba91fc2016-08-16 21:39:171154void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska139a72f2017-09-06 21:57:031155 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:051156 if (mojom::WidgetInputHandlerHost* host =
1157 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1158 host->DidOverscroll(params);
1159 }
Dave Tapuska139a72f2017-09-06 21:57:031160 } else {
1161 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1162 }
fsamuel72464894f2015-12-15 06:59:311163}
1164
fsamuele8326c742016-01-12 00:49:391165void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1166 // Nothing to do here. RenderWidget created the |input_handler| and will take
1167 // ownership of it. We just verify here that we don't already have an input
1168 // handler.
1169 DCHECK(!input_handler_);
1170}
1171
changwan75e3b2072017-01-16 02:55:001172void RenderWidget::ShowVirtualKeyboard() {
1173 UpdateTextInputStateInternal(true, false);
1174}
1175
changwan62f57292017-02-17 08:28:251176void RenderWidget::ClearTextInputState() {
1177 text_input_info_ = blink::WebTextInputInfo();
1178 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1179 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1180 can_compose_inline_ = false;
1181 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201182 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251183}
1184
changwan75e3b2072017-01-16 02:55:001185void RenderWidget::UpdateTextInputState() {
1186 UpdateTextInputStateInternal(false, false);
1187}
1188
1189void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1190 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311191 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001192
fsamuel72464894f2015-12-15 06:59:311193 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001194 DCHECK(!reply_to_request);
1195 // show_virtual_keyboard should still be effective even if it was set inside
1196 // the IME
fsamuel72464894f2015-12-15 06:59:311197 // event guard.
changwan75e3b2072017-01-16 02:55:001198 if (show_virtual_keyboard)
1199 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311200 return;
1201 }
1202
dglazkov97b6c2b2016-10-25 17:35:551203 ui::TextInputType new_type = GetTextInputType();
1204 if (IsDateTimeInput(new_type))
1205 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311206
dglazkov97b6c2b2016-10-25 17:35:551207 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351208 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541209 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101210 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541211 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311212
1213 bool new_can_compose_inline = CanComposeInline();
1214
1215 // Only sends text input params if they are changed or if the ime should be
1216 // shown.
changwan75e3b2072017-01-16 02:55:001217 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561218 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1219 text_input_info_ != new_info ||
1220 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381221 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551222 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311223 params.mode = new_mode;
1224 params.flags = new_info.flags;
AJITH KUMAR V9e7b5572017-11-14 00:54:211225#if defined(OS_ANDROID)
AJITH KUMAR V041c0b02017-08-08 10:39:201226 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1227 // Due to a focus change, values will be reset by the frame.
1228 // That case we only need fresh NEXT/PREVIOUS information.
1229 // Also we won't send ViewHostMsg_TextInputStateChanged if next/previous
1230 // focusable status is changed.
1231 if (auto* controller = GetInputMethodController()) {
1232 next_previous_flags_ =
1233 controller->ComputeWebTextInputNextPreviousFlags();
1234 } else {
1235 // For safety in case GetInputMethodController() is null, because -1 is
1236 // invalid value to send to browser process.
1237 next_previous_flags_ = 0;
1238 }
1239 }
AJITH KUMAR V9e7b5572017-11-14 00:54:211240#else
1241 next_previous_flags_ = 0;
1242#endif
AJITH KUMAR V041c0b02017-08-08 10:39:201243 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541244 params.value = new_info.value.Utf8();
1245 params.selection_start = new_info.selection_start;
1246 params.selection_end = new_info.selection_end;
1247 params.composition_start = new_info.composition_start;
1248 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311249 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001250 // TODO(changwan): change instances of show_ime_if_needed to
1251 // show_virtual_keyboard.
1252 params.show_ime_if_needed = show_virtual_keyboard;
1253 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311254 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1255
1256 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551257 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311258 text_input_mode_ = new_mode;
1259 can_compose_inline_ = new_can_compose_inline;
1260 text_input_flags_ = new_info.flags;
1261 }
1262}
1263
1264bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581265 possible_drag_event_info_.event_source =
1266 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1267 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541268 gfx::Point(event.global_x, event.global_y);
avid7d6b2e2016-03-04 19:41:171269
fsamuel72464894f2015-12-15 06:59:311270 return false;
1271}
1272
1273bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551274 for (auto& observer : render_frames_)
1275 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081276
paulmeyer6ef5a792016-11-08 20:33:581277 possible_drag_event_info_.event_source =
1278 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1279 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541280 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581281
avid7d6b2e2016-03-04 19:41:171282 if (owner_delegate_)
1283 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1284
fsamuel72464894f2015-12-15 06:59:311285 return false;
[email protected]fd847792013-10-24 17:12:351286}
1287
initial.commit09911bf2008-07-26 23:55:291288///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391289// RenderWidgetScreenMetricsDelegate
1290
1291void RenderWidget::Redraw() {
1292 set_next_paint_is_resize_ack();
1293 if (compositor_)
1294 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1295}
1296
bokanc63441c2016-04-27 15:49:121297void RenderWidget::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:541298 GetWebWidget()->Resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121299}
1300
1301gfx::Size RenderWidget::GetSizeForWebWidget() const {
1302 if (IsUseZoomForDSFEnabled())
1303 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1304
1305 return size_;
1306}
1307
mfomitchev2600fd7c2016-02-17 20:53:391308void RenderWidget::Resize(const ResizeParams& params) {
Saman Samif7731342018-01-24 22:18:441309 // The content_source_id that the browser sends us should never be larger than
1310 // |current_content_source_id_|.
1311 DCHECK_GE(1u << 30, current_content_source_id_ - params.content_source_id);
1312
engedy6cb63c92016-02-23 14:14:581313 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271314 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1315 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581316
Fady Samuel85a1bf72017-10-27 14:30:201317 bool screen_info_changed = screen_info_ != params.screen_info;
1318
mfomitchev2600fd7c2016-02-17 20:53:391319 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581320
Saman Sami766e0b02018-01-31 17:19:201321 // If this resize needs to be acked, make sure we ack it only after we commit.
1322 // It is possible to get DidCommitAndDraw calls that belong to the previous
1323 // commit, in which case we should not ack this resize.
1324 if (params.needs_resize_ack)
1325 did_commit_after_resize_ = false;
1326
Miguel Casas5e1018052018-01-09 19:17:361327 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1328 if (render_thread)
1329 render_thread->SetRenderingColorSpace(screen_info_.color_space);
1330
ccameron2f451532016-09-07 21:49:271331 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1332 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581333 OnDeviceScaleFactorChanged();
wjmaclean8a795f32016-08-11 23:49:581334 }
mfomitchev2600fd7c2016-02-17 20:53:391335
1336 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1337 // A resize ack shouldn't be requested if we have not ACK'd the previous
1338 // one.
Saman Samif7731342018-01-24 22:18:441339 DCHECK(!compositor_ || !params.needs_resize_ack ||
1340 !next_paint_is_resize_ack());
mfomitchev2600fd7c2016-02-17 20:53:391341 }
1342
1343 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211344 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391345 return;
1346
Saman Samif7731342018-01-24 22:18:441347 // If the content_source_id of ResizeParams doesn't match
1348 // |current_content_source_id_|, then the given LocalSurfaceId was generated
1349 // before the navigation. Continue with the resize but don't use the
1350 // LocalSurfaceId until the right one comes.
1351 if (params.local_surface_id &&
1352 params.content_source_id == current_content_source_id_) {
fsamuelca02c4e2017-05-09 13:34:141353 local_surface_id_ = *params.local_surface_id;
Saman Samif7731342018-01-24 22:18:441354 }
fsamuelca02c4e2017-05-09 13:34:141355
ianwene5fc5782016-08-18 04:05:151356 if (compositor_) {
Fady Samuel319e429c2017-10-02 18:31:551357 // If surface synchronization is enabled, then this will use the provided
fsamuelca02c4e2017-05-09 13:34:141358 // |local_surface_id_| to submit the next generated CompositorFrame.
1359 // If the ID is not valid, then the compositor will defer commits until
1360 // it receives a valid surface ID. This is a no-op if surface
1361 // synchronization is disabled.
Fady Samuel2bb02292017-10-17 23:59:151362 DCHECK(!compositor_->IsSurfaceSynchronizationEnabled() ||
Saman Samif7731342018-01-24 22:18:441363 !params.needs_resize_ack || params.local_surface_id->is_valid());
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271364 compositor_->SetViewportSize(params.physical_backing_size,
1365 local_surface_id_);
1366 compositor_->SetBrowserControlsHeight(
1367 params.top_controls_height, params.bottom_controls_height,
1368 params.browser_controls_shrink_blink_size);
1369 compositor_->SetRasterColorSpace(
1370 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151371 }
mfomitchev2600fd7c2016-02-17 20:53:391372
mfomitchev2600fd7c2016-02-17 20:53:391373 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391374
1375 // NOTE: We may have entered fullscreen mode without changing our size.
1376 bool fullscreen_change =
1377 is_fullscreen_granted_ != params.is_fullscreen_granted;
1378 is_fullscreen_granted_ = params.is_fullscreen_granted;
1379 display_mode_ = params.display_mode;
1380
bokanc63441c2016-04-27 15:49:121381 size_ = params.new_size;
1382 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391383
bokanc63441c2016-04-27 15:49:121384 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221385
mfomitchev2600fd7c2016-02-17 20:53:391386 WebSize visual_viewport_size;
1387
1388 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181389 visual_viewport_size = gfx::ScaleToCeiledSize(
1390 params.visible_viewport_size,
1391 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391392 } else {
1393 visual_viewport_size = visible_viewport_size_;
1394 }
1395
Blink Reformat1c4d759e2017-04-09 16:34:541396 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391397
bokanc63441c2016-04-27 15:49:121398 // When resizing, we want to wait to paint before ACK'ing the resize. This
1399 // ensures that we only resize as fast as we can paint. We only need to
1400 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391401 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1402 // In this case there is no paint/composite and therefore no
Fady Samuelcc3e3b4a2017-10-03 02:09:211403 // ViewHostMsg_ResizeOrRepaint_ACK to send the resize ack with. We'd need to
1404 // send the ack through a fake ViewHostMsg_ResizeOrRepaint_ACK or a
1405 // different message.
mfomitchev2600fd7c2016-02-17 20:53:391406 DCHECK(!params.needs_resize_ack);
1407 }
1408
1409 // Send the Resize_ACK flag once we paint again if requested.
1410 if (params.needs_resize_ack)
1411 set_next_paint_is_resize_ack();
1412
1413 if (fullscreen_change)
1414 DidToggleFullscreen();
1415
engedy6cb63c92016-02-23 14:14:581416 if (orientation_changed)
1417 OnOrientationChange();
1418
Fady Samuel85a1bf72017-10-27 14:30:201419 if (screen_info_changed) {
1420 for (auto& observer : render_frame_proxies_)
1421 observer.OnScreenInfoChanged(params.screen_info);
1422
Saman Samid189e5dfd2017-12-20 22:55:311423 // Notify all embedded BrowserPlugins of the updated ScreenInfo.
1424 for (auto& observer : browser_plugins_)
1425 observer.ScreenInfoChanged(params.screen_info);
Fady Samuel85a1bf72017-10-27 14:30:201426 }
1427
mfomitchev2600fd7c2016-02-17 20:53:391428 // If a resize ack is requested and it isn't set-up, then no more resizes will
1429 // come in and in general things will go wrong.
1430 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
Saman Samif7731342018-01-24 22:18:441431
1432 // If this resize was initiated before navigation and surface synchronization
1433 // is on, it is not expected to be acked.
1434 if (compositor_ && compositor_->IsSurfaceSynchronizationEnabled() &&
1435 params.needs_resize_ack && !local_surface_id_.is_valid()) {
1436 DCHECK_NE(params.content_source_id, current_content_source_id_);
1437 reset_next_paint_is_resize_ack();
1438 }
mfomitchev2600fd7c2016-02-17 20:53:391439}
1440
1441void RenderWidget::SetScreenMetricsEmulationParameters(
1442 bool enabled,
1443 const blink::WebDeviceEmulationParams& params) {
1444 // This is only supported in RenderView.
1445 NOTREACHED();
1446}
1447
1448void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1449 const gfx::Rect& window_screen_rect) {
1450 view_screen_rect_ = view_screen_rect;
1451 window_screen_rect_ = window_screen_rect;
1452}
1453
1454///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461455// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291456
Fady Samueld10aadd82017-11-03 18:23:571457void RenderWidget::AutoResizeCompositor(
1458 const viz::LocalSurfaceId& local_surface_id) {
danakjddaec912015-09-25 19:38:401459 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
Fady Samueld10aadd82017-11-03 18:23:571460 local_surface_id_ = local_surface_id;
[email protected]97e1bf72013-03-06 14:06:051461 if (compositor_)
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271462 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
[email protected]97e1bf72013-03-06 14:06:051463}
1464
Blink Reformat1c4d759e2017-04-09 16:34:541465blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221466 DCHECK(!host_closing_);
1467
loyso6e6efc42017-01-21 02:23:031468 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1469 auto animation_host = cc::AnimationHost::CreateMainInstance();
1470
wjmacleana755e302017-04-20 00:43:161471 // Oopif status must be set before the LayerTreeHost is created.
1472 compositor_->SetIsForOopif(for_oopif_);
loyso6e6efc42017-01-21 02:23:031473 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1474 compositor_.get(), compositor_.get(), animation_host.get(),
1475 compositor_deps_, device_scale_factor_, screen_info_);
1476 compositor_->Initialize(std::move(layer_tree_host),
1477 std::move(animation_host));
1478
Saman Samif7731342018-01-24 22:18:441479 // We can get into this state if surface synchronization is on and the last
1480 // resize was initiated before navigation, in which case we don't have to ack
1481 // it.
1482 if (compositor_->IsSurfaceSynchronizationEnabled() && !auto_resize_mode_ &&
1483 next_paint_is_resize_ack() && !local_surface_id_.is_valid()) {
1484 reset_next_paint_is_resize_ack();
1485 }
1486
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271487 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
oshimad5279032015-12-16 18:22:331488 OnDeviceScaleFactorChanged();
ccameron01912992017-05-23 07:34:031489 compositor_->SetRasterColorSpace(
Christopher Camerona1ea2b72017-08-02 01:59:091490 screen_info_.color_space.GetRasterColorSpace());
kenrb5d78b842017-03-06 21:06:011491 compositor_->SetContentSourceId(current_content_source_id_);
sievers71c62dd52015-10-07 01:44:391492 // For background pages and certain tests, we don't want to trigger
danakjc7afae52017-06-20 21:12:411493 // LayerTreeFrameSink creation.
dtapuskab08611f2017-04-24 16:10:221494 bool should_generate_frame_sink =
1495 !compositor_never_visible_ && RenderThreadImpl::current();
1496 if (!should_generate_frame_sink)
sievers71c62dd52015-10-07 01:44:391497 compositor_->SetNeverVisible();
1498
pimanc4af3072015-10-02 03:45:591499 StartCompositor();
staraz067f58242016-11-07 21:06:411500 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1501 compositor_->SetFrameSinkId(
Fady Samueld5c26182017-07-12 02:43:331502 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371503
wjmaclean1d970622017-01-21 22:28:241504 RenderThreadImpl* render_thread = RenderThreadImpl::current();
Dave Tapuska9db80842017-07-24 17:24:261505 if (render_thread) {
dtapuska9ec1a912017-04-21 15:18:311506 input_event_queue_ = new MainThreadEventQueue(
Alexander Timinbb0860d2018-01-29 13:27:161507 this, render_thread->GetRendererScheduler()->InputTaskRunner(),
dtapuskab08611f2017-04-24 16:10:221508 render_thread->GetRendererScheduler(), should_generate_frame_sink);
Dave Tapuska9db80842017-07-24 17:24:261509
1510 InputHandlerManager* input_handler_manager =
1511 render_thread->input_handler_manager();
1512 if (input_handler_manager) {
1513 input_handler_manager->AddInputHandler(
1514 routing_id_, compositor()->GetInputHandler(), input_event_queue_,
1515 weak_ptr_factory_.GetWeakPtr(),
1516 compositor_deps_->IsScrollAnimatorEnabled());
1517 has_added_input_handler_ = true;
1518 }
wjmaclean1d970622017-01-21 22:28:241519 }
1520
Khushal3e96e662017-10-30 23:16:501521 UpdateURLForCompositorUkm();
1522
loyso50b51c22017-01-10 07:18:371523 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591524}
1525
Chris Harrelsond7ab99b2018-01-24 17:51:361526void RenderWidget::IntrinsicSizingInfoChanged(
1527 const blink::WebIntrinsicSizingInfo& sizing_info) {
1528 Send(new ViewHostMsg_IntrinsicSizingInfoChanged(routing_id_, sizing_info));
1529}
1530
ennef3c58142014-12-09 21:44:381531void RenderWidget::WillCloseLayerTreeView() {
1532 if (host_closing_)
1533 return;
1534
1535 // Prevent new compositors or output surfaces from being created.
1536 host_closing_ = true;
1537
[email protected]aeeedad2014-08-22 18:16:221538 // Always send this notification to prevent new layer tree views from
1539 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211540 if (blink::WebWidget* widget = GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541541 widget->WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221542}
1543
Blink Reformat1c4d759e2017-04-09 16:34:541544void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1545 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
dglazkovf0e1d6d2015-10-10 02:13:481546 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1547 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1548 }
dglazkov79c426102015-08-31 21:22:431549
ericwilligers88e69742016-10-17 19:29:551550 for (auto& observer : render_frames_)
1551 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431552}
1553
[email protected]586871b2014-07-22 17:05:111554// static
dchengcedca5612016-04-09 01:40:151555std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111556 IPC::Message* msg,
1557 MessageDeliveryPolicy policy,
1558 FrameSwapMessageQueue* frame_swap_message_queue,
1559 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111560 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111561 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151562 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1563 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111564 &first_message_for_frame);
1565 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151566 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111567 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061568 return promise;
[email protected]586871b2014-07-22 17:05:111569 }
dcheng4b6b5ff2014-10-16 00:42:061570 return nullptr;
[email protected]586871b2014-07-22 17:05:111571}
1572
1573void RenderWidget::QueueMessage(IPC::Message* msg,
1574 MessageDeliveryPolicy policy) {
1575 // RenderThreadImpl::current() is NULL in some tests.
1576 if (!compositor_ || !RenderThreadImpl::current()) {
1577 Send(msg);
1578 return;
1579 }
1580
dchengcedca5612016-04-09 01:40:151581 std::unique_ptr<cc::SwapPromise> swap_promise =
1582 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111583 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111584 compositor_->GetSourceFrameNumber());
1585
Ken Buchanance710eb2017-08-30 23:46:521586 if (swap_promise)
dcheng07945f632015-12-26 07:59:321587 compositor_->QueueSwapPromise(std::move(swap_promise));
[email protected]586871b2014-07-22 17:05:111588}
1589
Blink Reformat1c4d759e2017-04-09 16:34:541590void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301591 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521592 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181593 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291594 // Only send a SetCursor message if we need to make a change.
1595 if (!current_cursor_.IsEqual(cursor)) {
1596 current_cursor_ = cursor;
1597 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1598 }
1599}
1600
aelias5971e47d2017-06-16 02:39:381601void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
1602 Send(new ViewHostMsg_AutoscrollStart(routing_id_, point));
1603}
1604
1605void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
1606 Send(new ViewHostMsg_AutoscrollFling(routing_id_, velocity));
1607}
1608
1609void RenderWidget::AutoscrollEnd() {
1610 Send(new ViewHostMsg_AutoscrollEnd(routing_id_));
1611}
1612
initial.commit09911bf2008-07-26 23:55:291613// We are supposed to get a single call to Show for a newly created RenderWidget
1614// that was created via RenderWidget::CreateWebView. So, we wait until this
1615// point to dispatch the ShowWidget message.
1616//
1617// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281618// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291619//
Blink Reformat1c4d759e2017-04-09 16:34:541620void RenderWidget::Show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291621 DCHECK(!did_show_) << "received extraneous Show call";
1622 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351623 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291624
[email protected]8de12d942010-11-17 20:42:441625 if (did_show_)
1626 return;
1627
1628 did_show_ = true;
nickf7b38222016-11-22 21:59:351629
1630 // The opener is responsible for actually showing this widget.
1631 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351632 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351633
bokanc007c3a2015-02-03 07:15:561634 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441635 // that's okay. It'll be ignored if as_popup is false, or the browser
1636 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561637 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291638}
1639
[email protected]2533ce12009-05-09 00:02:241640void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381641 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241642 Send(new ViewHostMsg_Close(routing_id_));
1643}
1644
dgozmancf9039cd2015-04-06 12:01:311645void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551646 for (auto& observer : render_frames_)
1647 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311648}
1649
Blink Reformat1c4d759e2017-04-09 16:34:541650void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081651 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321652 if (is_swapped_out_) {
1653 // This widget is currently swapped out, and the active widget is in a
1654 // different process. Have the browser route the close request to the
1655 // active widget instead, so that the correct unload handlers are run.
1656 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1657 return;
1658 }
1659
initial.commit09911bf2008-07-26 23:55:291660 // If a page calls window.close() twice, we'll end up here twice, but that's
1661 // OK. It is safe to send multiple Close messages.
1662
[email protected]2533ce12009-05-09 00:02:241663 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1664 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1665 // could be closed before the JS finishes executing. So instead, post a
1666 // message back to the message loop, which won't run until the JS is
1667 // complete, and then the Close message can be sent.
Hajime Hoshiabb3c8f2017-12-04 18:41:391668 task_runner_->PostTask(FROM_HERE,
1669 base::BindOnce(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291670}
1671
1672void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031673 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381674 WillCloseLayerTreeView();
1675 compositor_.reset();
lfg8ff33912016-09-13 20:59:211676 if (webwidget_internal_) {
Blink Reformat1c4d759e2017-04-09 16:34:541677 webwidget_internal_->Close();
lfg8ff33912016-09-13 20:59:211678 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291679 }
1680}
1681
Ehsan Karamad655d7b8a2018-01-12 18:38:381682blink::WebFrameWidget* RenderWidget::GetFrameWidget() const {
1683 blink::WebWidget* web_widget = GetWebWidget();
1684 if (!web_widget)
1685 return nullptr;
1686
1687 if (!web_widget->IsWebFrameWidget()) {
1688 // TODO(ekaramad): This should not happen. If we have a WebWidget and we
1689 // need a WebFrameWidget then we should be getting a WebFrameWidget. But
1690 // unfortunately this does not seem to be the case in some scenarios --
1691 // specifically when a RenderViewImpl swaps out during navigation the
1692 // WebViewImpl loses its WebViewFrameWidget but sometimes we receive IPCs
1693 // which are destined for WebFrameWidget (https://crbug.com/669219).
1694 return nullptr;
1695 }
1696
1697 return static_cast<blink::WebFrameWidget*>(web_widget);
1698}
1699
bokan841fdc72016-10-06 00:16:351700void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1701 DCHECK(window_rect);
1702 float scale = popup_origin_scale_for_emulation_;
1703 if (!scale)
1704 return;
1705 window_rect->x =
1706 popup_view_origin_for_emulation_.x() +
1707 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1708 window_rect->y =
1709 popup_view_origin_for_emulation_.y() +
1710 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1711}
1712
1713void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1714 DCHECK(window_rect);
1715 float scale = popup_origin_scale_for_emulation_;
1716 if (!scale)
1717 return;
1718 window_rect->x =
1719 popup_screen_origin_for_emulation_.x() +
1720 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1721 window_rect->y =
1722 popup_screen_origin_for_emulation_.y() +
1723 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1724}
1725
Blink Reformat1c4d759e2017-04-09 16:34:541726WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351727 WebRect rect;
bokan6b08cd22016-10-05 00:55:211728 if (pending_window_rect_count_) {
1729 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1730 // the RootWindowRect is probably going to return wrong results since the
1731 // browser may not have processed the Move yet. There isn't really anything
1732 // good to do in this case, and it shouldn't happen - since this size is
1733 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351734 rect = pending_window_rect_;
1735 } else {
1736 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211737 }
[email protected]2533ce12009-05-09 00:02:241738
bokan841fdc72016-10-06 00:16:351739 ScreenRectToEmulatedIfNeeded(&rect);
1740 return rect;
bokan6b08cd22016-10-05 00:55:211741}
1742
Blink Reformat1c4d759e2017-04-09 16:34:541743WebRect RenderWidget::ViewRect() {
bokan841fdc72016-10-06 00:16:351744 WebRect rect = view_screen_rect_;
1745 ScreenRectToEmulatedIfNeeded(&rect);
1746 return rect;
initial.commit09911bf2008-07-26 23:55:291747}
1748
Blink Reformat1c4d759e2017-04-09 16:34:541749void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301750 WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541751 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301752}
1753
Blink Reformat1c4d759e2017-04-09 16:34:541754void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
oshima33ec97cd2015-12-14 19:40:241755 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351756 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511757
[email protected]5b45ad42013-10-25 00:42:041758 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201759 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561760 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1761 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031762 } else {
bokanc007c3a2015-02-03 07:15:561763 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031764 }
initial.commit09911bf2008-07-26 23:55:291765 } else {
bokanc007c3a2015-02-03 07:15:561766 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291767 }
1768}
1769
[email protected]2533ce12009-05-09 00:02:241770void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1771 pending_window_rect_ = rect;
1772 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241773
bokan6b08cd22016-10-05 00:55:211774 // Popups don't get size updates back from the browser so just store the set
1775 // values.
Blink Reformat1c4d759e2017-04-09 16:34:541776 if (popup_type_ != blink::kWebPopupTypeNone) {
1777 window_screen_rect_ = rect;
1778 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241779 }
[email protected]d4547452008-08-28 18:36:371780}
1781
wjmacleanee244e02017-05-26 21:06:071782void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1783 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071784 has_host_context_menu_location_ = true;
1785 host_context_menu_location_ = location;
1786 if (GetWebWidget()) {
1787 GetWebWidget()->ShowContextMenu(
1788 static_cast<blink::WebMenuSourceType>(source_type));
1789 }
1790 has_host_context_menu_location_ = false;
1791}
1792
[email protected]fa7b1dc2010-06-23 17:53:041793void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261794 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111795 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:071796 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:111797 int selection_start,
1798 int selection_end) {
ekaramad5aff1942017-01-06 01:26:351799 if (!ShouldHandleImeEvents())
1800 return;
1801
brettw4b461082016-11-19 18:55:161802#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491803 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:111804 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:491805 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091806 return;
1807 }
1808#endif
[email protected]66fca5bc2013-05-23 06:58:291809 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011810 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011811 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541812 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:111813 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561814 replacement_range.IsValid()
1815 ? WebRange(replacement_range.start(), replacement_range.length())
1816 : WebRange(),
1817 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041818 // If we failed to set the composition text, then we need to let the browser
1819 // process to cancel the input method's ongoing composition session, to make
1820 // sure we are in a consistent state.
Dave Tapuska139a72f2017-09-06 21:57:031821 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:051822 if (mojom::WidgetInputHandlerHost* host =
1823 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1824 host->ImeCancelComposition();
1825 }
Dave Tapuska139a72f2017-09-06 21:57:031826 } else {
1827 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1828 }
[email protected]7f00efa2010-04-15 05:01:261829 }
nonafa291792016-08-10 02:36:181830 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041831}
1832
rlanday7efe2302017-01-11 00:14:281833void RenderWidget::OnImeCommitText(
1834 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111835 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:281836 const gfx::Range& replacement_range,
1837 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351838 if (!ShouldHandleImeEvents())
1839 return;
1840
brettw4b461082016-11-19 18:55:161841#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491842 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1843 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1844 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091845 return;
1846 }
1847#endif
[email protected]66fca5bc2013-05-23 06:58:291848 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391849 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261850 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541851 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:111852 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561853 replacement_range.IsValid()
1854 ? WebRange(replacement_range.start(), replacement_range.length())
1855 : WebRange(),
1856 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261857 }
aelias87b8f7c2016-09-14 03:19:291858 input_handler_->set_handling_input_event(false);
1859 UpdateCompositionInfo(false /* not an immediate request */);
1860}
1861
1862void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351863 if (!ShouldHandleImeEvents())
1864 return;
1865
brettw4b461082016-11-19 18:55:161866#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491867 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1868 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291869 return;
1870 }
1871#endif
1872
changwan38c3eb612016-12-09 01:45:561873 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291874 return;
1875 ImeEventGuard guard(this);
1876 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011877 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541878 controller->FinishComposingText(
1879 keep_selection ? WebInputMethodController::kKeepSelection
1880 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011881 }
fsamuele8326c742016-01-12 00:49:391882 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181883 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291884}
1885
oshimad5279032015-12-16 18:22:331886void RenderWidget::OnDeviceScaleFactorChanged() {
1887 if (!compositor_)
1888 return;
oshimad5279032015-12-16 18:22:331889 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181890 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331891 else
Blink Reformat1c4d759e2017-04-09 16:34:541892 compositor_->SetDeviceScaleFactor(device_scale_factor_);
oshimad5279032015-12-16 18:22:331893}
1894
[email protected]0bc1f572013-04-17 01:46:311895void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121896 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211897 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121898 return;
1899
[email protected]0bc1f572013-04-17 01:46:311900 // Even if the browser provides an empty damage rect, it's still expecting to
1901 // receive a repaint ack so just damage the entire widget bounds.
1902 if (size_to_paint.IsEmpty()) {
1903 size_to_paint = size_;
1904 }
1905
[email protected]ec7dc112008-08-06 05:30:121906 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051907 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311908 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121909}
1910
[email protected]4873c7d2009-07-16 06:36:281911void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
EhsanK955ba582017-11-30 21:14:401912 if (auto* frame = GetFocusedWebLocalFrameInWidget())
1913 frame->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111914}
1915
[email protected]80ad8622012-11-07 16:33:031916void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1917 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511918 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391919 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1920 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511921 } else {
mfomitchev2600fd7c2016-02-17 20:53:391922 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511923 }
[email protected]80ad8622012-11-07 16:33:031924 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1925}
1926
lfgdb5c4ed2016-03-04 23:09:071927void RenderWidget::OnUpdateWindowScreenRect(
1928 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211929 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071930 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211931 else
lfgdb5c4ed2016-03-04 23:09:071932 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071933}
1934
kenrbea731792017-01-13 15:10:481935void RenderWidget::OnSetViewportIntersection(
1936 const gfx::Rect& viewport_intersection) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251937 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:121938 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:251939 frame_widget->SetRemoteViewportIntersection(viewport_intersection);
kenrbea731792017-01-13 15:10:481940 }
1941}
1942
kenrb04323782017-06-23 01:23:321943void RenderWidget::OnSetIsInert(bool inert) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251944 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:121945 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:251946 frame_widget->SetIsInert(inert);
kenrb04323782017-06-23 01:23:321947 }
1948}
1949
Ken Buchanan8a319fb2017-11-15 18:37:121950void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled,
1951 bool subtree_throttled) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251952 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:121953 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:251954 frame_widget->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled);
Ken Buchanan8a319fb2017-11-15 18:37:121955 }
1956}
1957
paulmeyer90f6c31d2016-11-12 00:17:591958void RenderWidget::OnDragTargetDragEnter(
1959 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:521960 const gfx::PointF& client_point,
1961 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:591962 WebDragOperationsMask ops,
1963 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251964 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1965 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:591966 return;
1967
Ehsan Karamadf3ca2a82018-01-20 01:05:251968 WebDragOperation operation = frame_widget->DragTargetDragEnter(
1969 DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point,
1970 ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591971
1972 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1973}
1974
Ella Ge80a52dce2017-11-15 18:01:521975void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point,
1976 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:591977 WebDragOperationsMask ops,
1978 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251979 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1980 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:591981 return;
1982
Ehsan Karamadf3ca2a82018-01-20 01:05:251983 WebDragOperation operation = frame_widget->DragTargetDragOver(
1984 ConvertWindowPointToViewport(client_point), screen_point, ops,
1985 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591986
1987 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1988}
1989
Ella Ge80a52dce2017-11-15 18:01:521990void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point,
1991 const gfx::PointF& screen_point) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251992 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1993 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:591994 return;
Ehsan Karamadf3ca2a82018-01-20 01:05:251995
1996 frame_widget
1997
Blink Reformat1c4d759e2017-04-09 16:34:541998 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:171999 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:592000}
2001
2002void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:522003 const gfx::PointF& client_point,
2004 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592005 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252006 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2007 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592008 return;
2009
Ehsan Karamadf3ca2a82018-01-20 01:05:252010 frame_widget->DragTargetDrop(DropDataToWebDragData(drop_data),
2011 ConvertWindowPointToViewport(client_point),
2012 screen_point, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592013}
2014
Ella Ge80a52dce2017-11-15 18:01:522015void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point,
2016 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:212017 WebDragOperation op) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252018 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2019 if (!frame_widget)
paulmeyer8fc8ea92016-11-15 05:12:212020 return;
2021
Ehsan Karamadf3ca2a82018-01-20 01:05:252022 frame_widget->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
2023 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:212024}
2025
2026void RenderWidget::OnDragSourceSystemDragEnded() {
2027 if (!GetWebWidget())
2028 return;
2029
Blink Reformat1c4d759e2017-04-09 16:34:542030 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:212031}
2032
Blink Reformat1c4d759e2017-04-09 16:34:542033void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:262034#if defined(OS_CHROMEOS)
2035 // On ChromeOS, virtual keyboard is triggered only when users leave the
2036 // mouse button or the finger and a text input element is focused at that
2037 // time. Focus event itself shouldn't trigger virtual keyboard.
2038 UpdateTextInputState();
2039#else
changwan75e3b2072017-01-16 02:55:002040 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:262041#endif
boliu7b2be2f2016-11-04 04:58:312042
2043// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
2044// virtual keyboard.
2045#if !defined(OS_ANDROID)
2046 FocusChangeComplete();
2047#endif
[email protected]0d1ebed12013-08-05 22:01:132048}
2049
fsamuel72464894f2015-12-15 06:59:312050ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:162051#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492052 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2053 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:092054#endif
ekaramad5aff1942017-01-06 01:26:352055 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:542056 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:312057 return ui::TEXT_INPUT_TYPE_NONE;
2058}
2059
nonafa291792016-08-10 02:36:182060void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
2061 if (!monitor_composition_info_ && !immediate_request)
2062 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:592063
nonafa291792016-08-10 02:36:182064 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
2065 gfx::Range range;
2066 std::vector<gfx::Rect> character_bounds;
2067
2068 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
2069 // Composition information is only available on editable node.
2070 range = gfx::Range::InvalidRange();
2071 } else {
2072 GetCompositionRange(&range);
2073 GetCompositionCharacterBounds(&character_bounds);
2074 }
2075
2076 if (!immediate_request &&
2077 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:312078 return;
nonafa291792016-08-10 02:36:182079 }
fsamuel72464894f2015-12-15 06:59:312080 composition_character_bounds_ = character_bounds;
2081 composition_range_ = range;
Dave Tapuska139a72f2017-09-06 21:57:032082 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:052083 if (mojom::WidgetInputHandlerHost* host =
2084 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
2085 host->ImeCompositionRangeChanged(composition_range_,
2086 composition_character_bounds_);
2087 }
Dave Tapuska139a72f2017-09-06 21:57:032088 } else {
2089 Send(new InputHostMsg_ImeCompositionRangeChanged(
2090 routing_id(), composition_range_, composition_character_bounds_));
2091 }
fsamuel72464894f2015-12-15 06:59:312092}
2093
Blink Reformat1c4d759e2017-04-09 16:34:542094void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:542095 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:462096 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:332097 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:542098 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:462099 gfx::Rect window_rect =
2100 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
2101 rect->x = window_rect.x();
2102 rect->y = window_rect.y();
2103 rect->width = window_rect.width();
2104 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:542105 }
2106}
2107
Blink Reformat1c4d759e2017-04-09 16:34:542108void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
oshimaa6985b62016-01-27 08:58:302109 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:182110 rect->x *= GetOriginalDeviceScaleFactor();
2111 rect->y *= GetOriginalDeviceScaleFactor();
2112 rect->width *= GetOriginalDeviceScaleFactor();
2113 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:302114 }
2115}
2116
changwan8c342742016-02-26 00:53:392117void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:262118#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392119 DCHECK(!ime_event_guard_);
2120 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:002121 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212122#endif
Dave Tapuska9db80842017-07-24 17:24:262123}
[email protected]105dffb42013-02-20 03:46:212124
ekaramadc9b70a72017-03-23 16:14:232125void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2126 bool monitor_updates) {
2127 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182128 if (!immediate_request)
2129 return;
2130 UpdateCompositionInfo(true /* immediate request */);
2131}
2132
[email protected]fcdc5642014-05-09 14:32:242133void RenderWidget::OnOrientationChange() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382134 if (auto* frame_widget = GetFrameWidget()) {
Alex Moshchuk0b409c42017-09-13 02:09:002135 // LocalRoot() might return null for provisional main frames. In this case,
2136 // the frame hasn't committed a navigation and is not swapped into the tree
2137 // yet, so it doesn't make sense to send orientation change events to it.
2138 //
2139 // TODO(https://crbug.com/578349): This check should be cleaned up
2140 // once provisional frames are gone.
Ehsan Karamad655d7b8a2018-01-12 18:38:382141 if (frame_widget->LocalRoot())
2142 frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302143 }
[email protected]fcdc5642014-05-09 14:32:242144}
2145
[email protected]bee16aab2009-08-26 15:55:032146void RenderWidget::SetHidden(bool hidden) {
2147 if (is_hidden_ == hidden)
2148 return;
2149
jdduke8fac9d102014-12-20 02:40:132150 // The status has changed. Tell the RenderThread about it and ensure
2151 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032152 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132153
Scott Violet1098538e2017-10-05 19:23:332154#if defined(USE_AURA)
Sadrul Habib Chowdhury1dbe3b42017-11-18 02:27:432155 if (IsRunningWithMus())
Scott Violet1098538e2017-10-05 19:23:332156 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden);
2157#endif
2158
tasakb95dbb50c2017-02-08 18:07:502159 if (is_hidden_) {
[email protected]b2db9272014-01-10 17:42:002160 RenderThreadImpl::current()->WidgetHidden();
Takashi SAKAMOTO870f6262017-08-22 04:08:272161 first_update_visual_state_after_hidden_ = true;
Lei Zhang9b359d32017-11-28 00:57:022162 } else {
[email protected]b2db9272014-01-10 17:42:002163 RenderThreadImpl::current()->WidgetRestored();
Lei Zhang9b359d32017-11-28 00:57:022164 }
alexclarke7fa93942015-10-21 15:37:112165
2166 if (render_widget_scheduling_state_)
2167 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:032168}
2169
[email protected]2b624c562011-10-27 22:58:262170void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212171 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262172 return;
2173
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122174 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542175 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262176 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542177 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262178 }
[email protected]2b624c562011-10-27 22:58:262179}
2180
[email protected]674741932009-02-04 23:44:462181bool RenderWidget::next_paint_is_resize_ack() const {
Fady Samuelcc3e3b4a2017-10-03 02:09:212182 return ViewHostMsg_ResizeOrRepaint_ACK_Flags::is_resize_ack(
2183 next_paint_flags_);
[email protected]674741932009-02-04 23:44:462184}
2185
[email protected]674741932009-02-04 23:44:462186void RenderWidget::set_next_paint_is_resize_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212187 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462188}
2189
[email protected]674741932009-02-04 23:44:462190void RenderWidget::set_next_paint_is_repaint_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212191 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462192}
2193
Saman Samif7731342018-01-24 22:18:442194void RenderWidget::reset_next_paint_is_resize_ack() {
2195 DCHECK(next_paint_is_resize_ack());
2196 next_paint_flags_ ^= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK;
2197}
2198
changwanf2a707b2015-10-30 08:22:162199void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2200 if (!ime_event_guard_)
2201 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292202}
2203
changwanf2a707b2015-10-30 08:22:162204void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
2205 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:002206 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:162207 return;
2208 }
2209 ime_event_guard_ = nullptr;
2210
[email protected]66fca5bc2013-05-23 06:58:292211 // While handling an ime event, text input state and selection bounds updates
2212 // are ignored. These must explicitly be updated once finished handling the
2213 // ime event.
2214 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472215#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002216 if (guard->show_virtual_keyboard())
2217 ShowVirtualKeyboard();
2218 else
2219 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472220#endif
[email protected]66fca5bc2013-05-23 06:58:292221}
2222
[email protected]7c8873e2013-02-05 08:03:012223void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162224#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492225 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092226 // TODO(kinaba) http://crbug.com/101101
2227 // Current Pepper IME API does not handle selection bounds. So we simply
2228 // use the caret position as an empty range for now. It will be updated
2229 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492230 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542231 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092232 *focus = caret;
2233 *anchor = caret;
2234 return;
2235 }
2236#endif
[email protected]7c8873e2013-02-05 08:03:012237 WebRect focus_webrect;
2238 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542239 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2240 ConvertViewportToWindow(&focus_webrect);
2241 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242242 *focus = focus_webrect;
2243 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322244}
2245
[email protected]e99ef6f2011-10-16 01:13:002246void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082247 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212248 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002249 return;
changwanf2a707b2015-10-30 08:22:162250 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292251 return;
[email protected]e99ef6f2011-10-16 01:13:002252
mohsenb0eeba72015-08-09 06:20:082253#if defined(USE_AURA)
2254 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2255 // Aura beucause composited selection updates are not working for webview tags
2256 // which regresses IME inside webview. Remove this when composited selection
2257 // updates are fixed for webviews. See, http://crbug.com/510568.
2258 bool send_ipc = true;
2259#else
jddukeacf809e2014-09-23 20:38:382260 // With composited selection updates, the selection bounds will be reported
2261 // directly by the compositor, in which case explicit IPC selection
2262 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082263 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542264 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082265#endif
2266 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382267 ViewHostMsg_SelectionBounds_Params params;
EhsanK955ba582017-11-30 21:14:402268 params.is_anchor_first = false;
jddukeacf809e2014-09-23 20:38:382269 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2270 if (selection_anchor_rect_ != params.anchor_rect ||
2271 selection_focus_rect_ != params.focus_rect) {
2272 selection_anchor_rect_ = params.anchor_rect;
2273 selection_focus_rect_ = params.focus_rect;
EhsanK955ba582017-11-30 21:14:402274 if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) {
2275 focused_frame->SelectionTextDirection(params.focus_dir,
2276 params.anchor_dir);
2277 params.is_anchor_first = focused_frame->IsSelectionAnchorFirst();
2278 }
jddukeacf809e2014-09-23 20:38:382279 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2280 }
[email protected]58b48a0d2012-06-13 07:01:352281 }
jddukeacf809e2014-09-23 20:38:382282
nonafa291792016-08-10 02:36:182283 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002284}
2285
lfgb00fcad2016-07-14 14:16:332286void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2287 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542288 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332289 if (size_.width() != new_size_in_window.width ||
2290 size_.height() != new_size_in_window.height) {
2291 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2292
2293 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542294 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2295 size_.height());
lfgb00fcad2016-07-14 14:16:332296 view_screen_rect_ = new_pos;
2297 window_screen_rect_ = new_pos;
2298 }
2299
Fady Samueld10aadd82017-11-03 18:23:572300 AutoResizeCompositor(viz::LocalSurfaceId());
lfgb00fcad2016-07-14 14:16:332301
Fady Samuel319e429c2017-10-02 18:31:552302 if (!resizing_mode_selector_->is_synchronous_mode()) {
Fady Samueld10aadd82017-11-03 18:23:572303 need_resize_ack_for_auto_resize_ = true;
Fady Samuel319e429c2017-10-02 18:31:552304 // If surface synchronization is off, then ResizeAcks go to the browser in
2305 // response to a DidReceiveCompositorFrame. With surface synchronization
2306 // on, that notification will not arrive here because the compositor is
2307 // deferring commits and thus submission of CompositorFrames.
2308 if (!size_.IsEmpty() && compositor_ &&
2309 compositor_->IsSurfaceSynchronizationEnabled()) {
Fady Samuelcc3e3b4a2017-10-03 02:09:212310 DidResizeOrRepaintAck();
Fady Samuel319e429c2017-10-02 18:31:552311 }
2312 }
lfgb00fcad2016-07-14 14:16:332313 }
2314}
2315
[email protected]58b48a0d2012-06-13 07:01:352316void RenderWidget::GetCompositionCharacterBounds(
2317 std::vector<gfx::Rect>* bounds) {
2318 DCHECK(bounds);
2319 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092320
brettw4b461082016-11-19 18:55:162321#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492322 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092323 return;
2324#endif
2325
lfg8ff33912016-09-13 20:59:212326 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:092327 return;
2328 blink::WebVector<blink::WebRect> bounds_from_blink;
Blink Reformat1c4d759e2017-04-09 16:34:542329 if (!GetWebWidget()->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092330 return;
2331
2332 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542333 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092334 bounds->push_back(bounds_from_blink[i]);
2335 }
[email protected]58b48a0d2012-06-13 07:01:352336}
2337
[email protected]db4fc1e2013-09-06 20:01:512338void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162339#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492340 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092341 return;
2342#endif
EhsanKcdee7b72017-11-08 21:30:092343 blink::WebInputMethodController* controller = GetInputMethodController();
2344 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542345 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212346 *range = gfx::Range::InvalidRange();
2347 return;
[email protected]88dbe32f2013-06-20 23:31:362348 }
Blink Reformat1c4d759e2017-04-09 16:34:542349 range->set_start(web_range.StartOffset());
2350 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362351}
2352
[email protected]501ea13d2013-07-09 17:03:292353bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512354 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292355 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082356 if (!range.IsValid())
2357 return false;
[email protected]501ea13d2013-07-09 17:03:292358 if (composition_range_ != range)
2359 return true;
2360 if (bounds.size() != composition_character_bounds_.size())
2361 return true;
2362 for (size_t i = 0; i < bounds.size(); ++i) {
2363 if (bounds[i] != composition_character_bounds_[i])
2364 return true;
2365 }
2366 return false;
2367}
[email protected]501ea13d2013-07-09 17:03:292368
[email protected]ad26ef42011-06-17 07:59:452369bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162370#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492371 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2372 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092373#endif
[email protected]ad26ef42011-06-17 07:59:452374 return true;
[email protected]56ea1a62011-05-30 07:05:572375}
2376
Blink Reformat1c4d759e2017-04-09 16:34:542377blink::WebScreenInfo RenderWidget::GetScreenInfo() {
ccameron2f451532016-09-07 21:49:272378 blink::WebScreenInfo web_screen_info;
Blink Reformat1c4d759e2017-04-09 16:34:542379 web_screen_info.device_scale_factor = screen_info_.device_scale_factor;
ccameronab0aab82017-06-24 17:21:542380 web_screen_info.color_space = screen_info_.color_space;
ccameron2f451532016-09-07 21:49:272381 web_screen_info.depth = screen_info_.depth;
Blink Reformat1c4d759e2017-04-09 16:34:542382 web_screen_info.depth_per_component = screen_info_.depth_per_component;
2383 web_screen_info.is_monochrome = screen_info_.is_monochrome;
ccameron2f451532016-09-07 21:49:272384 web_screen_info.rect = blink::WebRect(screen_info_.rect);
Blink Reformat1c4d759e2017-04-09 16:34:542385 web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect);
ccameron2f451532016-09-07 21:49:272386 switch (screen_info_.orientation_type) {
2387 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542388 web_screen_info.orientation_type =
2389 blink::kWebScreenOrientationPortraitPrimary;
ccameron2f451532016-09-07 21:49:272390 break;
2391 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542392 web_screen_info.orientation_type =
2393 blink::kWebScreenOrientationPortraitSecondary;
ccameron2f451532016-09-07 21:49:272394 break;
2395 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542396 web_screen_info.orientation_type =
2397 blink::kWebScreenOrientationLandscapePrimary;
ccameron2f451532016-09-07 21:49:272398 break;
2399 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542400 web_screen_info.orientation_type =
2401 blink::kWebScreenOrientationLandscapeSecondary;
ccameron2f451532016-09-07 21:49:272402 break;
2403 default:
Blink Reformat1c4d759e2017-04-09 16:34:542404 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
ccameron2f451532016-09-07 21:49:272405 break;
2406 }
Blink Reformat1c4d759e2017-04-09 16:34:542407 web_screen_info.orientation_angle = screen_info_.orientation_angle;
Fady Samuel85a1bf72017-10-27 14:30:202408
ccameron2f451532016-09-07 21:49:272409 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282410}
2411
donnda070f3c2015-01-16 19:54:112412#if defined(OS_ANDROID)
Donn Denman43a439e2017-08-29 04:20:452413void RenderWidget::ShowUnhandledTapUIIfNeeded(
2414 const WebTappedInfo& tapped_info) {
2415 // Unpack tapped_info. TODO(donnd): inline unpacking.
2416 bool page_changed = tapped_info.PageChanged();
2417 const WebNode& tapped_node = tapped_info.GetNode();
2418 const WebPoint& tapped_position = tapped_info.Position();
Blink Reformat1c4d759e2017-04-09 16:34:542419 bool should_trigger = !page_changed && tapped_node.IsTextNode() &&
2420 !tapped_node.IsContentEditable() &&
2421 !tapped_node.IsInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112422 if (should_trigger) {
Jaebaek Seo53ab80a662018-01-29 04:50:462423 float x_px = IsUseZoomForDSFEnabled()
Jaebaek Seo655110e2017-12-19 23:27:392424 ? tapped_position.x
2425 : tapped_position.x * device_scale_factor_;
Jaebaek Seo53ab80a662018-01-29 04:50:462426 float y_px = IsUseZoomForDSFEnabled()
Jaebaek Seo655110e2017-12-19 23:27:392427 ? tapped_position.y
2428 : tapped_position.y * device_scale_factor_;
2429 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_, x_px, y_px));
donnda070f3c2015-01-16 19:54:112430 }
2431}
2432#endif
2433
Blink Reformat1c4d759e2017-04-09 16:34:542434void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2435 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022436#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562437 if (event_cancelled)
2438 return;
Blink Reformat1c4d759e2017-04-09 16:34:542439 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002440 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542441 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212442 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352443 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542444 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002445 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462446 else
changwan75e3b2072017-01-16 02:55:002447 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562448 }
ekaramada110f642016-12-21 19:47:282449// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2450// crbug/420130.
2451#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:542452 if (event.GetType() != blink::WebGestureEvent::kGestureTap)
ekaramada110f642016-12-21 19:47:282453 return;
2454
2455 // TODO(estade): hit test the event against focused node to make sure
2456 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352457 blink::WebInputMethodController* controller = GetInputMethodController();
2458 blink::WebTextInputType text_input_type =
Blink Reformat1c4d759e2017-04-09 16:34:542459 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282460
2461 Send(new ViewHostMsg_FocusedNodeTouched(
Blink Reformat1c4d759e2017-04-09 16:34:542462 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
ekaramada110f642016-12-21 19:47:282463#endif
[email protected]c68c3e4e2013-01-24 00:36:562464#endif
2465}
2466
Blink Reformat1c4d759e2017-04-09 16:34:542467void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312468 const blink::WebFloatSize& overscrollDelta,
2469 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422470 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:542471 const blink::WebFloatSize& velocity,
Sandra Sun2288e8532017-11-30 22:50:162472 const blink::WebOverscrollBehavior& behavior) {
bokan731ec382016-04-07 03:16:482473#if defined(OS_MACOSX)
2474 // On OSX the user can disable the elastic overscroll effect. If that's the
2475 // case, don't forward the overscroll notification.
2476 DCHECK(compositor_deps());
2477 if (!compositor_deps()->IsElasticOverscrollEnabled())
2478 return;
2479#endif
bokane53a10f2016-04-13 23:48:312480 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:542481 position, velocity, behavior);
sataya.m582c9ce2015-06-09 08:03:422482}
2483
[email protected]7912e822014-04-16 02:37:032484void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392485 if (!is_hidden())
Blink Reformat1c4d759e2017-04-09 16:34:542486 compositor_->SetVisible(true);
[email protected]7912e822014-04-16 02:37:032487}
2488
[email protected]24ed0432013-04-24 07:50:312489RenderWidgetCompositor* RenderWidget::compositor() const {
2490 return compositor_.get();
2491}
2492
fsamuel72464894f2015-12-15 06:59:312493void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392494 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372495}
[email protected]c3d45532011-10-07 19:20:402496
Blink Reformat1c4d759e2017-04-09 16:34:542497void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112498 if (render_widget_scheduling_state_)
2499 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552500 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2501}
2502
Dave Tapuskadfe486c12017-06-09 16:53:132503void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
2504 if (input_event_queue_)
2505 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
2506}
2507
Dave Tapuskabafc2ba32017-11-28 01:54:372508void RenderWidget::RequestUnbufferedInputEvents() {
2509 if (input_event_queue_)
2510 input_event_queue_->RequestUnbufferedInputEvents();
2511}
2512
xidachenfa0199e72017-05-11 11:34:262513void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:262514 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:512515 return;
2516
Dave Tapuska139a72f2017-09-06 21:57:032517 if (widget_input_handler_manager_) {
2518 widget_input_handler_manager_->ProcessTouchAction(touch_action);
2519 } else {
2520 Send(new InputHostMsg_SetTouchAction(routing_id_, touch_action));
2521 }
[email protected]5d0bbdfa92013-12-10 00:35:512522}
2523
[email protected]e3244ed2014-06-20 20:04:272524void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2525 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162526}
2527
[email protected]e3244ed2014-06-20 20:04:272528void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2529 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162530}
2531
[email protected]de3c5d82014-05-28 22:12:592532void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2533 render_frames_.AddObserver(frame);
2534}
2535
2536void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2537 render_frames_.RemoveObserver(frame);
2538}
2539
Saman Samid189e5dfd2017-12-20 22:55:312540void RenderWidget::RegisterBrowserPlugin(BrowserPlugin* browser_plugin) {
2541 browser_plugins_.AddObserver(browser_plugin);
2542}
2543
2544void RenderWidget::UnregisterBrowserPlugin(BrowserPlugin* browser_plugin) {
2545 browser_plugins_.RemoveObserver(browser_plugin);
2546}
2547
lfg43e08e62016-02-03 18:51:372548void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2549 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2550 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2551}
2552
oshima50872a72016-03-04 13:26:182553float RenderWidget::GetOriginalDeviceScaleFactor() const {
2554 return
2555 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272556 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182557 device_scale_factor_;
2558}
2559
Ella Ge80a52dce2017-11-15 18:01:522560gfx::PointF RenderWidget::ConvertWindowPointToViewport(
2561 const gfx::PointF& point) {
paulmeyer90f6c31d2016-11-12 00:17:592562 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542563 ConvertWindowToViewport(&point_in_viewport);
Ella Ge80a52dce2017-11-15 18:01:522564 return gfx::PointF(point_in_viewport.x, point_in_viewport.y);
2565}
2566
2567gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) {
2568 return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point)));
paulmeyer90f6c31d2016-11-12 00:17:592569}
2570
Blink Reformat1c4d759e2017-04-09 16:34:542571bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:212572 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2573}
2574
Blink Reformat1c4d759e2017-04-09 16:34:542575void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:212576 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2577}
2578
Blink Reformat1c4d759e2017-04-09 16:34:542579bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:212580 return mouse_lock_dispatcher_->IsMouseLockedTo(
2581 webwidget_mouse_lock_target_.get());
2582}
2583
Blink Reformat1c4d759e2017-04-09 16:34:542584void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:582585 const WebDragData& data,
2586 WebDragOperationsMask mask,
2587 const WebImage& image,
2588 const WebPoint& webImageOffset) {
2589 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542590 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:582591 DropData drop_data(DropDataBuilder::Build(data));
2592 drop_data.referrer_policy = policy;
2593 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592594 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
Blink Reformat1c4d759e2017-04-09 16:34:542595 image.GetSkBitmap(), imageOffset,
paulmeyer6ef5a792016-11-08 20:33:582596 possible_drag_event_info_));
2597}
2598
kenrb5d78b842017-03-06 21:06:012599uint32_t RenderWidget::GetContentSourceId() {
2600 return current_content_source_id_;
2601}
2602
Saman Samif7731342018-01-24 22:18:442603void RenderWidget::DidNavigate() {
2604 if (!compositor_)
2605 return;
2606 compositor_->SetContentSourceId(++current_content_source_id_);
2607 local_surface_id_ = viz::LocalSurfaceId();
2608 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
2609 // If surface synchronization is on, navigation implicitly acks any resize
2610 // that has happened so far so we can get the next ResizeParams containing the
2611 // LocalSurfaceId that should be used after navigation.
2612 if (compositor_->IsSurfaceSynchronizationEnabled() && !auto_resize_mode_ &&
2613 next_paint_is_resize_ack()) {
2614 reset_next_paint_is_resize_ack();
2615 }
kenrb5d78b842017-03-06 21:06:012616}
2617
lfg8ff33912016-09-13 20:59:212618blink::WebWidget* RenderWidget::GetWebWidget() const {
2619 return webwidget_internal_;
2620}
2621
ekaramad2daaf672016-11-10 20:29:012622blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2623 const {
Ehsan Karamad655d7b8a2018-01-12 18:38:382624 if (auto* frame_widget = GetFrameWidget())
2625 return frame_widget->GetActiveWebInputMethodController();
2626
2627 return nullptr;
ekaramad2daaf672016-11-10 20:29:012628}
2629
Dave Tapuska139a72f2017-09-06 21:57:032630void RenderWidget::SetupWidgetInputHandler(
2631 mojom::WidgetInputHandlerRequest request,
2632 mojom::WidgetInputHandlerHostPtr host) {
Dave Tapuskab66c28f2017-11-15 17:18:472633 widget_input_handler_manager_->AddInterface(std::move(request),
2634 std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:502635}
2636
Dave Tapuska485aca92017-08-08 00:47:582637void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
2638 // Close the old binding if there was one.
2639 // A RenderWidgetHost should not need more than one channel.
2640 widget_binding_.Close();
2641 widget_binding_.Bind(std::move(request));
2642}
2643
Fady Samuelcc3e3b4a2017-10-03 02:09:212644void RenderWidget::DidResizeOrRepaintAck() {
Fady Samueld10aadd82017-11-03 18:23:572645 if (!next_paint_flags_ && !need_resize_ack_for_auto_resize_)
Fady Samuel319e429c2017-10-02 18:31:552646 return;
2647
Fady Samuelcc3e3b4a2017-10-03 02:09:212648 ViewHostMsg_ResizeOrRepaint_ACK_Params params;
Fady Samuel319e429c2017-10-02 18:31:552649 params.view_size = size_;
2650 params.flags = next_paint_flags_;
2651 params.sequence_number = ++resize_or_repaint_ack_num_;
2652
Fady Samuelcc3e3b4a2017-10-03 02:09:212653 Send(new ViewHostMsg_ResizeOrRepaint_ACK(routing_id_, params));
Fady Samuel319e429c2017-10-02 18:31:552654 next_paint_flags_ = 0;
Fady Samueld10aadd82017-11-03 18:23:572655 need_resize_ack_for_auto_resize_ = false;
Fady Samuel319e429c2017-10-02 18:31:552656}
2657
Khushal3e96e662017-10-30 23:16:502658void RenderWidget::UpdateURLForCompositorUkm() {
2659 DCHECK(compositor_);
Ehsan Karamad655d7b8a2018-01-12 18:38:382660 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2661 if (!frame_widget)
Khushal3e96e662017-10-30 23:16:502662 return;
2663
Ehsan Karamad655d7b8a2018-01-12 18:38:382664 auto* render_frame = RenderFrameImpl::FromWebFrame(frame_widget->LocalRoot());
Khushal3e96e662017-10-30 23:16:502665 if (!render_frame->IsMainFrame())
2666 return;
2667
2668 compositor_->SetURLForUkm(render_frame->GetWebFrame()->GetDocument().Url());
2669}
2670
EhsanK955ba582017-11-30 21:14:402671blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const {
Ehsan Karamad655d7b8a2018-01-12 18:38:382672 if (auto* frame_widget = GetFrameWidget())
2673 return frame_widget->FocusedWebLocalFrameInWidget();
2674 return nullptr;
EhsanK955ba582017-11-30 21:14:402675}
2676
EhsanK22d482e2017-08-10 17:29:492677#if BUILDFLAG(ENABLE_PLUGINS)
2678PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382679 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2680 if (!frame_widget)
EhsanK22d482e2017-08-10 17:29:492681 return nullptr;
2682
2683 // Focused pepper instance might not always be in the focused frame. For
2684 // instance if a pepper instance and its embedder frame are focused an then
2685 // another frame takes focus using javascript, the embedder frame will no
2686 // longer be focused while the pepper instance is (the embedder frame's
2687 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
2688 // is fullscreen, clicking into the pepper will not refocus the embedder
2689 // frame. This is why we have to traverse the whole frame tree to find the
2690 // focused plugin.
Ehsan Karamad655d7b8a2018-01-12 18:38:382691 blink::WebFrame* current_frame = frame_widget->LocalRoot();
EhsanK22d482e2017-08-10 17:29:492692 while (current_frame) {
2693 RenderFrameImpl* render_frame =
2694 current_frame->IsWebLocalFrame()
2695 ? RenderFrameImpl::FromWebFrame(current_frame)
2696 : nullptr;
2697 if (render_frame && render_frame->focused_pepper_plugin())
2698 return render_frame->focused_pepper_plugin();
2699 current_frame = current_frame->TraverseNext();
2700 }
2701 return nullptr;
2702}
2703#endif
2704
[email protected]e9ff79c2012-10-19 21:31:262705} // namespace content