blob: 6a5a08d23a48e91e13ddc075a98682fed0494011 [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"
oshima750cb4342015-10-31 00:59:0132#include "content/common/content_switches_internal.h"
paulmeyer6ef5a792016-11-08 20:33:5833#include "content/common/drag_event_source_info.h"
34#include "content/common/drag_messages.h"
[email protected]c084330e02013-04-27 01:08:1535#include "content/common/input_messages.h"
jcivelliae1560a2016-11-01 22:40:2336#include "content/common/render_message_filter.mojom.h"
Nasko Oskovf97e8b02017-07-25 02:45:4237#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3838#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5039#include "content/common/view_messages.h"
mlamouriafca06dd2017-01-27 23:35:1840#include "content/public/common/content_client.h"
changwan7ded3752016-03-09 23:25:1241#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2942#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4243#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5944#include "content/public/common/drop_data.h"
Khushal3e96e662017-10-30 23:16:5045#include "content/public/common/service_names.mojom.h"
Jaebaek Seo655110e2017-12-19 23:27:3946#include "content/public/common/use_zoom_for_dsf_policy.h"
mlamouriafca06dd2017-01-27 23:35:1847#include "content/public/renderer/content_renderer_client.h"
Fady Samuel85a1bf72017-10-27 14:30:2048#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]953bd0062013-08-01 00:58:4049#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3950#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5851#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5152#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1153#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1154#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2855#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2956#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1357#include "content/renderer/input/input_handler_manager.h"
dtapuska9ec1a912017-04-21 15:18:3158#include "content/renderer/input/main_thread_event_queue.h"
Dave Tapuska9db80842017-07-24 17:24:2659#include "content/renderer/input/widget_input_handler_manager.h"
Scott Violet1098538e2017-10-05 19:23:3360#include "content/renderer/mash_util.h"
[email protected]adab2332013-07-25 18:04:3261#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1662#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2763#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0564#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4465#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5566#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4467#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0968#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0469#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4770#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1871#include "ipc/ipc_sync_message.h"
Antoine Laboure55c9ef82017-11-10 18:51:2372#include "ipc/ipc_sync_message_filter.h"
brettw4b461082016-11-19 18:55:1673#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4874#include "skia/ext/platform_canvas.h"
kinukoa4293022017-01-27 06:43:2575#include "third_party/WebKit/public/platform/FilePathConversion.h"
[email protected]ec173b522013-11-14 11:01:1876#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5977#include "third_party/WebKit/public/platform/WebDragData.h"
78#include "third_party/WebKit/public/platform/WebDragOperation.h"
dtapuskaa794bd0812017-01-06 15:22:5579#include "third_party/WebKit/public/platform/WebMouseEvent.h"
donnda070f3c2015-01-16 19:54:1180#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3081#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:3082#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]aaf68892013-07-18 00:11:3083#include "third_party/WebKit/public/platform/WebSize.h"
84#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5185#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
86#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
ekaramad27ca69b12017-04-20 18:34:2987#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]19193682014-04-03 15:01:4388#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5989#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0190#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5991#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1192#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3193#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3194#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
95#include "third_party/WebKit/public/web/WebRange.h"
Donn Denman43a439e2017-08-29 04:20:4596#include "third_party/WebKit/public/web/WebTappedInfo.h"
kenrba7199832015-01-22 23:44:5997#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0898#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4199#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:59100#include "ui/base/clipboard/clipboard.h"
[email protected]faec7b12012-06-19 14:42:13101#include "ui/base/ui_base_switches.h"
dtapuska97286c882017-02-24 23:14:43102#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:50103#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:09104#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32105#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48106#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:27107#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:41108#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48109
[email protected]eeb93112013-05-01 19:41:10110#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15111#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24112#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10113#endif
114
[email protected]661eb9d2009-02-03 02:11:48115#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52116#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41117#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48118#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44119
sadrul943e3b32016-08-04 18:22:59120#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10121#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19122#endif
123
ekaramad330ba4232016-09-23 17:57:47124#if defined(OS_MACOSX)
125#include "content/renderer/text_input_client_observer.h"
126#endif
127
Ryan Landay9e42fd742017-08-12 01:59:11128using blink::WebImeTextSpan;
[email protected]180ef242013-11-07 06:50:46129using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43130using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59131using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58132using blink::WebDragOperationsMask;
133using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59134using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46135using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58136using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46137using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49138using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01139using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58140using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46141using blink::WebMouseEvent;
142using blink::WebMouseWheelEvent;
143using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11144using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46145using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11146using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46147using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48148using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46149using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46150using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59151using blink::WebString;
Donn Denman43a439e2017-08-29 04:20:45152using blink::WebTappedInfo;
[email protected]180ef242013-11-07 06:50:46153using blink::WebTextDirection;
154using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25155using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46156using blink::WebVector;
157using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26158
paulmeyer90f6c31d2016-11-12 00:17:59159namespace content {
160
[email protected]6a4d7f62013-01-07 21:32:13161namespace {
[email protected]b256eca2013-07-11 10:57:40162
163typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
164
AJITH KUMAR V041c0b02017-08-08 10:39:20165static const int kInvalidNextPreviousFlagsValue = -1;
166
lfgbee1e0a2016-06-08 21:24:21167class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
168 public:
169 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
170 : webwidget_(webwidget) {}
171
172 void OnLockMouseACK(bool succeeded) override {
173 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54174 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21175 else
Blink Reformat1c4d759e2017-04-09 16:34:54176 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21177 }
178
Blink Reformat1c4d759e2017-04-09 16:34:54179 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21180
181 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
182 // The WebWidget handles mouse lock in Blink's handleInputEvent().
183 return false;
184 }
185
186 private:
187 blink::WebWidget* webwidget_;
188};
189
dglazkov97b6c2b2016-10-25 17:35:55190bool IsDateTimeInput(ui::TextInputType type) {
191 return type == ui::TEXT_INPUT_TYPE_DATE ||
192 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
193 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
194 type == ui::TEXT_INPUT_TYPE_MONTH ||
195 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
196}
197
paulmeyer90f6c31d2016-11-12 00:17:59198WebDragData DropMetaDataToWebDragData(
199 const std::vector<DropData::Metadata>& drop_meta_data) {
200 std::vector<WebDragData::Item> item_list;
201 for (const auto& meta_data_item : drop_meta_data) {
202 if (meta_data_item.kind == DropData::Kind::STRING) {
203 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54204 item.storage_type = WebDragData::Item::kStorageTypeString;
205 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59206 // Have to pass a dummy URL here instead of an empty URL because the
207 // DropData received by browser_plugins goes through a round trip:
208 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
209 // will contain an empty URL (which means no URL is dragged) if the URL in
210 // WebDragData is empty.
211 if (base::EqualsASCII(meta_data_item.mime_type,
212 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54213 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59214 }
215 item_list.push_back(item);
216 continue;
217 }
218
219 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
220 // just the mimetype. This is needed to drag files to WebView on Android
221 // platform.
222 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
223 !meta_data_item.filename.empty()) {
224 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54225 item.storage_type = WebDragData::Item::kStorageTypeFilename;
226 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59227 item_list.push_back(item);
228 continue;
229 }
230
231 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
232 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54233 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
234 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59235 item_list.push_back(item);
236 continue;
237 }
238 }
239
240 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54241 result.Initialize();
242 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59243 return result;
244}
245
246WebDragData DropDataToWebDragData(const DropData& drop_data) {
247 std::vector<WebDragData::Item> item_list;
248
249 // These fields are currently unused when dragging into WebKit.
250 DCHECK(drop_data.download_metadata.empty());
251 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23252 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59253
254 if (!drop_data.text.is_null()) {
255 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54256 item.storage_type = WebDragData::Item::kStorageTypeString;
257 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
258 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59259 item_list.push_back(item);
260 }
261
262 if (!drop_data.url.is_empty()) {
263 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54264 item.storage_type = WebDragData::Item::kStorageTypeString;
265 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
266 item.string_data = WebString::FromUTF8(drop_data.url.spec());
267 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59268 item_list.push_back(item);
269 }
270
271 if (!drop_data.html.is_null()) {
272 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54273 item.storage_type = WebDragData::Item::kStorageTypeString;
274 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
275 item.string_data = WebString::FromUTF16(drop_data.html.string());
276 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59277 item_list.push_back(item);
278 }
279
280 for (std::vector<ui::FileInfo>::const_iterator it =
281 drop_data.filenames.begin();
282 it != drop_data.filenames.end();
283 ++it) {
284 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54285 item.storage_type = WebDragData::Item::kStorageTypeFilename;
286 item.filename_data = blink::FilePathToWebString(it->path);
287 item.display_name_data =
kinukoa4293022017-01-27 06:43:25288 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59289 item_list.push_back(item);
290 }
291
292 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
293 drop_data.file_system_files.begin();
294 it != drop_data.file_system_files.end();
295 ++it) {
296 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54297 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
298 item.file_system_url = it->url;
299 item.file_system_file_size = it->size;
300 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59301 item_list.push_back(item);
302 }
303
Stuart Langley48300392017-11-02 03:54:44304 for (const auto& it : drop_data.custom_data) {
paulmeyer90f6c31d2016-11-12 00:17:59305 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54306 item.storage_type = WebDragData::Item::kStorageTypeString;
Stuart Langley48300392017-11-02 03:54:44307 item.string_type = WebString::FromUTF16(it.first);
308 item.string_data = WebString::FromUTF16(it.second);
paulmeyer90f6c31d2016-11-12 00:17:59309 item_list.push_back(item);
310 }
311
312 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54313 result.Initialize();
314 result.SetItems(item_list);
315 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59316 return result;
317}
318
lfg1568d112016-08-30 16:06:29319content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
320 nullptr;
321
322content::RenderWidget::RenderWidgetInitializedCallback
323 g_render_widget_initialized = nullptr;
324
dtapuskac4dd5be2016-10-25 15:11:10325ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
326 // Check the type is in the range representable by ui::TextInputType.
327 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
328 << "blink::WebTextInputType and ui::TextInputType not synchronized";
329 return static_cast<ui::TextInputType>(type);
330}
331
332ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
333 // Check the mode is in the range representable by ui::TextInputMode.
334 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
335 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
336 return static_cast<ui::TextInputMode>(mode);
337}
338
[email protected]b256eca2013-07-11 10:57:40339} // namespace
340
[email protected]b2e4c70132013-10-03 02:07:51341// RenderWidget ---------------------------------------------------------------
342
Hajime Hoshiabb3c8f2017-12-04 18:41:39343RenderWidget::RenderWidget(
344 int32_t widget_routing_id,
345 CompositorDependencies* compositor_deps,
346 blink::WebPopupType popup_type,
347 const ScreenInfo& screen_info,
348 bool swapped_out,
349 bool hidden,
350 bool never_visible,
351 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
352 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45353 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36354 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21355 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44356 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29357 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51358 auto_resize_mode_(false),
Fady Samueld10aadd82017-11-03 18:23:57359 need_resize_ack_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29360 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04361 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39362 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12363 is_fullscreen_granted_(false),
Blink Reformat1c4d759e2017-04-09 16:34:54364 display_mode_(blink::kWebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16365 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48366 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22367 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44368 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20369 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55370 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40371 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20372 text_input_flags_(0),
AJITH KUMAR V041c0b02017-08-08 10:39:20373 next_previous_flags_(kInvalidNextPreviousFlagsValue),
[email protected]86ba5fcb2013-09-04 00:36:53374 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18375 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12376 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48377 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04378 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27379 device_scale_factor_(screen_info_.device_scale_factor),
nonafa291792016-08-10 02:36:18380 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51381 popup_origin_scale_for_emulation_(0.f),
samans26510e442017-06-01 22:29:12382 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
[email protected]a09d53ce2014-01-31 00:46:42383 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08384 has_host_context_menu_location_(false),
wjmaclean1d970622017-01-21 22:28:24385 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09386 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47387#if defined(OS_MACOSX)
388 text_input_client_observer_(new TextInputClientObserver(this)),
389#endif
Takashi SAKAMOTO870f6262017-08-22 04:08:27390 first_update_visual_state_after_hidden_(false),
tasakb95dbb50c2017-02-08 18:07:50391 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01392 current_content_source_id_(0),
Dave Tapuska1bdf1832017-07-07 18:07:19393 widget_binding_(this, std::move(widget_request)),
Hajime Hoshiabb3c8f2017-12-04 18:41:39394 task_runner_(task_runner),
wjmaclean1d970622017-01-21 22:28:24395 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45396 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05397 if (!swapped_out)
398 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27399 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11400
401 // In tests there may not be a RenderThreadImpl.
402 if (RenderThreadImpl::current()) {
403 render_widget_scheduling_state_ = RenderThreadImpl::current()
404 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32405 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11406 render_widget_scheduling_state_->SetHidden(is_hidden_);
407 }
sadrul602ce1362017-01-26 06:41:10408#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14409 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
Sadrul Habib Chowdhury1dbe3b42017-11-18 02:27:43410 if (IsRunningWithMus())
Scott Violet1098538e2017-10-05 19:23:33411 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_);
sadrul602ce1362017-01-26 06:41:10412#endif
initial.commit09911bf2008-07-26 23:55:29413}
414
415RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21416 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16417
dtapuska9ec1a912017-04-21 15:18:31418 if (input_event_queue_)
419 input_event_queue_->ClearClient();
420
[email protected]992db4c2011-05-12 15:37:15421 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02422 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15423 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11424#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14425 // It is possible for a RenderWidget to be destroyed before it was embedded
426 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
427 // explicitly delete it here.
428 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11429#endif
initial.commit09911bf2008-07-26 23:55:29430}
431
[email protected]484955942010-08-19 16:13:18432// static
lfg1568d112016-08-30 16:06:29433void RenderWidget::InstallCreateHook(
434 CreateRenderWidgetFunction create_render_widget,
435 RenderWidgetInitializedCallback render_widget_initialized) {
436 CHECK(!g_create_render_widget && !g_render_widget_initialized);
437 g_create_render_widget = create_render_widget;
438 g_render_widget_initialized = render_widget_initialized;
439}
440
441// static
nickf7b38222016-11-22 21:59:35442RenderWidget* RenderWidget::CreateForPopup(
443 RenderViewImpl* opener,
444 CompositorDependencies* compositor_deps,
445 blink::WebPopupType popup_type,
Hajime Hoshiabb3c8f2017-12-04 18:41:39446 const ScreenInfo& screen_info,
447 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Dave Tapuska1bdf1832017-07-07 18:07:19448 mojom::WidgetPtr widget_channel;
449 mojom::WidgetRequest widget_channel_request =
450 mojo::MakeRequest(&widget_channel);
451
nick4df698d82016-11-11 20:39:23452 // Do a synchronous IPC to obtain a routing ID.
453 int32_t routing_id = MSG_ROUTING_NONE;
454 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
Dave Tapuska1bdf1832017-07-07 18:07:19455 opener->GetRoutingID(), popup_type, std::move(widget_channel),
456 &routing_id)) {
nick4df698d82016-11-11 20:39:23457 return nullptr;
458 }
459
Hajime Hoshiabb3c8f2017-12-04 18:41:39460 scoped_refptr<RenderWidget> widget(new RenderWidget(
461 routing_id, compositor_deps, popup_type, screen_info, false, false, false,
462 task_runner, std::move(widget_channel_request)));
nickf7b38222016-11-22 21:59:35463 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24464 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
nickf7b38222016-11-22 21:59:35465 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23466 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
467 return widget.get();
initial.commit09911bf2008-07-26 23:55:29468}
469
[email protected]484955942010-08-19 16:13:18470// static
kenrba7199832015-01-22 23:44:59471RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23472 int widget_routing_id,
kenrba7199832015-01-22 23:44:59473 bool hidden,
ccameron2f451532016-09-07 21:49:27474 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59475 CompositorDependencies* compositor_deps,
476 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23477 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55478 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
479 // same routing ID for both the view routing ID and the main frame widget
480 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23481 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55482 if (view) {
avi8a45c1092016-03-01 16:12:34483 view->AttachWebFrameWidget(
484 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
485 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55486 }
Hajime Hoshiabb3c8f2017-12-04 18:41:39487 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
488 frame->GetTaskRunner(blink::TaskType::kUnthrottled);
dcheng35d31c112015-07-22 00:17:36489 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29490 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45491 ? g_create_render_widget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54492 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45493 hidden, false)
494 : new RenderWidget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54495 blink::kWebPopupTypeNone, screen_info, false,
Hajime Hoshiabb3c8f2017-12-04 18:41:39496 hidden, false, task_runner));
simonhong628f9812015-04-27 23:13:20497 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23498 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59499 // this function returns.
nickf7b38222016-11-22 21:59:35500 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23501 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
502
503 if (g_render_widget_initialized)
504 g_render_widget_initialized(widget.get());
505 return widget.get();
kenrba7199832015-01-22 23:44:59506}
507
508// static
lfgcaab5142016-02-26 19:06:52509blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08510 RenderWidget* render_widget,
511 blink::WebLocalFrame* frame) {
Blink Reformat1c4d759e2017-04-09 16:34:54512 return blink::WebFrameWidget::Create(render_widget, frame);
dchengda9b4bb2015-07-20 20:58:08513}
514
515// static
kenrba7199832015-01-22 23:44:59516blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18517 switch (render_widget->popup_type_) {
Blink Reformat1c4d759e2017-04-09 16:34:54518 case blink::kWebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18519 break;
Blink Reformat1c4d759e2017-04-09 16:34:54520 case blink::kWebPopupTypePage:
521 return WebPagePopup::Create(render_widget);
[email protected]484955942010-08-19 16:13:18522 default:
523 NOTREACHED();
524 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28525 return nullptr;
[email protected]484955942010-08-19 16:13:18526}
527
dchengda9b4bb2015-07-20 20:58:08528void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32529 OnClose();
kenrba7199832015-01-22 23:44:59530}
531
alexmos78c9c0d2016-10-14 18:57:03532void RenderWidget::SetSwappedOut(bool is_swapped_out) {
533 // We should only toggle between states.
534 DCHECK(is_swapped_out_ != is_swapped_out);
535 is_swapped_out_ = is_swapped_out;
536
537 // If we are swapping out, we will call ReleaseProcess, allowing the process
538 // to exit if all of its RenderViews are swapped out. We wait until the
539 // WasSwappedOut call to do this, to allow the unload handler to finish.
540 // If we are swapping in, we call AddRefProcess to prevent the process from
541 // exiting.
542 if (!is_swapped_out_)
543 RenderProcess::current()->AddRefProcess();
544}
545
nickf7b38222016-11-22 21:59:35546void RenderWidget::Init(const ShowCallback& show_callback,
547 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21548 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23549 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29550
Jeremy Roman04f27c372017-10-27 15:20:55551 input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45552
Dave Tapuska9db80842017-07-24 17:24:26553 if (base::FeatureList::IsEnabled(features::kMojoInputMessages)) {
554 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
555
Dave Tapuska525eb15e2017-08-17 21:05:50556 widget_input_handler_manager_ = WidgetInputHandlerManager::Create(
Dave Tapuska139a72f2017-09-06 21:57:03557 weak_ptr_factory_.GetWeakPtr(),
Dave Tapuska9db80842017-07-24 17:24:26558 render_thread_impl && compositor_
559 ? render_thread_impl->compositor_task_runner()
560 : nullptr,
561 render_thread_impl ? render_thread_impl->GetRendererScheduler()
562 : nullptr);
563 }
564
nickf7b38222016-11-22 21:59:35565 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29566
lfg8ff33912016-09-13 20:59:21567 webwidget_internal_ = web_widget;
568 webwidget_mouse_lock_target_.reset(
569 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21570 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29571
nick4df698d82016-11-11 20:39:23572 RenderThread::Get()->AddRoute(routing_id_, this);
573 // Take a reference on behalf of the RenderThread. This will be balanced
574 // when we receive ViewMsg_Close.
575 AddRef();
576 if (RenderThreadImpl::current()) {
577 RenderThreadImpl::current()->WidgetCreated();
578 if (is_hidden_)
579 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29580 }
581}
582
[email protected]949b6592014-08-20 13:17:52583void RenderWidget::WasSwappedOut() {
584 // If we have been swapped out and no one else is using this process,
585 // it's safe to exit now.
586 CHECK(is_swapped_out_);
587 RenderProcess::current()->ReleaseProcess();
588}
589
[email protected]b2e4c70132013-10-03 02:07:51590void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39591 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51592 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43593 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00594 popup_screen_origin_for_emulation_ =
Lei Zhang9b359d32017-11-28 00:57:02595 emulator->original_screen_rect().origin();
[email protected]5f75aa42014-04-01 23:00:56596 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27597 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51598}
599
[email protected]2d6836f42014-07-02 17:25:31600gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
601 if (screen_metrics_emulator_)
602 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
603 return anchor;
604}
605
thakis18e426412017-03-15 12:06:37606#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51607void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39608 ExternalPopupMenu* popup,
609 RenderWidgetScreenMetricsEmulator* emulator) {
Pavel Feldmancc099f72017-07-20 23:09:00610 popup->SetOriginScaleForEmulation(emulator->scale());
[email protected]b2e4c70132013-10-03 02:07:51611}
[email protected]53907862014-03-25 15:42:40612#endif
[email protected]b2e4c70132013-10-03 02:07:51613
Fady Samuel69b33b52017-11-08 22:01:52614void RenderWidget::SetLocalSurfaceIdForAutoResize(
615 uint64_t sequence_number,
616 const content::ScreenInfo& screen_info,
617 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
630 // Notify all BrowserPlugins of the updated ScreenInfo.
631 if (BrowserPluginManager::Get())
632 BrowserPluginManager::Get()->ScreenInfoChanged(screen_info);
633 }
634
635 AutoResizeCompositor(local_surface_id);
636}
637
[email protected]b2e4c70132013-10-03 02:07:51638void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
639 if (screen_metrics_emulator_)
640 screen_metrics_emulator_->OnShowContextMenu(params);
641}
642
[email protected]a95986a82010-12-24 06:19:28643bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47644#if defined(OS_MACOSX)
645 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
646 return text_input_client_observer_->OnMessageReceived(message);
647#endif
lfgbee1e0a2016-06-08 21:24:21648 if (mouse_lock_dispatcher_ &&
649 mouse_lock_dispatcher_->OnMessageReceived(message))
650 return true;
651
[email protected]a95986a82010-12-24 06:19:28652 bool handled = true;
653 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15654 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22655 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
656 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22657 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29658 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
659 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
660 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15661 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46662 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
663 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15664 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
wjmacleanee244e02017-05-26 21:06:07665 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]a95986a82010-12-24 06:19:28666 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28667 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
Fady Samuel319e429c2017-10-02 18:31:55668 IPC_MESSAGE_HANDLER(ViewMsg_SetLocalSurfaceIdForAutoResize,
669 OnSetLocalSurfaceIdForAutoResize)
dgozman9260b0a12015-03-16 13:45:20670 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
671 OnEnableDeviceEmulation)
672 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
673 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28674 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41675 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25676 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28677 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
678 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03679 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48680 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
681 OnSetViewportIntersection)
kenrb04323782017-06-23 01:23:32682 IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert)
Ken Buchanan8a319fb2017-11-15 18:37:12683 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRenderThrottlingStatus,
684 OnUpdateRenderThrottlingStatus)
lfg43e08e62016-02-03 18:51:37685 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
686 OnWaitNextFrameForTests)
ekaramadc9b70a72017-03-23 16:14:23687 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdates,
688 OnRequestCompositionUpdates)
paulmeyer90f6c31d2016-11-12 00:17:59689 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
690 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
691 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
692 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21693 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
694 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
695 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21696#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39697 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
698 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21699#endif
[email protected]a95986a82010-12-24 06:19:28700 IPC_MESSAGE_UNHANDLED(handled = false)
701 IPC_END_MESSAGE_MAP()
702 return handled;
703}
initial.commit09911bf2008-07-26 23:55:29704
705bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42706 // Don't send any messages after the browser has told us to close, and filter
707 // most outgoing messages while swapped out.
708 if ((is_swapped_out_ &&
709 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
710 closing_) {
initial.commit09911bf2008-07-26 23:55:29711 delete message;
712 return false;
713 }
714
715 // If given a messsage without a routing ID, then assign our routing ID.
716 if (message->routing_id() == MSG_ROUTING_NONE)
717 message->set_routing_id(routing_id_);
718
[email protected]380244092011-10-07 17:26:27719 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44720}
721
dtapuska014ed082016-11-11 21:58:48722void RenderWidget::SendOrCrash(IPC::Message* message) {
723 bool result = Send(message);
724 CHECK(closing_ || result) << "Failed to send message";
725}
726
ekaramad5aff1942017-01-06 01:26:35727bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26728 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
729 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
730 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
731 // will be processed regardless of page focus. We should revisit this after
732 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
Blink Reformat1c4d759e2017-04-09 16:34:54733 return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
ekaramadb6483a052017-02-10 02:23:26734 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35735}
736
bokanc007c3a2015-02-03 07:15:56737void RenderWidget::SetWindowRectSynchronously(
738 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39739 ResizeParams params;
740 params.screen_info = screen_info_;
741 params.new_size = new_window_rect.size();
742 params.physical_backing_size =
743 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39744 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39745 params.is_fullscreen_granted = is_fullscreen_granted_;
746 params.display_mode = display_mode_;
747 params.needs_resize_ack = false;
748 Resize(params);
749
bokanc007c3a2015-02-03 07:15:56750 view_screen_rect_ = new_window_rect;
751 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02752 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56753 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02754}
755
initial.commit09911bf2008-07-26 23:55:29756void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32757 DCHECK(content::RenderThread::Get());
758 if (closing_)
759 return;
760 NotifyOnClose();
761 closing_ = true;
762
763 // Browser correspondence is no longer needed at this point.
764 if (routing_id_ != MSG_ROUTING_NONE) {
765 RenderThread::Get()->RemoveRoute(routing_id_);
766 SetHidden(false);
767 if (RenderThreadImpl::current())
768 RenderThreadImpl::current()->WidgetDestroyed();
769 }
770
771 if (for_oopif_) {
772 // Widgets for frames may be created and closed at any time while the frame
773 // is alive. However, the closing process must happen synchronously. Frame
774 // widget and frames hold pointers to each other. If Close() is deferred to
775 // the message loop like in the non-frame widget case, WebWidget::close()
776 // can end up accessing members of an already-deleted frame.
777 Close();
778 } else {
779 // If there is a Send call on the stack, then it could be dangerous to close
780 // now. Post a task that only gets invoked when there are no nested message
781 // loops.
Hajime Hoshiabb3c8f2017-12-04 18:41:39782 task_runner_->PostNonNestableTask(
tzikff2a81a2017-09-15 05:10:06783 FROM_HERE, base::BindOnce(&RenderWidget::Close, this));
dchengd96a27a2015-07-24 20:17:32784 }
785
786 // Balances the AddRef taken when we called AddRoute.
787 Release();
initial.commit09911bf2008-07-26 23:55:29788}
789
fsamuel664e8b62016-01-20 19:54:01790void RenderWidget::OnResize(const ResizeParams& params) {
EhsanKbd2cea992017-11-23 18:49:08791 gfx::Size old_visible_viewport_size = visible_viewport_size_;
792
[email protected]5b45ad42013-10-25 00:42:04793 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32794 return;
795
[email protected]b2e4c70132013-10-03 02:07:51796 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39797 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51798 return;
799 }
800
mfomitchev2600fd7c2016-02-17 20:53:39801 Resize(params);
EhsanKbd2cea992017-11-23 18:49:08802
803 if (old_visible_viewport_size != visible_viewport_size_) {
804 for (auto& render_frame : render_frames_)
805 render_frame.DidChangeVisibleViewport();
806 }
initial.commit09911bf2008-07-26 23:55:29807}
808
Fady Samuel319e429c2017-10-02 18:31:55809void RenderWidget::OnSetLocalSurfaceIdForAutoResize(
810 uint64_t sequence_number,
Fady Samuel69b33b52017-11-08 22:01:52811 const gfx::Size& min_size,
812 const gfx::Size& max_size,
813 const content::ScreenInfo& screen_info,
Fady Samuel319e429c2017-10-02 18:31:55814 const viz::LocalSurfaceId& local_surface_id) {
815 if (!auto_resize_mode_ || resize_or_repaint_ack_num_ != sequence_number)
816 return;
Fady Samuel69b33b52017-11-08 22:01:52817
818 SetLocalSurfaceIdForAutoResize(sequence_number, screen_info,
819 local_surface_id);
Fady Samuel319e429c2017-10-02 18:31:55820}
821
dgozman9260b0a12015-03-16 13:45:20822void RenderWidget::OnEnableDeviceEmulation(
Lei Zhang9b359d32017-11-28 00:57:02823 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39824 if (!screen_metrics_emulator_) {
825 ResizeParams resize_params;
826 resize_params.screen_info = screen_info_;
827 resize_params.new_size = size_;
828 resize_params.physical_backing_size = physical_backing_size_;
829 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39830 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
831 resize_params.display_mode = display_mode_;
832 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
833 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18834 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39835 } else {
dgozman9260b0a12015-03-16 13:45:20836 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39837 }
dgozman9260b0a12015-03-16 13:45:20838}
839
840void RenderWidget::OnDisableDeviceEmulation() {
841 screen_metrics_emulator_.reset();
842}
843
initial.commit09911bf2008-07-26 23:55:29844void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31845 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29846 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03847 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55848 for (auto& observer : render_frames_)
849 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29850}
851
[email protected]3399dd822014-08-09 11:14:24852void RenderWidget::OnWasShown(bool needs_repainting,
853 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41854 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29855 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21856 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29857 return;
858
tasakb95dbb50c2017-02-08 18:07:50859 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29860 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03861 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55862 for (auto& observer : render_frames_)
863 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29864
[email protected]8a23afb32014-04-30 22:40:23865 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29866 return;
initial.commit09911bf2008-07-26 23:55:29867
[email protected]3399dd822014-08-09 11:14:24868 if (compositor_) {
869 ui::LatencyInfo swap_latency_info(latency_info);
danakj87fbafb2017-04-04 16:54:11870 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
871 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info);
872 // Force this SwapPromiseMonitor to trigger and insert a SwapPromise.
Blink Reformat1c4d759e2017-04-09 16:34:54873 compositor_->SetNeedsBeginFrame();
[email protected]3399dd822014-08-09 11:14:24874 }
initial.commit09911bf2008-07-26 23:55:29875}
876
[email protected]53d3f302009-12-21 04:42:05877void RenderWidget::OnRequestMoveAck() {
878 DCHECK(pending_window_rect_count_);
879 pending_window_rect_count_--;
880}
881
[email protected]ed7defa2013-03-12 21:29:59882GURL RenderWidget::GetURLForGraphicsContext3D() {
883 return GURL();
[email protected]65225772011-05-12 21:10:24884}
885
nzolghadr5d8596502017-01-23 22:59:35886void RenderWidget::OnHandleInputEvent(
887 const blink::WebInputEvent* input_event,
888 const std::vector<const blink::WebInputEvent*>& coalesced_events,
889 const ui::LatencyInfo& latency_info,
890 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23891 if (!input_event)
892 return;
nzolghadr5d8596502017-01-23 22:59:35893
Dave Tapuskaea83d3bd2017-06-13 16:14:55894 HandledEventCallback callback;
895 if (dispatch_type == DISPATCH_TYPE_BLOCKING) {
896 callback = base::Bind(
897 &RenderWidget::SendInputEventAck, this, input_event->GetType(),
898 ui::WebInputEventTraits::GetUniqueTouchEventId(*input_event));
899 }
nzolghadr5d8596502017-01-23 22:59:35900 input_handler_->HandleInputEvent(
901 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
Dave Tapuskaea83d3bd2017-06-13 16:14:55902 latency_info, std::move(callback));
fsamuel78f86e42016-01-20 04:10:23903}
904
Navid Zolghadr0d86e5f2017-10-23 18:09:22905int RenderWidget::GetWidgetRoutingIdAtPoint(const gfx::Point& point) {
906 return input_handler_->GetWidgetRoutingIdAtPoint(point);
907}
908
Dave Tapuskaea83d3bd2017-06-13 16:14:55909void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31910 const blink::WebCoalescedInputEvent& input_event,
911 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55912 HandledEventCallback callback) {
913 input_handler_->HandleInputEvent(input_event, latency_info,
914 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31915}
916
Dave Tapuskaea83d3bd2017-06-13 16:14:55917void RenderWidget::SendInputEventAck(
918 blink::WebInputEvent::Type type,
919 uint32_t touch_event_id,
920 InputEventAckState ack_state,
921 const ui::LatencyInfo& latency_info,
Dave Tapuskab28a1082017-08-30 15:37:26922 std::unique_ptr<ui::DidOverscrollParams> overscroll_params,
923 base::Optional<cc::TouchAction> touch_action) {
Dave Tapuskaea83d3bd2017-06-13 16:14:55924 InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_state,
Dave Tapuskab28a1082017-08-30 15:37:26925 latency_info, std::move(overscroll_params), touch_event_id,
926 touch_action);
dtapuska9ec1a912017-04-21 15:18:31927 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
928}
929
dtapuska9d46ef7d2017-05-26 19:06:06930scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
931 return input_event_queue_;
932}
933
fsamuel78f86e42016-01-20 04:10:23934void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21935 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54936 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23937}
938
939void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21940 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54941 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23942}
943
alexmos56567492016-09-13 00:52:46944void RenderWidget::OnSetEditCommandsForNextKeyEvent(
945 const EditCommands& edit_commands) {
946 edit_commands_ = edit_commands;
947}
948
fsamuel78f86e42016-01-20 04:10:23949void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08950 has_focus_ = enable;
951
lfg8ff33912016-09-13 20:59:21952 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54953 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08954
ericwilligers88e69742016-10-17 19:29:55955 for (auto& observer : render_frames_)
956 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23957}
958
dtapuska3d5624d32016-08-30 04:34:00959void RenderWidget::SetNeedsMainFrame() {
960 RenderWidgetCompositor* rwc = compositor();
961 if (!rwc)
962 return;
Blink Reformat1c4d759e2017-04-09 16:34:54963 rwc->SetNeedsBeginFrame();
dtapuska3d5624d32016-08-30 04:34:00964}
965
fsamuel78f86e42016-01-20 04:10:23966///////////////////////////////////////////////////////////////////////////////
967// RenderWidgetCompositorDelegate
968
969void RenderWidget::ApplyViewportDeltas(
970 const gfx::Vector2dF& inner_delta,
971 const gfx::Vector2dF& outer_delta,
972 const gfx::Vector2dF& elastic_overscroll_delta,
973 float page_scale,
974 float top_controls_delta) {
Blink Reformat1c4d759e2017-04-09 16:34:54975 GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta,
lfg8ff33912016-09-13 20:59:21976 elastic_overscroll_delta, page_scale,
977 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23978}
979
sahel1b47fda72017-03-28 17:03:07980void RenderWidget::RecordWheelAndTouchScrollingCount(
981 bool has_scrolled_by_wheel,
982 bool has_scrolled_by_touch) {
Blink Reformat1c4d759e2017-04-09 16:34:54983 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07984 has_scrolled_by_touch);
985}
986
fsamuel78f86e42016-01-20 04:10:23987void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska9ec1a912017-04-21 15:18:31988 if (input_event_queue_) {
989 input_event_queue_->DispatchRafAlignedInput(
990 ui::EventTimeStampFromSeconds(frame_time_sec));
991 }
dtapuska3d5624d32016-08-30 04:34:00992
Blink Reformat1c4d759e2017-04-09 16:34:54993 GetWebWidget()->BeginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23994}
995
danakjc7afae52017-06-20 21:12:41996void RenderWidget::RequestNewLayerTreeFrameSink(
danakjc7afae52017-06-20 21:12:41997 const LayerTreeFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:21998 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03999 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:411000 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:391001 DCHECK(!compositor_never_visible_);
danakjc7afae52017-06-20 21:12:411002 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
danakjab9ef4d2017-10-31 23:38:331003 routing_id_, frame_swap_message_queue_, GetURLForGraphicsContext3D(),
1004 callback);
[email protected]ba91a792013-02-06 09:48:281005}
1006
fsamuel78f86e42016-01-20 04:10:231007void RenderWidget::DidCommitAndDrawCompositorFrame() {
1008 // NOTE: Tests may break if this event is renamed or moved. See
1009 // tab_capture_performancetest.cc.
1010 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:081011
ericwilligers88e69742016-10-17 19:29:551012 for (auto& observer : render_frames_)
1013 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:081014
fsamuel78f86e42016-01-20 04:10:231015 // Notify subclasses that we initiated the paint operation.
1016 DidInitiatePaint();
1017}
1018
1019void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:551020 for (auto& observer : render_frames_)
1021 observer.DidCommitCompositorFrame();
1022 for (auto& observer : render_frame_proxies_)
1023 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:231024}
1025
1026void RenderWidget::DidCompletePageScaleAnimation() {}
1027
danakj6c872fc02016-10-22 04:29:491028void RenderWidget::DidReceiveCompositorFrameAck() {
1029 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
Fady Samuelcc3e3b4a2017-10-03 02:09:211030 DidResizeOrRepaintAck();
fsamuel78f86e42016-01-20 04:10:231031}
1032
fsamuel78f86e42016-01-20 04:10:231033bool RenderWidget::IsClosing() const {
1034 return host_closing_;
1035}
1036
danakj53eccbc2016-03-02 22:51:071037void RenderWidget::RequestScheduleAnimation() {
Blink Reformat1c4d759e2017-04-09 16:34:541038 ScheduleAnimation();
initial.commit09911bf2008-07-26 23:55:291039}
1040
fsamuel78f86e42016-01-20 04:10:231041void RenderWidget::UpdateVisualState() {
Blink Reformat1c4d759e2017-04-09 16:34:541042 GetWebWidget()->UpdateAllLifecyclePhases();
1043 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:501044
Takashi SAKAMOTO870f6262017-08-22 04:08:271045 if (first_update_visual_state_after_hidden_) {
1046 RecordTimeToFirstActivePaint();
1047 first_update_visual_state_after_hidden_ = false;
1048 }
1049}
tasakb95dbb50c2017-02-08 18:07:501050
Takashi SAKAMOTO870f6262017-08-22 04:08:271051void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501052 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501053 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271054 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1055 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1056 sample);
1057 }
1058 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1059 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1060 UMA_HISTOGRAM_TIMES(
1061 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1062 "AfterBackgrounded.5min",
1063 sample);
1064 }
fsamuel78f86e42016-01-20 04:10:231065}
1066
1067void RenderWidget::WillBeginCompositorFrame() {
1068 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1069
Blink Reformat1c4d759e2017-04-09 16:34:541070 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291071
dglazkov06854c5c2016-08-31 00:19:591072 // The UpdateTextInputState can result in further layout and possibly
1073 // enable GPU acceleration so they need to be called before any painting
1074 // is done.
changwan75e3b2072017-01-16 02:55:001075 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591076 UpdateSelectionBounds();
1077
ericwilligers88e69742016-10-17 19:29:551078 for (auto& observer : render_frame_proxies_)
1079 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291080}
1081
jbroman6ccbc7d472016-07-27 04:45:411082std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:041083 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:411084 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
1085 routing_id_, std::move(request));
1086}
1087
fsamuel72464894f2015-12-15 06:59:311088///////////////////////////////////////////////////////////////////////////////
1089// RenderWidgetInputHandlerDelegate
1090
avid7d6b2e2016-03-04 19:41:171091void RenderWidget::FocusChangeComplete() {
ekaramad27ca69b12017-04-20 18:34:291092 if (!GetWebWidget()->IsWebFrameWidget())
1093 return;
1094 blink::WebLocalFrame* focused =
1095 static_cast<blink::WebFrameWidget*>(GetWebWidget())
1096 ->LocalRoot()
1097 ->View()
1098 ->FocusedFrame();
1099 if (focused && focused->AutofillClient())
1100 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171101}
fsamuel72464894f2015-12-15 06:59:311102
dtapuska1827dd22016-03-11 15:24:591103void RenderWidget::ObserveGestureEventAndResult(
1104 const blink::WebGestureEvent& gesture_event,
1105 const gfx::Vector2dF& unused_delta,
Sandra Sunac5cdd832017-12-11 03:27:131106 const cc::OverscrollBehavior& overscroll_behavior,
dtapuska1827dd22016-03-11 15:24:591107 bool event_processed) {
1108 if (!compositor_deps_->IsElasticOverscrollEnabled())
1109 return;
1110
1111 cc::InputHandlerScrollResult scroll_result;
1112 scroll_result.did_scroll = event_processed;
1113 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1114 scroll_result.unused_scroll_delta = unused_delta;
Sandra Sunac5cdd832017-12-11 03:27:131115 scroll_result.overscroll_behavior = overscroll_behavior;
dtapuska1827dd22016-03-11 15:24:591116
1117 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1118 InputHandlerManager* input_handler_manager =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281119 render_thread ? render_thread->input_handler_manager() : nullptr;
dtapuska1827dd22016-03-11 15:24:591120 if (input_handler_manager) {
1121 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1122 routing_id_, gesture_event, scroll_result);
Dave Tapuska9db80842017-07-24 17:24:261123 } else if (widget_input_handler_manager_) {
1124 widget_input_handler_manager_->ObserveGestureEventOnMainThread(
1125 gesture_event, scroll_result);
dtapuska1827dd22016-03-11 15:24:591126 }
1127}
1128
avid7d6b2e2016-03-04 19:41:171129void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461130 ClearEditCommands();
1131}
1132
1133void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1134 const std::string& value) {
1135 ClearEditCommands();
1136 edit_commands_.emplace_back(name, value);
1137}
1138
1139void RenderWidget::ClearEditCommands() {
1140 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171141}
fsamuel72464894f2015-12-15 06:59:311142
chongza8ba91fc2016-08-16 21:39:171143void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska139a72f2017-09-06 21:57:031144 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:051145 if (mojom::WidgetInputHandlerHost* host =
1146 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1147 host->DidOverscroll(params);
1148 }
Dave Tapuska139a72f2017-09-06 21:57:031149 } else {
1150 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1151 }
fsamuel72464894f2015-12-15 06:59:311152}
1153
fsamuele8326c742016-01-12 00:49:391154void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1155 // Nothing to do here. RenderWidget created the |input_handler| and will take
1156 // ownership of it. We just verify here that we don't already have an input
1157 // handler.
1158 DCHECK(!input_handler_);
1159}
1160
changwan75e3b2072017-01-16 02:55:001161void RenderWidget::ShowVirtualKeyboard() {
1162 UpdateTextInputStateInternal(true, false);
1163}
1164
changwan62f57292017-02-17 08:28:251165void RenderWidget::ClearTextInputState() {
1166 text_input_info_ = blink::WebTextInputInfo();
1167 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1168 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1169 can_compose_inline_ = false;
1170 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201171 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251172}
1173
changwan75e3b2072017-01-16 02:55:001174void RenderWidget::UpdateTextInputState() {
1175 UpdateTextInputStateInternal(false, false);
1176}
1177
1178void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1179 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311180 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001181
fsamuel72464894f2015-12-15 06:59:311182 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001183 DCHECK(!reply_to_request);
1184 // show_virtual_keyboard should still be effective even if it was set inside
1185 // the IME
fsamuel72464894f2015-12-15 06:59:311186 // event guard.
changwan75e3b2072017-01-16 02:55:001187 if (show_virtual_keyboard)
1188 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311189 return;
1190 }
1191
dglazkov97b6c2b2016-10-25 17:35:551192 ui::TextInputType new_type = GetTextInputType();
1193 if (IsDateTimeInput(new_type))
1194 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311195
dglazkov97b6c2b2016-10-25 17:35:551196 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351197 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541198 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101199 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541200 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311201
1202 bool new_can_compose_inline = CanComposeInline();
1203
1204 // Only sends text input params if they are changed or if the ime should be
1205 // shown.
changwan75e3b2072017-01-16 02:55:001206 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561207 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1208 text_input_info_ != new_info ||
1209 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381210 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551211 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311212 params.mode = new_mode;
1213 params.flags = new_info.flags;
AJITH KUMAR V9e7b5572017-11-14 00:54:211214#if defined(OS_ANDROID)
AJITH KUMAR V041c0b02017-08-08 10:39:201215 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1216 // Due to a focus change, values will be reset by the frame.
1217 // That case we only need fresh NEXT/PREVIOUS information.
1218 // Also we won't send ViewHostMsg_TextInputStateChanged if next/previous
1219 // focusable status is changed.
1220 if (auto* controller = GetInputMethodController()) {
1221 next_previous_flags_ =
1222 controller->ComputeWebTextInputNextPreviousFlags();
1223 } else {
1224 // For safety in case GetInputMethodController() is null, because -1 is
1225 // invalid value to send to browser process.
1226 next_previous_flags_ = 0;
1227 }
1228 }
AJITH KUMAR V9e7b5572017-11-14 00:54:211229#else
1230 next_previous_flags_ = 0;
1231#endif
AJITH KUMAR V041c0b02017-08-08 10:39:201232 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541233 params.value = new_info.value.Utf8();
1234 params.selection_start = new_info.selection_start;
1235 params.selection_end = new_info.selection_end;
1236 params.composition_start = new_info.composition_start;
1237 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311238 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001239 // TODO(changwan): change instances of show_ime_if_needed to
1240 // show_virtual_keyboard.
1241 params.show_ime_if_needed = show_virtual_keyboard;
1242 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311243 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1244
1245 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551246 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311247 text_input_mode_ = new_mode;
1248 can_compose_inline_ = new_can_compose_inline;
1249 text_input_flags_ = new_info.flags;
1250 }
1251}
1252
1253bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581254 possible_drag_event_info_.event_source =
1255 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1256 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541257 gfx::Point(event.global_x, event.global_y);
avid7d6b2e2016-03-04 19:41:171258
fsamuel72464894f2015-12-15 06:59:311259 return false;
1260}
1261
1262bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551263 for (auto& observer : render_frames_)
1264 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081265
paulmeyer6ef5a792016-11-08 20:33:581266 possible_drag_event_info_.event_source =
1267 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1268 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541269 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581270
avid7d6b2e2016-03-04 19:41:171271 if (owner_delegate_)
1272 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1273
fsamuel72464894f2015-12-15 06:59:311274 return false;
[email protected]fd847792013-10-24 17:12:351275}
1276
initial.commit09911bf2008-07-26 23:55:291277///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391278// RenderWidgetScreenMetricsDelegate
1279
1280void RenderWidget::Redraw() {
1281 set_next_paint_is_resize_ack();
1282 if (compositor_)
1283 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1284}
1285
bokanc63441c2016-04-27 15:49:121286void RenderWidget::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:541287 GetWebWidget()->Resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121288}
1289
1290gfx::Size RenderWidget::GetSizeForWebWidget() const {
1291 if (IsUseZoomForDSFEnabled())
1292 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1293
1294 return size_;
1295}
1296
mfomitchev2600fd7c2016-02-17 20:53:391297void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581298 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271299 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1300 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581301
Fady Samuel85a1bf72017-10-27 14:30:201302 bool screen_info_changed = screen_info_ != params.screen_info;
1303
mfomitchev2600fd7c2016-02-17 20:53:391304 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581305
ccameron2f451532016-09-07 21:49:271306 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1307 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581308 OnDeviceScaleFactorChanged();
wjmaclean8a795f32016-08-11 23:49:581309 }
mfomitchev2600fd7c2016-02-17 20:53:391310
1311 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1312 // A resize ack shouldn't be requested if we have not ACK'd the previous
1313 // one.
1314 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1315 }
1316
1317 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211318 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391319 return;
1320
fsamuelca02c4e2017-05-09 13:34:141321 if (params.local_surface_id)
1322 local_surface_id_ = *params.local_surface_id;
1323
ianwene5fc5782016-08-18 04:05:151324 if (compositor_) {
Fady Samuel319e429c2017-10-02 18:31:551325 // If surface synchronization is enabled, then this will use the provided
fsamuelca02c4e2017-05-09 13:34:141326 // |local_surface_id_| to submit the next generated CompositorFrame.
1327 // If the ID is not valid, then the compositor will defer commits until
1328 // it receives a valid surface ID. This is a no-op if surface
1329 // synchronization is disabled.
Fady Samuel2bb02292017-10-17 23:59:151330 DCHECK(!compositor_->IsSurfaceSynchronizationEnabled() ||
1331 !params.needs_resize_ack || local_surface_id_.is_valid());
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271332 compositor_->SetViewportSize(params.physical_backing_size,
1333 local_surface_id_);
1334 compositor_->SetBrowserControlsHeight(
1335 params.top_controls_height, params.bottom_controls_height,
1336 params.browser_controls_shrink_blink_size);
1337 compositor_->SetRasterColorSpace(
1338 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151339 }
mfomitchev2600fd7c2016-02-17 20:53:391340
mfomitchev2600fd7c2016-02-17 20:53:391341 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391342
1343 // NOTE: We may have entered fullscreen mode without changing our size.
1344 bool fullscreen_change =
1345 is_fullscreen_granted_ != params.is_fullscreen_granted;
1346 is_fullscreen_granted_ = params.is_fullscreen_granted;
1347 display_mode_ = params.display_mode;
1348
bokanc63441c2016-04-27 15:49:121349 size_ = params.new_size;
1350 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391351
bokanc63441c2016-04-27 15:49:121352 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221353
mfomitchev2600fd7c2016-02-17 20:53:391354 WebSize visual_viewport_size;
1355
1356 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181357 visual_viewport_size = gfx::ScaleToCeiledSize(
1358 params.visible_viewport_size,
1359 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391360 } else {
1361 visual_viewport_size = visible_viewport_size_;
1362 }
1363
Blink Reformat1c4d759e2017-04-09 16:34:541364 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391365
bokanc63441c2016-04-27 15:49:121366 // When resizing, we want to wait to paint before ACK'ing the resize. This
1367 // ensures that we only resize as fast as we can paint. We only need to
1368 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391369 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1370 // In this case there is no paint/composite and therefore no
Fady Samuelcc3e3b4a2017-10-03 02:09:211371 // ViewHostMsg_ResizeOrRepaint_ACK to send the resize ack with. We'd need to
1372 // send the ack through a fake ViewHostMsg_ResizeOrRepaint_ACK or a
1373 // different message.
mfomitchev2600fd7c2016-02-17 20:53:391374 DCHECK(!params.needs_resize_ack);
1375 }
1376
1377 // Send the Resize_ACK flag once we paint again if requested.
1378 if (params.needs_resize_ack)
1379 set_next_paint_is_resize_ack();
1380
1381 if (fullscreen_change)
1382 DidToggleFullscreen();
1383
engedy6cb63c92016-02-23 14:14:581384 if (orientation_changed)
1385 OnOrientationChange();
1386
Fady Samuel85a1bf72017-10-27 14:30:201387 if (screen_info_changed) {
1388 for (auto& observer : render_frame_proxies_)
1389 observer.OnScreenInfoChanged(params.screen_info);
1390
1391 // Notify all BrowserPlugins of the updated ScreenInfo.
1392 if (BrowserPluginManager::Get())
1393 BrowserPluginManager::Get()->ScreenInfoChanged(params.screen_info);
1394 }
1395
mfomitchev2600fd7c2016-02-17 20:53:391396 // If a resize ack is requested and it isn't set-up, then no more resizes will
1397 // come in and in general things will go wrong.
1398 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1399}
1400
1401void RenderWidget::SetScreenMetricsEmulationParameters(
1402 bool enabled,
1403 const blink::WebDeviceEmulationParams& params) {
1404 // This is only supported in RenderView.
1405 NOTREACHED();
1406}
1407
1408void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1409 const gfx::Rect& window_screen_rect) {
1410 view_screen_rect_ = view_screen_rect;
1411 window_screen_rect_ = window_screen_rect;
1412}
1413
1414///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461415// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291416
Fady Samueld10aadd82017-11-03 18:23:571417void RenderWidget::AutoResizeCompositor(
1418 const viz::LocalSurfaceId& local_surface_id) {
danakjddaec912015-09-25 19:38:401419 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
Fady Samueld10aadd82017-11-03 18:23:571420 local_surface_id_ = local_surface_id;
[email protected]97e1bf72013-03-06 14:06:051421 if (compositor_)
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271422 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
[email protected]97e1bf72013-03-06 14:06:051423}
1424
Blink Reformat1c4d759e2017-04-09 16:34:541425blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221426 DCHECK(!host_closing_);
1427
loyso6e6efc42017-01-21 02:23:031428 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1429 auto animation_host = cc::AnimationHost::CreateMainInstance();
1430
wjmacleana755e302017-04-20 00:43:161431 // Oopif status must be set before the LayerTreeHost is created.
1432 compositor_->SetIsForOopif(for_oopif_);
loyso6e6efc42017-01-21 02:23:031433 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1434 compositor_.get(), compositor_.get(), animation_host.get(),
1435 compositor_deps_, device_scale_factor_, screen_info_);
1436 compositor_->Initialize(std::move(layer_tree_host),
1437 std::move(animation_host));
1438
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271439 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
oshimad5279032015-12-16 18:22:331440 OnDeviceScaleFactorChanged();
ccameron01912992017-05-23 07:34:031441 compositor_->SetRasterColorSpace(
Christopher Camerona1ea2b72017-08-02 01:59:091442 screen_info_.color_space.GetRasterColorSpace());
kenrb5d78b842017-03-06 21:06:011443 compositor_->SetContentSourceId(current_content_source_id_);
sievers71c62dd52015-10-07 01:44:391444 // For background pages and certain tests, we don't want to trigger
danakjc7afae52017-06-20 21:12:411445 // LayerTreeFrameSink creation.
dtapuskab08611f2017-04-24 16:10:221446 bool should_generate_frame_sink =
1447 !compositor_never_visible_ && RenderThreadImpl::current();
1448 if (!should_generate_frame_sink)
sievers71c62dd52015-10-07 01:44:391449 compositor_->SetNeverVisible();
1450
pimanc4af3072015-10-02 03:45:591451 StartCompositor();
staraz067f58242016-11-07 21:06:411452 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1453 compositor_->SetFrameSinkId(
Fady Samueld5c26182017-07-12 02:43:331454 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371455
wjmaclean1d970622017-01-21 22:28:241456 RenderThreadImpl* render_thread = RenderThreadImpl::current();
Dave Tapuska9db80842017-07-24 17:24:261457 if (render_thread) {
dtapuska9ec1a912017-04-21 15:18:311458 input_event_queue_ = new MainThreadEventQueue(
1459 this, render_thread->GetRendererScheduler()->CompositorTaskRunner(),
dtapuskab08611f2017-04-24 16:10:221460 render_thread->GetRendererScheduler(), should_generate_frame_sink);
Dave Tapuska9db80842017-07-24 17:24:261461
1462 InputHandlerManager* input_handler_manager =
1463 render_thread->input_handler_manager();
1464 if (input_handler_manager) {
1465 input_handler_manager->AddInputHandler(
1466 routing_id_, compositor()->GetInputHandler(), input_event_queue_,
1467 weak_ptr_factory_.GetWeakPtr(),
1468 compositor_deps_->IsScrollAnimatorEnabled());
1469 has_added_input_handler_ = true;
1470 }
wjmaclean1d970622017-01-21 22:28:241471 }
1472
Khushal3e96e662017-10-30 23:16:501473 UpdateURLForCompositorUkm();
1474
loyso50b51c22017-01-10 07:18:371475 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591476}
1477
ennef3c58142014-12-09 21:44:381478void RenderWidget::WillCloseLayerTreeView() {
1479 if (host_closing_)
1480 return;
1481
1482 // Prevent new compositors or output surfaces from being created.
1483 host_closing_ = true;
1484
[email protected]aeeedad2014-08-22 18:16:221485 // Always send this notification to prevent new layer tree views from
1486 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211487 if (blink::WebWidget* widget = GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541488 widget->WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221489}
1490
Blink Reformat1c4d759e2017-04-09 16:34:541491void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1492 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
dglazkovf0e1d6d2015-10-10 02:13:481493 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1494 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1495 }
dglazkov79c426102015-08-31 21:22:431496
ericwilligers88e69742016-10-17 19:29:551497 for (auto& observer : render_frames_)
1498 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431499}
1500
[email protected]586871b2014-07-22 17:05:111501// static
dchengcedca5612016-04-09 01:40:151502std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111503 IPC::Message* msg,
1504 MessageDeliveryPolicy policy,
1505 FrameSwapMessageQueue* frame_swap_message_queue,
1506 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111507 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111508 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151509 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1510 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111511 &first_message_for_frame);
1512 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151513 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111514 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061515 return promise;
[email protected]586871b2014-07-22 17:05:111516 }
dcheng4b6b5ff2014-10-16 00:42:061517 return nullptr;
[email protected]586871b2014-07-22 17:05:111518}
1519
1520void RenderWidget::QueueMessage(IPC::Message* msg,
1521 MessageDeliveryPolicy policy) {
1522 // RenderThreadImpl::current() is NULL in some tests.
1523 if (!compositor_ || !RenderThreadImpl::current()) {
1524 Send(msg);
1525 return;
1526 }
1527
dchengcedca5612016-04-09 01:40:151528 std::unique_ptr<cc::SwapPromise> swap_promise =
1529 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111530 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111531 compositor_->GetSourceFrameNumber());
1532
Ken Buchanance710eb2017-08-30 23:46:521533 if (swap_promise)
dcheng07945f632015-12-26 07:59:321534 compositor_->QueueSwapPromise(std::move(swap_promise));
[email protected]586871b2014-07-22 17:05:111535}
1536
Blink Reformat1c4d759e2017-04-09 16:34:541537void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301538 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521539 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181540 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291541 // Only send a SetCursor message if we need to make a change.
1542 if (!current_cursor_.IsEqual(cursor)) {
1543 current_cursor_ = cursor;
1544 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1545 }
1546}
1547
aelias5971e47d2017-06-16 02:39:381548void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
1549 Send(new ViewHostMsg_AutoscrollStart(routing_id_, point));
1550}
1551
1552void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
1553 Send(new ViewHostMsg_AutoscrollFling(routing_id_, velocity));
1554}
1555
1556void RenderWidget::AutoscrollEnd() {
1557 Send(new ViewHostMsg_AutoscrollEnd(routing_id_));
1558}
1559
initial.commit09911bf2008-07-26 23:55:291560// We are supposed to get a single call to Show for a newly created RenderWidget
1561// that was created via RenderWidget::CreateWebView. So, we wait until this
1562// point to dispatch the ShowWidget message.
1563//
1564// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281565// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291566//
Blink Reformat1c4d759e2017-04-09 16:34:541567void RenderWidget::Show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291568 DCHECK(!did_show_) << "received extraneous Show call";
1569 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351570 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291571
[email protected]8de12d942010-11-17 20:42:441572 if (did_show_)
1573 return;
1574
1575 did_show_ = true;
nickf7b38222016-11-22 21:59:351576
1577 // The opener is responsible for actually showing this widget.
1578 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351579 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351580
bokanc007c3a2015-02-03 07:15:561581 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441582 // that's okay. It'll be ignored if as_popup is false, or the browser
1583 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561584 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291585}
1586
[email protected]2533ce12009-05-09 00:02:241587void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381588 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241589 Send(new ViewHostMsg_Close(routing_id_));
1590}
1591
dgozmancf9039cd2015-04-06 12:01:311592void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551593 for (auto& observer : render_frames_)
1594 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311595}
1596
Blink Reformat1c4d759e2017-04-09 16:34:541597void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081598 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321599 if (is_swapped_out_) {
1600 // This widget is currently swapped out, and the active widget is in a
1601 // different process. Have the browser route the close request to the
1602 // active widget instead, so that the correct unload handlers are run.
1603 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1604 return;
1605 }
1606
initial.commit09911bf2008-07-26 23:55:291607 // If a page calls window.close() twice, we'll end up here twice, but that's
1608 // OK. It is safe to send multiple Close messages.
1609
[email protected]2533ce12009-05-09 00:02:241610 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1611 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1612 // could be closed before the JS finishes executing. So instead, post a
1613 // message back to the message loop, which won't run until the JS is
1614 // complete, and then the Close message can be sent.
Hajime Hoshiabb3c8f2017-12-04 18:41:391615 task_runner_->PostTask(FROM_HERE,
1616 base::BindOnce(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291617}
1618
1619void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031620 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381621 WillCloseLayerTreeView();
1622 compositor_.reset();
lfg8ff33912016-09-13 20:59:211623 if (webwidget_internal_) {
Blink Reformat1c4d759e2017-04-09 16:34:541624 webwidget_internal_->Close();
lfg8ff33912016-09-13 20:59:211625 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291626 }
1627}
1628
bokan841fdc72016-10-06 00:16:351629void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1630 DCHECK(window_rect);
1631 float scale = popup_origin_scale_for_emulation_;
1632 if (!scale)
1633 return;
1634 window_rect->x =
1635 popup_view_origin_for_emulation_.x() +
1636 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1637 window_rect->y =
1638 popup_view_origin_for_emulation_.y() +
1639 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1640}
1641
1642void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1643 DCHECK(window_rect);
1644 float scale = popup_origin_scale_for_emulation_;
1645 if (!scale)
1646 return;
1647 window_rect->x =
1648 popup_screen_origin_for_emulation_.x() +
1649 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1650 window_rect->y =
1651 popup_screen_origin_for_emulation_.y() +
1652 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1653}
1654
Blink Reformat1c4d759e2017-04-09 16:34:541655WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351656 WebRect rect;
bokan6b08cd22016-10-05 00:55:211657 if (pending_window_rect_count_) {
1658 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1659 // the RootWindowRect is probably going to return wrong results since the
1660 // browser may not have processed the Move yet. There isn't really anything
1661 // good to do in this case, and it shouldn't happen - since this size is
1662 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351663 rect = pending_window_rect_;
1664 } else {
1665 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211666 }
[email protected]2533ce12009-05-09 00:02:241667
bokan841fdc72016-10-06 00:16:351668 ScreenRectToEmulatedIfNeeded(&rect);
1669 return rect;
bokan6b08cd22016-10-05 00:55:211670}
1671
Blink Reformat1c4d759e2017-04-09 16:34:541672WebRect RenderWidget::ViewRect() {
bokan841fdc72016-10-06 00:16:351673 WebRect rect = view_screen_rect_;
1674 ScreenRectToEmulatedIfNeeded(&rect);
1675 return rect;
initial.commit09911bf2008-07-26 23:55:291676}
1677
Blink Reformat1c4d759e2017-04-09 16:34:541678void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301679 WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541680 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301681}
1682
Blink Reformat1c4d759e2017-04-09 16:34:541683void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
oshima33ec97cd2015-12-14 19:40:241684 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351685 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511686
[email protected]5b45ad42013-10-25 00:42:041687 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201688 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561689 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1690 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031691 } else {
bokanc007c3a2015-02-03 07:15:561692 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031693 }
initial.commit09911bf2008-07-26 23:55:291694 } else {
bokanc007c3a2015-02-03 07:15:561695 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291696 }
1697}
1698
[email protected]2533ce12009-05-09 00:02:241699void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1700 pending_window_rect_ = rect;
1701 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241702
bokan6b08cd22016-10-05 00:55:211703 // Popups don't get size updates back from the browser so just store the set
1704 // values.
Blink Reformat1c4d759e2017-04-09 16:34:541705 if (popup_type_ != blink::kWebPopupTypeNone) {
1706 window_screen_rect_ = rect;
1707 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241708 }
[email protected]d4547452008-08-28 18:36:371709}
1710
wjmacleanee244e02017-05-26 21:06:071711void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1712 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071713 has_host_context_menu_location_ = true;
1714 host_context_menu_location_ = location;
1715 if (GetWebWidget()) {
1716 GetWebWidget()->ShowContextMenu(
1717 static_cast<blink::WebMenuSourceType>(source_type));
1718 }
1719 has_host_context_menu_location_ = false;
1720}
1721
[email protected]fa7b1dc2010-06-23 17:53:041722void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261723 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111724 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:071725 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:111726 int selection_start,
1727 int selection_end) {
ekaramad5aff1942017-01-06 01:26:351728 if (!ShouldHandleImeEvents())
1729 return;
1730
brettw4b461082016-11-19 18:55:161731#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491732 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:111733 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:491734 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091735 return;
1736 }
1737#endif
[email protected]66fca5bc2013-05-23 06:58:291738 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011739 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011740 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541741 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:111742 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561743 replacement_range.IsValid()
1744 ? WebRange(replacement_range.start(), replacement_range.length())
1745 : WebRange(),
1746 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041747 // If we failed to set the composition text, then we need to let the browser
1748 // process to cancel the input method's ongoing composition session, to make
1749 // sure we are in a consistent state.
Dave Tapuska139a72f2017-09-06 21:57:031750 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:051751 if (mojom::WidgetInputHandlerHost* host =
1752 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1753 host->ImeCancelComposition();
1754 }
Dave Tapuska139a72f2017-09-06 21:57:031755 } else {
1756 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1757 }
[email protected]7f00efa2010-04-15 05:01:261758 }
nonafa291792016-08-10 02:36:181759 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041760}
1761
rlanday7efe2302017-01-11 00:14:281762void RenderWidget::OnImeCommitText(
1763 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111764 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:281765 const gfx::Range& replacement_range,
1766 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351767 if (!ShouldHandleImeEvents())
1768 return;
1769
brettw4b461082016-11-19 18:55:161770#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491771 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1772 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1773 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091774 return;
1775 }
1776#endif
[email protected]66fca5bc2013-05-23 06:58:291777 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391778 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261779 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541780 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:111781 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561782 replacement_range.IsValid()
1783 ? WebRange(replacement_range.start(), replacement_range.length())
1784 : WebRange(),
1785 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261786 }
aelias87b8f7c2016-09-14 03:19:291787 input_handler_->set_handling_input_event(false);
1788 UpdateCompositionInfo(false /* not an immediate request */);
1789}
1790
1791void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351792 if (!ShouldHandleImeEvents())
1793 return;
1794
brettw4b461082016-11-19 18:55:161795#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491796 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1797 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291798 return;
1799 }
1800#endif
1801
changwan38c3eb612016-12-09 01:45:561802 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291803 return;
1804 ImeEventGuard guard(this);
1805 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011806 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541807 controller->FinishComposingText(
1808 keep_selection ? WebInputMethodController::kKeepSelection
1809 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011810 }
fsamuele8326c742016-01-12 00:49:391811 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181812 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291813}
1814
oshimad5279032015-12-16 18:22:331815void RenderWidget::OnDeviceScaleFactorChanged() {
1816 if (!compositor_)
1817 return;
oshimad5279032015-12-16 18:22:331818 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181819 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331820 else
Blink Reformat1c4d759e2017-04-09 16:34:541821 compositor_->SetDeviceScaleFactor(device_scale_factor_);
oshimad5279032015-12-16 18:22:331822}
1823
[email protected]0bc1f572013-04-17 01:46:311824void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121825 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211826 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121827 return;
1828
[email protected]0bc1f572013-04-17 01:46:311829 // Even if the browser provides an empty damage rect, it's still expecting to
1830 // receive a repaint ack so just damage the entire widget bounds.
1831 if (size_to_paint.IsEmpty()) {
1832 size_to_paint = size_;
1833 }
1834
[email protected]ec7dc112008-08-06 05:30:121835 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051836 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311837 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121838}
1839
[email protected]4873c7d2009-07-16 06:36:281840void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
EhsanK955ba582017-11-30 21:14:401841 if (auto* frame = GetFocusedWebLocalFrameInWidget())
1842 frame->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111843}
1844
[email protected]80ad8622012-11-07 16:33:031845void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1846 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511847 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391848 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1849 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511850 } else {
mfomitchev2600fd7c2016-02-17 20:53:391851 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511852 }
[email protected]80ad8622012-11-07 16:33:031853 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1854}
1855
lfgdb5c4ed2016-03-04 23:09:071856void RenderWidget::OnUpdateWindowScreenRect(
1857 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211858 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071859 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211860 else
lfgdb5c4ed2016-03-04 23:09:071861 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071862}
1863
kenrbea731792017-01-13 15:10:481864void RenderWidget::OnSetViewportIntersection(
1865 const gfx::Rect& viewport_intersection) {
Ken Buchanan8a319fb2017-11-15 18:37:121866 if (GetWebWidget()) {
1867 DCHECK(GetWebWidget()->IsWebFrameWidget());
1868 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
kenrbea731792017-01-13 15:10:481869 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541870 ->SetRemoteViewportIntersection(viewport_intersection);
kenrbea731792017-01-13 15:10:481871 }
1872}
1873
kenrb04323782017-06-23 01:23:321874void RenderWidget::OnSetIsInert(bool inert) {
Ken Buchanan8a319fb2017-11-15 18:37:121875 if (GetWebWidget()) {
1876 DCHECK(GetWebWidget()->IsWebFrameWidget());
1877 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
kenrb04323782017-06-23 01:23:321878 static_cast<WebFrameWidget*>(GetWebWidget())->SetIsInert(inert);
1879 }
1880}
1881
Ken Buchanan8a319fb2017-11-15 18:37:121882void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled,
1883 bool subtree_throttled) {
1884 if (GetWebWidget()) {
1885 DCHECK(GetWebWidget()->IsWebFrameWidget());
1886 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
1887 static_cast<WebFrameWidget*>(GetWebWidget())
1888 ->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled);
1889 }
1890}
1891
paulmeyer90f6c31d2016-11-12 00:17:591892void RenderWidget::OnDragTargetDragEnter(
1893 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:521894 const gfx::PointF& client_point,
1895 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:591896 WebDragOperationsMask ops,
1897 int key_modifiers) {
1898 if (!GetWebWidget())
1899 return;
1900
Blink Reformat1c4d759e2017-04-09 16:34:541901 DCHECK(GetWebWidget()->IsWebFrameWidget());
1902 WebDragOperation operation =
1903 static_cast<WebFrameWidget*>(GetWebWidget())
1904 ->DragTargetDragEnter(DropMetaDataToWebDragData(drop_meta_data),
1905 client_point, screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591906
1907 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1908}
1909
Ella Ge80a52dce2017-11-15 18:01:521910void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point,
1911 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:591912 WebDragOperationsMask ops,
1913 int key_modifiers) {
1914 if (!GetWebWidget())
1915 return;
1916
Blink Reformat1c4d759e2017-04-09 16:34:541917 DCHECK(GetWebWidget()->IsWebFrameWidget());
paulmeyer90f6c31d2016-11-12 00:17:591918 WebDragOperation operation =
Blink Reformat1c4d759e2017-04-09 16:34:541919 static_cast<WebFrameWidget*>(GetWebWidget())
1920 ->DragTargetDragOver(ConvertWindowPointToViewport(client_point),
1921 screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591922
1923 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1924}
1925
Ella Ge80a52dce2017-11-15 18:01:521926void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point,
1927 const gfx::PointF& screen_point) {
paulmeyer90f6c31d2016-11-12 00:17:591928 if (!GetWebWidget())
1929 return;
Blink Reformat1c4d759e2017-04-09 16:34:541930 DCHECK(GetWebWidget()->IsWebFrameWidget());
kenrb07c272802017-02-07 23:48:171931 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541932 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:171933 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:591934}
1935
1936void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:521937 const gfx::PointF& client_point,
1938 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:591939 int key_modifiers) {
1940 if (!GetWebWidget())
1941 return;
1942
Blink Reformat1c4d759e2017-04-09 16:34:541943 DCHECK(GetWebWidget()->IsWebFrameWidget());
1944 static_cast<WebFrameWidget*>(GetWebWidget())
1945 ->DragTargetDrop(DropDataToWebDragData(drop_data),
1946 ConvertWindowPointToViewport(client_point), screen_point,
1947 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591948}
1949
Ella Ge80a52dce2017-11-15 18:01:521950void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point,
1951 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:211952 WebDragOperation op) {
1953 if (!GetWebWidget())
1954 return;
1955
Blink Reformat1c4d759e2017-04-09 16:34:541956 static_cast<WebFrameWidget*>(GetWebWidget())
1957 ->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
1958 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:211959}
1960
1961void RenderWidget::OnDragSourceSystemDragEnded() {
1962 if (!GetWebWidget())
1963 return;
1964
Blink Reformat1c4d759e2017-04-09 16:34:541965 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:211966}
1967
Blink Reformat1c4d759e2017-04-09 16:34:541968void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:261969#if defined(OS_CHROMEOS)
1970 // On ChromeOS, virtual keyboard is triggered only when users leave the
1971 // mouse button or the finger and a text input element is focused at that
1972 // time. Focus event itself shouldn't trigger virtual keyboard.
1973 UpdateTextInputState();
1974#else
changwan75e3b2072017-01-16 02:55:001975 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:261976#endif
boliu7b2be2f2016-11-04 04:58:311977
1978// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1979// virtual keyboard.
1980#if !defined(OS_ANDROID)
1981 FocusChangeComplete();
1982#endif
[email protected]0d1ebed12013-08-05 22:01:131983}
1984
fsamuel72464894f2015-12-15 06:59:311985ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:161986#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491987 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
1988 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:091989#endif
ekaramad5aff1942017-01-06 01:26:351990 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541991 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:311992 return ui::TEXT_INPUT_TYPE_NONE;
1993}
1994
nonafa291792016-08-10 02:36:181995void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1996 if (!monitor_composition_info_ && !immediate_request)
1997 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591998
nonafa291792016-08-10 02:36:181999 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
2000 gfx::Range range;
2001 std::vector<gfx::Rect> character_bounds;
2002
2003 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
2004 // Composition information is only available on editable node.
2005 range = gfx::Range::InvalidRange();
2006 } else {
2007 GetCompositionRange(&range);
2008 GetCompositionCharacterBounds(&character_bounds);
2009 }
2010
2011 if (!immediate_request &&
2012 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:312013 return;
nonafa291792016-08-10 02:36:182014 }
fsamuel72464894f2015-12-15 06:59:312015 composition_character_bounds_ = character_bounds;
2016 composition_range_ = range;
Dave Tapuska139a72f2017-09-06 21:57:032017 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:052018 if (mojom::WidgetInputHandlerHost* host =
2019 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
2020 host->ImeCompositionRangeChanged(composition_range_,
2021 composition_character_bounds_);
2022 }
Dave Tapuska139a72f2017-09-06 21:57:032023 } else {
2024 Send(new InputHostMsg_ImeCompositionRangeChanged(
2025 routing_id(), composition_range_, composition_character_bounds_));
2026 }
fsamuel72464894f2015-12-15 06:59:312027}
2028
Blink Reformat1c4d759e2017-04-09 16:34:542029void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:542030 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:462031 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:332032 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:542033 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:462034 gfx::Rect window_rect =
2035 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
2036 rect->x = window_rect.x();
2037 rect->y = window_rect.y();
2038 rect->width = window_rect.width();
2039 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:542040 }
2041}
2042
Blink Reformat1c4d759e2017-04-09 16:34:542043void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
oshimaa6985b62016-01-27 08:58:302044 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:182045 rect->x *= GetOriginalDeviceScaleFactor();
2046 rect->y *= GetOriginalDeviceScaleFactor();
2047 rect->width *= GetOriginalDeviceScaleFactor();
2048 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:302049 }
2050}
2051
changwan8c342742016-02-26 00:53:392052void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:262053#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392054 DCHECK(!ime_event_guard_);
2055 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:002056 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212057#endif
Dave Tapuska9db80842017-07-24 17:24:262058}
[email protected]105dffb42013-02-20 03:46:212059
ekaramadc9b70a72017-03-23 16:14:232060void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2061 bool monitor_updates) {
2062 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182063 if (!immediate_request)
2064 return;
2065 UpdateCompositionInfo(true /* immediate request */);
2066}
2067
[email protected]fcdc5642014-05-09 14:32:242068void RenderWidget::OnOrientationChange() {
lfg8d649cc2017-04-28 18:04:302069 WebWidget* web_widget = GetWebWidget();
2070 if (web_widget && web_widget->IsWebFrameWidget()) {
2071 WebFrameWidget* web_frame_widget = static_cast<WebFrameWidget*>(web_widget);
Alex Moshchuk0b409c42017-09-13 02:09:002072 // LocalRoot() might return null for provisional main frames. In this case,
2073 // the frame hasn't committed a navigation and is not swapped into the tree
2074 // yet, so it doesn't make sense to send orientation change events to it.
2075 //
2076 // TODO(https://crbug.com/578349): This check should be cleaned up
2077 // once provisional frames are gone.
2078 if (web_frame_widget->LocalRoot())
2079 web_frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302080 }
[email protected]fcdc5642014-05-09 14:32:242081}
2082
[email protected]bee16aab2009-08-26 15:55:032083void RenderWidget::SetHidden(bool hidden) {
2084 if (is_hidden_ == hidden)
2085 return;
2086
jdduke8fac9d102014-12-20 02:40:132087 // The status has changed. Tell the RenderThread about it and ensure
2088 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032089 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132090
Scott Violet1098538e2017-10-05 19:23:332091#if defined(USE_AURA)
Sadrul Habib Chowdhury1dbe3b42017-11-18 02:27:432092 if (IsRunningWithMus())
Scott Violet1098538e2017-10-05 19:23:332093 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden);
2094#endif
2095
tasakb95dbb50c2017-02-08 18:07:502096 if (is_hidden_) {
[email protected]b2db9272014-01-10 17:42:002097 RenderThreadImpl::current()->WidgetHidden();
Takashi SAKAMOTO870f6262017-08-22 04:08:272098 first_update_visual_state_after_hidden_ = true;
Lei Zhang9b359d32017-11-28 00:57:022099 } else {
[email protected]b2db9272014-01-10 17:42:002100 RenderThreadImpl::current()->WidgetRestored();
Lei Zhang9b359d32017-11-28 00:57:022101 }
alexclarke7fa93942015-10-21 15:37:112102
2103 if (render_widget_scheduling_state_)
2104 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:032105}
2106
[email protected]2b624c562011-10-27 22:58:262107void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212108 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262109 return;
2110
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122111 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542112 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262113 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542114 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262115 }
[email protected]2b624c562011-10-27 22:58:262116}
2117
[email protected]674741932009-02-04 23:44:462118bool RenderWidget::next_paint_is_resize_ack() const {
Fady Samuelcc3e3b4a2017-10-03 02:09:212119 return ViewHostMsg_ResizeOrRepaint_ACK_Flags::is_resize_ack(
2120 next_paint_flags_);
[email protected]674741932009-02-04 23:44:462121}
2122
[email protected]674741932009-02-04 23:44:462123void RenderWidget::set_next_paint_is_resize_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212124 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462125}
2126
[email protected]674741932009-02-04 23:44:462127void RenderWidget::set_next_paint_is_repaint_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212128 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462129}
2130
changwanf2a707b2015-10-30 08:22:162131void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2132 if (!ime_event_guard_)
2133 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292134}
2135
changwanf2a707b2015-10-30 08:22:162136void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
2137 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:002138 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:162139 return;
2140 }
2141 ime_event_guard_ = nullptr;
2142
[email protected]66fca5bc2013-05-23 06:58:292143 // While handling an ime event, text input state and selection bounds updates
2144 // are ignored. These must explicitly be updated once finished handling the
2145 // ime event.
2146 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472147#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002148 if (guard->show_virtual_keyboard())
2149 ShowVirtualKeyboard();
2150 else
2151 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472152#endif
[email protected]66fca5bc2013-05-23 06:58:292153}
2154
[email protected]7c8873e2013-02-05 08:03:012155void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162156#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492157 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092158 // TODO(kinaba) http://crbug.com/101101
2159 // Current Pepper IME API does not handle selection bounds. So we simply
2160 // use the caret position as an empty range for now. It will be updated
2161 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492162 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542163 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092164 *focus = caret;
2165 *anchor = caret;
2166 return;
2167 }
2168#endif
[email protected]7c8873e2013-02-05 08:03:012169 WebRect focus_webrect;
2170 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542171 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2172 ConvertViewportToWindow(&focus_webrect);
2173 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242174 *focus = focus_webrect;
2175 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322176}
2177
[email protected]e99ef6f2011-10-16 01:13:002178void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082179 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212180 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002181 return;
changwanf2a707b2015-10-30 08:22:162182 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292183 return;
[email protected]e99ef6f2011-10-16 01:13:002184
mohsenb0eeba72015-08-09 06:20:082185#if defined(USE_AURA)
2186 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2187 // Aura beucause composited selection updates are not working for webview tags
2188 // which regresses IME inside webview. Remove this when composited selection
2189 // updates are fixed for webviews. See, http://crbug.com/510568.
2190 bool send_ipc = true;
2191#else
jddukeacf809e2014-09-23 20:38:382192 // With composited selection updates, the selection bounds will be reported
2193 // directly by the compositor, in which case explicit IPC selection
2194 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082195 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542196 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082197#endif
2198 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382199 ViewHostMsg_SelectionBounds_Params params;
EhsanK955ba582017-11-30 21:14:402200 params.is_anchor_first = false;
jddukeacf809e2014-09-23 20:38:382201 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2202 if (selection_anchor_rect_ != params.anchor_rect ||
2203 selection_focus_rect_ != params.focus_rect) {
2204 selection_anchor_rect_ = params.anchor_rect;
2205 selection_focus_rect_ = params.focus_rect;
EhsanK955ba582017-11-30 21:14:402206 if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) {
2207 focused_frame->SelectionTextDirection(params.focus_dir,
2208 params.anchor_dir);
2209 params.is_anchor_first = focused_frame->IsSelectionAnchorFirst();
2210 }
jddukeacf809e2014-09-23 20:38:382211 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2212 }
[email protected]58b48a0d2012-06-13 07:01:352213 }
jddukeacf809e2014-09-23 20:38:382214
nonafa291792016-08-10 02:36:182215 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002216}
2217
lfgb00fcad2016-07-14 14:16:332218void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2219 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542220 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332221 if (size_.width() != new_size_in_window.width ||
2222 size_.height() != new_size_in_window.height) {
2223 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2224
2225 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542226 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2227 size_.height());
lfgb00fcad2016-07-14 14:16:332228 view_screen_rect_ = new_pos;
2229 window_screen_rect_ = new_pos;
2230 }
2231
Fady Samueld10aadd82017-11-03 18:23:572232 AutoResizeCompositor(viz::LocalSurfaceId());
lfgb00fcad2016-07-14 14:16:332233
Fady Samuel319e429c2017-10-02 18:31:552234 if (!resizing_mode_selector_->is_synchronous_mode()) {
Fady Samueld10aadd82017-11-03 18:23:572235 need_resize_ack_for_auto_resize_ = true;
Fady Samuel319e429c2017-10-02 18:31:552236 // If surface synchronization is off, then ResizeAcks go to the browser in
2237 // response to a DidReceiveCompositorFrame. With surface synchronization
2238 // on, that notification will not arrive here because the compositor is
2239 // deferring commits and thus submission of CompositorFrames.
2240 if (!size_.IsEmpty() && compositor_ &&
2241 compositor_->IsSurfaceSynchronizationEnabled()) {
Fady Samuelcc3e3b4a2017-10-03 02:09:212242 DidResizeOrRepaintAck();
Fady Samuel319e429c2017-10-02 18:31:552243 }
2244 }
lfgb00fcad2016-07-14 14:16:332245 }
2246}
2247
[email protected]58b48a0d2012-06-13 07:01:352248void RenderWidget::GetCompositionCharacterBounds(
2249 std::vector<gfx::Rect>* bounds) {
2250 DCHECK(bounds);
2251 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092252
brettw4b461082016-11-19 18:55:162253#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492254 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092255 return;
2256#endif
2257
lfg8ff33912016-09-13 20:59:212258 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:092259 return;
2260 blink::WebVector<blink::WebRect> bounds_from_blink;
Blink Reformat1c4d759e2017-04-09 16:34:542261 if (!GetWebWidget()->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092262 return;
2263
2264 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542265 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092266 bounds->push_back(bounds_from_blink[i]);
2267 }
[email protected]58b48a0d2012-06-13 07:01:352268}
2269
[email protected]db4fc1e2013-09-06 20:01:512270void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162271#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492272 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092273 return;
2274#endif
EhsanKcdee7b72017-11-08 21:30:092275 blink::WebInputMethodController* controller = GetInputMethodController();
2276 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542277 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212278 *range = gfx::Range::InvalidRange();
2279 return;
[email protected]88dbe32f2013-06-20 23:31:362280 }
Blink Reformat1c4d759e2017-04-09 16:34:542281 range->set_start(web_range.StartOffset());
2282 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362283}
2284
[email protected]501ea13d2013-07-09 17:03:292285bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512286 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292287 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082288 if (!range.IsValid())
2289 return false;
[email protected]501ea13d2013-07-09 17:03:292290 if (composition_range_ != range)
2291 return true;
2292 if (bounds.size() != composition_character_bounds_.size())
2293 return true;
2294 for (size_t i = 0; i < bounds.size(); ++i) {
2295 if (bounds[i] != composition_character_bounds_[i])
2296 return true;
2297 }
2298 return false;
2299}
[email protected]501ea13d2013-07-09 17:03:292300
[email protected]ad26ef42011-06-17 07:59:452301bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162302#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492303 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2304 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092305#endif
[email protected]ad26ef42011-06-17 07:59:452306 return true;
[email protected]56ea1a62011-05-30 07:05:572307}
2308
Blink Reformat1c4d759e2017-04-09 16:34:542309blink::WebScreenInfo RenderWidget::GetScreenInfo() {
ccameron2f451532016-09-07 21:49:272310 blink::WebScreenInfo web_screen_info;
Blink Reformat1c4d759e2017-04-09 16:34:542311 web_screen_info.device_scale_factor = screen_info_.device_scale_factor;
ccameronab0aab82017-06-24 17:21:542312 web_screen_info.color_space = screen_info_.color_space;
ccameron2f451532016-09-07 21:49:272313 web_screen_info.depth = screen_info_.depth;
Blink Reformat1c4d759e2017-04-09 16:34:542314 web_screen_info.depth_per_component = screen_info_.depth_per_component;
2315 web_screen_info.is_monochrome = screen_info_.is_monochrome;
ccameron2f451532016-09-07 21:49:272316 web_screen_info.rect = blink::WebRect(screen_info_.rect);
Blink Reformat1c4d759e2017-04-09 16:34:542317 web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect);
ccameron2f451532016-09-07 21:49:272318 switch (screen_info_.orientation_type) {
2319 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542320 web_screen_info.orientation_type =
2321 blink::kWebScreenOrientationPortraitPrimary;
ccameron2f451532016-09-07 21:49:272322 break;
2323 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542324 web_screen_info.orientation_type =
2325 blink::kWebScreenOrientationPortraitSecondary;
ccameron2f451532016-09-07 21:49:272326 break;
2327 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542328 web_screen_info.orientation_type =
2329 blink::kWebScreenOrientationLandscapePrimary;
ccameron2f451532016-09-07 21:49:272330 break;
2331 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542332 web_screen_info.orientation_type =
2333 blink::kWebScreenOrientationLandscapeSecondary;
ccameron2f451532016-09-07 21:49:272334 break;
2335 default:
Blink Reformat1c4d759e2017-04-09 16:34:542336 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
ccameron2f451532016-09-07 21:49:272337 break;
2338 }
Blink Reformat1c4d759e2017-04-09 16:34:542339 web_screen_info.orientation_angle = screen_info_.orientation_angle;
Fady Samuel85a1bf72017-10-27 14:30:202340
ccameron2f451532016-09-07 21:49:272341 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282342}
2343
donnda070f3c2015-01-16 19:54:112344#if defined(OS_ANDROID)
Donn Denman43a439e2017-08-29 04:20:452345void RenderWidget::ShowUnhandledTapUIIfNeeded(
2346 const WebTappedInfo& tapped_info) {
2347 // Unpack tapped_info. TODO(donnd): inline unpacking.
2348 bool page_changed = tapped_info.PageChanged();
2349 const WebNode& tapped_node = tapped_info.GetNode();
2350 const WebPoint& tapped_position = tapped_info.Position();
Blink Reformat1c4d759e2017-04-09 16:34:542351 bool should_trigger = !page_changed && tapped_node.IsTextNode() &&
2352 !tapped_node.IsContentEditable() &&
2353 !tapped_node.IsInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112354 if (should_trigger) {
Jaebaek Seo655110e2017-12-19 23:27:392355 float x_px = UseZoomForDSFEnabled()
2356 ? tapped_position.x
2357 : tapped_position.x * device_scale_factor_;
2358 float y_px = UseZoomForDSFEnabled()
2359 ? tapped_position.y
2360 : tapped_position.y * device_scale_factor_;
2361 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_, x_px, y_px));
donnda070f3c2015-01-16 19:54:112362 }
2363}
2364#endif
2365
Blink Reformat1c4d759e2017-04-09 16:34:542366void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2367 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022368#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562369 if (event_cancelled)
2370 return;
Blink Reformat1c4d759e2017-04-09 16:34:542371 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002372 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542373 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212374 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352375 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542376 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002377 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462378 else
changwan75e3b2072017-01-16 02:55:002379 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562380 }
ekaramada110f642016-12-21 19:47:282381// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2382// crbug/420130.
2383#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:542384 if (event.GetType() != blink::WebGestureEvent::kGestureTap)
ekaramada110f642016-12-21 19:47:282385 return;
2386
2387 // TODO(estade): hit test the event against focused node to make sure
2388 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352389 blink::WebInputMethodController* controller = GetInputMethodController();
2390 blink::WebTextInputType text_input_type =
Blink Reformat1c4d759e2017-04-09 16:34:542391 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282392
2393 Send(new ViewHostMsg_FocusedNodeTouched(
Blink Reformat1c4d759e2017-04-09 16:34:542394 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
ekaramada110f642016-12-21 19:47:282395#endif
[email protected]c68c3e4e2013-01-24 00:36:562396#endif
2397}
2398
Blink Reformat1c4d759e2017-04-09 16:34:542399void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312400 const blink::WebFloatSize& overscrollDelta,
2401 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422402 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:542403 const blink::WebFloatSize& velocity,
Sandra Sun2288e8532017-11-30 22:50:162404 const blink::WebOverscrollBehavior& behavior) {
bokan731ec382016-04-07 03:16:482405#if defined(OS_MACOSX)
2406 // On OSX the user can disable the elastic overscroll effect. If that's the
2407 // case, don't forward the overscroll notification.
2408 DCHECK(compositor_deps());
2409 if (!compositor_deps()->IsElasticOverscrollEnabled())
2410 return;
2411#endif
bokane53a10f2016-04-13 23:48:312412 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:542413 position, velocity, behavior);
sataya.m582c9ce2015-06-09 08:03:422414}
2415
[email protected]7912e822014-04-16 02:37:032416void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392417 if (!is_hidden())
Blink Reformat1c4d759e2017-04-09 16:34:542418 compositor_->SetVisible(true);
[email protected]7912e822014-04-16 02:37:032419}
2420
[email protected]24ed0432013-04-24 07:50:312421RenderWidgetCompositor* RenderWidget::compositor() const {
2422 return compositor_.get();
2423}
2424
fsamuel72464894f2015-12-15 06:59:312425void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392426 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372427}
[email protected]c3d45532011-10-07 19:20:402428
Blink Reformat1c4d759e2017-04-09 16:34:542429void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112430 if (render_widget_scheduling_state_)
2431 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552432 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2433}
2434
Dave Tapuskadfe486c12017-06-09 16:53:132435void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
2436 if (input_event_queue_)
2437 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
2438}
2439
Dave Tapuskabafc2ba32017-11-28 01:54:372440void RenderWidget::RequestUnbufferedInputEvents() {
2441 if (input_event_queue_)
2442 input_event_queue_->RequestUnbufferedInputEvents();
2443}
2444
xidachenfa0199e72017-05-11 11:34:262445void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:262446 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:512447 return;
2448
Dave Tapuska139a72f2017-09-06 21:57:032449 if (widget_input_handler_manager_) {
2450 widget_input_handler_manager_->ProcessTouchAction(touch_action);
2451 } else {
2452 Send(new InputHostMsg_SetTouchAction(routing_id_, touch_action));
2453 }
[email protected]5d0bbdfa92013-12-10 00:35:512454}
2455
[email protected]e3244ed2014-06-20 20:04:272456void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2457 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162458}
2459
[email protected]e3244ed2014-06-20 20:04:272460void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2461 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162462}
2463
[email protected]de3c5d82014-05-28 22:12:592464void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2465 render_frames_.AddObserver(frame);
2466}
2467
2468void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2469 render_frames_.RemoveObserver(frame);
2470}
2471
lfg43e08e62016-02-03 18:51:372472void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2473 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2474 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2475}
2476
oshima50872a72016-03-04 13:26:182477float RenderWidget::GetOriginalDeviceScaleFactor() const {
2478 return
2479 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272480 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182481 device_scale_factor_;
2482}
2483
Ella Ge80a52dce2017-11-15 18:01:522484gfx::PointF RenderWidget::ConvertWindowPointToViewport(
2485 const gfx::PointF& point) {
paulmeyer90f6c31d2016-11-12 00:17:592486 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542487 ConvertWindowToViewport(&point_in_viewport);
Ella Ge80a52dce2017-11-15 18:01:522488 return gfx::PointF(point_in_viewport.x, point_in_viewport.y);
2489}
2490
2491gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) {
2492 return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point)));
paulmeyer90f6c31d2016-11-12 00:17:592493}
2494
Blink Reformat1c4d759e2017-04-09 16:34:542495bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:212496 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2497}
2498
Blink Reformat1c4d759e2017-04-09 16:34:542499void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:212500 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2501}
2502
Blink Reformat1c4d759e2017-04-09 16:34:542503bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:212504 return mouse_lock_dispatcher_->IsMouseLockedTo(
2505 webwidget_mouse_lock_target_.get());
2506}
2507
Blink Reformat1c4d759e2017-04-09 16:34:542508void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:582509 const WebDragData& data,
2510 WebDragOperationsMask mask,
2511 const WebImage& image,
2512 const WebPoint& webImageOffset) {
2513 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542514 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:582515 DropData drop_data(DropDataBuilder::Build(data));
2516 drop_data.referrer_policy = policy;
2517 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592518 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
Blink Reformat1c4d759e2017-04-09 16:34:542519 image.GetSkBitmap(), imageOffset,
paulmeyer6ef5a792016-11-08 20:33:582520 possible_drag_event_info_));
2521}
2522
kenrb5d78b842017-03-06 21:06:012523uint32_t RenderWidget::GetContentSourceId() {
2524 return current_content_source_id_;
2525}
2526
2527void RenderWidget::IncrementContentSourceId() {
2528 if (compositor_)
2529 compositor_->SetContentSourceId(++current_content_source_id_);
2530}
2531
lfg8ff33912016-09-13 20:59:212532blink::WebWidget* RenderWidget::GetWebWidget() const {
2533 return webwidget_internal_;
2534}
2535
ekaramad2daaf672016-11-10 20:29:012536blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2537 const {
Blink Reformat1c4d759e2017-04-09 16:34:542538 if (!GetWebWidget()->IsWebFrameWidget()) {
ekaramad5a9f52a2016-12-07 01:35:182539 // TODO(ekaramad): We should not get here in response to IME IPC or updates
2540 // when the RenderWidget is swapped out. We should top sending IPCs from the
2541 // browser side (https://crbug.com/669219).
2542 // If there is no WebFrameWidget, then there will be no
2543 // InputMethodControllers for a WebLocalFrame.
2544 return nullptr;
2545 }
ekaramad2daaf672016-11-10 20:29:012546 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:542547 ->GetActiveWebInputMethodController();
ekaramad2daaf672016-11-10 20:29:012548}
2549
Dave Tapuska139a72f2017-09-06 21:57:032550void RenderWidget::SetupWidgetInputHandler(
2551 mojom::WidgetInputHandlerRequest request,
2552 mojom::WidgetInputHandlerHostPtr host) {
Dave Tapuskab66c28f2017-11-15 17:18:472553 widget_input_handler_manager_->AddInterface(std::move(request),
2554 std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:502555}
2556
Dave Tapuska485aca92017-08-08 00:47:582557void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
2558 // Close the old binding if there was one.
2559 // A RenderWidgetHost should not need more than one channel.
2560 widget_binding_.Close();
2561 widget_binding_.Bind(std::move(request));
2562}
2563
Fady Samuelcc3e3b4a2017-10-03 02:09:212564void RenderWidget::DidResizeOrRepaintAck() {
Fady Samueld10aadd82017-11-03 18:23:572565 if (!next_paint_flags_ && !need_resize_ack_for_auto_resize_)
Fady Samuel319e429c2017-10-02 18:31:552566 return;
2567
Fady Samuelcc3e3b4a2017-10-03 02:09:212568 ViewHostMsg_ResizeOrRepaint_ACK_Params params;
Fady Samuel319e429c2017-10-02 18:31:552569 params.view_size = size_;
2570 params.flags = next_paint_flags_;
2571 params.sequence_number = ++resize_or_repaint_ack_num_;
2572
Fady Samuelcc3e3b4a2017-10-03 02:09:212573 Send(new ViewHostMsg_ResizeOrRepaint_ACK(routing_id_, params));
Fady Samuel319e429c2017-10-02 18:31:552574 next_paint_flags_ = 0;
Fady Samueld10aadd82017-11-03 18:23:572575 need_resize_ack_for_auto_resize_ = false;
Fady Samuel319e429c2017-10-02 18:31:552576}
2577
Khushal3e96e662017-10-30 23:16:502578void RenderWidget::UpdateURLForCompositorUkm() {
2579 DCHECK(compositor_);
2580
2581 if (!GetWebWidget() || !GetWebWidget()->IsWebFrameWidget())
2582 return;
2583
2584 auto* render_frame = RenderFrameImpl::FromWebFrame(
2585 static_cast<blink::WebFrameWidget*>(GetWebWidget())->LocalRoot());
2586 if (!render_frame->IsMainFrame())
2587 return;
2588
2589 compositor_->SetURLForUkm(render_frame->GetWebFrame()->GetDocument().Url());
2590}
2591
EhsanK955ba582017-11-30 21:14:402592blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const {
2593 if (!GetWebWidget() || !GetWebWidget()->IsWebFrameWidget())
2594 return nullptr;
2595 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
2596 ->FocusedWebLocalFrameInWidget();
2597}
2598
EhsanK22d482e2017-08-10 17:29:492599#if BUILDFLAG(ENABLE_PLUGINS)
2600PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
2601 if (!GetWebWidget() || !GetWebWidget()->IsWebFrameWidget())
2602 return nullptr;
2603
2604 // Focused pepper instance might not always be in the focused frame. For
2605 // instance if a pepper instance and its embedder frame are focused an then
2606 // another frame takes focus using javascript, the embedder frame will no
2607 // longer be focused while the pepper instance is (the embedder frame's
2608 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
2609 // is fullscreen, clicking into the pepper will not refocus the embedder
2610 // frame. This is why we have to traverse the whole frame tree to find the
2611 // focused plugin.
2612 blink::WebFrame* current_frame =
2613 static_cast<blink::WebFrameWidget*>(GetWebWidget())->LocalRoot();
2614 while (current_frame) {
2615 RenderFrameImpl* render_frame =
2616 current_frame->IsWebLocalFrame()
2617 ? RenderFrameImpl::FromWebFrame(current_frame)
2618 : nullptr;
2619 if (render_frame && render_frame->focused_pepper_plugin())
2620 return render_frame->focused_pepper_plugin();
2621 current_frame = current_frame->TraverseNext();
2622 }
2623 return nullptr;
2624}
2625#endif
2626
[email protected]e9ff79c2012-10-19 21:31:262627} // namespace content