blob: 1dbfe83aafcff7cb7ad96519db90b1e93fa021b7 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// 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]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
avib7348942015-12-25 20:57:107#include <stddef.h>
8
w.shackleton49bcd392016-01-06 17:38:229#include <cmath>
[email protected]2bb171882012-03-07 02:09:4610#include <utility>
rkaplowe56a52032017-02-07 00:14:5411#include <vector>
[email protected]b75b8292010-10-01 07:28:2512
[email protected]36fb2c7c2011-04-04 15:49:0813#include "base/command_line.h"
creisfafed882016-07-29 00:03:0914#include "base/debug/dump_without_crashing.h"
zqzhang181047e62016-07-01 13:37:1715#include "base/feature_list.h"
jinsukkim79df88a2017-01-04 06:26:1516#include "base/i18n/character_encoding.h"
[email protected]cbb1ef592013-06-05 19:49:4617#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0718#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5619#include "base/logging.h"
avib7348942015-12-25 20:57:1020#include "base/macros.h"
fdorayba121422016-12-23 19:51:4821#include "base/memory/ptr_util.h"
dmazzonid95ae842016-04-12 21:17:3922#include "base/memory/ref_counted.h"
asvitkine8d51e9d2016-09-02 23:55:4323#include "base/metrics/histogram_macros.h"
bratell0a7406f2017-03-28 07:46:3724#include "base/metrics/user_metrics.h"
Avi Drissman4891b852018-09-25 18:12:5825#include "base/no_destructor.h"
[email protected]04cbd3d2013-12-04 04:58:2026#include "base/process/process.h"
skyostil95082a62015-06-05 19:53:0727#include "base/single_thread_task_runner.h"
Arthur Sonzogni929d29f2018-09-17 14:19:4428#include "base/stl_util.h"
[email protected]348fbaac2013-06-11 06:31:5129#include "base/strings/string16.h"
30#include "base/strings/string_number_conversions.h"
Avi Drissman4891b852018-09-25 18:12:5831#include "base/strings/string_split.h"
[email protected]348fbaac2013-06-11 06:31:5132#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0033#include "base/strings/utf_string_conversions.h"
Eric Seckler8652dcd52018-09-20 10:42:2834#include "base/task/post_task.h"
gab30f26df2016-05-11 19:37:5535#include "base/threading/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3736#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4237#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1038#include "build/build_config.h"
Min Qinda0ed2062018-02-23 22:00:5339#include "components/download/public/common/download_stats.h"
nzolghadrd87a308d2016-12-07 15:45:5640#include "components/rappor/public/rappor_utils.h"
rsleevi24f64dc22015-08-07 21:39:2141#include "components/url_formatter/url_formatter.h"
James Wallace-Leeeafc94cb92018-07-23 21:35:0942#include "content/browser/accessibility/accessibility_tree_formatter.h"
43#include "content/browser/accessibility/accessibility_tree_formatter_blink.h"
[email protected]95640212014-07-26 18:14:3044#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1845#include "content/browser/bad_message.h"
Max Morinddebb972018-09-20 10:04:1446#include "content/browser/browser_main_loop.h"
[email protected]7a846df2012-09-20 19:17:3947#include "content/browser/browser_plugin/browser_plugin_embedder.h"
48#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5949#include "content/browser/child_process_security_policy_impl.h"
Pavel Feldman3c1842b2017-08-02 05:00:1650#include "content/browser/devtools/protocol/page_handler.h"
dgozmanf00c4f72016-10-19 17:45:1551#include "content/browser/devtools/render_frame_devtools_agent_host.h"
Becca Hughes3b5a43482018-07-17 22:31:5552#include "content/browser/display_cutout/display_cutout_host_impl.h"
[email protected]5f2aa722013-08-07 16:59:4153#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0454#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]aa4f3972012-03-01 18:12:1255#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1656#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1757#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1658#include "content/browser/frame_host/cross_process_frame_connector.h"
ananta4b7467a52016-09-23 01:42:3859#include "content/browser/frame_host/frame_tree_node.h"
[email protected]d4a8ca482013-10-30 21:06:4060#include "content/browser/frame_host/interstitial_page_impl.h"
61#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3362#include "content/browser/frame_host/navigation_handle_impl.h"
Arthur Hemeryc3380172018-01-22 14:00:1763#include "content/browser/frame_host/navigation_request.h"
[email protected]6ea6bdf2013-12-06 13:35:0164#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1865#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0766#include "content/browser/frame_host/render_frame_proxy_host.h"
Kenneth Russell954ed9ce2018-04-12 23:07:0167#include "content/browser/gpu/gpu_data_manager_impl.h"
csharrison2e8c98e2016-08-01 23:56:2568#include "content/browser/loader/loader_io_thread_notifier.h"
[email protected]678c0362012-12-05 08:02:4469#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4070#include "content/browser/manifest/manifest_manager_host.h"
Max Morin5bc74f52018-05-09 07:00:2171#include "content/browser/media/audio_stream_broker.h"
dalecurtisbc6572e12014-09-12 19:22:3072#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5273#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1874#include "content/browser/media/media_web_contents_observer.h"
zqzhang1adf3cb2016-11-01 11:26:4575#include "content/browser/media/session/media_session_impl.h"
tommyclieb25b2a2014-11-03 19:45:0976#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3077#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5078#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3279#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5080#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5981#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4882#include "content/browser/renderer_host/render_widget_host_view_base.h"
Ken Buchanandaef006b2017-08-17 18:32:1583#include "content/browser/renderer_host/render_widget_host_view_child_frame.h"
ekaramadadd882292016-06-08 15:22:5684#include "content/browser/renderer_host/text_input_manager.h"
leon.han552e9de2017-02-09 14:37:3085#include "content/browser/screen_orientation/screen_orientation_provider.h"
[email protected]b6583592012-01-25 19:52:3386#include "content/browser/site_instance_impl.h"
lfgc740d4b22016-04-15 16:45:3387#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1188#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5889#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0390#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5691#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1492#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4293#include "content/common/browser_plugin/browser_plugin_messages.h"
Paul Meyer0c58c3712016-11-17 22:59:5194#include "content/common/drag_messages.h"
[email protected]f114fa42013-12-06 17:06:4495#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1796#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0797#include "content/common/page_messages.h"
nasko34634672016-07-29 18:46:0698#include "content/common/page_state_serialization.h"
rockot5c478a72016-09-28 23:14:1899#include "content/common/render_message_filter.mojom.h"
[email protected]2c5569662011-03-22 20:45:02100#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:36101#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:11102#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:28103#include "content/public/browser/browser_plugin_guest_manager.h"
Eric Seckler8652dcd52018-09-20 10:42:28104#include "content/public/browser/browser_task_traits.h"
Gabriel Charette790754c2018-03-16 21:32:59105#include "content/public/browser/browser_thread.h"
[email protected]87f3c082011-10-19 18:07:44106#include "content/public/browser/content_browser_client.h"
[email protected]e582fdd2011-12-20 16:48:17107#include "content/public/browser/download_manager.h"
ekaramada110f642016-12-21 19:47:28108#include "content/public/browser/focused_node_details.h"
ekaramad1beabecc2016-09-23 20:18:17109#include "content/public/browser/guest_mode.h"
[email protected]d9083482012-01-06 00:38:46110#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:15111#include "content/public/browser/javascript_dialog_manager.h"
skyf65d9bb2017-03-24 02:26:39112#include "content/public/browser/keyboard_event_processing_result.h"
[email protected]09d31d52012-03-11 22:30:27113#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:00114#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:37115#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:14116#include "content/public/browser/notification_service.h"
scottmg011d96e32016-06-29 19:15:08117#include "content/public/browser/notification_types.h"
[email protected]95640212014-07-26 18:14:30118#include "content/public/browser/render_widget_host_iterator.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:06119#include "content/public/browser/restore_type.h"
estark5ea80e52015-06-19 18:43:12120#include "content/public/browser/security_style_explanations.h"
falken52a56e32016-12-08 05:02:40121#include "content/public/browser/ssl_status.h"
[email protected]4c3a23582012-08-18 08:54:34122#include "content/public/browser/storage_partition.h"
rockotf62002a2016-09-15 00:08:59123#include "content/public/browser/web_contents_binding_set.h"
[email protected]674bc592011-12-20 23:00:42124#include "content/public/browser/web_contents_delegate.h"
Lei Zhangee3b63ad2018-06-06 23:25:31125#include "content/public/browser/web_ui_controller.h"
[email protected]e091df82011-10-11 18:13:21126#include "content/public/common/bindings_policy.h"
carloskd80262f52015-12-16 14:40:35127#include "content/public/common/browser_side_navigation_policy.h"
alexmosc9e76ec2016-05-16 22:59:37128#include "content/public/common/child_process_host.h"
[email protected]54087fe2011-10-28 22:02:48129#include "content/public/common/content_constants.h"
Francois Doray3f2afbd2018-04-06 19:18:18130#include "content/public/common/content_features.h"
[email protected]64d69de42012-02-06 00:19:54131#include "content/public/common/content_switches.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:06132#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:49133#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20134#include "content/public/common/result_codes.h"
Ke He7319dbe2017-11-09 05:54:44135#include "content/public/common/service_manager_connection.h"
[email protected]f16cc6782013-12-16 23:42:57136#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05137#include "content/public/common/web_preferences.h"
Max Morinddebb972018-09-20 10:04:14138#include "media/base/user_input_monitor.h"
wjmaclean64951902016-04-29 20:59:12139#include "net/base/url_util.h"
[email protected]8bfc8272013-09-09 20:10:53140#include "net/http/http_cache.h"
141#include "net/http/http_transaction_factory.h"
rhalavati0fbaeef32017-06-01 15:56:30142#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]8bfc8272013-09-09 20:10:53143#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34144#include "net/url_request/url_request_context_getter.h"
Scott Violet02e38b92018-03-27 23:42:14145#include "ppapi/buildflags/buildflags.h"
Ke He31d0bb02018-02-24 07:16:24146#include "services/device/public/mojom/constants.mojom.h"
Mounir Lamourifd9dcefa2017-07-06 10:26:55147#include "services/metrics/public/cpp/ukm_recorder.h"
Ke He7319dbe2017-11-09 05:54:44148#include "services/service_manager/public/cpp/connector.h"
rockot734fb662016-10-15 16:41:30149#include "services/service_manager/public/cpp/interface_provider.h"
Becca Hughes6daf5662018-06-27 16:50:54150#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Blink Reformata30d4232018-04-07 15:31:06151#include "third_party/blink/public/common/frame/sandbox_flags.h"
152#include "third_party/blink/public/common/mime_util/mime_util.h"
153#include "third_party/blink/public/platform/web_security_style.h"
halton.huoca2eabd2015-07-06 08:17:40154#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39155#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56156#include "ui/base/layout.h"
Daniel Cheng90196c82018-04-25 21:49:14157#include "ui/events/base_event_utils.h"
chongz4a9751942016-08-17 17:49:39158#include "ui/events/blink/web_input_event_traits.h"
[email protected]66bd5512012-08-01 02:02:52159#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31160
ekaramada110f642016-12-21 19:47:28161#if defined(OS_WIN)
162#include "content/browser/renderer_host/dip_util.h"
163#include "ui/gfx/geometry/dip_util.h"
164#endif
165
[email protected]583418cc2013-01-17 14:01:10166#if defined(OS_ANDROID)
mfomitchev2b8b066a2016-01-28 19:23:15167#include "content/browser/android/date_time_chooser_android.h"
sammcf5f1b0f2016-09-20 23:05:11168#include "content/browser/android/java_interfaces_impl.h"
dalecurtisc85ed632016-01-13 00:22:46169#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18170#include "content/browser/web_contents/web_contents_android.h"
Ke He31d0bb02018-02-24 07:16:24171#include "services/device/public/mojom/nfc.mojom.h"
mcnee336ea2c2017-05-23 22:50:59172#else // !OS_ANDROID
173#include "content/browser/host_zoom_map_impl.h"
174#include "content/browser/host_zoom_map_observer.h"
mfomitchev2b8b066a2016-01-28 19:23:15175#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10176
brettw4b461082016-11-19 18:55:16177#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17178#include "content/browser/media/session/pepper_playback_observer.h"
Lei Zhangebcc6302018-01-12 19:46:45179#endif
zqzhang181047e62016-07-01 13:37:17180
[email protected]8ff00d72012-10-23 19:12:21181namespace content {
[email protected]420ae012009-04-24 05:16:32182namespace {
183
[email protected]960b0372014-05-19 18:01:00184const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41185const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05186
[email protected]155c7f22013-12-09 17:07:18187#if defined(OS_ANDROID)
rob.buisf06a8bf2017-03-10 18:11:32188const void* const kWebContentsAndroidKey = &kWebContentsAndroidKey;
Lei Zhangebcc6302018-01-12 19:46:45189#endif
[email protected]155c7f22013-12-09 17:07:18190
Avi Drissmana9114822018-03-23 18:25:55191base::LazyInstance<std::vector<
192 WebContentsImpl::FriendWrapper::CreatedCallback>>::DestructorAtExit
193 g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
[email protected]cbb1ef592013-06-05 19:49:46194
[email protected]8bfc8272013-09-09 20:10:53195void NotifyCacheOnIO(
196 scoped_refptr<net::URLRequestContextGetter> request_context,
197 const GURL& url,
198 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58199 net::HttpCache* cache = request_context->GetURLRequestContext()->
200 http_transaction_factory()->GetCache();
201 if (cache)
202 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53203}
204
dcheng57e39e22016-01-21 00:25:38205bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
206 for (FrameTreeNode* node : tree->Nodes()) {
207 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
208 return true;
alexmos4cf2aa32015-07-15 23:40:43209 }
dcheng57e39e22016-01-21 00:25:38210 return false;
[email protected]95640212014-07-26 18:14:30211}
212
kenrb19221852016-04-29 17:21:40213bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) {
214 // This method scans the frame tree rather than checking whether
215 // host->delegate() == this, which allows it to return false when the host
216 // for a frame that is pending or pending deletion.
217 if (!host)
218 return false;
219
220 for (FrameTreeNode* node : tree->Nodes()) {
221 if (node->current_frame_host()->GetRenderWidgetHost() == host)
222 return true;
223 }
224 return false;
225}
226
dmazzonif8a31042016-12-03 00:52:13227void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) {
228 static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode();
[email protected]95640212014-07-26 18:14:30229}
230
dtseng0dd3fa12015-07-22 19:00:52231void ResetAccessibility(RenderFrameHost* rfh) {
232 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
233}
234
paulmeyerfeafc2d2017-04-25 21:46:40235// Helper for GetInnerWebContents().
236bool GetInnerWebContentsHelper(
237 std::vector<WebContentsImpl*>* all_guest_contents,
238 WebContents* guest_contents) {
239 all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents));
240 return false;
241}
242
Ian Clelland5cbaaf82017-11-27 22:00:03243RenderFrameHostImpl* FindOpenerRFH(const WebContents::CreateParams& params) {
244 RenderFrameHostImpl* opener_rfh = nullptr;
alexmose201c7cd2015-06-10 17:14:21245 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
Ian Clelland5cbaaf82017-11-27 22:00:03246 opener_rfh = RenderFrameHostImpl::FromID(params.opener_render_process_id,
247 params.opener_render_frame_id);
alexmose201c7cd2015-06-10 17:14:21248 }
Ian Clelland5cbaaf82017-11-27 22:00:03249 return opener_rfh;
lukasza6f8ac622017-06-06 03:10:20250}
251
Dominick Ng37a15052018-07-17 23:56:35252// Returns |true| if |type| is the kind of user input that should trigger the
253// user interaction observers.
254bool IsUserInteractionInputType(blink::WebInputEvent::Type type) {
255 // Ideally, this list would be based more off of
256 // https://whatwg.org/C/interaction.html#triggered-by-user-activation.
257 return type == blink::WebInputEvent::kMouseDown ||
258 type == blink::WebInputEvent::kGestureScrollBegin ||
259 type == blink::WebInputEvent::kTouchStart ||
260 type == blink::WebInputEvent::kRawKeyDown;
261}
262
263// Returns |true| if |type| is the kind of user input that should be used as
264// a user gesture signal for resource load dispatches.
265bool IsResourceLoadUserInteractionInputType(blink::WebInputEvent::Type type) {
266 return type == blink::WebInputEvent::kMouseDown ||
267 type == blink::WebInputEvent::kTouchStart ||
268 type == blink::WebInputEvent::kRawKeyDown;
269}
270
Pavel Feldman3c1842b2017-08-02 05:00:16271// Ensures that OnDialogClosed is only called once.
272class CloseDialogCallbackWrapper
273 : public base::RefCountedThreadSafe<CloseDialogCallbackWrapper> {
274 public:
Avi Drissmane04d3992017-10-05 15:11:36275 using CloseCallback =
276 base::OnceCallback<void(bool, bool, const base::string16&)>;
277
278 explicit CloseDialogCallbackWrapper(CloseCallback callback)
279 : callback_(std::move(callback)) {}
Pavel Feldman3c1842b2017-08-02 05:00:16280
281 void Run(bool dialog_was_suppressed,
282 bool success,
283 const base::string16& user_input) {
Avi Drissmane04d3992017-10-05 15:11:36284 if (callback_.is_null())
Pavel Feldman3c1842b2017-08-02 05:00:16285 return;
Avi Drissmane04d3992017-10-05 15:11:36286 std::move(callback_).Run(dialog_was_suppressed, success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:16287 }
288
289 private:
290 friend class base::RefCountedThreadSafe<CloseDialogCallbackWrapper>;
291 ~CloseDialogCallbackWrapper() {}
Avi Drissmane04d3992017-10-05 15:11:36292
293 CloseCallback callback_;
Pavel Feldman3c1842b2017-08-02 05:00:16294};
295
Arthur Sonzogni929d29f2018-09-17 14:19:44296bool FrameCompareDepth(RenderFrameHostImpl* a, RenderFrameHostImpl* b) {
297 return a->frame_tree_node()->depth() < b->frame_tree_node()->depth();
298}
299
lukasza6f8ac622017-06-06 03:10:20300} // namespace
301
Erik Chenbb8e738e2018-04-28 14:10:43302std::unique_ptr<WebContents> WebContents::Create(
303 const WebContents::CreateParams& params) {
erikchen50735fd2018-05-05 15:08:33304 return WebContentsImpl::CreateWithOpener(params, FindOpenerRFH(params));
[email protected]d1198fd2012-08-13 22:50:19305}
306
erikchenade1fef2018-05-02 22:07:57307std::unique_ptr<WebContents> WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59308 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30309 const SessionStorageNamespaceMap& session_storage_namespace_map) {
erikchenade1fef2018-05-02 22:07:57310 std::unique_ptr<WebContentsImpl> new_contents(
311 new WebContentsImpl(params.browser_context));
Ian Clelland5cbaaf82017-11-27 22:00:03312 RenderFrameHostImpl* opener_rfh = FindOpenerRFH(params);
313 FrameTreeNode* opener = nullptr;
314 if (opener_rfh)
315 opener = opener_rfh->frame_tree_node();
316 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
[email protected]fdac6ade2013-07-20 01:06:30317
318 for (SessionStorageNamespaceMap::const_iterator it =
319 session_storage_namespace_map.begin();
320 it != session_storage_namespace_map.end();
321 ++it) {
322 new_contents->GetController()
323 .SetSessionStorageNamespace(it->first, it->second.get());
324 }
325
Sam McNally69a33772018-06-27 16:54:12326 if (params.guest_delegate) {
327 // This makes |new_contents| act as a guest.
328 // For more info, see comment above class BrowserPluginGuest.
329 BrowserPluginGuest::Create(new_contents.get(), params.guest_delegate);
330 }
331
[email protected]54944cde2012-12-09 09:24:59332 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19333 return new_contents;
[email protected]a81343d232011-12-27 07:39:20334}
[email protected]746d3052012-05-22 15:15:47335
benwells5e7260d2017-03-20 23:36:33336void WebContentsImpl::FriendWrapper::AddCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37337 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46338 g_created_callbacks.Get().push_back(callback);
339}
340
benwells5e7260d2017-03-20 23:36:33341void WebContentsImpl::FriendWrapper::RemoveCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37342 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46343 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
344 if (g_created_callbacks.Get().at(i).Equals(callback)) {
345 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
346 return;
347 }
348 }
349}
350
avidf38c952015-10-27 13:45:13351WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
352 if (!rvh)
353 return nullptr;
[email protected]746d3052012-05-22 15:15:47354 return rvh->GetDelegate()->GetAsWebContents();
355}
356
[email protected]a86c0e962013-12-17 17:10:39357WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13358 if (!rfh)
359 return nullptr;
360 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39361}
362
ananta4b7467a52016-09-23 01:42:38363WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) {
364 FrameTreeNode* frame_tree_node =
365 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
anantab8cfa3b2016-10-14 22:43:19366 if (!frame_tree_node)
367 return nullptr;
jam8c4edd02017-05-06 18:50:33368 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
ananta4b7467a52016-09-23 01:42:38369}
370
leon.han552e9de2017-02-09 14:37:30371void WebContents::SetScreenOrientationDelegate(
372 ScreenOrientationDelegate* delegate) {
373 ScreenOrientationProvider::SetDelegate(delegate);
374}
375
[email protected]7fff43e2013-05-21 20:21:10376// WebContentsImpl::DestructionObserver ----------------------------------------
377
378class WebContentsImpl::DestructionObserver : public WebContentsObserver {
379 public:
380 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
381 : WebContentsObserver(watched_contents),
382 owner_(owner) {
383 }
384
385 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58386 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58387 owner_->OnWebContentsDestroyed(
388 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10389 }
390
391 private:
392 WebContentsImpl* owner_;
393
394 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
395};
396
Joel Hockey85b379d2017-12-11 10:42:13397// WebContentsImpl::ColorChooser ----------------------------------------------
Joel Hockey163835a2017-12-20 11:51:57398class WebContentsImpl::ColorChooser : public blink::mojom::ColorChooser {
Joel Hockey85b379d2017-12-11 10:42:13399 public:
400 ColorChooser(content::ColorChooser* chooser,
Joel Hockey163835a2017-12-20 11:51:57401 blink::mojom::ColorChooserRequest request,
402 blink::mojom::ColorChooserClientPtr client)
Joel Hockey85b379d2017-12-11 10:42:13403 : chooser_(chooser),
404 binding_(this, std::move(request)),
405 client_(std::move(client)) {
406 binding_.set_connection_error_handler(
407 base::BindOnce([](content::ColorChooser* chooser) { chooser->End(); },
408 base::Unretained(chooser)));
409 }
[email protected]8ed16472014-04-11 19:02:48410
Joel Hockey85b379d2017-12-11 10:42:13411 ~ColorChooser() override { chooser_->End(); }
[email protected]8ed16472014-04-11 19:02:48412
Joel Hockey85b379d2017-12-11 10:42:13413 void SetSelectedColor(SkColor color) override {
414 chooser_->SetSelectedColor(color);
415 }
416
417 void DidChooseColorInColorChooser(SkColor color) {
418 client_->DidChooseColor(color);
419 }
420
421 private:
422 // Color chooser that was opened by this tab.
423 std::unique_ptr<content::ColorChooser> chooser_;
424
425 // mojo bindings.
Joel Hockey163835a2017-12-20 11:51:57426 mojo::Binding<blink::mojom::ColorChooser> binding_;
Joel Hockey85b379d2017-12-11 10:42:13427
428 // mojo renderer client.
Joel Hockey163835a2017-12-20 11:51:57429 blink::mojom::ColorChooserClientPtr client_;
Joel Hockey85b379d2017-12-11 10:42:13430};
nicka0ac8382016-12-15 23:59:23431
lazyboy6ec48b2a2015-06-29 15:18:14432// WebContentsImpl::WebContentsTreeNode ----------------------------------------
lfg601233692017-03-06 22:45:44433WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode(
434 WebContentsImpl* current_web_contents)
435 : current_web_contents_(current_web_contents),
436 outer_web_contents_(nullptr),
lazyboy6ec48b2a2015-06-29 15:18:14437 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33438 FrameTreeNode::kFrameTreeNodeInvalidId),
lfg601233692017-03-06 22:45:44439 focused_web_contents_(current_web_contents) {}
lazyboy6ec48b2a2015-06-29 15:18:14440
441WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
lfga3e2bdc2017-03-07 20:44:01442 if (OuterContentsFrameTreeNode())
443 OuterContentsFrameTreeNode()->RemoveObserver(this);
paulmeyerfeafc2d2017-04-25 21:46:40444
445 if (outer_web_contents_)
446 outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_);
lazyboy6ec48b2a2015-06-29 15:18:14447}
448
449void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
450 WebContentsImpl* outer_web_contents,
451 RenderFrameHostImpl* outer_contents_frame) {
lfg601233692017-03-06 22:45:44452 focused_web_contents_ = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:14453 outer_web_contents_ = outer_web_contents;
454 outer_contents_frame_tree_node_id_ =
455 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
456
paulmeyerfeafc2d2017-04-25 21:46:40457 outer_web_contents_->node_.AttachInnerWebContents(current_web_contents_);
lfga3e2bdc2017-03-07 20:44:01458 outer_contents_frame->frame_tree_node()->AddObserver(this);
lfg601233692017-03-06 22:45:44459}
lazyboy6ec48b2a2015-06-29 15:18:14460
paulmeyerfeafc2d2017-04-25 21:46:40461void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents(
462 WebContentsImpl* inner_web_contents) {
463 inner_web_contents_.push_back(inner_web_contents);
464}
465
466void WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents(
467 WebContentsImpl* inner_web_contents) {
468 DCHECK(std::find(inner_web_contents_.begin(), inner_web_contents_.end(),
469 inner_web_contents) != inner_web_contents_.end());
470 inner_web_contents_.erase(
471 std::remove(inner_web_contents_.begin(), inner_web_contents_.end(),
472 inner_web_contents),
473 inner_web_contents_.end());
474}
475
lfga3e2bdc2017-03-07 20:44:01476FrameTreeNode*
477WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const {
478 return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_);
lfg601233692017-03-06 22:45:44479}
480
lfga3e2bdc2017-03-07 20:44:01481void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed(
482 FrameTreeNode* node) {
483 DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id())
484 << "WebContentsTreeNode should only receive notifications for the "
485 "FrameTreeNode in its outer WebContents that hosts it.";
486 delete current_web_contents_; // deletes |this| too.
lazyboy6ec48b2a2015-06-29 15:18:14487}
488
avallee0206f782016-07-28 18:55:33489void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
490 WebContentsImpl* web_contents) {
491 DCHECK(!outer_web_contents())
492 << "Only the outermost WebContents tracks focus.";
493 focused_web_contents_ = web_contents;
494}
495
paulmeyerfeafc2d2017-04-25 21:46:40496WebContentsImpl*
497WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame(
498 const FrameTreeNode* frame) {
499 auto ftn_id = frame->frame_tree_node_id();
500 for (WebContentsImpl* contents : inner_web_contents_) {
501 if (contents->node_.outer_contents_frame_tree_node_id() == ftn_id) {
502 return contents;
503 }
504 }
505 return nullptr;
506}
507
508const std::vector<WebContentsImpl*>&
509WebContentsImpl::WebContentsTreeNode::inner_web_contents() const {
510 return inner_web_contents_;
511}
512
[email protected]b172aee2012-04-10 17:05:26513// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32514
alexmose201c7cd2015-06-10 17:14:21515WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28516 : delegate_(nullptr),
[email protected]69e797f2013-04-30 01:10:22517 controller_(this, browser_context),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28518 render_view_host_delegate_view_(nullptr),
alexmose201c7cd2015-06-10 17:14:21519 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01520 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57521 this,
522 this,
523 this,
524 this),
lfg601233692017-03-06 22:45:44525 node_(this),
[email protected]6dfed692014-05-22 04:18:03526 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23527 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
528 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34529 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26530 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56531 upload_size_(0),
532 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16533 is_resume_pending_(false),
creisadca9862017-06-16 19:12:11534 interstitial_page_(nullptr),
[email protected]b4c84012014-04-28 19:51:10535 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28536 theme_color_(SK_ColorTRANSPARENT),
537 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29538 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55539 capturer_count_(0),
[email protected]fdd61c62009-04-22 19:22:57540 is_being_destroyed_(false),
creis97867aa2017-02-17 18:39:45541 is_notifying_observers_(false),
[email protected]fdd61c62009-04-22 19:22:57542 notify_disconnection_(false),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28543 dialog_manager_(nullptr),
[email protected]7ab1e7d62009-10-14 23:32:01544 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39545 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38546 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21547 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
548 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22549 zoom_scroll_remainder_(0),
alexmosc9e76ec2016-05-16 22:59:37550 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42551 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03552 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]34ff1cfc2014-08-20 06:16:05553 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30554 last_dialog_suppressed_(false),
waffles1c12bf402016-02-10 17:45:48555 accessibility_mode_(
James Wallace-Leeeafc94cb92018-07-23 21:35:09556 BrowserAccessibilityStateImpl::GetInstance()->GetAccessibilityMode()),
avayvodcc85bbd2015-08-28 19:11:15557 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35558 bluetooth_connected_device_count_(0),
Guido Urdanetaf4008002018-05-03 10:43:04559 media_device_group_id_salt_base_(
560 BrowserContext::CreateRandomMediaDeviceIDSalt()),
mcnee336ea2c2017-05-23 22:50:59561#if !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:46562 page_scale_factor_is_one_(true),
mcnee336ea2c2017-05-23 22:50:59563#endif // !defined(OS_ANDROID)
qinmin72e8bd02016-10-21 19:35:37564 is_overlay_content_(false),
ekaramadf6750aa2017-06-06 18:29:42565 showing_context_menu_(false),
pkotwicz75ca8ffd2016-02-16 23:10:19566 loading_weak_factory_(this),
567 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55568 frame_tree_.SetFrameRemoveListener(
569 base::Bind(&WebContentsImpl::OnFrameRemoved,
570 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46571#if defined(OS_ANDROID)
572 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
573#else
qinmin58567c82015-01-07 21:00:20574 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46575#endif
brettw4b461082016-11-19 18:55:16576#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17577 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
578#endif
blundelle75a8f92017-03-27 08:11:17579
csharrisona2280cd2016-02-03 23:21:15580 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
mcnee336ea2c2017-05-23 22:50:59581#if !defined(OS_ANDROID)
scottmg276753cf2016-10-27 18:25:22582 host_zoom_map_observer_.reset(new HostZoomMapObserver(this));
mcnee336ea2c2017-05-23 22:50:59583#endif // !defined(OS_ANDROID)
Joel Hockey85b379d2017-12-11 10:42:13584
Becca Hughes86334622018-07-09 21:29:38585#if defined(OS_ANDROID)
Becca Hughesd11d6502018-07-31 17:01:28586 if (base::FeatureList::IsEnabled(features::kDisplayCutoutAPI))
587 display_cutout_host_impl_ = std::make_unique<DisplayCutoutHostImpl>(this);
Becca Hughes86334622018-07-09 21:29:38588#endif
Becca Hughes6fe54e432018-06-09 04:18:56589
Joel Hockey85b379d2017-12-11 10:42:13590 registry_.AddInterface(base::BindRepeating(
591 &WebContentsImpl::OnColorChooserFactoryRequest, base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35592}
initial.commit09911bf2008-07-26 23:55:29593
[email protected]b172aee2012-04-10 17:05:26594WebContentsImpl::~WebContentsImpl() {
creisba91ba82017-05-12 22:56:19595 // Imperfect sanity check against double free, given some crashes unexpectedly
596 // observed in the wild.
597 CHECK(!is_being_destroyed_);
598
599 // We generally keep track of is_being_destroyed_ to let other features know
600 // to avoid certain actions during destruction.
[email protected]420ae012009-04-24 05:16:32601 is_being_destroyed_ = true;
602
creis97867aa2017-02-17 18:39:45603 // A WebContents should never be deleted while it is notifying observers,
creisba91ba82017-05-12 22:56:19604 // since this will lead to a use-after-free as it continues to notify later
creis97867aa2017-02-17 18:39:45605 // observers.
606 CHECK(!is_notifying_observers_);
607
kenrb2a565f82015-09-02 20:24:59608 rwh_input_event_router_.reset();
609
rockotf62002a2016-09-15 00:08:59610 for (auto& entry : binding_sets_)
611 entry.second->CloseAllBindings();
612
avallee0206f782016-07-28 18:55:33613 WebContentsImpl* outermost = GetOutermostWebContents();
avallee9993fca2016-11-17 06:16:50614 if (this != outermost && ContainsOrIsFocusedWebContents()) {
avallee0206f782016-07-28 18:55:33615 // If the current WebContents is in focus, unset it.
avallee9993fca2016-11-17 06:16:50616 outermost->SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:33617 }
618
Nick Carterd73635b2018-03-13 18:31:41619 if (mouse_lock_widget_)
620 mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary();
621
dcheng72be33c2016-01-21 04:11:31622 for (FrameTreeNode* node : frame_tree_.Nodes()) {
623 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
624 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38625 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38626 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31627 }
carlosk35f35af2015-12-01 10:55:40628
dcheng57e39e22016-01-21 00:25:38629 for (RenderWidgetHostImpl* widget : created_widgets_)
630 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26631 created_widgets_.clear();
632
[email protected]3ab9cb82011-06-03 18:02:07633 // Clear out any JavaScript state.
avi5d3b8692016-10-12 22:00:46634 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:53635 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:46636 }
[email protected]3ab9cb82011-06-03 18:02:07637
Joel Hockey85b379d2017-12-11 10:42:13638 color_chooser_.reset();
[email protected]da8543762012-03-20 08:52:20639
[email protected]420ae012009-04-24 05:16:32640 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32641
[email protected]ca13a442012-04-17 14:00:12642 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21643 NotificationService::current()->Notify(
644 NOTIFICATION_WEB_CONTENTS_DESTROYED,
645 Source<WebContents>(this),
646 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32647
[email protected]df0c843f2014-05-23 20:37:23648 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14649 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23650 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59651
clamy0e119882015-07-31 16:12:33652 // Manually call the observer methods for the root frame tree node. It is
653 // necessary to manually delete all objects tracking navigations
654 // (NavigationHandle, NavigationRequest) for observers to be properly
655 // notified of these navigations stopping before the WebContents is
656 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23657 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56658
naskob21fe4872015-02-24 14:15:56659 root->current_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28660 root->current_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33661
Arthur Hemeryc3380172018-01-22 14:00:17662 // Do not update state as the WebContents is being destroyed.
663 frame_tree_.root()->ResetNavigationRequest(true, true);
664 if (root->speculative_frame_host()) {
665 root->speculative_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28666 root->speculative_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33667 }
[email protected]f273ee52013-10-18 16:05:27668
brettw4b461082016-11-19 18:55:16669#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17670 // Call this before WebContentsDestroyed() is broadcasted since
671 // AudioFocusManager will be destroyed after that.
672 pepper_playback_observer_.reset();
673#endif // defined(ENABLED_PLUGINS)
674
Chris Hamiltondf0d72cd2018-05-29 16:23:53675 // If audio is playing then notify external observers of the audio stream
676 // disappearing.
677 if (is_currently_audible_) {
678 is_currently_audible_ = false;
679 for (auto& observer : observers_)
680 observer.OnAudioStateChanged(false);
681
682 if (GetOuterWebContents())
683 GetOuterWebContents()->OnAudioStateChanged();
684 }
685
ericwilligersde386342016-10-19 02:35:09686 for (auto& observer : observers_)
687 observer.FrameDeleted(root->current_frame_host());
naskoa83483fb2015-02-27 16:57:10688
ericwilligersde386342016-10-19 02:35:09689 for (auto& observer : observers_)
690 observer.RenderViewDeleted(root->current_host());
[email protected]f273ee52013-10-18 16:05:27691
ericwilligersde386342016-10-19 02:35:09692 for (auto& observer : observers_)
693 observer.WebContentsDestroyed();
[email protected]12a46832014-05-09 13:35:58694
Becca Hughesd11d6502018-07-31 17:01:28695 if (display_cutout_host_impl_)
696 display_cutout_host_impl_->WebContentsDestroyed();
697
ericwilligersde386342016-10-19 02:35:09698 for (auto& observer : observers_)
699 observer.ResetWebContents();
[email protected]232a5812011-03-04 22:42:08700
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28701 SetDelegate(nullptr);
[email protected]b5a1d11c2011-02-17 03:09:42702}
703
erikchen50735fd2018-05-05 15:08:33704std::unique_ptr<WebContentsImpl> WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59705 const WebContents::CreateParams& params,
Ian Clelland5cbaaf82017-11-27 22:00:03706 RenderFrameHostImpl* opener_rfh) {
[email protected]e11f0e92013-06-12 15:12:03707 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
Ian Clelland5cbaaf82017-11-27 22:00:03708 FrameTreeNode* opener = nullptr;
709 if (opener_rfh)
710 opener = opener_rfh->frame_tree_node();
erikchen50735fd2018-05-05 15:08:33711 std::unique_ptr<WebContentsImpl> new_contents(
712 new WebContentsImpl(params.browser_context));
lukasza6f8ac622017-06-06 03:10:20713 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
alexmose201c7cd2015-06-10 17:14:21714
alexmosaedfc6f2016-01-21 23:57:38715 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
716 // flags, and these flags take effect immediately. An exception is if the
717 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
718 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
719 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
lukasza6f8ac622017-06-06 03:10:20720 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
alexmosaedfc6f2016-01-21 23:57:38721 if (opener) {
Ian Clelland5cbaaf82017-11-27 22:00:03722 blink::WebSandboxFlags opener_flags = opener_rfh->active_sandbox_flags();
alexmosaedfc6f2016-01-21 23:57:38723 const blink::WebSandboxFlags inherit_flag =
Blink Reformat1c4d759e2017-04-09 16:34:54724 blink::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts;
alexmosaedfc6f2016-01-21 23:57:38725 if ((opener_flags & inherit_flag) == inherit_flag) {
Ian Clellandcdc4f312017-10-13 22:24:12726 // TODO(iclelland): Transfer correct container policy from opener as well.
727 // https://crbug.com/774620
728 new_root->SetPendingFramePolicy({opener_flags, {}});
alexmosaedfc6f2016-01-21 23:57:38729 }
730 }
731
mark a. foltzef394fce2017-10-21 09:11:02732 // Apply starting sandbox flags.
Luna Luc3fdacdf2017-11-08 04:48:53733 blink::FramePolicy frame_policy(new_root->pending_frame_policy());
mark a. foltzef394fce2017-10-21 09:11:02734 frame_policy.sandbox_flags |= params.starting_sandbox_flags;
735 new_root->SetPendingFramePolicy(frame_policy);
736 new_root->CommitPendingFramePolicy();
737
alexmose201c7cd2015-06-10 17:14:21738 // This may be true even when opener is null, such as when opening blocked
739 // popups.
alexmos090fae8e2015-05-28 17:09:28740 if (params.created_with_opener)
741 new_contents->created_with_opener_ = true;
742
[email protected]4858e432014-06-23 18:14:17743 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06744 // This makes |new_contents| act as a guest.
745 // For more info, see comment above class BrowserPluginGuest.
erikchen50735fd2018-05-05 15:08:33746 BrowserPluginGuest::Create(new_contents.get(), params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06747 }
mark a. foltzef394fce2017-10-21 09:11:02748
[email protected]54944cde2012-12-09 09:24:59749 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19750 return new_contents;
751}
752
[email protected]95640212014-07-26 18:14:30753// static
754std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
755 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08756 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30757 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30758 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30759 RenderViewHost* rvh = RenderViewHost::From(rwh);
760 if (!rvh)
761 continue;
762 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
763 if (!web_contents)
764 continue;
avidf38c952015-10-27 13:45:13765 if (web_contents->GetRenderViewHost() != rvh)
766 continue;
767 // Because a WebContents can only have one current RVH at a time, there will
768 // be no duplicate WebContents here.
769 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30770 }
771 return result;
772}
773
clamya16aa8172015-05-26 13:07:25774// static
775WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
paulmeyerfeafc2d2017-04-25 21:46:40776 const FrameTreeNode* frame_tree_node) {
clamya16aa8172015-05-26 13:07:25777 return static_cast<WebContentsImpl*>(
778 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
779}
780
clamy0d32d6d2015-11-24 11:16:26781// static
782WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
783 int render_frame_host_id) {
784 DCHECK_CURRENTLY_ON(BrowserThread::UI);
785 RenderFrameHost* render_frame_host =
786 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
787 if (!render_frame_host)
788 return nullptr;
789
790 return WebContents::FromRenderFrameHost(render_frame_host);
791}
792
paulmeyerfeafc2d2017-04-25 21:46:40793// static
794WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode(
795 const FrameTreeNode* frame_tree_node) {
796 return WebContentsImpl::FromFrameTreeNode(frame_tree_node)
797 ->node_.GetInnerWebContentsInFrame(frame_tree_node);
798}
799
[email protected]b0936d22013-11-28 06:47:36800RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21801 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28802}
803
nicka0ac8382016-12-15 23:59:23804bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host,
[email protected]7bb761892012-07-20 09:32:47805 const IPC::Message& message) {
nicka0ac8382016-12-15 23:59:23806 for (auto& observer : observers_) {
Lukasz Anforowicz89f2c1b2017-08-30 21:36:46807 // TODO(nick, creis): https://crbug.com/758026: Replace all uses of this
808 // variant of OnMessageReceived with the version that takes a
809 // RenderFrameHost, and then delete it.
nicka0ac8382016-12-15 23:59:23810 if (observer.OnMessageReceived(message))
811 return true;
[email protected]64ffefa2014-05-10 12:06:33812 }
[email protected]403415a2011-01-10 18:57:53813
[email protected]724159a2010-12-30 01:11:18814 bool handled = true;
nicka0ac8382016-12-15 23:59:23815 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host)
816 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
817 OnFirstVisuallyNonEmptyPaint)
Yiming Zhoudd60b0b2018-07-20 18:51:35818 IPC_MESSAGE_HANDLER(ViewHostMsg_DidCommitAndDrawCompositorFrame,
819 OnCommitAndDrawCompositorFrame)
nicka0ac8382016-12-15 23:59:23820 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
821 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
822 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
823 OnPageScaleFactorChanged)
824 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
825 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
nicka0ac8382016-12-15 23:59:23826#if BUILDFLAG(ENABLE_PLUGINS)
827 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
828 OnRequestPpapiBrokerPermission)
829#endif
nicka0ac8382016-12-15 23:59:23830#if defined(OS_ANDROID)
831 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, OnOpenDateTimeDialog)
832#endif
833 IPC_MESSAGE_UNHANDLED(handled = false)
834 IPC_END_MESSAGE_MAP()
835
836 return handled;
837}
838
839bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host,
840 const IPC::Message& message) {
Lukasz Anforowicz02923102017-10-09 18:11:37841 {
842 WebUIImpl* web_ui = render_frame_host->web_ui();
843 if (web_ui && web_ui->OnMessageReceived(message, render_frame_host))
844 return true;
845 }
846
nicka0ac8382016-12-15 23:59:23847 for (auto& observer : observers_) {
848 if (observer.OnMessageReceived(message, render_frame_host))
849 return true;
850 }
851
852 bool handled = true;
853 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host)
[email protected]cfa856d62014-02-22 07:58:40854 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
855 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05856 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
857 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48858 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
859 OnDocumentLoadedInFrame)
860 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
avi7830c852015-08-31 23:46:25861 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18862 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54863 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18864 OnDidDisplayInsecureContent)
elawrenceb2ac2a232017-03-27 21:46:25865 IPC_MESSAGE_HANDLER(FrameHostMsg_DidContainInsecureFormAction,
866 OnDidContainInsecureFormAction)
avi3a3332622015-09-01 01:18:54867 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18868 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41869 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
870 OnDidDisplayContentWithCertificateErrors)
871 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
872 OnDidRunContentWithCertificateErrors)
avia23e16b2015-07-09 14:18:48873 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
874 OnRegisterProtocolHandler)
875 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
876 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01877 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
878 OnUpdatePageImportanceSignals)
lukasza178ff092017-06-07 23:39:50879 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
brettw4b461082016-11-19 18:55:16880#if BUILDFLAG(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00881 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
882 OnPepperInstanceCreated)
883 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
884 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42885 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:17886 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
887 OnPepperStartsPlayback)
888 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
889 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:42890 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]c4538072013-03-18 02:17:55891 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40892 OnBrowserPluginMessage(render_frame_host,
893 message))
thestigc4cac8f2014-09-04 21:17:50894#endif
[email protected]724159a2010-12-30 01:11:18895 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33896 IPC_END_MESSAGE_MAP()
[email protected]724159a2010-12-30 01:11:18897
[email protected]724159a2010-12-30 01:11:18898 return handled;
899}
900
[email protected]d1198fd2012-08-13 22:50:19901NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56902 return controller_;
903}
904
[email protected]d1198fd2012-08-13 22:50:19905const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56906 return controller_;
907}
908
[email protected]8ff00d72012-10-23 19:12:21909BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55910 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30911}
912
[email protected]b172aee2012-04-10 17:05:26913const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24914 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32915 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51916 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31917}
918
[email protected]a093ce02013-07-22 20:53:14919const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24920 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32921 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24922 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
923}
924
925const GURL& WebContentsImpl::GetLastCommittedURL() const {
926 // We may not have a navigation entry yet.
927 NavigationEntry* entry = controller_.GetLastCommittedEntry();
928 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
929}
930
[email protected]8ff00d72012-10-23 19:12:21931WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31932 return delegate_;
933}
934
[email protected]8ff00d72012-10-23 19:12:21935void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31936 // TODO(cbentzel): remove this debugging code?
937 if (delegate == delegate_)
938 return;
939 if (delegate_)
940 delegate_->Detach(this);
941 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08942 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31943 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08944 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00945 if (view_)
[email protected]e85165c642014-06-10 14:34:31946 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
Joel Einbinder848001c2017-09-19 21:39:31947 if (GetRenderViewHost())
948 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]a6b73c62013-02-11 23:05:08949 }
[email protected]be1f56ab2011-12-22 06:55:31950}
951
Lukasz Anforowicze9ae3722017-09-29 17:37:38952RenderFrameHostImpl* WebContentsImpl::GetMainFrame() const {
[email protected]94d0cc12013-12-18 00:07:41953 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16954}
955
nick53d5cbf2015-04-23 22:50:14956RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
957 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
958 if (!focused_node)
959 return nullptr;
960 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07961}
962
rob3e2a0732016-01-06 21:22:09963RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
creisf71a2632017-05-04 19:03:50964 int frame_tree_node_id,
965 int process_id) {
966 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
967
968 // Sanity check that this is in the caller's expected process. Otherwise a
969 // recent cross-process navigation may have led to a privilege change that the
970 // caller is not expecting.
971 if (!frame ||
972 frame->current_frame_host()->GetProcess()->GetID() != process_id)
973 return nullptr;
974
975 return frame->current_frame_host();
976}
977
978RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId(
rob3e2a0732016-01-06 21:22:09979 int frame_tree_node_id) {
creisf71a2632017-05-04 19:03:50980 // Beware using this! The RenderFrameHost may have changed since the caller
981 // obtained frame_tree_node_id.
rob3e2a0732016-01-06 21:22:09982 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
983 return frame ? frame->current_frame_host() : nullptr;
984}
985
[email protected]a86c0e962013-12-17 17:10:39986void WebContentsImpl::ForEachFrame(
Lei Zhangebcc6302018-01-12 19:46:45987 const base::RepeatingCallback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38988 for (FrameTreeNode* node : frame_tree_.Nodes()) {
989 on_frame.Run(node->current_frame_host());
990 }
[email protected]a86c0e962013-12-17 17:10:39991}
992
dchengafb53e22016-02-04 08:11:08993std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
994 std::vector<RenderFrameHost*> frame_hosts;
995 for (FrameTreeNode* node : frame_tree_.Nodes())
996 frame_hosts.push_back(node->current_frame_host());
997 return frame_hosts;
998}
999
lukaszacbdf52e2016-01-15 21:19:511000int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
1001 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:081002 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:251003 if (!rfh->IsRenderFrameLive())
1004 continue;
1005
dchengafb53e22016-02-04 08:11:081006 ++number_of_messages;
1007 IPC::Message* message_copy = new IPC::Message(*message);
1008 message_copy->set_routing_id(rfh->GetRoutingID());
1009 rfh->Send(message_copy);
1010 }
[email protected]a86c0e962013-12-17 17:10:391011 delete message;
lukaszacbdf52e2016-01-15 21:19:511012 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:391013}
1014
lfgdb5c4ed2016-03-04 23:09:071015void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:411016 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:071017}
1018
creisc014b402015-04-23 16:41:451019RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:211020 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:311021}
1022
creis89a0f782015-05-27 16:13:171023void WebContentsImpl::CancelActiveAndPendingDialogs() {
avi5d3b8692016-10-12 22:00:461024 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:531025 dialog_manager_->CancelDialogs(this, /*reset_state=*/false);
avi5d3b8692016-10-12 22:00:461026 }
creis89a0f782015-05-27 16:13:171027 if (browser_plugin_embedder_)
1028 browser_plugin_embedder_->CancelGuestDialogs();
1029}
1030
naskoc0fceff2015-04-30 15:53:521031void WebContentsImpl::ClosePage() {
1032 GetRenderViewHost()->ClosePage();
1033}
1034
[email protected]b172aee2012-04-10 17:05:261035RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:211036 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:311037}
1038
lfg265a2672016-04-23 03:11:021039RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
1040 if (GetOuterWebContents())
1041 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
1042 return GetRenderManager()->GetRenderWidgetHostView();
1043}
1044
[email protected]4aebbca2013-09-17 22:26:491045RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
1046 const {
vmpstr6d9996c82017-02-23 00:43:251047 if (auto* widget_host = GetFullscreenRenderWidgetHost())
ekaramadaeb3c5c2016-11-09 03:22:351048 return widget_host->GetView();
1049 return nullptr;
[email protected]4aebbca2013-09-17 22:26:491050}
1051
[email protected]8ff00d72012-10-23 19:12:211052WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:311053 return view_.get();
1054}
1055
leon.han552e9de2017-02-09 14:37:301056void WebContentsImpl::OnScreenOrientationChange() {
1057 DCHECK(screen_orientation_provider_);
Becca Hughese9e27952018-06-25 17:08:271058 screen_orientation_provider_->OnOrientationChange();
leon.hane4db177a2017-02-07 14:19:161059}
1060
yusufod41c5f92015-03-06 00:14:281061SkColor WebContentsImpl::GetThemeColor() const {
1062 return theme_color_;
1063}
1064
Doug Turner63f3c7b2017-07-29 05:10:011065void WebContentsImpl::SetAccessibilityMode(ui::AXMode mode) {
[email protected]95640212014-07-26 18:14:301066 if (mode == accessibility_mode_)
1067 return;
1068
dmazzonif8a31042016-12-03 00:52:131069 // Don't allow accessibility to be enabled for WebContents that are never
1070 // visible, like background pages.
1071 if (IsNeverVisible())
1072 return;
1073
[email protected]95640212014-07-26 18:14:301074 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:381075
1076 for (FrameTreeNode* node : frame_tree_.Nodes()) {
dmazzonif8a31042016-12-03 00:52:131077 UpdateAccessibilityModeOnFrame(node->current_frame_host());
clamy610c63b32017-12-22 15:05:181078 // Also update accessibility mode on the speculative RenderFrameHost for
1079 // this FrameTreeNode, if one exists.
Alex Moshchuk3d8a1f392017-10-24 19:01:261080 RenderFrameHost* speculative_frame_host =
1081 node->render_manager()->speculative_frame_host();
1082 if (speculative_frame_host)
1083 UpdateAccessibilityModeOnFrame(speculative_frame_host);
dcheng57e39e22016-01-21 00:25:381084 }
[email protected]95640212014-07-26 18:14:301085}
1086
Doug Turner63f3c7b2017-07-29 05:10:011087void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) {
1088 ui::AXMode new_mode(accessibility_mode_);
dougtcd3dad732017-03-14 03:26:231089 new_mode |= mode;
1090 SetAccessibilityMode(new_mode);
[email protected]95640212014-07-26 18:14:301091}
1092
Avi Drissman1e620f32018-03-16 13:57:291093// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
1094// Handles the callbacks from parallel snapshot requests to each frame,
1095// and feeds the results to an AXTreeCombiner, which converts them into a
1096// single combined accessibility tree.
1097class WebContentsImpl::AXTreeSnapshotCombiner
1098 : public base::RefCounted<AXTreeSnapshotCombiner> {
1099 public:
1100 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
1101 : callback_(std::move(callback)) {}
1102
1103 AXTreeSnapshotCallback AddFrame(bool is_root) {
1104 // Adds a reference to |this|.
1105 return base::BindOnce(&AXTreeSnapshotCombiner::ReceiveSnapshot, this,
1106 is_root);
1107 }
1108
1109 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
1110 combiner_.AddTree(snapshot, is_root);
1111 }
1112
1113 private:
1114 friend class base::RefCounted<AXTreeSnapshotCombiner>;
1115
1116 // This is called automatically after the last call to ReceiveSnapshot
1117 // when there are no more references to this object.
1118 ~AXTreeSnapshotCombiner() {
1119 combiner_.Combine();
1120 std::move(callback_).Run(combiner_.combined());
1121 }
1122
1123 ui::AXTreeCombiner combiner_;
1124 AXTreeSnapshotCallback callback_;
1125};
1126
1127void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback,
1128 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391129 // Send a request to each of the frames in parallel. Each one will return
1130 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
1131 // them into a single tree and call |callback| with that result, then
1132 // delete |combiner|.
Avi Drissman1e620f32018-03-16 13:57:291133 FrameTreeNode* root_node = frame_tree_.root();
tzik58faa742018-08-01 10:54:181134 auto combiner =
1135 base::MakeRefCounted<AXTreeSnapshotCombiner>(std::move(callback));
Avi Drissman1e620f32018-03-16 13:57:291136
tzik58faa742018-08-01 10:54:181137 RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner.get(), ax_mode);
Avi Drissman1e620f32018-03-16 13:57:291138}
1139
1140void WebContentsImpl::RecursiveRequestAXTreeSnapshotOnFrame(
1141 FrameTreeNode* root_node,
1142 AXTreeSnapshotCombiner* combiner,
1143 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391144 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
Avi Drissman1e620f32018-03-16 13:57:291145 WebContentsImpl* inner_contents =
1146 node_.GetInnerWebContentsInFrame(frame_tree_node);
1147 if (inner_contents) {
1148 inner_contents->RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner,
1149 ax_mode);
1150 } else {
1151 bool is_root = frame_tree_node == root_node;
1152 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
1153 combiner->AddFrame(is_root), ax_mode);
1154 }
dmazzonid95ae842016-04-12 21:17:391155 }
dmazzoni83ba5c82015-04-14 07:11:511156}
1157
Becca Hughes3b5a43482018-07-17 22:31:551158void WebContentsImpl::NotifyViewportFitChanged(
1159 blink::mojom::ViewportFit value) {
1160 for (auto& observer : observers_)
1161 observer.ViewportFitChanged(value);
1162}
1163
mcnee336ea2c2017-05-23 22:50:591164#if !defined(OS_ANDROID)
akabac6bd1212018-06-25 20:10:481165void WebContentsImpl::UpdateZoom() {
1166 RenderWidgetHostImpl* rwh = GetRenderViewHost()->GetWidget();
1167 if (rwh->GetView())
1168 rwh->SynchronizeVisualProperties();
wjmaclean64951902016-04-29 20:59:121169}
1170
wjmaclean64951902016-04-29 20:59:121171
1172void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
akabac6bd1212018-06-25 20:10:481173 const std::string& host) {
wjmaclean64951902016-04-29 20:59:121174 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1175 if (!entry)
1176 return;
1177
1178 GURL url = HostZoomMap::GetURLFromEntry(entry);
1179 if (host != net::GetHostOrSpecFromURL(url) ||
1180 (!scheme.empty() && !url.SchemeIs(scheme))) {
1181 return;
1182 }
1183
akabac6bd1212018-06-25 20:10:481184 UpdateZoom();
wjmaclean64951902016-04-29 20:59:121185}
mcnee336ea2c2017-05-23 22:50:591186#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:121187
rockotf62002a2016-09-15 00:08:591188base::Closure WebContentsImpl::AddBindingSet(
1189 const std::string& interface_name,
1190 WebContentsBindingSet* binding_set) {
1191 auto result =
1192 binding_sets_.insert(std::make_pair(interface_name, binding_set));
1193 DCHECK(result.second);
1194 return base::Bind(&WebContentsImpl::RemoveBindingSet,
1195 weak_factory_.GetWeakPtr(), interface_name);
1196}
1197
rockot8bbad222017-03-22 04:34:051198WebContentsBindingSet* WebContentsImpl::GetBindingSet(
1199 const std::string& interface_name) {
1200 auto it = binding_sets_.find(interface_name);
1201 if (it == binding_sets_.end())
1202 return nullptr;
1203 return it->second;
1204}
1205
paulmeyerfeafc2d2017-04-25 21:46:401206std::vector<WebContentsImpl*> WebContentsImpl::GetInnerWebContents() {
1207 if (browser_plugin_embedder_) {
1208 std::vector<WebContentsImpl*> inner_contents;
1209 GetBrowserContext()->GetGuestManager()->ForEachGuest(
Mark Pilgrimd84121732018-03-22 14:12:121210 this, base::BindRepeating(&GetInnerWebContentsHelper, &inner_contents));
paulmeyerfeafc2d2017-04-25 21:46:401211 return inner_contents;
1212 }
1213
1214 return node_.inner_web_contents();
1215}
1216
1217std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() {
1218 std::vector<WebContentsImpl*> all_contents(1, this);
1219
1220 for (size_t i = 0; i != all_contents.size(); ++i) {
1221 for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) {
1222 all_contents.push_back(inner_contents);
1223 }
1224 }
1225
1226 return all_contents;
1227}
1228
Sam McNally145fb172017-05-10 00:13:231229void WebContentsImpl::NotifyManifestUrlChanged(
1230 const base::Optional<GURL>& manifest_url) {
1231 for (auto& observer : observers_)
1232 observer.DidUpdateWebManifestURL(manifest_url);
1233}
1234
[email protected]8ff00d72012-10-23 19:12:211235WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:401236 WebUI* commited_web_ui = GetCommittedWebUI();
1237 return commited_web_ui ? commited_web_ui
1238 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:311239}
1240
[email protected]8ff00d72012-10-23 19:12:211241WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:401242 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341243}
1244
Changwan Ryuc1134a82018-03-07 02:10:141245void WebContentsImpl::SetUserAgentOverride(const std::string& override,
1246 bool override_in_new_tabs) {
[email protected]bf70edce2012-06-20 22:32:221247 if (GetUserAgentOverride() == override)
1248 return;
1249
Changwan Ryuc1134a82018-03-07 02:10:141250 should_override_user_agent_in_new_tabs_ = override_in_new_tabs;
1251
[email protected]bf70edce2012-06-20 22:32:221252 renderer_preferences_.user_agent_override = override;
1253
1254 // Send the new override string to the renderer.
1255 RenderViewHost* host = GetRenderViewHost();
1256 if (host)
1257 host->SyncRendererPrefs();
1258
1259 // Reload the page if a load is currently in progress to avoid having
1260 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271261 NavigationEntry* entry = controller_.GetVisibleEntry();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281262 if (IsLoading() && entry != nullptr && entry->GetIsOverridingUserAgent())
toyoshim6142d96f2016-12-19 09:07:251263 controller_.Reload(ReloadType::BYPASSING_CACHE, true);
[email protected]8d0f3312012-08-18 01:47:531264
ericwilligersde386342016-10-19 02:35:091265 for (auto& observer : observers_)
1266 observer.UserAgentOverrideSet(override);
[email protected]86ef6a392012-05-11 22:03:111267}
1268
1269const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:221270 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111271}
1272
Changwan Ryuc1134a82018-03-07 02:10:141273bool WebContentsImpl::ShouldOverrideUserAgentInNewTabs() {
1274 return should_override_user_agent_in_new_tabs_;
1275}
1276
dmazzonidd3d51a72016-12-14 18:41:011277void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() {
dougtcd3dad732017-03-14 03:26:231278 if (!GetAccessibilityMode().is_mode_off()) {
dchengafb53e22016-02-04 08:11:081279 for (RenderFrameHost* rfh : GetAllFrames())
1280 ResetAccessibility(rfh);
1281 } else {
Doug Turner63f3c7b2017-07-29 05:10:011282 AddAccessibilityMode(ui::kAXModeWebContentsOnly);
dchengafb53e22016-02-04 08:11:081283 }
[email protected]95640212014-07-26 18:14:301284}
1285
dmazzonidd3d51a72016-12-14 18:41:011286bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011287 return accessibility_mode_ == ui::kAXModeWebContentsOnly;
[email protected]95640212014-07-26 18:14:301288}
1289
1290bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011291 return accessibility_mode_ == ui::kAXModeComplete;
[email protected]95640212014-07-26 18:14:301292}
1293
kouhei40f03cb2015-09-24 07:47:011294const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
1295 return page_importance_signals_;
1296}
1297
Guido Urdanetaf4008002018-05-03 10:43:041298const std::string& WebContentsImpl::GetMediaDeviceGroupIDSaltBase() const {
1299 return media_device_group_id_salt_base_;
1300}
1301
Becca Hughes6daf5662018-06-27 16:50:541302#if defined(OS_ANDROID)
1303
1304void WebContentsImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) {
Becca Hughes86334622018-07-09 21:29:381305 if (display_cutout_host_impl_)
1306 display_cutout_host_impl_->SetDisplayCutoutSafeArea(insets);
Becca Hughes6daf5662018-06-27 16:50:541307}
1308
1309#endif
1310
[email protected]fcf75d42013-12-03 20:11:261311const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:551312 // Transient entries take precedence. They are used for interstitial pages
1313 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231314 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231315 if (entry) {
jshin1fb76462016-04-05 22:13:031316 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231317 }
carlosk35f35af2015-12-01 10:55:401318
1319 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
1320 WebUI* our_web_ui = navigating_web_ui
1321 ? navigating_web_ui
1322 : GetRenderManager()->current_frame_host()->web_ui();
1323
[email protected]7ade2732011-02-10 00:13:581324 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541325 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321326 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541327 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351328 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261329 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541330 if (!title.empty())
1331 return title;
1332 }
1333 }
1334
1335 // We use the title for the last committed entry rather than a pending
1336 // navigation entry. For example, when the user types in a URL, we want to
1337 // keep the old page's title until the new load has committed and we get a new
1338 // title.
[email protected]96d185d2009-04-24 03:28:541339 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321340
creis072b61f2015-09-28 20:52:241341 // We make an exception for initial navigations. We only want to use the title
1342 // from the visible entry if:
1343 // 1. The pending entry has been explicitly assigned a title to display.
1344 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1345 // which case there is a pending entry index other than -1.
1346 //
1347 // Otherwise, we want to stick with the last committed entry's title during
1348 // new navigations, which have pending entries at index -1 with no title.
1349 if (controller_.IsInitialNavigation() &&
1350 ((controller_.GetVisibleEntry() &&
1351 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1352 controller_.GetPendingEntryIndex() != -1)) {
1353 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471354 }
[email protected]59167c22013-06-03 18:07:321355
[email protected]45d0ef7f2011-01-05 13:46:231356 if (entry) {
jshin1fb76462016-04-05 22:13:031357 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231358 }
[email protected]987fc3a2011-05-26 14:18:091359
1360 // |page_title_when_no_navigation_entry_| is finally used
1361 // if no title cannot be retrieved.
1362 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541363}
1364
creiscce56cd2014-09-29 22:45:221365SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211366 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541367}
1368
[email protected]b172aee2012-04-10 17:05:261369bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251370 return frame_tree_.IsLoading() &&
creisadca9862017-06-16 19:12:111371 !(ShowingInterstitialPage() && interstitial_page_->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491372}
1373
[email protected]6dfed692014-05-22 04:18:031374bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251375 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031376}
1377
[email protected]b172aee2012-04-10 17:05:261378bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031379 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311380}
1381
[email protected]b172aee2012-04-10 17:05:261382const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311383 return load_state_;
1384}
1385
[email protected]fcf75d42013-12-03 20:11:261386const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311387 return load_state_host_;
1388}
1389
avib7348942015-12-25 20:57:101390uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311391 return upload_size_;
1392}
1393
avib7348942015-12-25 20:57:101394uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311395 return upload_position_;
1396}
1397
[email protected]b172aee2012-04-10 17:05:261398const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541399 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311400}
1401
Charles Zhaod72f99d2018-09-17 14:18:271402bool WebContentsImpl::WasDiscarded() {
1403 return GetFrameTree()->root()->was_discarded();
1404}
1405
Shubhie Panickerddf2a4e2018-03-06 00:09:061406void WebContentsImpl::SetWasDiscarded(bool was_discarded) {
1407 GetFrameTree()->root()->set_was_discarded();
1408}
1409
[email protected]222f5822014-02-05 23:40:491410void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251411 DCHECK(!is_being_destroyed_);
Francois Doraye6161152018-03-27 22:05:371412 const bool was_captured = IsBeingCaptured();
[email protected]54597982013-02-06 01:59:551413 ++capturer_count_;
1414 DVLOG(1) << "There are now " << capturer_count_
1415 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491416
1417 // Note: This provides a hint to upstream code to size the views optimally
1418 // for quality (e.g., to avoid scaling).
1419 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1420 preferred_size_for_capture_ = capture_size;
1421 OnPreferredSizeChanged(preferred_size_);
1422 }
ccameron8807c38f2015-01-17 00:29:191423
Francois Doraye6161152018-03-27 22:05:371424 if (GetVisibility() != Visibility::VISIBLE && !was_captured) {
1425 // Ensure that all views act as if they were visible before capture begins.
1426 // TODO(fdoray): Replace RenderWidgetHostView::WasUnOccluded() with a method
1427 // to explicitly notify the RenderWidgetHostView that capture began.
1428 // https://crbug.com/668690
1429 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1430 view->WasUnOccluded();
1431 }
[email protected]54597982013-02-06 01:59:551432}
1433
1434void WebContentsImpl::DecrementCapturerCount() {
1435 --capturer_count_;
1436 DVLOG(1) << "There are now " << capturer_count_
1437 << " capturing(s) of WebContentsImpl@" << this;
1438 DCHECK_LE(0, capturer_count_);
1439
[email protected]5a652232013-02-12 06:15:251440 if (is_being_destroyed_)
1441 return;
1442
Francois Doray24fc62c2017-12-11 17:27:331443 if (!IsBeingCaptured()) {
[email protected]222f5822014-02-05 23:40:491444 const gfx::Size old_size = preferred_size_for_capture_;
1445 preferred_size_for_capture_ = gfx::Size();
1446 OnPreferredSizeChanged(old_size);
[email protected]222f5822014-02-05 23:40:491447
Francois Doraye6161152018-03-27 22:05:371448 if (visibility_ == Visibility::HIDDEN) {
Francois Doray18800972017-08-25 22:38:581449 DVLOG(1) << "Executing delayed WasHidden().";
1450 WasHidden();
Francois Doraye6161152018-03-27 22:05:371451 } else if (visibility_ == Visibility::OCCLUDED) {
Mitsuru Oshima04a80242018-03-03 03:06:151452 WasOccluded();
Francois Doraye6161152018-03-27 22:05:371453 }
[email protected]54597982013-02-06 01:59:551454 }
[email protected]be1f56ab2011-12-22 06:55:311455}
1456
Francois Doray24fc62c2017-12-11 17:27:331457bool WebContentsImpl::IsBeingCaptured() const {
1458 return capturer_count_ > 0;
[email protected]f2bd40812013-07-20 04:30:441459}
1460
miu50f97892014-09-22 22:49:521461bool WebContentsImpl::IsAudioMuted() const {
Max Morinb5506f72018-05-16 07:33:101462 if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) {
1463 return audio_stream_factory_ && audio_stream_factory_->IsMuted();
1464 }
miu50f97892014-09-22 22:49:521465 return audio_muter_.get() && audio_muter_->is_muting();
1466}
1467
1468void WebContentsImpl::SetAudioMuted(bool mute) {
1469 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1470 << " for WebContentsImpl@" << this;
1471
1472 if (mute == IsAudioMuted())
1473 return;
1474
Max Morinb5506f72018-05-16 07:33:101475 if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) {
1476 GetAudioStreamFactory()->SetMuted(mute);
miu50f97892014-09-22 22:49:521477 } else {
Max Morinb5506f72018-05-16 07:33:101478 if (mute) {
1479 if (!audio_muter_)
1480 audio_muter_.reset(new WebContentsAudioMuter(this));
1481 audio_muter_->StartMuting();
1482 } else {
1483 DCHECK(audio_muter_);
1484 audio_muter_->StopMuting();
1485 }
miu50f97892014-09-22 22:49:521486 }
1487
ericwilligersde386342016-10-19 02:35:091488 for (auto& observer : observers_)
1489 observer.DidUpdateAudioMutingState(mute);
wjmaclean2f797c782016-01-07 14:52:031490
Jan Rucka442c83f2017-08-08 13:27:541491 // Notification for UI updates in response to the changed muting state.
1492 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1493}
1494
1495bool WebContentsImpl::IsCurrentlyAudible() {
Chris Hamiltondf0d72cd2018-05-29 16:23:531496 return is_currently_audible_;
miu50f97892014-09-22 22:49:521497}
1498
ortunodf4d7982016-04-08 02:33:351499bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1500 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201501}
1502
sawtellea7333a82018-05-31 02:36:361503bool WebContentsImpl::HasPictureInPictureVideo() const {
1504 return has_picture_in_picture_video_;
1505}
1506
1507void WebContentsImpl::SetHasPictureInPictureVideo(
1508 bool has_picture_in_picture_video) {
1509 // If status of |this| is already accurate, there is no need to update.
1510 if (has_picture_in_picture_video == has_picture_in_picture_video_)
1511 return;
1512 has_picture_in_picture_video_ = has_picture_in_picture_video;
1513 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
François Beaufort058085d2018-08-30 15:29:141514 for (auto& observer : observers_)
1515 observer.MediaPictureInPictureChanged(has_picture_in_picture_video_);
sawtellea7333a82018-05-31 02:36:361516}
1517
[email protected]b172aee2012-04-10 17:05:261518bool WebContentsImpl::IsCrashed() const {
Dominic Mazzoni73a48322018-05-25 18:14:071519 switch (crashed_status_) {
1520 case base::TERMINATION_STATUS_PROCESS_CRASHED:
1521 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
1522 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
1523 case base::TERMINATION_STATUS_OOM:
1524 case base::TERMINATION_STATUS_LAUNCH_FAILED:
oshima620225722015-06-04 19:45:271525#if defined(OS_CHROMEOS)
Dominic Mazzoni73a48322018-05-25 18:14:071526 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM:
oshima620225722015-06-04 19:45:271527#endif
Dominic Mazzoni73a48322018-05-25 18:14:071528#if defined(OS_ANDROID)
1529 case base::TERMINATION_STATUS_OOM_PROTECTED:
1530#endif
1531 return true;
1532 case base::TERMINATION_STATUS_NORMAL_TERMINATION:
1533 case base::TERMINATION_STATUS_STILL_RUNNING:
1534 return false;
1535 case base::TERMINATION_STATUS_MAX_ENUM:
1536 NOTREACHED();
1537 return false;
1538 }
1539
1540 NOTREACHED();
1541 return false;
[email protected]3c9e1872010-11-18 16:17:491542}
1543
[email protected]b172aee2012-04-10 17:05:261544void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1545 int error_code) {
[email protected]443b80e2010-12-14 00:42:231546 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341547 return;
1548
[email protected]443b80e2010-12-14 00:42:231549 crashed_status_ = status;
1550 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211551 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341552}
1553
[email protected]b172aee2012-04-10 17:05:261554base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311555 return crashed_status_;
1556}
1557
afakhry98241832016-03-11 19:27:471558int WebContentsImpl::GetCrashedErrorCode() const {
1559 return crashed_error_code_;
1560}
1561
[email protected]b172aee2012-04-10 17:05:261562bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311563 return is_being_destroyed_;
1564}
1565
[email protected]7f924832014-08-09 05:57:221566void WebContentsImpl::NotifyNavigationStateChanged(
1567 InvalidateTypes changed_flags) {
dalecurtis88c240072015-12-09 02:11:181568 // Notify the media observer of potential audibility changes.
1569 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271570 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301571 }
1572
[email protected]d5f942ba2008-09-26 19:30:341573 if (delegate_)
1574 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441575
1576 if (GetOuterWebContents())
1577 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341578}
1579
Chris Hamiltondf0d72cd2018-05-29 16:23:531580void WebContentsImpl::OnAudioStateChanged() {
1581 // This notification can come from any embedded contents or from this
1582 // WebContents' stream monitor. Aggregate these signals to get the actual
1583 // state.
1584 bool is_currently_audible =
1585 audio_stream_monitor_.IsCurrentlyAudible() ||
1586 (browser_plugin_embedder_ &&
1587 browser_plugin_embedder_->AreAnyGuestsCurrentlyAudible());
1588 if (is_currently_audible == is_currently_audible_)
1589 return;
1590
1591 // Update internal state.
1592 is_currently_audible_ = is_currently_audible;
1593 was_ever_audible_ = was_ever_audible_ || is_currently_audible_;
1594
1595 SendPageMessage(
1596 new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_currently_audible_));
altimind8bd26c2016-11-04 11:44:541597
altiminec87fd1f2016-11-17 20:22:491598 // Notification for UI updates in response to the changed audio state.
altimind8bd26c2016-11-04 11:44:541599 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
Jan Rucka442c83f2017-08-08 13:27:541600
Chris Hamiltondf0d72cd2018-05-29 16:23:531601 // Ensure that audio state changes propagate from innermost to outermost
1602 // WebContents.
1603 if (GetOuterWebContents())
1604 GetOuterWebContents()->OnAudioStateChanged();
Tommy Steimel18360512017-11-01 00:38:191605
Chris Hamiltoneb41198f2018-05-24 18:41:261606 for (auto& observer : observers_)
Chris Hamiltondf0d72cd2018-05-29 16:23:531607 observer.OnAudioStateChanged(is_currently_audible_);
altimind8bd26c2016-11-04 11:44:541608}
1609
gab0dccfef2015-05-20 18:43:391610base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021611 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331612}
1613
[email protected]9e2e4632012-07-27 16:38:411614void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541615 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591616
EhsanK2075c7e2017-08-21 02:42:391617 if (auto* view = GetRenderWidgetHostView()) {
lfgf949e0e2017-05-10 22:18:111618 view->Show();
[email protected]789e9152009-08-04 21:59:431619#if defined(OS_MACOSX)
lfgf949e0e2017-05-10 22:18:111620 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431621#endif
1622 }
[email protected]96d185d2009-04-24 03:28:541623
EhsanK2075c7e2017-08-21 02:42:391624 if (!ShowingInterstitialPage())
1625 SetVisibilityForChildViews(true);
1626
lfg717154072016-06-30 15:04:161627 SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE));
1628
gab0dccfef2015-05-20 18:43:391629 last_active_time_ = base::TimeTicks::Now();
Francois Doraye6161152018-03-27 22:05:371630 SetVisibility(Visibility::VISIBLE);
Lukasz Anforowicz873e6082018-05-17 00:12:331631
1632 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1633 RenderFrameProxyHost* parent = node->render_manager()->GetProxyToParent();
1634 if (!parent)
1635 continue;
1636
1637 if (parent->cross_process_frame_connector()->IsVisible()) {
1638 // MaybeLogCrash will check 1) if there was a crash or not and 2) if the
1639 // crash might have been already logged earlier as kCrashedWhileVisible.
1640 parent->cross_process_frame_connector()->MaybeLogCrash(
1641 CrossProcessFrameConnector::CrashVisibility::kShownAfterCrashing);
1642 }
1643 }
[email protected]be1f56ab2011-12-22 06:55:311644}
1645
[email protected]b172aee2012-04-10 17:05:261646void WebContentsImpl::WasHidden() {
Jennifer Apacible72c31412018-06-19 16:52:241647 // If there are entities capturing screenshots or video (e.g. mirroring),
1648 // or in Picture-in-Picture mode, don't activate the "disable rendering"
1649 // optimization.
1650 if (!IsBeingCaptured() && !HasPictureInPictureVideo()) {
[email protected]151a63d2011-12-20 22:32:521651 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551652 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261653 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521654 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331655 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521656 // calls us).
EhsanK2075c7e2017-08-21 02:42:391657 if (auto* view = GetRenderWidgetHostView())
lfgf949e0e2017-05-10 22:18:111658 view->Hide();
lfg717154072016-06-30 15:04:161659
EhsanK2075c7e2017-08-21 02:42:391660 if (!ShowingInterstitialPage())
Igor Eremeevef59187a2017-09-29 00:25:421661 SetVisibilityForChildViews(false);
EhsanK2075c7e2017-08-21 02:42:391662
lfg717154072016-06-30 15:04:161663 SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
[email protected]96d185d2009-04-24 03:28:541664 }
1665
Francois Doraye6161152018-03-27 22:05:371666 SetVisibility(Visibility::HIDDEN);
[email protected]375fa1b2012-05-22 22:05:371667}
1668
Daniel Cheng90196c82018-04-25 21:49:141669bool WebContentsImpl::HasRecentInteractiveInputEvent() const {
1670 static constexpr base::TimeDelta kMaxInterval =
1671 base::TimeDelta::FromSeconds(5);
1672 base::TimeDelta delta =
1673 ui::EventTimeForNow() - last_interactive_input_event_time_;
1674 // Note: the expectation is that the caller is typically expecting an input
1675 // event, e.g. validating that a WebUI message that requires a gesture is
1676 // actually attached to a gesture. Logging to UMA here should hopefully give
1677 // sufficient data if 5 seconds is actually sufficient (or even too high a
1678 // threshhold).
1679 UMA_HISTOGRAM_TIMES("Tabs.TimeSinceLastInteraction", delta);
1680 return delta <= kMaxInterval;
1681}
1682
Avi Drissman738ea192018-08-29 20:24:161683void WebContentsImpl::SetIgnoreInputEvents(bool ignore_input_events) {
1684 ignore_input_events_ = ignore_input_events;
1685}
1686
Bo Liu168c8642017-08-28 18:26:021687#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:501688void WebContentsImpl::SetMainFrameImportance(
1689 ChildProcessImportance importance) {
1690 GetMainFrame()->GetRenderWidgetHost()->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281691 if (ShowingInterstitialPage()) {
Bo Liu16dd7b8322018-05-02 21:19:501692 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
1693 ->GetRenderWidgetHost()
1694 ->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281695 }
Bo Liu7c6779e92017-08-16 02:02:281696}
Bo Liu168c8642017-08-28 18:26:021697#endif
Bo Liu7c6779e92017-08-16 02:02:281698
ccameron8807c38f2015-01-17 00:29:191699void WebContentsImpl::WasOccluded() {
Francois Doray24fc62c2017-12-11 17:27:331700 if (!IsBeingCaptured()) {
Francois Doray18800972017-08-25 22:38:581701 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1702 view->WasOccluded();
1703 }
Francois Doraye6161152018-03-27 22:05:371704 SetVisibility(Visibility::OCCLUDED);
ccameron8807c38f2015-01-17 00:29:191705}
1706
Francois Dorayfe4a1772018-02-17 04:17:091707Visibility WebContentsImpl::GetVisibility() const {
Francois Doraye6161152018-03-27 22:05:371708 return visibility_;
Francois Dorayfe4a1772018-02-17 04:17:091709}
1710
Alex Moshchuk6fcaca752018-07-14 02:13:591711// TODO(alexmos): rename to NeedToFireBeforeUnloadOrUnload().
[email protected]b172aee2012-04-10 17:05:261712bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311713 // TODO(creis): Should we fire even for interstitial pages?
Alex Moshchuk6fcaca752018-07-14 02:13:591714 if (ShowingInterstitialPage())
1715 return false;
1716
1717 if (!WillNotifyDisconnection())
1718 return false;
1719
1720 // Don't fire if the main frame's RenderViewHost indicates that beforeunload
1721 // and unload have already executed (e.g., after receiving a ClosePage ACK)
1722 // or should be ignored.
1723 if (GetRenderViewHost()->SuddenTerminationAllowed())
1724 return false;
1725
1726 // TODO(alexmos): This checks for both beforeunload and unload handlers from
1727 // the whole main frame process. Remove this and explicitly check whether
1728 // the main frame has each of these handlers. This can be done for
1729 // beforeunload via RenderFrameHostImpl::ShouldDispatchBeforeUnload(), and
1730 // something similar is needed for unload.
1731 if (!GetMainFrame()->GetProcess()->SuddenTerminationAllowed())
1732 return true;
1733
1734 // Check whether any subframes need to run beforeunload handlers.
1735 //
1736 // TODO(alexmos): Also check whether subframes need to run unload handlers in
1737 // addition to beforeunload.
1738 return GetMainFrame()->ShouldDispatchBeforeUnload(
1739 true /* check_subframes_only */);
[email protected]be1f56ab2011-12-22 06:55:311740}
1741
Chris Hamilton3b3e315d2018-09-19 13:16:211742void WebContentsImpl::DispatchBeforeUnload(bool auto_cancel) {
1743 auto before_unload_type =
1744 auto_cancel ? RenderFrameHostImpl::BeforeUnloadType::DISCARD
1745 : RenderFrameHostImpl::BeforeUnloadType::TAB_CLOSE;
1746 GetMainFrame()->DispatchBeforeUnload(before_unload_type, false);
[email protected]1c3f80bd2014-04-08 23:02:061747}
1748
lazyboy6ec48b2a2015-06-29 15:18:141749void WebContentsImpl::AttachToOuterWebContentsFrame(
1750 WebContents* outer_web_contents,
1751 RenderFrameHost* outer_contents_frame) {
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391752 DCHECK(!node_.outer_web_contents());
1753
lfg91a79e12016-04-01 23:52:191754 RenderFrameHostManager* render_manager = GetRenderManager();
1755
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391756 // When attaching a WebContents as an inner WebContents, we need to replace
1757 // the Webcontents' view with a WebContentsViewChildFrame.
1758 view_.reset(new WebContentsViewChildFrame(
1759 this, GetContentClient()->browser()->GetWebContentsViewDelegate(this),
1760 &render_view_host_delegate_view_));
1761
lfg91a79e12016-04-01 23:52:191762 // When the WebContents being initialized has an opener, the browser side
1763 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1764 // created. This is needed because the usual initialization happens during
1765 // the first navigation, but when attaching a new window we don't navigate
1766 // before attaching. If the browser side is already initialized, the calls
1767 // below will just early return.
1768 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1769 GetMainFrame()->Init();
1770 if (!render_manager->GetRenderWidgetHostView())
1771 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1772
avallee7529b2a2017-04-26 11:37:511773 auto* outer_web_contents_impl =
1774 static_cast<WebContentsImpl*>(outer_web_contents);
1775 auto* outer_contents_frame_impl =
1776 static_cast<RenderFrameHostImpl*>(outer_contents_frame);
lazyboy6ec48b2a2015-06-29 15:18:141777 // Create a link to our outer WebContents.
avallee7529b2a2017-04-26 11:37:511778 node_.ConnectToOuterWebContents(outer_web_contents_impl,
1779 outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141780
1781 DCHECK(outer_contents_frame);
1782
1783 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1784 // SiteInstance of the outer WebContents. The proxy will be used to send
1785 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191786 render_manager->CreateOuterDelegateProxy(
avallee7529b2a2017-04-26 11:37:511787 outer_contents_frame->GetSiteInstance(), outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141788
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141789 ReattachToOuterWebContentsFrame();
ekaramadadd882292016-06-08 15:22:561790
avallee7529b2a2017-04-26 11:37:511791 if (outer_web_contents_impl->frame_tree_.GetFocusedFrame() ==
1792 outer_contents_frame_impl->frame_tree_node()) {
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:571793 SetFocusedFrame(frame_tree_.root(),
1794 outer_contents_frame->GetSiteInstance());
avallee7529b2a2017-04-26 11:37:511795 }
1796
ekaramadadd882292016-06-08 15:22:561797 // At this point, we should destroy the TextInputManager which will notify all
1798 // the RWHV in this WebContents. The RWHV in this WebContents should use the
1799 // TextInputManager owned by the outer WebContents.
1800 // TODO(ekaramad): Is it possible to have TextInputState before attaching to
1801 // outer WebContents? In such a case, is this still the right way to hand off
1802 // state tracking from inner WebContents's TextInputManager to that of the
1803 // outer WebContent (crbug.com/609846)?
1804 text_input_manager_.reset(nullptr);
lazyboy6ec48b2a2015-06-29 15:18:141805}
1806
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141807void WebContentsImpl::ReattachToOuterWebContentsFrame() {
1808 DCHECK(node_.outer_web_contents());
1809 auto* render_manager = GetRenderManager();
1810 auto* parent_frame =
1811 node_.OuterContentsFrameTreeNode()->current_frame_host()->GetParent();
1812 render_manager->SetRWHViewForInnerContents(
1813 render_manager->GetRenderWidgetHostView());
1814
1815 static_cast<RenderWidgetHostViewChildFrame*>(
1816 render_manager->GetRenderWidgetHostView())
1817 ->RegisterFrameSinkId();
1818
1819 // Set up the the guest's AX tree to point back at the embedder's AX tree.
1820 GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(
1821 parent_frame->GetAXTreeID());
1822 GetMainFrame()->UpdateAXTreeData();
1823}
1824
dalecurtis6c58ed02016-10-28 23:02:371825void WebContentsImpl::DidChangeVisibleSecurityState() {
1826 if (delegate_) {
1827 delegate_->VisibleSecurityStateChanged(this);
cjgrant6d1d727a2016-12-09 21:16:571828 for (auto& observer : observers_)
1829 observer.DidChangeVisibleSecurityState();
dalecurtis6c58ed02016-10-28 23:02:371830 }
1831}
1832
Ahmed Fakhryd70bf37b2018-04-04 17:07:241833void WebContentsImpl::NotifyPreferencesChanged() {
1834 std::set<RenderViewHost*> render_view_host_set;
1835 for (FrameTreeNode* node : frame_tree_.Nodes()) {
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531836 render_view_host_set.insert(
1837 node->current_frame_host()->GetRenderViewHost());
Ahmed Fakhryd70bf37b2018-04-04 17:07:241838 }
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531839
Ahmed Fakhryd70bf37b2018-04-04 17:07:241840 for (RenderViewHost* render_view_host : render_view_host_set)
1841 render_view_host->OnWebkitPreferencesChanged();
1842}
1843
[email protected]b172aee2012-04-10 17:05:261844void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381845 for (FrameTreeNode* node : frame_tree_.Nodes())
1846 node->StopLoading();
ericwilligersde386342016-10-19 02:35:091847 for (auto& observer : observers_)
1848 observer.NavigationStopped();
[email protected]0bfbf882011-12-22 18:19:271849}
1850
Francois Doray47f759d2018-06-11 18:13:511851void WebContentsImpl::SetPageFrozen(bool frozen) {
1852 // A visible page is never frozen.
1853 DCHECK_NE(Visibility::VISIBLE, GetVisibility());
1854
1855 SendPageMessage(new PageMsg_SetPageFrozen(MSG_ROUTING_NONE, frozen));
Fadi Meawada6573e02018-03-10 00:52:111856}
1857
erikchen6c7df7f7a2018-05-03 18:13:591858std::unique_ptr<WebContents> WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441859 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211860 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451861 // before.
[email protected]54944cde2012-12-09 09:24:591862 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451863 create_params.initial_size = GetContainerBounds().size();
Ian Clelland5cbaaf82017-11-27 22:00:031864 FrameTreeNode* opener = frame_tree_.root()->opener();
1865 RenderFrameHostImpl* opener_rfh = nullptr;
1866 if (opener)
1867 opener_rfh = opener->current_frame_host();
erikchen6c7df7f7a2018-05-03 18:13:591868 std::unique_ptr<WebContentsImpl> tc =
erikchen50735fd2018-05-05 15:08:331869 CreateWithOpener(create_params, opener_rfh);
Francois Dorayeaace782017-06-21 16:37:241870 tc->GetController().CopyStateFrom(controller_, true);
ericwilligersde386342016-10-19 02:35:091871 for (auto& observer : observers_)
erikchen6c7df7f7a2018-05-03 18:13:591872 observer.DidCloneToNewWebContents(this, tc.get());
[email protected]0bfbf882011-12-22 18:19:271873 return tc;
1874}
1875
[email protected]14392a52012-05-02 20:28:441876void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211877 const NotificationSource& source,
1878 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441879 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211880 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1881 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031882 RenderWidgetHostView* view = host->GetView();
1883 if (view == GetFullscreenRenderWidgetHostView()) {
1884 // We cannot just call view_->RestoreFocus() here. On some platforms,
1885 // attempting to focus the currently-invisible WebContentsView will be
1886 // flat-out ignored. Therefore, this boolean is used to track whether
1887 // we will request focus after the fullscreen widget has been
1888 // destroyed.
1889 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1890 } else {
alexmosc2a8cec2016-05-23 22:19:531891 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:031892 i != pending_widget_views_.end(); ++i) {
1893 if (host->GetView() == i->second) {
1894 pending_widget_views_.erase(i);
1895 break;
1896 }
[email protected]bafe6cd2012-05-23 23:09:501897 }
1898 }
1899 break;
1900 }
[email protected]14392a52012-05-02 20:28:441901 default:
1902 NOTREACHED();
1903 }
1904}
1905
[email protected]ec6c05f2013-10-23 18:41:571906WebContents* WebContentsImpl::GetWebContents() {
1907 return this;
1908}
1909
[email protected]54944cde2012-12-09 09:24:591910void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211911 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361912 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211913 // it should be hidden.
Francois Doraye6161152018-03-27 22:05:371914 visibility_ =
1915 params.initially_hidden ? Visibility::HIDDEN : Visibility::VISIBLE;
[email protected]d6fa88f2013-10-18 16:00:431916
Sebastien Marchand28cf23182018-06-20 02:39:351917 if (!params.last_active_time.is_null())
1918 last_active_time_ = params.last_active_time;
1919
dcheng3ce04b62015-10-26 23:30:551920 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541921 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551922 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1923 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541924 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551925 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1926 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1927
1928 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1929 if (!site_instance)
1930 site_instance = SiteInstance::Create(params.browser_context);
Lukasz Anforowicz3caa8372018-06-05 17:22:071931 if (params.desired_renderer_state == CreateParams::kNoRendererProcess) {
1932 static_cast<SiteInstanceImpl*>(site_instance.get())
1933 ->PreventAssociationWithSpareProcess();
1934 }
dcheng3ce04b62015-10-26 23:30:551935
1936 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1937 // local root by definition.
1938 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1939 // longer be necessary to eagerly grab a routing ID for the view.
1940 // https://crbug.com/545684
1941 int32_t view_routing_id = params.routing_id;
1942 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1943 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
Albert J. Wongcb004632018-07-10 22:58:251944 view_routing_id = site_instance->GetProcess()->GetNextRoutingID();
1945 main_frame_widget_routing_id =
dcheng3ce04b62015-10-26 23:30:551946 site_instance->GetProcess()->GetNextRoutingID();
1947 }
1948
Albert J. Wongcb004632018-07-10 22:58:251949 DCHECK_NE(view_routing_id, main_frame_widget_routing_id);
1950
Dave Tapuska485aca92017-08-08 00:47:581951 GetRenderManager()->Init(
1952 site_instance.get(), view_routing_id, params.main_frame_routing_id,
1953 main_frame_widget_routing_id, params.renderer_initiated_creation);
lukasza464d8692016-02-22 19:26:321954
lukasza5140a412016-09-15 21:12:301955 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
1956 // main frame - let's do the same thing here.
1957 std::string unique_name;
lukasza464d8692016-02-22 19:26:321958 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191959
[email protected]fc2b46b2014-05-03 16:33:451960 WebContentsViewDelegate* delegate =
1961 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1962
sky52a39e342016-12-17 17:23:221963 if (GuestMode::IsCrossProcessFrameGuest(this)) {
1964 view_.reset(new WebContentsViewChildFrame(
1965 this, delegate, &render_view_host_delegate_view_));
1966 } else {
1967 view_.reset(CreateWebContentsView(this, delegate,
1968 &render_view_host_delegate_view_));
Scott Violetc884c7fd2017-11-03 23:51:011969 if (browser_plugin_guest_) {
1970 view_ = std::make_unique<WebContentsViewGuest>(
1971 this, browser_plugin_guest_.get(), std::move(view_),
1972 &render_view_host_delegate_view_);
1973 }
[email protected]d1198fd2012-08-13 22:50:191974 }
[email protected]fc2b46b2014-05-03 16:33:451975 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191976 CHECK(view_.get());
1977
[email protected]ed245db2012-12-18 08:00:451978 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591979 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191980
brettw4b461082016-11-19 18:55:161981#if BUILDFLAG(ENABLE_PLUGINS)
tommyclieb25b2a2014-11-03 19:45:091982 plugin_content_origin_whitelist_.reset(
1983 new PluginContentOriginWhitelist(this));
1984#endif
1985
[email protected]d1198fd2012-08-13 22:50:191986 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211987 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1988 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101989
leon.hane4db177a2017-02-07 14:19:161990 screen_orientation_provider_.reset(new ScreenOrientationProvider(this));
[email protected]01f83f92014-06-17 14:41:541991
mlamouriefdca9d2014-09-16 16:55:401992 manifest_manager_host_.reset(new ManifestManagerHost(this));
1993
mfomitchev2b8b066a2016-01-28 19:23:151994#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101995 date_time_chooser_.reset(new DateTimeChooserAndroid());
1996#endif
fsamuel7310a4262014-12-05 05:06:441997
1998 // BrowserPluginGuest::Init needs to be called after this WebContents has
1999 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
2000 if (browser_plugin_guest_)
2001 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:372002
2003 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
2004 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:562005
2006 // If the WebContents creation was renderer-initiated, it means that the
2007 // corresponding RenderView and main RenderFrame have already been created.
2008 // Ensure observers are notified about this.
2009 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:432010 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
Alex Moshchuk27caae82017-09-11 23:11:182011 GetRenderViewHost()->DispatchRenderViewCreated();
naskob21fe4872015-02-24 14:15:562012 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
2013 }
naskof5940b9f2015-03-02 23:04:052014
lof84501da082016-05-23 21:22:542015 // Create the renderer process in advance if requested.
Lukasz Anforowicz3caa8372018-06-05 17:22:072016 if (params.desired_renderer_state ==
2017 CreateParams::kInitializeAndWarmupRendererProcess) {
lof84501da082016-05-23 21:22:542018 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
2019 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
2020 }
2021 }
2022
naskof5940b9f2015-03-02 23:04:052023 // Ensure that observers are notified of the creation of this WebContents's
2024 // main RenderFrameHost. It must be done here for main frames, since the
2025 // NotifySwappedFromRenderManager expects view_ to already be created and that
2026 // happens after RenderFrameHostManager::Init.
2027 NotifySwappedFromRenderManager(
2028 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:192029}
2030
[email protected]7fff43e2013-05-21 20:21:102031void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
2032 RemoveDestructionObserver(web_contents);
2033
[email protected]ceee8cd2013-03-08 04:59:512034 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:532035 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:512036 ++iter) {
erikchenbee5c9622018-04-27 19:30:252037 if (iter->second.get() != web_contents)
[email protected]ceee8cd2013-03-08 04:59:512038 continue;
erikchenbee5c9622018-04-27 19:30:252039
2040 // Someone else has deleted the WebContents. That should never happen!
2041 // TODO(erikchen): Fix semantics here. https://crbug.com/832879.
2042 iter->second.release();
[email protected]ceee8cd2013-03-08 04:59:512043 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:512044 return;
2045 }
2046 NOTREACHED();
[email protected]14392a52012-05-02 20:28:442047}
2048
[email protected]7fff43e2013-05-21 20:21:102049void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
2050 if (!ContainsKey(destruction_observers_, web_contents)) {
2051 destruction_observers_[web_contents] =
Jeremy Roman04f27c372017-10-27 15:20:552052 std::make_unique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:102053 }
2054}
2055
2056void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:462057 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:102058}
2059
[email protected]b172aee2012-04-10 17:05:262060void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312061 observers_.AddObserver(observer);
2062}
2063
[email protected]b172aee2012-04-10 17:05:262064void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312065 observers_.RemoveObserver(observer);
2066}
2067
[email protected]948481d2014-06-11 18:32:222068std::set<RenderWidgetHostView*>
2069WebContentsImpl::GetRenderWidgetHostViewsInTree() {
2070 std::set<RenderWidgetHostView*> set;
2071 if (ShowingInterstitialPage()) {
lfgf949e0e2017-05-10 22:18:112072 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView())
2073 set.insert(rwhv);
[email protected]948481d2014-06-11 18:32:222074 } else {
dchengafb53e22016-02-04 08:11:082075 for (RenderFrameHost* rfh : GetAllFrames()) {
lfgf949e0e2017-05-10 22:18:112076 if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
2077 ->frame_tree_node()
2078 ->render_manager()
2079 ->GetRenderWidgetHostView()) {
2080 set.insert(rwhv);
2081 }
dchengafb53e22016-02-04 08:11:082082 }
[email protected]948481d2014-06-11 18:32:222083 }
[email protected]de3c5d82014-05-28 22:12:592084 return set;
2085}
2086
[email protected]b172aee2012-04-10 17:05:262087void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:342088 if (delegate_)
2089 delegate_->ActivateContents(this);
2090}
2091
avi3e4b8512015-11-11 01:55:492092void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
2093 if (!RenderViewHostImpl::From(render_widget_host))
2094 return;
2095
[email protected]63954792011-07-11 04:17:482096 if (delegate_)
2097 delegate_->LostCapture();
2098}
2099
Steven Holte38041342018-06-22 22:00:572100ukm::SourceId WebContentsImpl::GetUkmSourceIdForLastCommittedSource() const {
2101 return last_committed_source_id_;
2102}
2103
Ahmed Fakhry58e6ef542018-09-04 18:05:382104void WebContentsImpl::SetTopControlsShownRatio(float ratio) {
2105 if (delegate_)
2106 delegate_->SetTopControlsShownRatio(this, ratio);
2107}
2108
Ahmed Fakhry6efd6eb2018-09-25 17:35:452109bool WebContentsImpl::DoBrowserControlsShrinkRendererSize() const {
2110 return delegate_ && delegate_->DoBrowserControlsShrinkRendererSize(this);
2111}
2112
Ahmed Fakhry58e6ef542018-09-04 18:05:382113int WebContentsImpl::GetTopControlsHeight() const {
2114 return delegate_ ? delegate_->GetTopControlsHeight() : 0;
2115}
2116
2117void WebContentsImpl::SetTopControlsGestureScrollInProgress(bool in_progress) {
2118 if (delegate_)
2119 delegate_->SetTopControlsGestureScrollInProgress(in_progress);
2120}
2121
lazyboy63f5b312015-11-23 20:19:522122void WebContentsImpl::RenderWidgetCreated(
2123 RenderWidgetHostImpl* render_widget_host) {
2124 created_widgets_.insert(render_widget_host);
2125}
2126
[email protected]b24b68a2012-09-24 21:57:262127void WebContentsImpl::RenderWidgetDeleted(
2128 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:522129 // Note that |is_being_destroyed_| can be true at this point as
2130 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
2131 // us here.
2132 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262133
lazyboy63f5b312015-11-23 20:19:522134 if (is_being_destroyed_)
2135 return;
[email protected]44470a22013-01-24 01:21:542136
2137 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:372138 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
2139 render_widget_host->GetProcess()->GetID() ==
2140 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:492141 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:532142 delegate_->ExitFullscreenModeForTab(this);
ericwilligersde386342016-10-19 02:35:092143 for (auto& observer : observers_)
2144 observer.DidDestroyFullscreenWidget();
alexmosc9e76ec2016-05-16 22:59:372145 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:542146 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:032147 if (fullscreen_widget_had_focus_at_shutdown_)
2148 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:542149 }
lfgbee1e0a2016-06-08 21:24:212150
lfg7d4caad2017-03-22 09:01:452151 if (render_widget_host == mouse_lock_widget_)
lfgff8dfc8d2016-10-21 17:42:322152 LostMouseLock(mouse_lock_widget_);
Joe Downing192998b22018-03-22 15:51:362153
Joe Downingc1a57efe2018-05-09 18:23:542154 CancelKeyboardLock(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262155}
2156
miu9e14e492014-10-25 02:39:042157void WebContentsImpl::RenderWidgetGotFocus(
2158 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:372159 // Notify the observers if an embedded fullscreen widget was focused.
2160 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2161 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
Michael Thiessen896405db2017-07-20 17:52:322162 NotifyWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:372163 }
miu9e14e492014-10-25 02:39:042164}
2165
zijiehe3bee08e22017-05-17 04:14:462166void WebContentsImpl::RenderWidgetLostFocus(
2167 RenderWidgetHostImpl* render_widget_host) {
Michael Thiessen896405db2017-07-20 17:52:322168 // Notify the observers if an embedded fullscreen widget lost focus.
2169 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2170 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
2171 NotifyWebContentsLostFocus(render_widget_host);
2172 }
zijiehe3bee08e22017-05-17 04:14:462173}
2174
estaded0a0c992015-01-21 14:12:062175void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:312176 RenderWidgetHostImpl* render_widget_host,
Christopher Cameron07f666b2018-02-13 23:41:192177 const ScreenInfo& screen_info,
rouslan2f5993f2015-01-29 00:18:312178 bool width_changed) {
creisc014b402015-04-23 16:41:452179 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:292180 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:062181 return;
estaded0a0c992015-01-21 14:12:062182
lfg8d649cc2017-04-28 18:04:302183 SendPageMessage(new PageMsg_UpdateScreenInfo(MSG_ROUTING_NONE, screen_info));
2184
ericwilligersde386342016-10-19 02:35:092185 for (auto& observer : observers_)
2186 observer.MainFrameWasResized(width_changed);
estaded0a0c992015-01-21 14:12:062187}
2188
skyf65d9bb2017-03-24 02:26:392189KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(
2190 const NativeWebKeyboardEvent& event) {
2191 return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event)
2192 : KeyboardEventProcessingResult::NOT_HANDLED;
[email protected]63954792011-07-11 04:17:482193}
2194
[email protected]b172aee2012-04-10 17:05:262195void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:102196 if (browser_plugin_embedder_ &&
2197 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
2198 return;
2199 }
[email protected]63954792011-07-11 04:17:482200 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132201 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:482202}
2203
[email protected]d92026ef2014-03-03 21:04:132204bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:462205 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:192206#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:332207 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
2208 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:192209 // -the OS already has a gesture to do this through pinch-zoom
2210 // -if a user starts an inertial scroll, let's go, and presses control
2211 // (i.e. control+tab) then the OS's buffered scroll events will come in
2212 // with control key set which isn't what the user wants
Blink Reformat1c4d759e2017-04-09 16:34:542213 if (delegate_ && event.wheel_ticks_y &&
Ehsan Karamad0f83cb112018-09-06 22:07:362214 event.event_action == blink::WebMouseWheelEvent::EventAction::kPageZoom) {
w.shackleton49bcd392016-01-06 17:38:222215 // Count only integer cumulative scrolls as zoom events; this handles
2216 // smooth scroll and regular scroll device behavior.
Blink Reformat1c4d759e2017-04-09 16:34:542217 zoom_scroll_remainder_ += event.wheel_ticks_y;
w.shackleton49bcd392016-01-06 17:38:222218 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
2219 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
2220 if (whole_zoom_scroll_remainder_ != 0) {
2221 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
2222 }
[email protected]fb3f066e2013-02-12 19:12:522223 return true;
2224 }
[email protected]bccc4472013-04-18 16:37:192225#endif
[email protected]fb3f066e2013-02-12 19:12:522226 return false;
2227}
2228
[email protected]04bce562014-01-30 05:34:542229bool WebContentsImpl::PreHandleGestureEvent(
2230 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:032231 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:542232}
2233
kenrb2a565f82015-09-02 20:24:592234RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:452235 if (!is_being_destroyed_ && GetOuterWebContents())
2236 return GetOuterWebContents()->GetInputEventRouter();
2237
2238 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:592239 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
2240 return rwh_input_event_router_.get();
2241}
2242
alexmos3fcd0ca2015-10-23 18:18:332243void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
2244 // Focus loss may occur while this WebContents is being destroyed. Don't
2245 // send the message in this case, as the main frame's RenderFrameHost and
2246 // other state has already been cleared.
2247 if (is_being_destroyed_)
2248 return;
2249
2250 frame_tree_.ReplicatePageFocus(is_focused);
2251}
2252
alexmosc4cbacb2015-11-21 01:29:222253RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
2254 RenderWidgetHostImpl* receiving_widget) {
alexmosc4cbacb2015-11-21 01:29:222255 // Events for widgets other than the main frame (e.g., popup menus) should be
2256 // forwarded directly to the widget they arrived on.
2257 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
2258 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522259
lfg1453e412017-04-11 00:48:502260 WebContentsImpl* focused_contents = GetFocusedWebContents();
2261
2262 // If the focused WebContents is showing an interstitial, return the
2263 // interstitial's widget.
2264 if (focused_contents->ShowingInterstitialPage()) {
2265 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112266 focused_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502267 ->GetRenderWidgetHost();
2268 }
2269
paulmeyerfeafc2d2017-04-25 21:46:402270 // If the focused WebContents is a guest WebContents, then get the focused
2271 // frame in the embedder WebContents instead.
2272 FrameTreeNode* focused_frame = nullptr;
2273 if (focused_contents->browser_plugin_guest_ &&
2274 !GuestMode::IsCrossProcessFrameGuest(focused_contents)) {
2275 focused_frame = frame_tree_.GetFocusedFrame();
2276 } else {
2277 focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
2278 }
lfg1453e412017-04-11 00:48:502279
alexmosc4d183e2015-11-06 00:46:522280 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:222281 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522282
alexmos732ca3a2015-12-08 02:01:022283 // The view may be null if a subframe's renderer process has crashed while
2284 // the subframe has focus. Drop the event in that case. Do not give
2285 // it to the main frame, so that the user doesn't unexpectedly type into the
2286 // wrong frame if a focused subframe renderer crashes while they type.
2287 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
2288 if (!view)
2289 return nullptr;
2290
2291 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:522292}
2293
avallee9993fca2016-11-17 06:16:502294RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
lfg1453e412017-04-11 00:48:502295 WebContentsImpl* focused_web_contents = GetFocusedWebContents();
2296
2297 if (focused_web_contents->ShowingInterstitialPage()) {
2298 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112299 focused_web_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502300 ->GetRenderWidgetHost();
2301 }
Alex Valléedc80ae2ed2017-09-06 21:55:442302 if (!GuestMode::IsCrossProcessFrameGuest(focused_web_contents) &&
2303 focused_web_contents->browser_plugin_guest_) {
2304 // If this is a guest, we need to be controlled by our embedder.
2305 return focused_web_contents->GetOuterWebContents()
2306 ->GetMainFrame()
2307 ->GetRenderWidgetHost();
2308 }
lfg1453e412017-04-11 00:48:502309
2310 return focused_web_contents->GetMainFrame()->GetRenderWidgetHost();
avallee9993fca2016-11-17 06:16:502311}
2312
Dave Tapuska3ed44192018-05-01 18:53:302313void WebContentsImpl::EnterFullscreenMode(
2314 const GURL& origin,
2315 const blink::WebFullscreenOptions& options) {
mlamouri7a78d6fd2015-01-17 13:23:532316 // This method is being called to enter renderer-initiated fullscreen mode.
2317 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:492318 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372319 if (widget_view) {
2320 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2321 ->ShutdownAndDestroyWidget(true);
2322 }
[email protected]4aebbca2013-09-17 22:26:492323
Joe Downing13dd76b2018-04-09 18:32:152324 if (delegate_) {
Dave Tapuska3ed44192018-05-01 18:53:302325 delegate_->EnterFullscreenModeForTab(this, origin, options);
mlamouri7a78d6fd2015-01-17 13:23:532326
Joe Downing13dd76b2018-04-09 18:32:152327 if (keyboard_lock_widget_)
2328 delegate_->RequestKeyboardLock(this, esc_key_locked_);
2329 }
2330
ericwilligersde386342016-10-19 02:35:092331 for (auto& observer : observers_)
2332 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false);
mlamouri7a78d6fd2015-01-17 13:23:532333}
2334
bokanece34a82016-01-28 19:49:462335void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532336 // This method is being called to leave renderer-initiated fullscreen mode.
2337 // Make sure any existing fullscreen widget is shut down first.
2338 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372339 if (widget_view) {
2340 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2341 ->ShutdownAndDestroyWidget(true);
2342 }
mlamouri7a78d6fd2015-01-17 13:23:532343
Joe Downing13dd76b2018-04-09 18:32:152344 if (delegate_) {
mlamouri7a78d6fd2015-01-17 13:23:532345 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:372346
Joe Downing13dd76b2018-04-09 18:32:152347 if (keyboard_lock_widget_)
2348 delegate_->CancelKeyboardLockRequest(this);
2349 }
2350
bokanece34a82016-01-28 19:49:462351 // The fullscreen state is communicated to the renderer through a resize
2352 // message. If the change in fullscreen state doesn't cause a view resize
2353 // then we must ensure web contents exit the fullscreen state by explicitly
2354 // sending a resize message. This is required for the situation of the browser
2355 // moving the view into a "browser fullscreen" state and then the contents
2356 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
2357 // have the side effect of the view resizing, hence the explicit call here is
2358 // required.
2359 if (!will_cause_resize) {
2360 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
2361 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:162362 render_widget_host->SynchronizeVisualProperties();
bokanece34a82016-01-28 19:49:462363 }
scheib3dcb6c932015-02-23 10:55:582364 }
2365
Arthur Sonzogni929d29f2018-09-17 14:19:442366 current_fullscreen_frame_ = nullptr;
Becca Hughese9e27952018-06-25 17:08:272367
ericwilligersde386342016-10-19 02:35:092368 for (auto& observer : observers_) {
2369 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
2370 will_cause_resize);
2371 }
Becca Hughesd11d6502018-07-31 17:01:282372
2373 if (display_cutout_host_impl_)
2374 display_cutout_host_impl_->DidExitFullscreen();
[email protected]8a5e0ca2011-08-25 06:30:472375}
2376
Becca Hughesfd5d8f892018-06-14 18:23:362377void WebContentsImpl::FullscreenStateChanged(RenderFrameHost* rfh,
2378 bool is_fullscreen) {
Arthur Sonzogni929d29f2018-09-17 14:19:442379 RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>(rfh);
Becca Hughesfd5d8f892018-06-14 18:23:362380
2381 if (is_fullscreen) {
Arthur Sonzogni929d29f2018-09-17 14:19:442382 if (!base::ContainsKey(fullscreen_frames_, frame)) {
2383 fullscreen_frames_.insert(frame);
2384 FullscreenFrameSetUpdated();
Becca Hughesfd5d8f892018-06-14 18:23:362385 }
Arthur Sonzogni929d29f2018-09-17 14:19:442386 return;
2387 }
Becca Hughesfd5d8f892018-06-14 18:23:362388
Arthur Sonzogni929d29f2018-09-17 14:19:442389 // If |frame| is no longer in fullscreen, remove it and any descendants.
2390 // See https://fullscreen.spec.whatwg.org.
2391 bool changed = false;
2392 base::EraseIf(fullscreen_frames_, [&](RenderFrameHostImpl* rfh) {
2393 for (auto* current = rfh; current; current = current->GetParent()) {
2394 if (current == frame) {
Becca Hughesfd5d8f892018-06-14 18:23:362395 changed = true;
Arthur Sonzogni929d29f2018-09-17 14:19:442396 return true;
Becca Hughesfd5d8f892018-06-14 18:23:362397 }
2398 }
Arthur Sonzogni929d29f2018-09-17 14:19:442399 return false;
2400 });
2401
2402 if (changed)
2403 FullscreenFrameSetUpdated();
2404}
2405
2406void WebContentsImpl::FullscreenFrameSetUpdated() {
2407 if (fullscreen_frames_.empty()) {
2408 current_fullscreen_frame_ = nullptr;
2409 return;
Becca Hughesfd5d8f892018-06-14 18:23:362410 }
2411
Arthur Sonzogni929d29f2018-09-17 14:19:442412 // Find the current fullscreen frame and call the observers.
2413 // If frame A is fullscreen, then frame B goes into inner fullscreen, then B
2414 // exits fullscreen - that will result in A being fullscreen.
2415 RenderFrameHostImpl* new_fullscreen_frame = *std::max_element(
2416 fullscreen_frames_.begin(), fullscreen_frames_.end(), FrameCompareDepth);
Becca Hughesfd5d8f892018-06-14 18:23:362417
Arthur Sonzogni929d29f2018-09-17 14:19:442418 // If we have already notified observers about this frame then we should not
2419 // fire the observers again.
2420 if (new_fullscreen_frame == current_fullscreen_frame_)
2421 return;
2422 current_fullscreen_frame_ = new_fullscreen_frame;
Becca Hughesfd5d8f892018-06-14 18:23:362423
Arthur Sonzogni929d29f2018-09-17 14:19:442424 for (auto& observer : observers_)
2425 observer.DidAcquireFullscreen(new_fullscreen_frame);
Becca Hughesfd5d8f892018-06-14 18:23:362426
Arthur Sonzogni929d29f2018-09-17 14:19:442427 if (display_cutout_host_impl_)
2428 display_cutout_host_impl_->DidAcquireFullscreen(new_fullscreen_frame);
Becca Hughesfd5d8f892018-06-14 18:23:362429}
2430
Clark DuValla0e42992018-09-17 17:00:112431#if defined(OS_ANDROID)
2432void WebContentsImpl::UpdateUserGestureCarryoverInfo() {
2433 if (delegate_)
2434 delegate_->UpdateUserGestureCarryoverInfo(this);
2435}
2436#endif
2437
alexmos5dd617d2016-06-07 04:21:152438bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:382439 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:122440}
2441
billorr21c005d2016-11-17 03:57:042442bool WebContentsImpl::IsFullscreen() {
2443 return IsFullscreenForCurrentTab();
2444}
2445
avibf58fa0c2015-11-11 01:45:522446blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
2447 RenderWidgetHostImpl* render_widget_host) const {
2448 if (!RenderViewHostImpl::From(render_widget_host))
Blink Reformat1c4d759e2017-04-09 16:34:542449 return blink::kWebDisplayModeBrowser;
avibf58fa0c2015-11-11 01:45:522450
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122451 return delegate_ ? delegate_->GetDisplayMode(this)
Blink Reformat1c4d759e2017-04-09 16:34:542452 : blink::kWebDisplayModeBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122453}
2454
avic3aa8422015-11-09 20:57:222455void WebContentsImpl::RequestToLockMouse(
2456 RenderWidgetHostImpl* render_widget_host,
2457 bool user_gesture,
lfgad8244352016-07-13 16:55:512458 bool last_unlocked_by_target,
2459 bool privileged) {
lfgf0cd46e2017-01-04 00:05:232460 for (WebContentsImpl* current = this; current;
2461 current = current->GetOuterWebContents()) {
2462 if (current->mouse_lock_widget_) {
2463 render_widget_host->GotResponseToLockMouseRequest(false);
2464 return;
2465 }
[email protected]e9621112011-10-17 05:38:372466 }
avic3aa8422015-11-09 20:57:222467
lfgad8244352016-07-13 16:55:512468 if (privileged) {
lfgf0cd46e2017-01-04 00:05:232469 DCHECK(!GetOuterWebContents());
lfgad8244352016-07-13 16:55:512470 mouse_lock_widget_ = render_widget_host;
2471 render_widget_host->GotResponseToLockMouseRequest(true);
2472 return;
2473 }
2474
lfgbee1e0a2016-06-08 21:24:212475 bool widget_in_frame_tree = false;
2476 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2477 if (node->current_frame_host()->GetRenderWidgetHost() ==
2478 render_widget_host) {
2479 widget_in_frame_tree = true;
2480 break;
2481 }
2482 }
2483
2484 if (widget_in_frame_tree && delegate_) {
lfgf0cd46e2017-01-04 00:05:232485 for (WebContentsImpl* current = this; current;
2486 current = current->GetOuterWebContents()) {
2487 current->mouse_lock_widget_ = render_widget_host;
2488 }
2489
avic3aa8422015-11-09 20:57:222490 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:212491 } else {
2492 render_widget_host->GotResponseToLockMouseRequest(false);
2493 }
[email protected]e9621112011-10-17 05:38:372494}
2495
avi3e4b8512015-11-11 01:55:492496void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:212497 CHECK(mouse_lock_widget_);
lfgf0cd46e2017-01-04 00:05:232498
2499 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this)
2500 return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host);
2501
lfgbee1e0a2016-06-08 21:24:212502 mouse_lock_widget_->SendMouseLockLost();
lfgf0cd46e2017-01-04 00:05:232503 for (WebContentsImpl* current = this; current;
2504 current = current->GetOuterWebContents()) {
2505 current->mouse_lock_widget_ = nullptr;
2506 }
avi3e4b8512015-11-11 01:55:492507
[email protected]e9621112011-10-17 05:38:372508 if (delegate_)
2509 delegate_->LostMouseLock();
2510}
2511
lfgad8244352016-07-13 16:55:512512bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
2513 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
2514 // assigned to the widget that requested the mouse lock, and the top-level
2515 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
Lucas Gadania0ea0172018-09-20 18:31:372516 auto* widget_host = GetTopLevelRenderWidgetHostView();
2517 return mouse_lock_widget_ == render_widget_host && widget_host &&
2518 widget_host->IsMouseLocked();
lfgad8244352016-07-13 16:55:512519}
2520
lfg84763c92017-02-16 18:55:152521RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() {
Lucas Gadania0ea0172018-09-20 18:31:372522 auto* widget_host = GetTopLevelRenderWidgetHostView();
2523 if ((widget_host && widget_host->IsMouseLocked()) ||
lfge2176fb2017-03-26 00:45:472524 (GetFullscreenRenderWidgetHostView() &&
Lucas Gadania0ea0172018-09-20 18:31:372525 GetFullscreenRenderWidgetHostView()->IsMouseLocked())) {
lfg84763c92017-02-16 18:55:152526 return mouse_lock_widget_;
Lucas Gadania0ea0172018-09-20 18:31:372527 }
lfg84763c92017-02-16 18:55:152528
2529 return nullptr;
2530}
2531
Joe Downing192998b22018-03-22 15:51:362532bool WebContentsImpl::RequestKeyboardLock(
Joe Downing13dd76b2018-04-09 18:32:152533 RenderWidgetHostImpl* render_widget_host,
2534 bool esc_key_locked) {
Joe Downing192998b22018-03-22 15:51:362535 DCHECK(render_widget_host);
Joe Downing192998b22018-03-22 15:51:362536 if (render_widget_host->delegate()->GetAsWebContents() != this) {
2537 NOTREACHED();
2538 return false;
2539 }
2540
2541 // KeyboardLock is only supported when called by the top-level browsing
2542 // context and is not supported in embedded content scenarios.
2543 if (GetOuterWebContents())
2544 return false;
2545
Joe Downing13dd76b2018-04-09 18:32:152546 esc_key_locked_ = esc_key_locked;
Joe Downing192998b22018-03-22 15:51:362547 keyboard_lock_widget_ = render_widget_host;
2548
Joe Downing13dd76b2018-04-09 18:32:152549 if (delegate_)
2550 delegate_->RequestKeyboardLock(this, esc_key_locked_);
Joe Downing192998b22018-03-22 15:51:362551 return true;
2552}
2553
2554void WebContentsImpl::CancelKeyboardLock(
2555 RenderWidgetHostImpl* render_widget_host) {
2556 if (!keyboard_lock_widget_ || render_widget_host != keyboard_lock_widget_)
2557 return;
2558
2559 RenderWidgetHostImpl* old_keyboard_lock_widget = keyboard_lock_widget_;
2560 keyboard_lock_widget_ = nullptr;
2561
Joe Downing13dd76b2018-04-09 18:32:152562 if (delegate_)
2563 delegate_->CancelKeyboardLockRequest(this);
2564
Joe Downing192998b22018-03-22 15:51:362565 old_keyboard_lock_widget->CancelKeyboardLock();
2566}
2567
2568RenderWidgetHostImpl* WebContentsImpl::GetKeyboardLockWidget() {
2569 return keyboard_lock_widget_;
2570}
2571
ekaramada4f42692016-02-11 19:48:372572void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
lfg9462cef2016-07-18 23:51:062573 if (visible && !GetOuterWebContents()->IsHidden())
ekaramada4f42692016-02-11 19:48:372574 WasShown();
lfg9462cef2016-07-18 23:51:062575 else if (!visible)
ekaramada4f42692016-02-11 19:48:372576 WasHidden();
2577}
2578
[email protected]bafe6cd2012-05-23 23:09:502579void WebContentsImpl::CreateNewWindow(
csharrison95f01e922017-04-24 18:52:352580 RenderFrameHost* opener,
nick5ae4d2d2017-01-06 01:18:352581 int32_t render_view_route_id,
dcheng3ce04b62015-10-26 23:30:552582 int32_t main_frame_route_id,
2583 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:182584 const mojom::CreateNewWindowParams& params,
[email protected]97714c82012-06-06 10:15:132585 SessionStorageNamespace* session_storage_namespace) {
nick5ae4d2d2017-01-06 01:18:352586 // We should have zero valid routing ids, or three valid routing IDs.
2587 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2588 (main_frame_route_id == MSG_ROUTING_NONE));
2589 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2590 (main_frame_widget_route_id == MSG_ROUTING_NONE));
csharrison95f01e922017-04-24 18:52:352591 DCHECK(opener);
nick5ae4d2d2017-01-06 01:18:352592
csharrison95f01e922017-04-24 18:52:352593 int render_process_id = opener->GetProcess()->GetID();
2594 SiteInstance* source_site_instance = opener->GetSiteInstance();
2595
2596 // The route IDs passed into this function can be trusted not to already
2597 // be in use; they were allocated by the RenderWidgetHelper by the caller.
nick5ae4d2d2017-01-06 01:18:352598 DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id));
2599
[email protected]bafe6cd2012-05-23 23:09:502600 // We usually create the new window in the same BrowsingInstance (group of
2601 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:552602 // if the opener is being suppressed (in a non-guest), we create a new
2603 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:252604 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:552605
[email protected]04cbd3d2013-12-04 04:58:202606 // If the opener is to be suppressed, the new window can be in any process.
2607 // Since routing ids are process specific, we must not have one passed in
2608 // as argument here.
nick5ae4d2d2017-01-06 01:18:352609 DCHECK(!params.opener_suppressed || render_view_route_id == MSG_ROUTING_NONE);
[email protected]04cbd3d2013-12-04 04:58:202610
[email protected]bafe6cd2012-05-23 23:09:502611 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:432612 params.opener_suppressed && !is_guest
2613 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
2614 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:502615
[email protected]d1198fd2012-08-13 22:50:192616 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:342617 //
2618 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:302619 const std::string& partition_id =
2620 GetContentClient()->browser()->
2621 GetStoragePartitionIdForSite(GetBrowserContext(),
2622 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:462623 StoragePartition* partition = BrowserContext::GetStoragePartition(
2624 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:412625 DOMStorageContextWrapper* dom_storage_context =
2626 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:192627 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2628 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2629 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:372630
2631 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:552632 !delegate_->ShouldCreateWebContents(
lukasza6f8ac622017-06-06 03:10:202633 this, opener, source_site_instance, render_view_route_id,
2634 main_frame_route_id, main_frame_widget_route_id,
2635 params.window_container_type, opener->GetLastCommittedURL(),
2636 params.frame_name, params.target_url, partition_id,
2637 session_storage_namespace)) {
jambaaab3a2016-11-05 00:46:182638 // Note: even though we're not creating a WebContents here, it could have
2639 // been created by the embedder so ensure that the RenderFrameHost is
2640 // properly initialized.
csharrisona2280cd2016-02-03 23:21:152641 // It's safe to only target the frame because the render process will not
2642 // have a chance to create more frames at this point.
jambaaab3a2016-11-05 00:46:182643 RenderFrameHostImpl* rfh =
2644 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id);
nick5ae4d2d2017-01-06 01:18:352645 if (rfh) {
2646 DCHECK(rfh->IsRenderFrameLive());
jambaaab3a2016-11-05 00:46:182647 rfh->Init();
nick5ae4d2d2017-01-06 01:18:352648 }
[email protected]dd6730412013-08-14 15:03:372649 return;
2650 }
2651
2652 // Create the new web contents. This will automatically create the new
2653 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462654 CreateParams create_params(GetBrowserContext(), site_instance.get());
nick5ae4d2d2017-01-06 01:18:352655 create_params.routing_id = render_view_route_id;
[email protected]227692c52013-05-31 22:43:042656 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:552657 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:122658 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432659 create_params.opener_render_process_id = render_process_id;
csharrison95f01e922017-04-24 18:52:352660 create_params.opener_render_frame_id = opener->GetRoutingID();
[email protected]50d326e2014-05-20 17:59:062661 create_params.opener_suppressed = params.opener_suppressed;
nick3b04f322016-08-31 19:29:192662 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
[email protected]50d326e2014-05-20 17:59:062663 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:192664 create_params.renderer_initiated_creation =
2665 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:062666
erikchenbee5c9622018-04-27 19:30:252667 std::unique_ptr<WebContents> new_contents;
[email protected]c4538072013-03-18 02:17:552668 if (!is_guest) {
2669 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:452670 create_params.initial_size = GetContainerBounds().size();
Erik Chenbb8e738e2018-04-28 14:10:432671 new_contents = WebContents::Create(create_params);
[email protected]4858e432014-06-23 18:14:172672 } else {
erikchenbee5c9622018-04-27 19:30:252673 new_contents = base::WrapUnique(
2674 GetBrowserPluginGuest()->CreateNewGuestWindow(create_params));
[email protected]c4538072013-03-18 02:17:552675 }
erikchenbee5c9622018-04-27 19:30:252676 WebContentsImpl* raw_new_contents =
2677 static_cast<WebContentsImpl*>(new_contents.get());
2678 raw_new_contents->GetController().SetSessionStorageNamespace(
2679 partition_id, session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192680
alexmos646fec02015-07-25 00:11:492681 // If the new frame has a name, make sure any SiteInstances that can find
2682 // this named frame have proxies for it. Must be called after
2683 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2684 // GetSessionStorageNamespace.
2685 if (!params.frame_name.empty())
erikchenbee5c9622018-04-27 19:30:252686 raw_new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
alexmos646fec02015-07-25 00:11:492687
[email protected]c4538072013-03-18 02:17:552688 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342689 // will be shown immediately).
2690 if (!params.opener_suppressed) {
2691 if (!is_guest) {
erikchenbee5c9622018-04-27 19:30:252692 WebContentsView* new_view = raw_new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502693
[email protected]d70bea92013-04-05 04:23:342694 // TODO(brettw): It seems bogus that we have to call this function on the
2695 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:432696 new_view->CreateViewForWidget(
2697 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:342698 }
[email protected]bafe6cd2012-05-23 23:09:502699 // Save the created window associated with the route so we can show it
2700 // later.
Albert J. Wongcb004632018-07-10 22:58:252701 //
2702 // TODO(ajwong): This should be keyed off the RenderFrame routing id or the
2703 // FrameTreeNode id instead of the routing id of the Widget for the main
2704 // frame. https://crbug.com/545684
nick5ae4d2d2017-01-06 01:18:352705 DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id);
Lukasz Anforowicz09060bdf72018-08-23 15:53:172706 pending_contents_[GlobalRoutingID(render_process_id,
2707 main_frame_widget_route_id)] =
erikchenbee5c9622018-04-27 19:30:252708 std::move(new_contents);
2709 AddDestructionObserver(raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502710 }
2711
2712 if (delegate_) {
Bryan McQuaded2b93c02017-07-14 22:26:312713 delegate_->WebContentsCreated(this, render_process_id,
2714 opener->GetRoutingID(), params.frame_name,
erikchenbee5c9622018-04-27 19:30:252715 params.target_url, raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502716 }
2717
Charlie Harrisonf60dd1c2018-08-15 21:15:412718 for (auto& observer : observers_) {
2719 observer.DidOpenRequestedURL(raw_new_contents, opener, params.target_url,
2720 params.referrer, params.disposition,
2721 ui::PAGE_TRANSITION_LINK,
2722 false, // started_from_context_menu
2723 true); // renderer_initiated
pnolandaae574e2017-03-06 21:04:212724 }
2725
Avi Drissmanba3b1b342017-08-29 18:16:132726 // Any new WebContents opened while this WebContents is in fullscreen can be
2727 // used to confuse the user, so drop fullscreen.
Avi Drissmand18c51972018-08-15 18:32:092728 ForSecurityDropFullscreen();
Avi Drissmanba3b1b342017-08-29 18:16:132729
[email protected]bafe6cd2012-05-23 23:09:502730 if (params.opener_suppressed) {
2731 // When the opener is suppressed, the original renderer cannot access the
2732 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002733 bool was_blocked = false;
erikchenbee5c9622018-04-27 19:30:252734
2735 base::WeakPtr<WebContentsImpl> weak_new_contents =
2736 raw_new_contents->weak_factory_.GetWeakPtr();
[email protected]eda238a12012-09-07 23:44:002737 if (delegate_) {
bokan107a47f2015-02-03 23:23:392738 gfx::Rect initial_rect;
nick0d558482017-02-13 22:27:222739
erikchenbee5c9622018-04-27 19:30:252740 delegate_->AddNewContents(this, std::move(new_contents),
2741 params.disposition, initial_rect,
Mustaq Ahmedc4cb7162018-06-05 16:28:362742 params.mimic_user_gesture, &was_blocked);
nick0d558482017-02-13 22:27:222743 if (!weak_new_contents)
2744 return; // The delegate deleted |new_contents| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002745 }
erikchenbee5c9622018-04-27 19:30:252746
[email protected]eda238a12012-09-07 23:44:002747 if (!was_blocked) {
nick3b04f322016-08-31 19:29:192748 OpenURLParams open_params(params.target_url, params.referrer,
2749 WindowOpenDisposition::CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352750 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212751 true /* is_renderer_initiated */);
Mustaq Ahmedc4cb7162018-06-05 16:28:362752 open_params.user_gesture = params.mimic_user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372753
2754 if (delegate_ && !is_guest &&
2755 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
erikchenbee5c9622018-04-27 19:30:252756 DCHECK(weak_new_contents);
mariakhomenkoa4971c12015-07-21 19:04:372757 // We are in asynchronous add new contents path, delay opening url
erikchenbee5c9622018-04-27 19:30:252758 weak_new_contents->delayed_open_url_params_.reset(
mariakhomenkoa4971c12015-07-21 19:04:372759 new OpenURLParams(open_params));
2760 } else {
erikchenbee5c9622018-04-27 19:30:252761 weak_new_contents->OpenURL(open_params);
mariakhomenkoa4971c12015-07-21 19:04:372762 }
[email protected]eda238a12012-09-07 23:44:002763 }
[email protected]bafe6cd2012-05-23 23:09:502764 }
2765}
2766
avib7348942015-12-25 20:57:102767void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
Albert J. Wongf6e13ed2018-09-18 15:25:472768 int32_t widget_route_id,
danakj829cdd142018-09-14 21:13:272769 mojom::WidgetPtr widget) {
Albert J. Wongf6e13ed2018-09-18 15:25:472770 CreateNewWidget(render_process_id, widget_route_id, /*is_fullscreen=*/false,
danakj829cdd142018-09-14 21:13:272771 std::move(widget));
[email protected]bafe6cd2012-05-23 23:09:502772}
2773
avib7348942015-12-25 20:57:102774void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
Albert J. Wongf6e13ed2018-09-18 15:25:472775 int32_t widget_route_id,
Dave Tapuska1bdf1832017-07-07 18:07:192776 mojom::WidgetPtr widget) {
Albert J. Wongf6e13ed2018-09-18 15:25:472777 CreateNewWidget(render_process_id, widget_route_id, /*is_fullscreen=*/true,
danakj829cdd142018-09-14 21:13:272778 std::move(widget));
[email protected]bafe6cd2012-05-23 23:09:502779}
2780
avib7348942015-12-25 20:57:102781void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2782 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502783 bool is_fullscreen,
danakj829cdd142018-09-14 21:13:272784 mojom::WidgetPtr widget) {
kenrba26d15092016-02-10 22:00:252785 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232786 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512787 // this WebContentsImpl instance. If any other process sends the request,
2788 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382789 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
Lukasz Anforowicz6f746282018-01-04 23:24:512790 ReceivedBadMessage(process, bad_message::WCI_NEW_WIDGET_PROCESS_MISMATCH);
[email protected]a8504022013-12-04 20:23:512791 return;
2792 }
2793
Dave Tapuska485aca92017-08-08 00:47:582794 RenderWidgetHostImpl* widget_host = new RenderWidgetHostImpl(
2795 this, process, route_id, std::move(widget), IsHidden());
[email protected]b24b68a2012-09-24 21:57:262796
[email protected]cfd80b02014-05-01 17:46:482797 RenderWidgetHostViewBase* widget_view =
2798 static_cast<RenderWidgetHostViewBase*>(
danakj0b246942018-09-17 21:30:272799 view_->CreateViewForChildWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192800 if (!widget_view)
2801 return;
danakj0b246942018-09-17 21:30:272802 // Fullscreen child widgets are frames, other child widgets are popups, and
2803 // popups should not get activated.
2804 if (!is_fullscreen)
2805 widget_view->SetWidgetType(WidgetType::kPopup);
[email protected]bafe6cd2012-05-23 23:09:502806 // Save the created widget associated with the route so we can show it later.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172807 pending_widget_views_[GlobalRoutingID(render_process_id, route_id)] =
alexmosc2a8cec2016-05-23 22:19:532808 widget_view;
[email protected]bafe6cd2012-05-23 23:09:502809}
2810
alexmosc2a8cec2016-05-23 22:19:532811void WebContentsImpl::ShowCreatedWindow(int process_id,
nick5ae4d2d2017-01-06 01:18:352812 int main_frame_widget_route_id,
[email protected]bafe6cd2012-05-23 23:09:502813 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392814 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502815 bool user_gesture) {
erikchenbee5c9622018-04-27 19:30:252816 std::unique_ptr<WebContents> popup =
nick5ae4d2d2017-01-06 01:18:352817 GetCreatedWindow(process_id, main_frame_widget_route_id);
nick0d558482017-02-13 22:27:222818 if (popup) {
erikchenbee5c9622018-04-27 19:30:252819 WebContentsImpl* raw_popup = static_cast<WebContentsImpl*>(popup.get());
[email protected]eda238a12012-09-07 23:44:002820 WebContentsDelegate* delegate = GetDelegate();
erikchenbee5c9622018-04-27 19:30:252821 raw_popup->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382822 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
erikchenbee5c9622018-04-27 19:30:252823 raw_popup->ResumeLoadingCreatedWebContents();
mariakhomenko44bdc4732015-04-29 01:55:382824
erikchenbee5c9622018-04-27 19:30:252825 base::WeakPtr<WebContentsImpl> weak_popup =
2826 raw_popup->weak_factory_.GetWeakPtr();
[email protected]eda238a12012-09-07 23:44:002827 if (delegate) {
erikchenbee5c9622018-04-27 19:30:252828 delegate->AddNewContents(this, std::move(popup), disposition,
2829 initial_rect, user_gesture, nullptr);
nick0d558482017-02-13 22:27:222830 if (!weak_popup)
2831 return; // The delegate deleted |popup| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002832 }
nick5ae4d2d2017-01-06 01:18:352833
erikchenbee5c9622018-04-27 19:30:252834 RenderWidgetHostImpl* rwh =
2835 weak_popup->GetMainFrame()->GetRenderWidgetHost();
nick0d558482017-02-13 22:27:222836 DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID());
Avi Drissman014dec72018-06-07 02:34:012837 rwh->Send(new ViewMsg_SetBounds_ACK(rwh->GetRoutingID()));
[email protected]eda238a12012-09-07 23:44:002838 }
[email protected]bafe6cd2012-05-23 23:09:502839}
2840
alexmosc2a8cec2016-05-23 22:19:532841void WebContentsImpl::ShowCreatedWidget(int process_id,
Albert J. Wongf6e13ed2018-09-18 15:25:472842 int widget_route_id,
bokan107a47f2015-02-03 23:23:392843 const gfx::Rect& initial_rect) {
Albert J. Wongf6e13ed2018-09-18 15:25:472844 ShowCreatedWidget(process_id, widget_route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502845}
2846
alexmosc2a8cec2016-05-23 22:19:532847void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
Albert J. Wongf6e13ed2018-09-18 15:25:472848 int widget_route_id) {
2849 ShowCreatedWidget(process_id, widget_route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:502850}
2851
alexmosc2a8cec2016-05-23 22:19:532852void WebContentsImpl::ShowCreatedWidget(int process_id,
2853 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502854 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392855 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482856 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:532857 static_cast<RenderWidgetHostViewBase*>(
2858 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502859 if (!widget_host_view)
2860 return;
[email protected]cfd80b02014-05-01 17:46:482861
Ivan Kotenkov2c0d2bb32017-11-01 15:41:282862 RenderWidgetHostView* view = nullptr;
lfgc740d4b22016-04-15 16:45:332863 if (GetOuterWebContents()) {
2864 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482865 } else {
2866 view = GetRenderWidgetHostView();
2867 }
2868
danakj0b246942018-09-17 21:30:272869 // Fullscreen child widgets are frames, other child widgets are popups.
[email protected]4aebbca2013-09-17 22:26:492870 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312871 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032872 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:372873 fullscreen_widget_process_id_ =
2874 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:312875 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492876 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2877 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
Dave Tapuska3ed44192018-05-01 18:53:302878 delegate_->EnterFullscreenModeForTab(this, GURL(),
2879 blink::WebFullscreenOptions());
[email protected]4aebbca2013-09-17 22:26:492880 } else {
[email protected]cfd80b02014-05-01 17:46:482881 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492882 }
ericwilligersde386342016-10-19 02:35:092883 for (auto& observer : observers_)
2884 observer.DidShowFullscreenWidget();
[email protected]4aebbca2013-09-17 22:26:492885 if (!widget_host_view->HasFocus())
2886 widget_host_view->Focus();
2887 } else {
bokan107a47f2015-02-03 23:23:392888 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492889 }
[email protected]89054502012-06-03 10:29:242890
yiyixcb1fbc4f2018-03-16 19:54:082891 RenderWidgetHostImpl* render_widget_host_impl = widget_host_view->host();
[email protected]89054502012-06-03 10:29:242892 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312893 // Only allow privileged mouse lock for fullscreen render widget, which is
2894 // used to implement Pepper Flash fullscreen.
2895 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502896}
2897
erikchenbee5c9622018-04-27 19:30:252898std::unique_ptr<WebContents> WebContentsImpl::GetCreatedWindow(
nick5ae4d2d2017-01-06 01:18:352899 int process_id,
2900 int main_frame_widget_route_id) {
Lukasz Anforowicz09060bdf72018-08-23 15:53:172901 auto key = GlobalRoutingID(process_id, main_frame_widget_route_id);
nick5ae4d2d2017-01-06 01:18:352902 auto iter = pending_contents_.find(key);
[email protected]bafe6cd2012-05-23 23:09:502903
2904 // Certain systems can block the creation of new windows. If we didn't succeed
2905 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:532906 if (iter == pending_contents_.end())
2907 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502908
erikchenbee5c9622018-04-27 19:30:252909 std::unique_ptr<WebContents> new_contents = std::move(iter->second);
nick5ae4d2d2017-01-06 01:18:352910 pending_contents_.erase(key);
erikchenbee5c9622018-04-27 19:30:252911 WebContentsImpl* raw_new_contents =
2912 static_cast<WebContentsImpl*>(new_contents.get());
2913 RemoveDestructionObserver(raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502914
[email protected]d70bea92013-04-05 04:23:342915 // Don't initialize the guest WebContents immediately.
erikchenbee5c9622018-04-27 19:30:252916 if (BrowserPluginGuest::IsGuest(raw_new_contents))
[email protected]d70bea92013-04-05 04:23:342917 return new_contents;
2918
Lukasz Anforowicz5510ed652018-06-06 16:16:192919 if (!new_contents->GetMainFrame()->GetProcess()->IsInitializedAndNotDead() ||
nick5ae4d2d2017-01-06 01:18:352920 !new_contents->GetMainFrame()->GetView()) {
alexmosc2a8cec2016-05-23 22:19:532921 return nullptr;
nick5ae4d2d2017-01-06 01:18:352922 }
[email protected]bafe6cd2012-05-23 23:09:502923
[email protected]bafe6cd2012-05-23 23:09:502924 return new_contents;
2925}
2926
alexmosc2a8cec2016-05-23 22:19:532927RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
2928 int route_id) {
Lukasz Anforowicz09060bdf72018-08-23 15:53:172929 auto iter = pending_widget_views_.find(GlobalRoutingID(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502930 if (iter == pending_widget_views_.end()) {
2931 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:532932 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502933 }
2934
2935 RenderWidgetHostView* widget_host_view = iter->second;
Lukasz Anforowicz09060bdf72018-08-23 15:53:172936 pending_widget_views_.erase(GlobalRoutingID(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502937
2938 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
Lukasz Anforowicz5510ed652018-06-06 16:16:192939 if (!widget_host->GetProcess()->IsInitializedAndNotDead()) {
[email protected]bafe6cd2012-05-23 23:09:502940 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:532941 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502942 }
2943
2944 return widget_host_view;
2945}
2946
[email protected]f13b4202012-06-12 23:53:232947void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092948 const MediaStreamRequest& request,
Mark Pilgrim57499082018-06-12 12:38:302949 MediaResponseCallback callback) {
[email protected]d19b84b2014-03-14 11:52:372950 if (delegate_) {
Mark Pilgrim57499082018-06-12 12:38:302951 delegate_->RequestMediaAccessPermission(this, request, std::move(callback));
[email protected]d19b84b2014-03-14 11:52:372952 } else {
Mark Pilgrim57499082018-06-12 12:38:302953 std::move(callback).Run(MediaStreamDevices(),
2954 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2955 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372956 }
[email protected]f13b4202012-06-12 23:53:232957}
2958
Chandan Padhia4b8bcb72017-09-12 16:41:042959bool WebContentsImpl::CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:582960 RenderFrameHost* render_frame_host,
Chandan Padhia4b8bcb72017-09-12 16:41:042961 const url::Origin& security_origin,
2962 MediaStreamType type) {
grunell657d4d82014-09-18 00:09:432963 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2964 type == MEDIA_DEVICE_VIDEO_CAPTURE);
Chandan Padhia4b8bcb72017-09-12 16:41:042965 return delegate_ && delegate_->CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:582966 render_frame_host, security_origin.GetURL(), type);
grunell657d4d82014-09-18 00:09:432967}
2968
guidou8a440b842017-01-30 13:58:432969std::string WebContentsImpl::GetDefaultMediaDeviceID(MediaStreamType type) {
2970 if (!delegate_)
2971 return std::string();
2972 return delegate_->GetDefaultMediaDeviceID(this, type);
2973}
2974
[email protected]cc9200432013-07-23 23:02:402975SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2976 SiteInstance* instance) {
2977 return controller_.GetSessionStorageNamespace(instance);
2978}
2979
[email protected]6de7fc482014-06-06 10:46:442980SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2981 return controller_.GetSessionStorageNamespaceMap();
2982}
2983
[email protected]9b159a52013-10-03 17:24:552984FrameTree* WebContentsImpl::GetFrameTree() {
2985 return &frame_tree_;
2986}
2987
aelias5252baa2016-04-10 01:18:022988bool WebContentsImpl::IsOverridingUserAgent() {
2989 return GetController().GetVisibleEntry() &&
2990 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2991}
2992
avi85ee8362016-10-08 02:09:082993bool WebContentsImpl::IsJavaScriptDialogShowing() const {
2994 return is_showing_javascript_dialog_;
2995}
2996
avic031d392017-03-03 03:09:422997bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() {
2998 // Ignore unresponsive renderers if the debugger is attached to them since the
2999 // unresponsiveness might be a result of the renderer sitting on a breakpoint.
3000 //
3001 // TODO(pfeldman): Fix this to only return true if the renderer is *actually*
3002 // sitting on a breakpoint. https://crbug.com/684202
3003 return DevToolsAgentHost::IsDebuggerAttached(this);
3004}
3005
Doug Turner63f3c7b2017-07-29 05:10:013006ui::AXMode WebContentsImpl::GetAccessibilityMode() const {
[email protected]95640212014-07-26 18:14:303007 return accessibility_mode_;
3008}
3009
Dominic Mazzonia7b0edb22017-08-09 16:32:513010void WebContentsImpl::AccessibilityEventReceived(
Dominic Mazzoniccbaa9b2018-06-06 07:44:233011 const AXEventNotificationDetails& details) {
ericwilligersde386342016-10-19 02:35:093012 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513013 observer.AccessibilityEventReceived(details);
[email protected]31a71eaf2014-03-13 01:47:363014}
3015
dmazzoni2400c462016-08-23 15:07:133016void WebContentsImpl::AccessibilityLocationChangesReceived(
3017 const std::vector<AXLocationChangeNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:093018 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513019 observer.AccessibilityLocationChangesReceived(details);
dmazzoni2400c462016-08-23 15:07:133020}
3021
James Wallace-Leeeafc94cb92018-07-23 21:35:093022base::string16 WebContentsImpl::DumpAccessibilityTree(bool internal) {
3023 auto* ax_mgr = GetOrCreateRootBrowserAccessibilityManager();
3024 DCHECK(ax_mgr);
3025 return AccessibilityTreeFormatter::DumpAccessibilityTreeFromManager(ax_mgr,
3026 internal);
3027}
3028
dmazzonia656928e2014-09-15 20:28:543029RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:403030 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:543031 int browser_plugin_instance_id) {
3032 BrowserPluginGuestManager* guest_manager =
3033 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:203034 if (!guest_manager)
3035 return nullptr;
3036
dmazzonia656928e2014-09-15 20:28:543037 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:443038 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:543039 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:203040 return nullptr;
3041
dmazzonia656928e2014-09-15 20:28:543042 return guest->GetMainFrame();
3043}
3044
Ke He7319dbe2017-11-09 05:54:443045device::mojom::GeolocationContext* WebContentsImpl::GetGeolocationContext() {
3046 if (geolocation_context_)
3047 return geolocation_context_.get();
3048
3049 auto request = mojo::MakeRequest(&geolocation_context_);
3050 if (!ServiceManagerConnection::GetForProcess())
3051 return geolocation_context_.get();
3052
3053 service_manager::Connector* connector =
3054 ServiceManagerConnection::GetForProcess()->GetConnector();
3055 connector->BindInterface(device::mojom::kServiceName, std::move(request));
Conley Owens6894c4f2017-07-10 19:29:133056 return geolocation_context_.get();
blundellc57b93f2014-10-29 13:19:573057}
3058
ke.he98b761e2017-05-09 05:59:173059device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() {
blundelld8cd72b2017-03-28 07:18:383060 if (!wake_lock_context_host_)
3061 wake_lock_context_host_.reset(new WakeLockContextHost(this));
blundelle75a8f92017-03-27 08:11:173062 return wake_lock_context_host_->GetWakeLockContext();
alogvinovf50445a2015-10-30 13:00:123063}
3064
juncai8e8d6ec2017-06-06 20:48:183065device::mojom::WakeLock* WebContentsImpl::GetRendererWakeLock() {
3066 // WebContents creates a long-lived connection to one WakeLock.
ke.he98b761e2017-05-09 05:59:173067 // All the frames' requests will be added into the BindingSet of
juncai8e8d6ec2017-06-06 20:48:183068 // WakeLock via this connection.
ke.he98b761e2017-05-09 05:59:173069 if (!renderer_wake_lock_) {
3070 device::mojom::WakeLockContext* wake_lock_context = GetWakeLockContext();
3071 if (!wake_lock_context) {
3072 return nullptr;
3073 }
ke.hef435c1e82017-05-11 04:09:103074 wake_lock_context->GetWakeLock(
Daniel Erat28922ba2017-11-08 16:18:263075 device::mojom::WakeLockType::kPreventDisplaySleep,
3076 device::mojom::WakeLockReason::kOther, "Wake Lock API",
ke.hef435c1e82017-05-11 04:09:103077 mojo::MakeRequest(&renderer_wake_lock_));
ke.he98b761e2017-05-09 05:59:173078 }
3079 return renderer_wake_lock_.get();
3080}
3081
blundellf5316fc2017-05-15 11:49:033082#if defined(OS_ANDROID)
Han Leonf6a2e5f2017-05-23 13:40:473083void WebContentsImpl::GetNFC(device::mojom::NFCRequest request) {
blundellf5316fc2017-05-15 11:49:033084 if (!nfc_host_)
3085 nfc_host_.reset(new NFCHost(this));
3086 nfc_host_->GetNFC(std::move(request));
3087}
3088#endif
3089
Evan Stade5e750ad02017-08-07 21:59:273090void WebContentsImpl::SetNotWaitingForResponse() {
3091 if (waiting_for_response_ == false)
3092 return;
3093
3094 waiting_for_response_ = false;
3095 if (delegate_)
3096 delegate_->LoadingStateChanged(this, is_load_to_different_document_);
Chris Hamiltonf82f2a702018-02-15 19:37:293097 for (auto& observer : observers_)
3098 observer.DidReceiveResponse();
Evan Stade5e750ad02017-08-07 21:59:273099}
3100
lfgbb9c28a2016-03-01 03:19:493101void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:373102 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:403103 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:373104 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
3105 }
lfgbb9c28a2016-03-01 03:19:493106
lfgdb5c4ed2016-03-04 23:09:073107 RenderWidgetHostViewBase* rwhv =
3108 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3109 if (rwhv) {
3110 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
3111 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
3112 }
3113
avallee9f43b012016-11-26 07:02:103114 if (browser_plugin_embedder_ && !is_being_destroyed_)
[email protected]a7568e62013-06-14 07:50:443115 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:043116}
3117
ekaramadadd882292016-06-08 15:22:563118TextInputManager* WebContentsImpl::GetTextInputManager() {
3119 if (GetOuterWebContents())
3120 return GetOuterWebContents()->GetTextInputManager();
3121
Darren Shenca53d5f2018-05-15 04:56:013122 if (!text_input_manager_) {
3123 text_input_manager_.reset(new TextInputManager(
3124 GetBrowserContext() &&
3125 !GetBrowserContext()->IsOffTheRecord()) /* should_do_learning */);
3126 }
ekaramadadd882292016-06-08 15:22:563127
3128 return text_input_manager_.get();
3129}
3130
paulmeyer7f6f1d4f2016-11-15 00:00:273131bool WebContentsImpl::OnUpdateDragCursor() {
3132 if (browser_plugin_embedder_)
3133 return browser_plugin_embedder_->OnUpdateDragCursor();
3134 return false;
3135}
3136
kenrb11f213a2017-03-24 18:12:063137bool WebContentsImpl::IsWidgetForMainFrame(
3138 RenderWidgetHostImpl* render_widget_host) {
3139 return render_widget_host == GetMainFrame()->GetRenderWidgetHost();
3140}
3141
[email protected]95640212014-07-26 18:14:303142BrowserAccessibilityManager*
3143 WebContentsImpl::GetRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223144 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3145 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3146 : GetMainFrame());
creisc014b402015-04-23 16:41:453147 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:303148}
3149
3150BrowserAccessibilityManager*
3151 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223152 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3153 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3154 : GetMainFrame());
creisc014b402015-04-23 16:41:453155 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:303156}
3157
Dave Tapuskab336b922017-07-06 19:24:053158void WebContentsImpl::ExecuteEditCommand(
3159 const std::string& command,
3160 const base::Optional<base::string16>& value) {
3161 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
3162 if (!focused_frame)
3163 return;
3164
3165 focused_frame->GetFrameInputHandler()->ExecuteEditCommand(command, value);
3166}
3167
mohsen7ab1ec16ec2015-07-02 18:26:233168void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:053169 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:233170 if (!focused_frame)
3171 return;
3172
dtapuska9d46ef7d2017-05-26 19:06:063173 focused_frame->GetFrameInputHandler()->MoveRangeSelectionExtent(extent);
mohsen7ab1ec16ec2015-07-02 18:26:233174}
3175
3176void WebContentsImpl::SelectRange(const gfx::Point& base,
3177 const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:053178 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:233179 if (!focused_frame)
3180 return;
3181
dtapuska9d46ef7d2017-05-26 19:06:063182 focused_frame->GetFrameInputHandler()->SelectRange(base, extent);
mohsen7ab1ec16ec2015-07-02 18:26:233183}
3184
Tessa Nijssenc4b101232018-06-25 20:28:083185#if defined(OS_MACOSX)
Tessa Nijssendbef4742018-06-29 21:02:083186void WebContentsImpl::DidChangeTextSelection(const base::string16& text,
Tessa Nijssenb4a66d52018-08-13 22:40:393187 const gfx::Range& range,
3188 size_t offset) {
Tessa Nijssendbef4742018-06-29 21:02:083189 for (auto& observer : observers_)
Tessa Nijssenb4a66d52018-08-13 22:40:393190 observer.DidChangeTextSelection(text, range, offset);
Tessa Nijssenc4b101232018-06-25 20:28:083191}
3192#endif
3193
Dave Tapuskab336b922017-07-06 19:24:053194void WebContentsImpl::MoveCaret(const gfx::Point& extent) {
3195 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
3196 if (!focused_frame)
3197 return;
3198
3199 focused_frame->GetFrameInputHandler()->MoveCaret(extent);
3200}
3201
Shimi Zhang37deeb22017-09-28 00:59:013202void WebContentsImpl::AdjustSelectionByCharacterOffset(
3203 int start_adjust,
3204 int end_adjust,
3205 bool show_selection_menu) {
Dave Tapuskab336b922017-07-06 19:24:053206 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
aurimasab0319022015-07-10 21:57:383207 if (!focused_frame)
3208 return;
3209
Shimi Zhang37deeb22017-09-28 00:59:013210 using blink::mojom::SelectionMenuBehavior;
dtapuska9d46ef7d2017-05-26 19:06:063211 focused_frame->GetFrameInputHandler()->AdjustSelectionByCharacterOffset(
Shimi Zhang37deeb22017-09-28 00:59:013212 start_adjust, end_adjust,
3213 show_selection_menu ? SelectionMenuBehavior::kShow
3214 : SelectionMenuBehavior::kHide);
aurimasab0319022015-07-10 21:57:383215}
3216
[email protected]b172aee2012-04-10 17:05:263217void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:493218 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:233219 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:493220 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:333221}
3222
avic3aa8422015-11-09 20:57:223223void WebContentsImpl::ResizeDueToAutoResize(
3224 RenderWidgetHostImpl* render_widget_host,
Fady Samuel97947112018-05-05 16:24:543225 const gfx::Size& new_size) {
avic3aa8422015-11-09 20:57:223226 if (render_widget_host != GetRenderViewHost()->GetWidget())
3227 return;
3228
kenrbe4f91082017-06-02 20:32:083229 auto_resize_size_ = new_size;
3230
3231 // Out-of-process iframe visible viewport sizes usually come from the
3232 // top-level RenderWidgetHostView, but when auto-resize is enabled on the
3233 // top frame then that size is used instead.
3234 for (FrameTreeNode* node : frame_tree_.Nodes()) {
3235 if (node->current_frame_host()->is_local_root()) {
3236 RenderWidgetHostImpl* host =
3237 node->current_frame_host()->GetRenderWidgetHost();
3238 if (host != render_widget_host)
Fady Samuel0b911822018-04-25 13:22:163239 host->SynchronizeVisualProperties();
kenrbe4f91082017-06-02 20:32:083240 }
3241 }
3242
[email protected]61e2b3cc2012-03-02 16:13:343243 if (delegate_)
3244 delegate_->ResizeDueToAutoResize(this, new_size);
3245}
3246
kenrbe4f91082017-06-02 20:32:083247gfx::Size WebContentsImpl::GetAutoResizeSize() {
3248 return auto_resize_size_;
3249}
3250
3251void WebContentsImpl::ResetAutoResizeSize() {
3252 auto_resize_size_ = gfx::Size();
3253}
3254
[email protected]b172aee2012-04-10 17:05:263255WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
Bo Liu300c6052018-06-12 04:46:073256 if (!delegate_) {
3257 // Embedder can delay setting a delegate on new WebContents with
3258 // WebContentsDelegate::ShouldResumeRequestsForCreatedWindow. In the mean
3259 // time, navigations, including the initial one, that goes through OpenURL
3260 // should be delayed until embedder is ready to resume loading.
3261 delayed_open_url_params_ = std::make_unique<OpenURLParams>(params);
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283262 return nullptr;
Bo Liu300c6052018-06-12 04:46:073263 }
[email protected]00c37fc2011-08-02 00:22:503264
[email protected]e5d549d2011-12-28 01:29:203265 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
pnoland488944652017-02-22 18:58:543266
3267 RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID(
3268 params.source_render_process_id, params.source_render_frame_id);
3269
3270 if (source_render_frame_host && params.source_site_instance) {
3271 CHECK_EQ(source_render_frame_host->GetSiteInstance(),
3272 params.source_site_instance.get());
3273 }
3274
3275 if (new_contents && source_render_frame_host && new_contents != this) {
3276 for (auto& observer : observers_) {
Lukasz Anforowicz48c9f872018-08-01 00:58:413277 observer.DidOpenRequestedURL(
3278 new_contents, source_render_frame_host, params.url, params.referrer,
3279 params.disposition, params.transition,
3280 params.started_from_context_menu, params.is_renderer_initiated);
pnoland488944652017-02-22 18:58:543281 }
3282 }
3283
[email protected]e5d549d2011-12-28 01:29:203284 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:343285}
3286
[email protected]a86c0e962013-12-17 17:10:393287void WebContentsImpl::RenderFrameForInterstitialPageCreated(
3288 RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:093289 for (auto& observer : observers_)
3290 observer.RenderFrameForInterstitialPageCreated(render_frame_host);
[email protected]ba45bfd2012-05-22 21:51:443291}
3292
[email protected]20ca0382013-02-28 19:50:073293void WebContentsImpl::AttachInterstitialPage(
3294 InterstitialPageImpl* interstitial_page) {
creisadca9862017-06-16 19:12:113295 DCHECK(!interstitial_page_ && interstitial_page);
3296 interstitial_page_ = interstitial_page;
[email protected]90fb08ed2013-09-24 17:43:293297
3298 // Cancel any visible dialogs so that they don't interfere with the
3299 // interstitial.
creis89a0f782015-05-27 16:13:173300 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:293301
ericwilligersde386342016-10-19 02:35:093302 for (auto& observer : observers_)
3303 observer.DidAttachInterstitialPage();
clamy44e84ce2016-02-22 15:38:253304
3305 // Stop the throbber if needed while the interstitial page is shown.
3306 if (frame_tree_.IsLoading())
3307 LoadingStateChanged(true, true, nullptr);
lfg1453e412017-04-11 00:48:503308
3309 // Connect to outer WebContents if necessary.
3310 if (node_.OuterContentsFrameTreeNode()) {
3311 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3312 DCHECK(
3313 static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView())
3314 ->IsRenderWidgetHostViewChildFrame());
3315 RenderWidgetHostViewChildFrame* view =
3316 static_cast<RenderWidgetHostViewChildFrame*>(
3317 interstitial_page->GetView());
3318 GetRenderManager()->SetRWHViewForInnerContents(view);
3319 }
3320 }
Bo Liu7c6779e92017-08-16 02:02:283321
Bo Liu168c8642017-08-28 18:26:023322#if defined(OS_ANDROID)
Bo Liu7c6779e92017-08-16 02:02:283323 // Update importance of the interstitial.
3324 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
3325 ->GetRenderWidgetHost()
3326 ->SetImportance(GetMainFrame()->GetRenderWidgetHost()->importance());
Bo Liu168c8642017-08-28 18:26:023327#endif
Dominic Mazzoniefb5f9e32017-12-21 01:08:223328
3329 if (accessibility_mode_.has_mode(ui::AXMode::kNativeAPIs)) {
3330 // Make sure that the main page's accessibility tree is hidden and the
3331 // interstitial gets focus.
3332 RenderFrameHostImpl* rfh =
3333 static_cast<RenderFrameHostImpl*>(GetMainFrame());
3334 if (rfh) {
3335 BrowserAccessibilityManager* accessibility_manager =
3336 rfh->browser_accessibility_manager();
3337 if (accessibility_manager)
3338 accessibility_manager->set_hidden_by_interstitial_page(true);
3339 }
3340 rfh = static_cast<RenderFrameHostImpl*>(
3341 GetInterstitialPage()->GetMainFrame());
3342 if (rfh) {
3343 BrowserAccessibilityManager* accessibility_manager =
3344 rfh->GetOrCreateBrowserAccessibilityManager();
3345 if (accessibility_manager)
3346 accessibility_manager->OnWindowFocused();
3347 }
3348 }
clamy44e84ce2016-02-22 15:38:253349}
3350
3351void WebContentsImpl::DidProceedOnInterstitial() {
3352 // The interstitial page should no longer be pausing the throbber.
creisadca9862017-06-16 19:12:113353 DCHECK(!(ShowingInterstitialPage() && interstitial_page_->pause_throbber()));
clamy44e84ce2016-02-22 15:38:253354
3355 // Restart the throbber now that the interstitial page no longer pauses it.
3356 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
3357 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073358}
3359
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043360void WebContentsImpl::DetachInterstitialPage(bool has_focus) {
Lucas Furukawa Gadani69b609192017-07-10 17:08:343361 bool interstitial_pausing_throbber =
3362 ShowingInterstitialPage() && interstitial_page_->pause_throbber();
3363 if (ShowingInterstitialPage())
3364 interstitial_page_ = nullptr;
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043365
Dominic Mazzoniefb5f9e32017-12-21 01:08:223366 // Make sure that the main page's accessibility tree is no longer
3367 // suppressed.
3368 RenderFrameHostImpl* rfh = GetMainFrame();
3369 if (rfh) {
3370 BrowserAccessibilityManager* accessibility_manager =
3371 rfh->browser_accessibility_manager();
3372 if (accessibility_manager)
3373 accessibility_manager->set_hidden_by_interstitial_page(false);
3374 }
3375
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043376 // If the focus was on the interstitial, let's keep it to the page.
3377 // (Note that in unit-tests the RVH may not have a view).
3378 if (has_focus && GetRenderViewHost()->GetWidget()->GetView())
3379 GetRenderViewHost()->GetWidget()->GetView()->Focus();
3380
Lucas Furukawa Gadani69b609192017-07-10 17:08:343381 for (auto& observer : observers_)
3382 observer.DidDetachInterstitialPage();
3383
3384 // Disconnect from outer WebContents if necessary. This must happen after the
3385 // interstitial page is cleared above, since the call to
3386 // SetRWHViewForInnerContents below may loop over all the
3387 // RenderWidgetHostViews in the tree (otherwise, including the now-deleted
3388 // view for the interstitial).
lfg1453e412017-04-11 00:48:503389 if (node_.OuterContentsFrameTreeNode()) {
3390 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3391 DCHECK(static_cast<RenderWidgetHostViewBase*>(
3392 GetRenderManager()->current_frame_host()->GetView())
3393 ->IsRenderWidgetHostViewChildFrame());
3394 RenderWidgetHostViewChildFrame* view =
3395 static_cast<RenderWidgetHostViewChildFrame*>(
3396 GetRenderManager()->current_frame_host()->GetView());
3397 GetRenderManager()->SetRWHViewForInnerContents(view);
3398 }
3399 }
3400
clamy44e84ce2016-02-22 15:38:253401 // Restart the throbber if needed now that the interstitial page is going
3402 // away.
3403 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
3404 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073405}
3406
avi2b177592014-12-10 02:08:023407void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
3408 int history_length) {
alexmos136fd6e62016-08-15 20:58:413409 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
3410 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:023411}
3412
3413void WebContentsImpl::SetHistoryOffsetAndLengthForView(
3414 RenderViewHost* render_view_host,
3415 int history_offset,
3416 int history_length) {
alexmos136fd6e62016-08-15 20:58:413417 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:023418 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:143419}
3420
toyoshim24a4c7ab2016-04-05 09:24:143421void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:173422 RenderFrameHost* focused_frame = GetFocusedFrame();
3423 if (!focused_frame)
3424 return;
3425
[email protected]959be4c2014-04-08 15:01:333426 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:143427 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:333428}
3429
megjablon3f5941072016-02-04 23:27:523430void WebContentsImpl::ReloadLoFiImages() {
3431 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
Robert Ogden34e97962018-09-14 23:50:273432 for (auto& observer : observers_)
3433 observer.DidReloadLoFiImages();
megjablon3f5941072016-02-04 23:27:523434}
3435
Ryan Sturmc65dbe42018-05-31 20:37:043436std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr>
3437WebContentsImpl::PauseSubresourceLoading() {
3438 std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr> handles;
3439 for (RenderFrameHost* rfh : GetAllFrames()) {
3440 if (!rfh->IsRenderFrameLive())
3441 continue;
3442 handles.push_back(rfh->PauseSubresourceLoading());
3443 }
3444 return handles;
3445}
3446
[email protected]959be4c2014-04-08 15:01:333447void WebContentsImpl::Undo() {
Dave Tapuskab336b922017-07-06 19:24:053448 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333449 if (!focused_frame)
3450 return;
3451
dtapuska9d46ef7d2017-05-26 19:06:063452 focused_frame->GetFrameInputHandler()->Undo();
[email protected]959be4c2014-04-08 15:01:333453 RecordAction(base::UserMetricsAction("Undo"));
3454}
3455
3456void WebContentsImpl::Redo() {
Dave Tapuskab336b922017-07-06 19:24:053457 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333458 if (!focused_frame)
3459 return;
dtapuska9d46ef7d2017-05-26 19:06:063460 focused_frame->GetFrameInputHandler()->Redo();
[email protected]959be4c2014-04-08 15:01:333461 RecordAction(base::UserMetricsAction("Redo"));
3462}
3463
3464void WebContentsImpl::Cut() {
Dave Tapuskab336b922017-07-06 19:24:053465 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333466 if (!focused_frame)
3467 return;
3468
dtapuska9d46ef7d2017-05-26 19:06:063469 focused_frame->GetFrameInputHandler()->Cut();
[email protected]959be4c2014-04-08 15:01:333470 RecordAction(base::UserMetricsAction("Cut"));
3471}
3472
3473void WebContentsImpl::Copy() {
Dave Tapuskab336b922017-07-06 19:24:053474 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333475 if (!focused_frame)
3476 return;
3477
dtapuska9d46ef7d2017-05-26 19:06:063478 focused_frame->GetFrameInputHandler()->Copy();
[email protected]959be4c2014-04-08 15:01:333479 RecordAction(base::UserMetricsAction("Copy"));
3480}
3481
3482void WebContentsImpl::CopyToFindPboard() {
3483#if defined(OS_MACOSX)
Dave Tapuskab336b922017-07-06 19:24:053484 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333485 if (!focused_frame)
3486 return;
3487
3488 // Windows/Linux don't have the concept of a find pasteboard.
dtapuska9d46ef7d2017-05-26 19:06:063489 focused_frame->GetFrameInputHandler()->CopyToFindPboard();
[email protected]959be4c2014-04-08 15:01:333490 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
3491#endif
3492}
3493
3494void WebContentsImpl::Paste() {
Dave Tapuskab336b922017-07-06 19:24:053495 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333496 if (!focused_frame)
3497 return;
3498
dtapuska9d46ef7d2017-05-26 19:06:063499 focused_frame->GetFrameInputHandler()->Paste();
[email protected]959be4c2014-04-08 15:01:333500 RecordAction(base::UserMetricsAction("Paste"));
3501}
3502
3503void WebContentsImpl::PasteAndMatchStyle() {
Dave Tapuskab336b922017-07-06 19:24:053504 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333505 if (!focused_frame)
3506 return;
3507
dtapuska9d46ef7d2017-05-26 19:06:063508 focused_frame->GetFrameInputHandler()->PasteAndMatchStyle();
[email protected]959be4c2014-04-08 15:01:333509 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
3510}
3511
3512void WebContentsImpl::Delete() {
Dave Tapuskab336b922017-07-06 19:24:053513 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333514 if (!focused_frame)
3515 return;
3516
dtapuska9d46ef7d2017-05-26 19:06:063517 focused_frame->GetFrameInputHandler()->Delete();
[email protected]959be4c2014-04-08 15:01:333518 RecordAction(base::UserMetricsAction("DeleteSelection"));
3519}
3520
3521void WebContentsImpl::SelectAll() {
Dave Tapuskab336b922017-07-06 19:24:053522 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333523 if (!focused_frame)
3524 return;
3525
dtapuska9d46ef7d2017-05-26 19:06:063526 focused_frame->GetFrameInputHandler()->SelectAll();
[email protected]959be4c2014-04-08 15:01:333527 RecordAction(base::UserMetricsAction("SelectAll"));
3528}
3529
yabinh351e7ec2017-03-10 02:43:243530void WebContentsImpl::CollapseSelection() {
Dave Tapuskab336b922017-07-06 19:24:053531 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333532 if (!focused_frame)
3533 return;
3534
dtapuska9d46ef7d2017-05-26 19:06:063535 focused_frame->GetFrameInputHandler()->CollapseSelection();
[email protected]1f3fc1d2014-04-03 14:50:173536}
3537
3538void WebContentsImpl::Replace(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053539 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173540 if (!focused_frame)
3541 return;
3542
dtapuska9d46ef7d2017-05-26 19:06:063543 focused_frame->GetFrameInputHandler()->Replace(word);
[email protected]1f3fc1d2014-04-03 14:50:173544}
3545
3546void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053547 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173548 if (!focused_frame)
3549 return;
3550
dtapuska9d46ef7d2017-05-26 19:06:063551 focused_frame->GetFrameInputHandler()->ReplaceMisspelling(word);
[email protected]959be4c2014-04-08 15:01:333552}
3553
3554void WebContentsImpl::NotifyContextMenuClosed(
3555 const CustomContextMenuContext& context) {
3556 RenderFrameHost* focused_frame = GetFocusedFrame();
3557 if (!focused_frame)
3558 return;
3559
3560 focused_frame->Send(new FrameMsg_ContextMenuClosed(
3561 focused_frame->GetRoutingID(), context));
3562}
3563
3564void WebContentsImpl::ExecuteCustomContextMenuCommand(
3565 int action, const CustomContextMenuContext& context) {
3566 RenderFrameHost* focused_frame = GetFocusedFrame();
3567 if (!focused_frame)
3568 return;
3569
3570 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
3571 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:003572}
3573
[email protected]fc2b46b2014-05-03 16:33:453574gfx::NativeView WebContentsImpl::GetNativeView() {
3575 return view_->GetNativeView();
3576}
3577
3578gfx::NativeView WebContentsImpl::GetContentNativeView() {
3579 return view_->GetContentNativeView();
3580}
3581
3582gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
3583 return view_->GetTopLevelNativeWindow();
3584}
3585
3586gfx::Rect WebContentsImpl::GetViewBounds() {
3587 return view_->GetViewBounds();
3588}
3589
3590gfx::Rect WebContentsImpl::GetContainerBounds() {
3591 gfx::Rect rv;
3592 view_->GetContainerBounds(&rv);
3593 return rv;
3594}
3595
3596DropData* WebContentsImpl::GetDropData() {
3597 return view_->GetDropData();
3598}
3599
3600void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:043601 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:453602}
3603
3604void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:043605 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:453606}
3607
3608void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:043609 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453610}
3611
3612void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:043613 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453614}
3615
[email protected]b172aee2012-04-10 17:05:263616void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
Maxim Podgorodskiya926c4ff2017-11-20 02:06:393617 view_->FocusThroughTabTraversal(reverse);
[email protected]96d185d2009-04-24 03:28:543618}
3619
[email protected]b172aee2012-04-10 17:05:263620bool WebContentsImpl::ShowingInterstitialPage() const {
creisadca9862017-06-16 19:12:113621 return interstitial_page_ != nullptr;
[email protected]96d185d2009-04-24 03:28:543622}
3623
Pete Williamson89aa1402017-07-07 19:58:413624void WebContentsImpl::AdjustPreviewsStateForNavigation(
3625 PreviewsState* previews_state) {
3626 if (delegate_)
Doug Arnettc681bbe2018-04-06 04:04:463627 delegate_->AdjustPreviewsStateForNavigation(this, previews_state);
Pete Williamson89aa1402017-07-07 19:58:413628}
3629
Maxim Podgorodskiya926c4ff2017-11-20 02:06:393630InterstitialPageImpl* WebContentsImpl::GetInterstitialPage() const {
creisadca9862017-06-16 19:12:113631 return interstitial_page_;
[email protected]686493142011-07-15 21:47:223632}
3633
Gyuyoung Kim80143f5e2018-04-02 02:40:253634void WebContentsImpl::PausePageScheduledTasks(bool paused) {
3635 SendPageMessage(
3636 new PageMsg_PausePageScheduledTasks(MSG_ROUTING_NONE, paused));
3637}
3638
[email protected]b172aee2012-04-10 17:05:263639bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:163640 // WebKit creates Document object when MIME type is application/xhtml+xml,
3641 // so we also support this MIME type.
3642 return contents_mime_type_ == "text/html" ||
3643 contents_mime_type_ == "text/xml" ||
3644 contents_mime_type_ == "application/xhtml+xml" ||
3645 contents_mime_type_ == "text/plain" ||
3646 contents_mime_type_ == "text/css" ||
Kinuko Yasuda74702f92017-07-31 03:27:533647 blink::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:163648}
3649
[email protected]b172aee2012-04-10 17:05:263650void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:593651 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:163652 if (!IsSavable()) {
Min Qinda0ed2062018-02-23 22:00:533653 download::RecordSavePackageEvent(
3654 download::SAVE_PACKAGE_DOWNLOAD_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:193655 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:143656 return;
[email protected]c7dd2f62011-07-18 15:57:593657 }
3658
3659 Stop();
3660
3661 // Create the save package and possibly prompt the user for the name to save
3662 // the page as. The user prompt is an asynchronous operation that runs on
3663 // another thread.
3664 save_package_ = new SavePackage(this);
3665 save_package_->GetSaveInfo();
3666}
3667
3668// Used in automated testing to bypass prompting the user for file names.
3669// Instead, the names and paths are hard coded rather than running them through
3670// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:343671bool WebContentsImpl::SavePage(const base::FilePath& main_file,
3672 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:213673 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:593674 // Stop the page from navigating.
3675 Stop();
3676
3677 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:213678 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:593679}
3680
[email protected]3c71576ce2013-07-23 02:00:013681void WebContentsImpl::SaveFrame(const GURL& url,
3682 const Referrer& referrer) {
Xing Liu10329bf2018-03-20 19:22:143683 SaveFrameWithHeaders(url, referrer, std::string(), base::string16());
kundaji6c7f9692015-03-09 18:00:373684}
3685
Xing Liu10329bf2018-03-20 19:22:143686void WebContentsImpl::SaveFrameWithHeaders(
3687 const GURL& url,
3688 const Referrer& referrer,
3689 const std::string& headers,
3690 const base::string16& suggested_filename) {
nasko89ad7742015-03-05 22:14:193691 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:013692 return;
sammc92af61552014-11-19 23:27:403693 if (delegate_ && delegate_->SaveFrame(url, referrer))
3694 return;
3695
nasko89ad7742015-03-05 22:14:193696 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:223697 // by explicitly passing in which frame this method should target. This would
3698 // indicate whether it's the main frame, and also tell us the frame pointer
3699 // to use for routing.
nasko89ad7742015-03-05 22:14:193700 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:223701 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:013702
brettw760f7442016-05-23 21:19:223703 StoragePartition* storage_partition = BrowserContext::GetStoragePartition(
3704 GetBrowserContext(), frame_host->GetSiteInstance());
avib7348942015-12-25 20:57:103705 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:013706 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:273707 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:013708 if (entry)
3709 post_id = entry->GetPostID();
3710 }
Ramin Halavati24e21012017-07-10 12:56:063711 net::NetworkTrafficAnnotationTag traffic_annotation =
3712 net::DefineNetworkTrafficAnnotation("download_web_contents_frame", R"(
3713 semantics {
3714 sender: "Save Page Action"
3715 description:
3716 "Saves the given frame's URL to the local file system."
3717 trigger:
3718 "The user has triggered a save operation on the frame through a "
3719 "context menu or other mechanism."
3720 data: "None."
3721 destination: WEBSITE
3722 }
3723 policy {
Ramin Halavati3b979782017-07-21 11:40:263724 cookies_allowed: YES
Ramin Halavati24e21012017-07-10 12:56:063725 cookies_store: "user"
3726 setting:
3727 "This feature cannot be disabled by settings, but it's is only "
3728 "triggered by user request."
3729 policy_exception_justification: "Not implemented."
3730 })");
Min Qina904f3302018-02-13 23:33:343731 auto params = std::make_unique<download::DownloadUrlParameters>(
brettw760f7442016-05-23 21:19:223732 url, frame_host->GetProcess()->GetID(),
3733 frame_host->GetRenderViewHost()->GetRoutingID(),
Ramin Halavati03efa732017-06-12 09:28:203734 frame_host->GetRoutingID(), storage_partition->GetURLRequestContext(),
Ramin Halavati24e21012017-07-10 12:56:063735 traffic_annotation);
Min Qina904f3302018-02-13 23:33:343736 params->set_referrer(referrer.url);
3737 params->set_referrer_policy(
3738 Referrer::ReferrerPolicyForUrlRequest(referrer.policy));
[email protected]3c71576ce2013-07-23 02:00:013739 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:013740 if (post_id >= 0)
3741 params->set_method("POST");
3742 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:373743
3744 if (headers.empty()) {
3745 params->set_prefer_cache(true);
3746 } else {
Min Qina904f3302018-02-13 23:33:343747 for (download::DownloadUrlParameters::RequestHeadersNameValuePair
3748 key_value : ParseDownloadHeaders(headers)) {
Megan Jablonski2f6a4c52017-07-10 23:01:253749 params->add_request_header(key_value.first, key_value.second);
kundaji6c7f9692015-03-09 18:00:373750 }
3751 }
Xing Liu10329bf2018-03-20 19:22:143752 params->set_suggested_name(suggested_filename);
Min Qin0ca8e1ee2018-01-31 00:49:353753 params->set_download_source(download::DownloadSource::WEB_CONTENTS_API);
thestig859c78892017-05-15 21:17:063754 BrowserContext::GetDownloadManager(GetBrowserContext())
Ramin Halavati03efa732017-06-12 09:28:203755 ->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:013756}
3757
[email protected]b172aee2012-04-10 17:05:263758void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:473759 const MHTMLGenerationParams& params,
Avi Drissman149b7832018-03-23 14:31:493760 base::OnceCallback<void(int64_t)> callback) {
3761 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params,
3762 std::move(callback));
[email protected]aa4f3972012-03-01 18:12:123763}
3764
[email protected]b172aee2012-04-10 17:05:263765const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:273766 return contents_mime_type_;
3767}
3768
[email protected]b172aee2012-04-10 17:05:263769bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:273770 return notify_disconnection_;
3771}
3772
[email protected]8ff00d72012-10-23 19:12:213773RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:273774 return &renderer_preferences_;
3775}
3776
[email protected]e35ccd52012-05-23 16:22:473777void WebContentsImpl::Close() {
3778 Close(GetRenderViewHost());
3779}
3780
Ella Ge80a52dce2017-11-15 18:01:523781void WebContentsImpl::DragSourceEndedAt(float client_x,
3782 float client_y,
3783 float screen_x,
3784 float screen_y,
Paul Meyer0c58c3712016-11-17 22:59:513785 blink::WebDragOperation operation,
3786 RenderWidgetHost* source_rwh) {
[email protected]cf200a562013-05-03 16:24:293787 if (browser_plugin_embedder_.get())
paulmeyer8fc8ea92016-11-15 05:12:213788 browser_plugin_embedder_->DragSourceEndedAt(
3789 client_x, client_y, screen_x, screen_y, operation);
Paul Meyer0c58c3712016-11-17 22:59:513790 if (source_rwh) {
Ella Ge80a52dce2017-11-15 18:01:523791 source_rwh->DragSourceEndedAt(gfx::PointF(client_x, client_y),
3792 gfx::PointF(screen_x, screen_y), operation);
Paul Meyer0c58c3712016-11-17 22:59:513793 }
[email protected]cf200a562013-05-03 16:24:293794}
3795
jam73f892642016-09-11 06:04:063796void WebContentsImpl::LoadStateChanged(
Charles Harrison911fa062018-03-06 21:01:463797 const std::string& host,
jam73f892642016-09-11 06:04:063798 const net::LoadStateWithParam& load_state,
3799 uint64_t upload_position,
3800 uint64_t upload_size) {
Charles Harrison911fa062018-03-06 21:01:463801 base::string16 host16 = url_formatter::IDNToUnicode(host);
Elly Fong-Jonescad9c3d12018-01-31 17:26:103802 // Drop no-op updates.
3803 if (load_state_.state == load_state.state &&
3804 load_state_.param == load_state.param &&
3805 upload_position_ == upload_position && upload_size_ == upload_size &&
Charles Harrison911fa062018-03-06 21:01:463806 load_state_host_ == host16) {
Elly Fong-Jonescad9c3d12018-01-31 17:26:103807 return;
3808 }
jam73f892642016-09-11 06:04:063809 load_state_ = load_state;
3810 upload_position_ = upload_position;
3811 upload_size_ = upload_size;
Charles Harrison911fa062018-03-06 21:01:463812 load_state_host_ = host16;
jam73f892642016-09-11 06:04:063813 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
3814 SetNotWaitingForResponse();
3815 if (IsLoading()) {
3816 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
3817 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
3818 }
3819}
3820
Francois Doraye6161152018-03-27 22:05:373821void WebContentsImpl::SetVisibility(Visibility visibility) {
3822 const Visibility previous_visibility = visibility_;
3823 visibility_ = visibility;
3824
Francois Dorayfe4a1772018-02-17 04:17:093825 // Notify observers if the visibility changed or if WasShown() is being called
3826 // for the first time.
Francois Dorayfe4a1772018-02-17 04:17:093827 if (visibility != previous_visibility ||
3828 (visibility == Visibility::VISIBLE && !did_first_set_visible_)) {
3829 for (auto& observer : observers_)
3830 observer.OnVisibilityChanged(visibility);
3831 }
3832}
3833
Michael Thiessen896405db2017-07-20 17:52:323834void WebContentsImpl::NotifyWebContentsFocused(
3835 RenderWidgetHost* render_widget_host) {
ericwilligersde386342016-10-19 02:35:093836 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323837 observer.OnWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:373838}
3839
Michael Thiessen896405db2017-07-20 17:52:323840void WebContentsImpl::NotifyWebContentsLostFocus(
3841 RenderWidgetHost* render_widget_host) {
zijiehe3bee08e22017-05-17 04:14:463842 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323843 observer.OnWebContentsLostFocus(render_widget_host);
zijiehe3bee08e22017-05-17 04:14:463844}
3845
Paul Meyer0c58c3712016-11-17 22:59:513846void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) {
3847 if (source_rwh)
3848 source_rwh->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:293849 if (browser_plugin_embedder_.get())
3850 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:343851}
3852
Daniel Cheng90196c82018-04-25 21:49:143853void WebContentsImpl::NavigatedByUser() {
Dominick Ng37a15052018-07-17 23:56:353854 SendUserGestureForResourceDispatchHost();
[email protected]e35ccd52012-05-23 16:22:473855}
3856
[email protected]b172aee2012-04-10 17:05:263857void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:273858 closed_by_user_gesture_ = value;
3859}
3860
[email protected]b172aee2012-04-10 17:05:263861bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:273862 return closed_by_user_gesture_;
3863}
3864
[email protected]b172aee2012-04-10 17:05:263865int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273866 return minimum_zoom_percent_;
3867}
3868
[email protected]b172aee2012-04-10 17:05:263869int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273870 return maximum_zoom_percent_;
3871}
3872
mcnee432e47d2015-11-09 19:37:463873void WebContentsImpl::SetPageScale(float page_scale_factor) {
Lukasz Anforowiczf4357ca2017-09-07 01:43:323874 GetRenderViewHost()->Send(new ViewMsg_SetPageScale(
3875 GetRenderViewHost()->GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:243876}
3877
[email protected]b172aee2012-04-10 17:05:263878gfx::Size WebContentsImpl::GetPreferredSize() const {
Francois Doray24fc62c2017-12-11 17:27:333879 return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_;
[email protected]bcd2815602012-01-14 18:17:233880}
3881
[email protected]b172aee2012-04-10 17:05:263882bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
lfgf0cd46e2017-01-04 00:05:233883 if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) &&
3884 GetBrowserPluginGuest())
[email protected]660f18e2014-05-15 20:53:053885 return GetBrowserPluginGuest()->LockMouse(allowed);
3886
lfgf0cd46e2017-01-04 00:05:233887 if (mouse_lock_widget_) {
3888 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
3889 return mouse_lock_widget_->delegate()
3890 ->GetAsWebContents()
3891 ->GotResponseToLockMouseRequest(allowed);
3892 }
lfgad8244352016-07-13 16:55:513893
lfgf0cd46e2017-01-04 00:05:233894 if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3895 return true;
3896 }
3897
3898 for (WebContentsImpl* current = this; current;
3899 current = current->GetOuterWebContents()) {
3900 current->mouse_lock_widget_ = nullptr;
3901 }
3902
lfgbee1e0a2016-06-08 21:24:213903 return false;
[email protected]0bfbf882011-12-22 18:19:273904}
3905
Joe Downing13dd76b2018-04-09 18:32:153906bool WebContentsImpl::GotResponseToKeyboardLockRequest(bool allowed) {
3907 if (!keyboard_lock_widget_)
3908 return false;
3909
3910 if (keyboard_lock_widget_->delegate()->GetAsWebContents() != this) {
3911 NOTREACHED();
3912 return false;
3913 }
3914
3915 // KeyboardLock is only supported when called by the top-level browsing
3916 // context and is not supported in embedded content scenarios.
3917 if (GetOuterWebContents())
3918 return false;
3919
3920 keyboard_lock_widget_->GotResponseToKeyboardLockRequest(allowed);
3921 return true;
3922}
3923
[email protected]b172aee2012-04-10 17:05:263924bool WebContentsImpl::HasOpener() const {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283925 return GetOpener() != nullptr;
[email protected]a0358d72012-03-09 14:06:503926}
3927
lukasza6f8ac622017-06-06 03:10:203928RenderFrameHostImpl* WebContentsImpl::GetOpener() const {
alexmose201c7cd2015-06-10 17:14:213929 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
lukasza6f8ac622017-06-06 03:10:203930 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen55ff3502014-12-18 20:52:573931}
3932
jochen6004a362017-02-04 00:11:403933bool WebContentsImpl::HasOriginalOpener() const {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283934 return GetOriginalOpener() != nullptr;
jochen6004a362017-02-04 00:11:403935}
3936
lukasza6f8ac622017-06-06 03:10:203937RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() const {
jochen6004a362017-02-04 00:11:403938 FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener();
lukasza6f8ac622017-06-06 03:10:203939 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen6004a362017-02-04 00:11:403940}
3941
[email protected]cb805452013-05-22 15:16:213942void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
Joel Hockey85b379d2017-12-11 10:42:133943 color_chooser_->DidChooseColorInColorChooser(color);
[email protected]da8543762012-03-20 08:52:203944}
3945
[email protected]cb805452013-05-22 15:16:213946void WebContentsImpl::DidEndColorChooser() {
Joel Hockey85b379d2017-12-11 10:42:133947 color_chooser_.reset();
[email protected]da8543762012-03-20 08:52:203948}
3949
halton.huoca2eabd2015-07-06 08:17:403950int WebContentsImpl::DownloadImage(
3951 const GURL& url,
3952 bool is_favicon,
3953 uint32_t max_bitmap_size,
3954 bool bypass_cache,
Avi Drissmana5a52dd2018-03-27 03:39:023955 WebContents::ImageDownloadCallback callback) {
amistry9f01b772015-07-29 01:54:553956 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:403957 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:063958 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:403959 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:553960 const int download_id = ++next_image_download_id;
3961 if (!mojo_image_downloader) {
3962 // If the renderer process is dead (i.e. crash, or memory pressure on
3963 // Android), the downloader service will be invalid. Pre-Mojo, this would
Avi Drissmana5a52dd2018-03-27 03:39:023964 // hang the callback indefinitely since the IPC would be dropped. Now,
amistry9f01b772015-07-29 01:54:553965 // respond with a 400 HTTP error code to indicate that something went wrong.
Eric Seckler8652dcd52018-09-20 10:42:283966 base::PostTaskWithTraits(
3967 FROM_HERE, {BrowserThread::UI},
tzike2aca992017-09-05 08:50:543968 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:023969 weak_factory_.GetWeakPtr(), std::move(callback),
3970 download_id, url, 400, std::vector<SkBitmap>(),
3971 std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:553972 return download_id;
3973 }
3974
halton.huoca2eabd2015-07-06 08:17:403975 mojo_image_downloader->DownloadImage(
sammcf6f4fcf2016-06-21 05:39:393976 url, is_favicon, max_bitmap_size, bypass_cache,
tzike2aca992017-09-05 08:50:543977 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:023978 weak_factory_.GetWeakPtr(), std::move(callback),
3979 download_id, url));
amistry9f01b772015-07-29 01:54:553980 return download_id;
[email protected]795c28972012-12-06 06:13:393981}
3982
[email protected]36ec24f2014-01-09 00:32:083983void WebContentsImpl::Find(int request_id,
3984 const base::string16& search_text,
Rakina Zata Amni3f77dff2018-09-08 16:19:433985 blink::mojom::FindOptionsPtr options) {
thestig6057a6b22015-11-12 23:01:333986 // Cowardly refuse to search for no text.
3987 if (search_text.empty()) {
3988 NOTREACHED();
3989 return;
3990 }
3991
Rakina Zata Amni3f77dff2018-09-08 16:19:433992 GetOrCreateFindRequestManager()->Find(request_id, search_text,
3993 std::move(options));
[email protected]36ec24f2014-01-09 00:32:083994}
3995
3996void WebContentsImpl::StopFinding(StopFindAction action) {
paulmeyerfeafc2d2017-04-25 21:46:403997 if (FindRequestManager* manager = GetFindRequestManager())
3998 manager->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:083999}
4000
Tommy Steimel18360512017-11-01 00:38:194001bool WebContentsImpl::WasEverAudible() {
4002 return was_ever_audible_;
4003}
4004
Avi Drissmana5a52dd2018-03-27 03:39:024005void WebContentsImpl::GetManifest(GetManifestCallback callback) {
4006 manifest_manager_host_->GetManifest(std::move(callback));
mlamouriefdca9d2014-09-16 16:55:404007}
4008
bokanece34a82016-01-28 19:49:464009void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:534010 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:434011 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:464012 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:534013}
4014
mariakhomenko44bdc4732015-04-29 01:55:384015void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:374016 if (delayed_open_url_params_.get()) {
4017 OpenURL(*delayed_open_url_params_.get());
4018 delayed_open_url_params_.reset(nullptr);
4019 return;
4020 }
4021
mariakhomenko44bdc4732015-04-29 01:55:384022 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
4023 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:164024 if (is_resume_pending_) {
4025 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:134026 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:164027 GetMainFrame()->Init();
4028 }
mariakhomenko44bdc4732015-04-29 01:55:384029}
4030
[email protected]b172aee2012-04-10 17:05:264031bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:264032 // When the browser is started with about:blank as the startup URL, focus
4033 // the location bar (which will also select its contents) so people can
4034 // simply begin typing to navigate elsewhere.
4035 //
4036 // We need to be careful not to trigger this for anything other than the
4037 // startup navigation. In particular, if we allow an attacker to open a
4038 // popup to about:blank, then navigate, focusing the Omnibox will cause the
4039 // end of the new URL to be scrolled into view instead of the start,
4040 // allowing the attacker to spoof other URLs. The conditions checked here
4041 // are all aimed at ensuring no such attacker-controlled navigation can
4042 // trigger this.
4043 //
4044 // Note that we check the pending entry instead of the visible one; for the
4045 // startup URL case these are the same, but for the attacker-controlled
4046 // navigation case the visible entry is the committed "about:blank" URL and
4047 // the pending entry is the problematic navigation elsewhere.
4048 NavigationEntryImpl* entry = controller_.GetPendingEntry();
4049 if (controller_.IsInitialNavigation() && entry &&
4050 !entry->is_renderer_initiated() &&
csharrisona3bd0b32016-10-19 18:40:484051 entry->GetURL() == url::kAboutBlankURL) {
[email protected]0c9406632013-02-08 01:13:334052 return true;
palmerc70cb1f2016-03-04 23:41:264053 }
[email protected]0c9406632013-02-08 01:13:334054 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:274055}
4056
[email protected]b172aee2012-04-10 17:05:264057void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:274058 if (delegate_)
4059 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:214060}
4061
clamy0e119882015-07-31 16:12:334062void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484063 TRACE_EVENT1("navigation", "WebContentsImpl::DidStartNavigation",
4064 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094065 for (auto& observer : observers_)
4066 observer.DidStartNavigation(navigation_handle);
Becca Hughesd11d6502018-07-31 17:01:284067
4068 if (display_cutout_host_impl_)
4069 display_cutout_host_impl_->DidStartNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:334070}
4071
4072void WebContentsImpl::DidRedirectNavigation(
4073 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484074 TRACE_EVENT1("navigation", "WebContentsImpl::DidRedirectNavigation",
4075 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094076 for (auto& observer : observers_)
4077 observer.DidRedirectNavigation(navigation_handle);
jam5f358e52017-02-13 16:37:034078
4079 // Notify accessibility if this is a reload. This has to called on the
4080 // BrowserAccessibilityManager associated with the old RFHI.
4081 if (navigation_handle->GetReloadType() != ReloadType::NONE) {
4082 NavigationHandleImpl* nhi =
4083 static_cast<NavigationHandleImpl*>(navigation_handle);
4084 BrowserAccessibilityManager* manager =
4085 nhi->frame_tree_node()
4086 ->current_frame_host()
4087 ->browser_accessibility_manager();
4088 if (manager)
4089 manager->UserIsReloading();
4090 }
clamy0e119882015-07-31 16:12:334091}
4092
clamyefca29e2015-09-17 00:22:114093void WebContentsImpl::ReadyToCommitNavigation(
4094 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484095 TRACE_EVENT1("navigation", "WebContentsImpl::ReadyToCommitNavigation",
4096 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094097 for (auto& observer : observers_)
4098 observer.ReadyToCommitNavigation(navigation_handle);
John Abd-El-Malekd4882642017-12-04 21:45:194099
Kenneth Russell954ed9ce2018-04-12 23:07:014100 // If any domains are blocked from accessing 3D APIs because they may
4101 // have caused the GPU to reset recently, unblock them here if the user
4102 // initiated this navigation. This implies that the user was involved in
4103 // the decision to navigate, so there's no concern about
4104 // denial-of-service issues. Want to do this as early as
4105 // possible to avoid race conditions with pages attempting to access
4106 // WebGL early on.
4107 //
4108 // TODO(crbug.com/617904): currently navigations initiated by the browser
4109 // (reload button, reload menu option, pressing return in the Omnibox)
4110 // return false from HasUserGesture(). If or when that is addressed,
4111 // remove the check for IsRendererInitiated() below.
4112 //
4113 // TODO(crbug.com/832180): HasUserGesture comes from the renderer
4114 // process and isn't validated. Until it is, don't trust it.
4115 if (!navigation_handle->IsRendererInitiated()) {
4116 GpuDataManagerImpl::GetInstance()->UnblockDomainFrom3DAPIs(
4117 navigation_handle->GetURL());
4118 }
4119
John Abd-El-Malekfde08e6da2017-12-05 04:06:244120 if (navigation_handle->IsSameDocument())
4121 return;
4122
Livvie Lin139bf442018-08-10 00:18:544123 // SSLInfo is not needed on subframe navigations since the main-frame
4124 // certificate is the only one that can be inspected (using the info
4125 // bubble) without refreshing the page with DevTools open.
4126 if (navigation_handle->IsInMainFrame())
4127 controller_.ssl_manager()->DidStartResourceResponse(
4128 navigation_handle->GetURL(),
4129 net::IsCertStatusError(navigation_handle->GetSSLInfo().cert_status));
John Abd-El-Malekfde08e6da2017-12-05 04:06:244130
4131 SetNotWaitingForResponse();
clamyefca29e2015-09-17 00:22:114132}
4133
clamy0e119882015-07-31 16:12:334134void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484135 TRACE_EVENT1("navigation", "WebContentsImpl::DidFinishNavigation",
4136 "navigation_handle", navigation_handle);
Steven Holte38041342018-06-22 22:00:574137
ericwilligersde386342016-10-19 02:35:094138 for (auto& observer : observers_)
4139 observer.DidFinishNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:334140
Becca Hughesd11d6502018-07-31 17:01:284141 if (display_cutout_host_impl_)
4142 display_cutout_host_impl_->DidFinishNavigation(navigation_handle);
4143
jam5f358e52017-02-13 16:37:034144 if (navigation_handle->HasCommitted()) {
dmazzonibf8cec42015-02-08 08:28:084145 BrowserAccessibilityManager* manager =
jam5f358e52017-02-13 16:37:034146 static_cast<RenderFrameHostImpl*>(
4147 navigation_handle->GetRenderFrameHost())
4148 ->browser_accessibility_manager();
4149 if (manager) {
4150 if (navigation_handle->IsErrorPage()) {
4151 manager->NavigationFailed();
4152 } else {
4153 manager->NavigationSucceeded();
4154 }
4155 }
Tommy Steimel18360512017-11-01 00:38:194156
4157 if (navigation_handle->IsInMainFrame() &&
4158 !navigation_handle->IsSameDocument()) {
4159 was_ever_audible_ = false;
Steven Holte38041342018-06-22 22:00:574160 last_committed_source_id_ =
4161 ukm::ConvertToSourceId(navigation_handle->GetNavigationId(),
4162 ukm::SourceIdType::NAVIGATION_ID);
Tommy Steimel18360512017-11-01 00:38:194163 }
dmazzonibf8cec42015-02-08 08:28:084164 }
[email protected]400992b2012-06-14 00:03:544165}
4166
[email protected]b80624c2014-02-09 02:46:554167void WebContentsImpl::DidFailLoadWithError(
4168 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:554169 const GURL& url,
[email protected]b80624c2014-02-09 02:46:554170 int error_code,
Yutaka Hirano16d3c5d2017-07-31 06:17:304171 const base::string16& error_description) {
ericwilligersde386342016-10-19 02:35:094172 for (auto& observer : observers_) {
Yutaka Hirano16d3c5d2017-07-31 06:17:304173 observer.DidFailLoad(render_frame_host, url, error_code, error_description);
ericwilligersde386342016-10-19 02:35:094174 }
[email protected]b80624c2014-02-09 02:46:554175}
4176
[email protected]52913802013-12-10 05:52:184177void WebContentsImpl::NotifyChangedNavigationState(
4178 InvalidateTypes changed_flags) {
4179 NotifyNavigationStateChanged(changed_flags);
4180}
4181
toyoshim0df1d3a2016-09-09 09:52:484182void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
4183 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:204184 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094185 for (auto& observer : observers_)
4186 observer.DidStartNavigationToPendingEntry(url, reload_type);
[email protected]3691e5cf2014-01-22 10:16:204187}
4188
lukasza1d025732016-09-28 21:36:084189bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:224190 if (!delegate_)
4191 return true;
lukasza1d025732016-09-28 21:36:084192 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:224193}
4194
[email protected]aa62afd2014-04-22 19:22:464195bool WebContentsImpl::ShouldPreserveAbortedURLs() {
4196 if (!delegate_)
4197 return false;
4198 return delegate_->ShouldPreserveAbortedURLs(this);
4199}
4200
[email protected]0d0f4c492014-04-02 06:42:574201void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:234202 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:574203 // Ensure fullscreen mode is exited before committing the navigation to a
4204 // different page. The next page will not start out assuming it is in
4205 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:234206 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:194207 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:574208 return;
4209 }
alexmos5dd617d2016-06-07 04:21:154210 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464211 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:154212 DCHECK(!IsFullscreenForCurrentTab());
Joe Downingc1a57efe2018-05-09 18:23:544213
4214 // Clean up keyboard lock state when navigating.
4215 CancelKeyboardLock(keyboard_lock_widget_);
[email protected]0d0f4c492014-04-02 06:42:574216}
4217
[email protected]37567b432014-02-12 01:12:224218void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:284219 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:224220 const LoadCommittedDetails& details,
4221 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
4222 if (details.is_navigation_to_different_page()) {
4223 // Clear the status bubble. This is a workaround for a bug where WebKit
4224 // doesn't let us know that the cursor left an element during a
4225 // transition (this is also why the mouse cursor remains as a hand after
4226 // clicking on a link); see bugs 1184641 and 980803. We don't want to
4227 // clear the bubble when a user navigates to a named anchor in the same
4228 // page.
Lukasz Anforowiczfd707142018-02-07 19:46:134229 ClearTargetURL();
lanwei9d343ad22015-02-11 01:46:004230
4231 RenderWidgetHostViewBase* rwhvb =
4232 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
4233 if (rwhvb)
4234 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:284235
peter90afaba2015-06-01 12:05:294236 did_first_visually_non_empty_paint_ = false;
4237
yusufod41c5f92015-03-06 00:14:284238 // Reset theme color on navigation to new page.
4239 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:224240 }
4241
[email protected]e85165c642014-06-10 14:34:314242 if (delegate_)
[email protected]37567b432014-02-12 01:12:224243 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:314244 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:224245}
4246
4247void WebContentsImpl::DidNavigateAnyFramePostCommit(
4248 RenderFrameHostImpl* render_frame_host,
4249 const LoadCommittedDetails& details,
4250 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:104251 // Now that something has committed, we don't need to track whether the
4252 // initial page has been accessed.
4253 has_accessed_initial_document_ = false;
4254
[email protected]37567b432014-02-12 01:12:224255 // If we navigate off the page, close all JavaScript dialogs.
eugenebutee08663a2017-04-27 17:43:124256 if (!details.is_same_document)
creis89a0f782015-05-27 16:13:174257 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:224258
avid53461d2016-02-25 17:15:044259 // If this is a user-initiated navigation, start allowing JavaScript dialogs
4260 // again.
avi5d3b8692016-10-12 22:00:464261 if (params.gesture == NavigationGestureUser && dialog_manager_) {
avi6879fcf2017-01-21 05:27:534262 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:464263 }
[email protected]37567b432014-02-12 01:12:224264}
4265
4266void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
4267 contents_mime_type_ = mime_type;
4268}
4269
[email protected]277857a2014-06-03 10:38:014270bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:314271 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:054272 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:314273 return false;
4274
[email protected]37567b432014-02-12 01:12:224275 if (delegate_)
4276 return delegate_->CanOverscrollContent();
4277
4278 return false;
4279}
4280
nicka0ac8382016-12-15 23:59:234281void WebContentsImpl::OnThemeColorChanged(RenderFrameHostImpl* source,
4282 SkColor theme_color) {
4283 if (source != GetMainFrame()) {
4284 // Only the main frame may control the theme.
4285 return;
4286 }
4287
peter90afaba2015-06-01 12:05:294288 // Update the theme color. This is to be published to observers after the
4289 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:284290 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:294291
4292 if (did_first_visually_non_empty_paint_ &&
4293 last_sent_theme_color_ != theme_color_) {
ericwilligersde386342016-10-19 02:35:094294 for (auto& observer : observers_)
4295 observer.DidChangeThemeColor(theme_color_);
peter90afaba2015-06-01 12:05:294296 last_sent_theme_color_ = theme_color_;
4297 }
[email protected]e7104762014-06-20 19:17:254298}
4299
[email protected]b172aee2012-04-10 17:05:264300void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
nicka0ac8382016-12-15 23:59:234301 RenderFrameHostImpl* source,
[email protected]724159a2010-12-30 01:11:184302 const GURL& url,
[email protected]70435962011-08-02 20:13:284303 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:184304 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:404305 ResourceType resource_type) {
ericwilligersde386342016-10-19 02:35:094306 for (auto& observer : observers_)
4307 observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type);
[email protected]b0f724c2013-09-05 04:21:134308
[email protected]8bfc8272013-09-09 20:10:534309 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
nicka0ac8382016-12-15 23:59:234310 StoragePartition* partition = source->GetProcess()->GetStoragePartition();
[email protected]8bfc8272013-09-09 20:10:534311 scoped_refptr<net::URLRequestContextGetter> request_context(
nicka0ac8382016-12-15 23:59:234312 resource_type == RESOURCE_TYPE_MEDIA
4313 ? partition->GetMediaURLRequestContext()
4314 : partition->GetURLRequestContext());
Eric Seckler8652dcd52018-09-20 10:42:284315 base::PostTaskWithTraits(
4316 FROM_HERE, {BrowserThread::IO},
tzike2aca992017-09-05 08:50:544317 base::BindOnce(&NotifyCacheOnIO, request_context, url, http_method));
[email protected]8bfc8272013-09-09 20:10:534318 }
[email protected]724159a2010-12-30 01:11:184319}
4320
nicka0ac8382016-12-15 23:59:234321void WebContentsImpl::OnDidDisplayInsecureContent(RenderFrameHostImpl* source) {
4322 // Any frame can trigger display of insecure content, so we don't check
4323 // |source| here.
carloskd9d97942017-02-16 08:58:094324 DidDisplayInsecureContent();
4325}
4326
4327void WebContentsImpl::DidDisplayInsecureContent() {
estarkc2273502016-10-12 22:03:024328 controller_.ssl_manager()->DidDisplayMixedContent();
[email protected]724159a2010-12-30 01:11:184329}
4330
elawrenceb2ac2a232017-03-27 21:46:254331void WebContentsImpl::OnDidContainInsecureFormAction(
4332 RenderFrameHostImpl* source) {
4333 controller_.ssl_manager()->DidContainInsecureFormAction();
4334}
4335
nicka0ac8382016-12-15 23:59:234336void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source,
4337 const GURL& security_origin,
estark910b4572015-12-09 20:55:414338 const GURL& target_url) {
nicka0ac8382016-12-15 23:59:234339 // TODO(nick, estark): Should we call FilterURL using |source|'s process on
4340 // these parameters? |target_url| seems unused, except for a log message. And
4341 // |security_origin| might be replaceable with the origin of the main frame.
carloskd9d97942017-02-16 08:58:094342 DidRunInsecureContent(security_origin, target_url);
4343}
4344
4345void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin,
4346 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:584347 LOG(WARNING) << security_origin << " ran insecure content from "
4348 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:394349 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:414350 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:294351 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:394352 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
estarkc2273502016-10-12 22:03:024353 controller_.ssl_manager()->DidRunMixedContent(security_origin);
[email protected]724159a2010-12-30 01:11:184354}
4355
carloskd9d97942017-02-16 08:58:094356void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364357 if (delegate_) {
4358 delegate_->PassiveInsecureContentFound(resource_url);
4359 }
carloskd9d97942017-02-16 08:58:094360}
4361
4362bool WebContentsImpl::ShouldAllowRunningInsecureContent(
4363 WebContents* web_contents,
4364 bool allowed_per_prefs,
4365 const url::Origin& origin,
4366 const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364367 if (delegate_) {
4368 return delegate_->ShouldAllowRunningInsecureContent(
4369 web_contents, allowed_per_prefs, origin, resource_url);
4370 }
4371
4372 return allowed_per_prefs;
carloskd9d97942017-02-16 08:58:094373}
4374
Lukasz Anforowicze1b954d92017-10-30 21:28:064375void WebContentsImpl::ViewSource(RenderFrameHostImpl* frame) {
4376 DCHECK_EQ(this, WebContents::FromRenderFrameHost(frame));
4377
4378 // Don't do anything if there is no |delegate_| that could accept and show the
4379 // new WebContents containing the view-source.
4380 if (!delegate_)
4381 return;
4382
4383 // Use the last committed entry, since the pending entry hasn't loaded yet and
4384 // won't be copied into the cloned tab.
4385 NavigationEntryImpl* last_committed_entry =
4386 static_cast<NavigationEntryImpl*>(frame->frame_tree_node()
4387 ->navigator()
4388 ->GetController()
4389 ->GetLastCommittedEntry());
4390 if (!last_committed_entry)
4391 return;
4392
4393 FrameNavigationEntry* frame_entry =
4394 last_committed_entry->GetFrameEntry(frame->frame_tree_node());
4395 if (!frame_entry)
4396 return;
4397
4398 // Any new WebContents opened while this WebContents is in fullscreen can be
4399 // used to confuse the user, so drop fullscreen.
Avi Drissmand18c51972018-08-15 18:32:094400 ForSecurityDropFullscreen();
Lukasz Anforowicze1b954d92017-10-30 21:28:064401
4402 // We intentionally don't share the SiteInstance with the original frame so
4403 // that view source has a consistent process model and always ends up in a new
4404 // process (https://crbug.com/699493).
4405 scoped_refptr<SiteInstanceImpl> site_instance_for_view_source = nullptr;
4406 // Referrer is not important, because view-source should not hit the network,
4407 // but should be served from the cache instead.
4408 Referrer referrer_for_view_source;
4409 // Do not restore title, derive it from the url.
4410 base::string16 title_for_view_source;
4411 auto navigation_entry = std::make_unique<NavigationEntryImpl>(
4412 site_instance_for_view_source, frame_entry->url(),
4413 referrer_for_view_source, title_for_view_source, ui::PAGE_TRANSITION_LINK,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:094414 /* is_renderer_initiated = */ false,
4415 /* blob_url_loader_factory = */ nullptr);
Lukasz Anforowicze1b954d92017-10-30 21:28:064416 navigation_entry->SetVirtualURL(GURL(content::kViewSourceScheme +
4417 std::string(":") +
4418 frame_entry->url().spec()));
4419
4420 // Do not restore scroller position.
4421 // TODO(creis, lukasza, arthursonzogni): Do not reuse the original PageState,
4422 // but start from a new one and only copy the needed data.
4423 const PageState& new_page_state =
4424 frame_entry->page_state().RemoveScrollOffset();
4425
4426 scoped_refptr<FrameNavigationEntry> new_frame_entry =
4427 navigation_entry->root_node()->frame_entry;
4428 new_frame_entry->set_method(frame_entry->method());
4429 new_frame_entry->SetPageState(new_page_state);
4430
4431 // Create a new WebContents, which is used to display the source code.
erikchenbee5c9622018-04-27 19:30:254432 std::unique_ptr<WebContents> view_source_contents =
Erik Chenbb8e738e2018-04-28 14:10:434433 Create(CreateParams(GetBrowserContext()));
Lukasz Anforowicze1b954d92017-10-30 21:28:064434
4435 // Restore the previously created NavigationEntry.
4436 std::vector<std::unique_ptr<NavigationEntry>> navigation_entries;
4437 navigation_entries.push_back(std::move(navigation_entry));
4438 view_source_contents->GetController().Restore(0, RestoreType::CURRENT_SESSION,
4439 &navigation_entries);
4440
4441 // Add |view_source_contents| as a new tab.
4442 gfx::Rect initial_rect;
4443 constexpr bool kUserGesture = true;
4444 bool ignored_was_blocked;
erikchenbee5c9622018-04-27 19:30:254445 delegate_->AddNewContents(this, std::move(view_source_contents),
Lukasz Anforowicze1b954d92017-10-30 21:28:064446 WindowOpenDisposition::NEW_FOREGROUND_TAB,
4447 initial_rect, kUserGesture, &ignored_was_blocked);
4448 // Note that the |delegate_| could have deleted |view_source_contents| during
4449 // AddNewContents method call.
4450}
4451
Jay Civellid5904f02018-03-23 19:43:574452void WebContentsImpl::SubresourceResponseStarted(const GURL& url,
4453 net::CertStatus cert_status) {
4454 controller_.ssl_manager()->DidStartResourceResponse(url, cert_status);
4455 SetNotWaitingForResponse();
4456}
4457
Jay Civelli116683f2018-03-27 19:56:234458void WebContentsImpl::ResourceLoadComplete(
Jay Civelli52a63302018-04-30 22:39:554459 RenderFrameHost* render_frame_host,
Clark DuVall36164bd2018-08-09 22:49:084460 const GlobalRequestID& request_id,
Jay Civelli116683f2018-03-27 19:56:234461 mojom::ResourceLoadInfoPtr resource_load_info) {
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254462 for (auto& observer : observers_) {
Clark DuVall36164bd2018-08-09 22:49:084463 observer.ResourceLoadComplete(render_frame_host, request_id,
4464 *resource_load_info);
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254465 }
John Abd-El-Malekd4882642017-12-04 21:45:194466}
4467
Wei Li5bb659742018-02-14 03:07:584468void WebContentsImpl::PrintCrossProcessSubframe(
4469 const gfx::Rect& rect,
4470 int document_cookie,
4471 RenderFrameHost* subframe_host) {
Wei Li5c0b4d12018-03-22 15:05:224472 auto* outer_contents = GetOuterWebContents();
4473 if (outer_contents) {
4474 // When an extension or app page is printed, the content should be
4475 // composited with outer content, so the outer contents should handle the
4476 // print request.
4477 outer_contents->PrintCrossProcessSubframe(rect, document_cookie,
4478 subframe_host);
4479 return;
4480 }
4481
Wei Li5bb659742018-02-14 03:07:584482 // If there is no delegate such as in tests or during deletion, do nothing.
4483 if (!delegate_)
4484 return;
4485
4486 delegate_->PrintCrossProcessSubframe(this, rect, document_cookie,
4487 subframe_host);
4488}
4489
rob.buis300b0872017-03-10 20:43:584490#if defined(OS_ANDROID)
4491base::android::ScopedJavaLocalRef<jobject>
4492WebContentsImpl::GetJavaRenderFrameHostDelegate() {
4493 return GetJavaWebContents();
4494}
4495#endif
4496
estark910b4572015-12-09 20:55:414497void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004498 RenderFrameHostImpl* source) {
estarkc2273502016-10-12 22:03:024499 controller_.ssl_manager()->DidDisplayContentWithCertErrors();
estark910b4572015-12-09 20:55:414500}
4501
4502void WebContentsImpl::OnDidRunContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004503 RenderFrameHostImpl* source) {
nicka0ac8382016-12-15 23:59:234504 // TODO(nick, estark): Do we need to consider |source| here somehow?
estarkcd2e30c2016-08-12 06:51:154505 NavigationEntry* entry = controller_.GetVisibleEntry();
4506 if (!entry)
estarkaeda1422016-05-10 02:31:124507 return;
4508
estarkaeda1422016-05-10 02:31:124509 // TODO(estark): check that this does something reasonable for
4510 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:154511 controller_.ssl_manager()->DidRunContentWithCertErrors(
4512 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:414513}
4514
nicka0ac8382016-12-15 23:59:234515void WebContentsImpl::OnDocumentLoadedInFrame(RenderFrameHostImpl* source) {
ericwilligersde386342016-10-19 02:35:094516 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:234517 observer.DocumentLoadedInFrame(source);
[email protected]724159a2010-12-30 01:11:184518}
4519
nicka0ac8382016-12-15 23:59:234520void WebContentsImpl::OnDidFinishLoad(RenderFrameHostImpl* source,
4521 const GURL& url) {
[email protected]8b3af1e2014-01-24 13:29:124522 GURL validated_url(url);
nicka0ac8382016-12-15 23:59:234523 source->GetProcess()->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:374524
ericwilligersde386342016-10-19 02:35:094525 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:234526 observer.DidFinishLoad(source, validated_url);
[email protected]1a55c5be2011-11-29 11:36:314527}
4528
nicka0ac8382016-12-15 23:59:234529void WebContentsImpl::OnGoToEntryAtOffset(RenderViewHostImpl* source,
Arthur Sonzognia7d715a2018-09-20 16:11:134530 int offset,
4531 bool has_user_gesture) {
4532 // Non-user initiated navigations coming from the renderer should be ignored
4533 // if there is an ongoing browser-initiated navigation.
4534 // See https://crbug.com/879965.
4535 // TODO(arthursonzogni): See if this should check for ongoing navigations in
4536 // the frame(s) affected by the session history navigation, rather than just
4537 // the main frame.
4538 if (!has_user_gesture) {
4539 NavigationRequest* ongoing_navigation_request =
4540 frame_tree_.root()->navigation_request();
4541 if (ongoing_navigation_request &&
4542 ongoing_navigation_request->browser_initiated()) {
4543 return;
4544 }
4545 }
4546
nicka0ac8382016-12-15 23:59:234547 // All frames are allowed to navigate the global history.
avi6ddfcae2015-06-30 15:50:574548 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
4549 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:264550}
4551
nicka0ac8382016-12-15 23:59:234552void WebContentsImpl::OnUpdateZoomLimits(RenderViewHostImpl* source,
4553 int minimum_percent,
[email protected]fce823222014-05-30 16:24:304554 int maximum_percent) {
[email protected]216813952011-05-19 22:21:264555 minimum_zoom_percent_ = minimum_percent;
4556 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:264557}
4558
nicka0ac8382016-12-15 23:59:234559void WebContentsImpl::OnPageScaleFactorChanged(RenderViewHostImpl* source,
4560 float page_scale_factor) {
mcnee336ea2c2017-05-23 22:50:594561#if !defined(OS_ANDROID)
4562 // While page scale factor is used on mobile, this PageScaleFactorIsOne logic
4563 // is only needed on desktop.
mcnee432e47d2015-11-09 19:37:464564 bool is_one = page_scale_factor == 1.f;
4565 if (is_one != page_scale_factor_is_one_) {
4566 page_scale_factor_is_one_ = is_one;
4567
4568 HostZoomMapImpl* host_zoom_map =
4569 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
4570
nicka0ac8382016-12-15 23:59:234571 if (host_zoom_map) {
mcnee432e47d2015-11-09 19:37:464572 host_zoom_map->SetPageScaleFactorIsOneForView(
nicka0ac8382016-12-15 23:59:234573 source->GetProcess()->GetID(), source->GetRoutingID(),
mcnee432e47d2015-11-09 19:37:464574 page_scale_factor_is_one_);
4575 }
4576 }
mcnee336ea2c2017-05-23 22:50:594577#endif // !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:464578
ericwilligersde386342016-10-19 02:35:094579 for (auto& observer : observers_)
4580 observer.OnPageScaleFactorChanged(page_scale_factor);
mcnee432e47d2015-11-09 19:37:464581}
4582
nicka0ac8382016-12-15 23:59:234583void WebContentsImpl::OnEnumerateDirectory(RenderViewHostImpl* source,
4584 int request_id,
[email protected]2dec8ec2013-02-07 19:20:344585 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:434586 if (!delegate_)
4587 return;
4588
[email protected]b9535422012-02-09 01:47:594589 ChildProcessSecurityPolicyImpl* policy =
4590 ChildProcessSecurityPolicyImpl::GetInstance();
nicka0ac8382016-12-15 23:59:234591 if (policy->CanReadFile(source->GetProcess()->GetID(), path)) {
4592 // TODO(nick): |this| param in the call below ought to be a RenderFrameHost.
[email protected]b9535422012-02-09 01:47:594593 delegate_->EnumerateDirectory(this, request_id, path);
nicka0ac8382016-12-15 23:59:234594 }
[email protected]3a29a6e2011-08-24 18:26:214595}
4596
nicka0ac8382016-12-15 23:59:234597void WebContentsImpl::OnRegisterProtocolHandler(RenderFrameHostImpl* source,
4598 const std::string& protocol,
[email protected]b172aee2012-04-10 17:05:264599 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:264600 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:364601 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234602 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4603 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]e5f2de02012-07-20 22:15:434604 if (!delegate_)
4605 return;
4606
[email protected]b9535422012-02-09 01:47:594607 ChildProcessSecurityPolicyImpl* policy =
4608 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:324609 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:594610 return;
[email protected]8f810632013-06-06 22:33:324611
[email protected]c125e532014-05-10 20:39:064612 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:204613}
4614
nicka0ac8382016-12-15 23:59:234615void WebContentsImpl::OnUnregisterProtocolHandler(RenderFrameHostImpl* source,
4616 const std::string& protocol,
[email protected]f5273e52014-07-14 16:30:204617 const GURL& url,
4618 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234619 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4620 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]f5273e52014-07-14 16:30:204621 if (!delegate_)
4622 return;
4623
4624 ChildProcessSecurityPolicyImpl* policy =
4625 ChildProcessSecurityPolicyImpl::GetInstance();
4626 if (policy->IsPseudoScheme(protocol))
4627 return;
4628
4629 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
4630}
4631
kouhei40f03cb2015-09-24 07:47:014632void WebContentsImpl::OnUpdatePageImportanceSignals(
nicka0ac8382016-12-15 23:59:234633 RenderFrameHostImpl* source,
kouhei40f03cb2015-09-24 07:47:014634 const PageImportanceSignals& signals) {
nicka0ac8382016-12-15 23:59:234635 // TODO(nick, kouhei): Fix this for oopifs; currently all frames' state gets
4636 // written to this one field.
kouhei40f03cb2015-09-24 07:47:014637 page_importance_signals_ = signals;
4638}
4639
mfomitchev2b8b066a2016-01-28 19:23:154640#if defined(OS_ANDROID)
[email protected]1ff427972013-02-07 21:14:074641void WebContentsImpl::OnOpenDateTimeDialog(
nicka0ac8382016-12-15 23:59:234642 RenderViewHostImpl* source,
[email protected]1ff427972013-02-07 21:14:074643 const ViewHostMsg_DateTimeDialogValue_Params& value) {
nicka0ac8382016-12-15 23:59:234644 date_time_chooser_->ShowDialog(
4645 GetTopLevelNativeWindow(), source, value.dialog_type, value.dialog_value,
4646 value.minimum, value.maximum, value.step, value.suggestions);
[email protected]583418cc2013-01-17 14:01:104647}
[email protected]59363fc92012-09-05 03:46:314648#endif
4649
nicka0ac8382016-12-15 23:59:234650void WebContentsImpl::OnDomOperationResponse(RenderFrameHostImpl* source,
4651 const std::string& json_string) {
4652 // TODO(nick, lukasza): The notification below should probably be updated to
4653 // include |source|.
avi60bd4902015-09-23 20:39:244654 std::string json = json_string;
4655 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
4656 Source<WebContents>(this),
4657 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:404658}
4659
nicka0ac8382016-12-15 23:59:234660void WebContentsImpl::OnAppCacheAccessed(RenderViewHostImpl* source,
4661 const GURL& manifest_url,
[email protected]b172aee2012-04-10 17:05:264662 bool blocked_by_policy) {
nicka0ac8382016-12-15 23:59:234663 // TODO(nick): Should we consider |source| here? Should we call FilterURL on
4664 // |manifest_url|?
4665
[email protected]7fc4bbb2011-09-08 21:23:104666 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094667 for (auto& observer : observers_)
4668 observer.AppCacheAccessed(manifest_url, blocked_by_policy);
[email protected]7fc4bbb2011-09-08 21:23:104669}
4670
Joel Hockey85b379d2017-12-11 10:42:134671void WebContentsImpl::OnColorChooserFactoryRequest(
Joel Hockey163835a2017-12-20 11:51:574672 blink::mojom::ColorChooserFactoryRequest request) {
Joel Hockey85b379d2017-12-11 10:42:134673 color_chooser_factory_bindings_.AddBinding(this, std::move(request));
4674}
4675
4676void WebContentsImpl::OpenColorChooser(
Joel Hockey163835a2017-12-20 11:51:574677 blink::mojom::ColorChooserRequest chooser_request,
4678 blink::mojom::ColorChooserClientPtr client,
[email protected]8ed16472014-04-11 19:02:484679 SkColor color,
Joel Hockey163835a2017-12-20 11:51:574680 std::vector<blink::mojom::ColorSuggestionPtr> suggestions) {
Joel Hockey85b379d2017-12-11 10:42:134681 content::ColorChooser* new_color_chooser =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:284682 delegate_ ? delegate_->OpenColorChooser(this, color, suggestions)
4683 : nullptr;
[email protected]820957a2014-01-14 14:56:304684 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:214685 return;
[email protected]8ed16472014-04-11 19:02:484686
Joel Hockey85b379d2017-12-11 10:42:134687 color_chooser_.reset();
4688 color_chooser_ = std::make_unique<ColorChooser>(
4689 new_color_chooser, std::move(chooser_request), std::move(client));
[email protected]da8543762012-03-20 08:52:204690}
4691
brettw4b461082016-11-19 18:55:164692#if BUILDFLAG(ENABLE_PLUGINS)
nicka0ac8382016-12-15 23:59:234693void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source,
4694 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094695 for (auto& observer : observers_)
4696 observer.PepperInstanceCreated();
nicka0ac8382016-12-15 23:59:234697 pepper_playback_observer_->PepperInstanceCreated(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004698}
4699
nicka0ac8382016-12-15 23:59:234700void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source,
4701 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094702 for (auto& observer : observers_)
4703 observer.PepperInstanceDeleted();
nicka0ac8382016-12-15 23:59:234704 pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004705}
4706
nicka0ac8382016-12-15 23:59:234707void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source,
4708 int plugin_child_id,
tommyclie6633ca72014-10-31 00:40:424709 const base::FilePath& path,
4710 bool is_hung) {
Steven Holte95922222018-09-14 20:06:234711 UMA_HISTOGRAM_COUNTS_1M("Pepper.PluginHung", 1);
tommyclie6633ca72014-10-31 00:40:424712
ericwilligersde386342016-10-19 02:35:094713 for (auto& observer : observers_)
4714 observer.PluginHungStatusChanged(plugin_child_id, path, is_hung);
tommyclie6633ca72014-10-31 00:40:424715}
4716
nicka0ac8382016-12-15 23:59:234717void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source,
4718 int32_t pp_instance) {
4719 pepper_playback_observer_->PepperStartsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174720}
4721
nicka0ac8382016-12-15 23:59:234722void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source,
4723 int32_t pp_instance) {
4724 pepper_playback_observer_->PepperStopsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174725}
4726
nicka0ac8382016-12-15 23:59:234727void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source,
4728 const base::FilePath& plugin_path,
tommyclie6633ca72014-10-31 00:40:424729 base::ProcessId plugin_pid) {
nicka0ac8382016-12-15 23:59:234730 // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted,
4731 // and is only used by BlinkTestController.
ericwilligersde386342016-10-19 02:35:094732 for (auto& observer : observers_)
4733 observer.PluginCrashed(plugin_path, plugin_pid);
tommyclie6633ca72014-10-31 00:40:424734}
4735
[email protected]d8415ad92012-08-23 14:40:504736void WebContentsImpl::OnRequestPpapiBrokerPermission(
nicka0ac8382016-12-15 23:59:234737 RenderViewHostImpl* source,
4738 int ppb_broker_route_id,
[email protected]d8415ad92012-08-23 14:40:504739 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:344740 const base::FilePath& plugin_path) {
nicka0ac8382016-12-15 23:59:234741 base::Callback<void(bool)> permission_result_callback = base::Bind(
4742 &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this),
4743 source->GetProcess()->GetID(), ppb_broker_route_id);
[email protected]8c8fc292012-11-23 18:57:164744 if (!delegate_) {
Tommy Nyquist4b749d02018-03-20 21:46:294745 std::move(permission_result_callback).Run(false);
[email protected]8c8fc292012-11-23 18:57:164746 return;
[email protected]d8415ad92012-08-23 14:40:504747 }
4748
nicka0ac8382016-12-15 23:59:234749 if (!delegate_->RequestPpapiBrokerPermission(this, url, plugin_path,
4750 permission_result_callback)) {
[email protected]8c8fc292012-11-23 18:57:164751 NOTIMPLEMENTED();
Tommy Nyquist4b749d02018-03-20 21:46:294752 std::move(permission_result_callback).Run(false);
[email protected]8c8fc292012-11-23 18:57:164753 }
[email protected]d8415ad92012-08-23 14:40:504754}
4755
nicka0ac8382016-12-15 23:59:234756void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id,
4757 int ppb_broker_route_id,
4758 bool result) {
4759 RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
4760 if (rph) {
4761 // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it
4762 // is not routed to a RenderView.
4763 rph->Send(
4764 new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result));
4765 }
[email protected]d8415ad92012-08-23 14:40:504766}
4767
fsamuel833ee7c2015-02-13 23:40:404768void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
4769 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:394770 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:144771 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:404772 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:374773}
brettw4b461082016-11-19 18:55:164774#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:374775
[email protected]795c28972012-12-06 06:13:394776void WebContentsImpl::OnUpdateFaviconURL(
lukasza178ff092017-06-07 23:39:504777 RenderFrameHostImpl* source,
[email protected]795c28972012-12-06 06:13:394778 const std::vector<FaviconURL>& candidates) {
lukasza178ff092017-06-07 23:39:504779 // Ignore favicons for non-main frame.
4780 if (source->GetParent()) {
4781 NOTREACHED();
4782 return;
4783 }
4784
pkotwiczf9bc20592015-04-21 18:57:064785 // We get updated favicon URLs after the page stops loading. If a cross-site
4786 // navigation occurs while a page is still loading, the initial page
4787 // may stop loading and send us updated favicon URLs after the navigation
4788 // for the new page has committed.
lukasza178ff092017-06-07 23:39:504789 if (!source->IsCurrent())
pkotwiczf9bc20592015-04-21 18:57:064790 return;
4791
ericwilligersde386342016-10-19 02:35:094792 for (auto& observer : observers_)
4793 observer.DidUpdateFaviconURL(candidates);
[email protected]795c28972012-12-06 06:13:394794}
4795
qinmin72e8bd02016-10-21 19:35:374796void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) {
4797 is_overlay_content_ = is_overlay_content;
4798}
4799
nicka0ac8382016-12-15 23:59:234800void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(RenderViewHostImpl* source) {
4801 // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if
4802 // |source| is the main frame.
ericwilligersde386342016-10-19 02:35:094803 for (auto& observer : observers_)
4804 observer.DidFirstVisuallyNonEmptyPaint();
yusufod41c5f92015-03-06 00:14:284805
peter90afaba2015-06-01 12:05:294806 did_first_visually_non_empty_paint_ = true;
4807
yusufod41c5f92015-03-06 00:14:284808 if (theme_color_ != last_sent_theme_color_) {
4809 // Theme color should have updated by now if there was one.
ericwilligersde386342016-10-19 02:35:094810 for (auto& observer : observers_)
4811 observer.DidChangeThemeColor(theme_color_);
yusufod41c5f92015-03-06 00:14:284812 last_sent_theme_color_ = theme_color_;
4813 }
[email protected]9f268072013-11-07 00:02:154814}
[email protected]d9030b82013-07-19 08:26:064815
Yiming Zhoudd60b0b2018-07-20 18:51:354816void WebContentsImpl::OnCommitAndDrawCompositorFrame(
4817 RenderViewHostImpl* source) {
4818 for (auto& observer : observers_)
4819 observer.DidCommitAndDrawCompositorFrame();
4820}
4821
[email protected]17e286e2013-03-01 23:29:394822void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
ericwilligersde386342016-10-19 02:35:094823 for (auto& observer : observers_)
4824 observer.BeforeFormRepostWarningShow();
[email protected]17e286e2013-03-01 23:29:394825}
4826
[email protected]ec6c05f2013-10-23 18:41:574827void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
4828 Activate();
4829 if (delegate_)
4830 delegate_->ShowRepostFormWarningDialog(this);
4831}
4832
[email protected]b4c84012014-04-28 19:51:104833bool WebContentsImpl::HasAccessedInitialDocument() {
4834 return has_accessed_initial_document_;
4835}
4836
afakhry6f0c1ec22016-07-14 13:55:134837void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:264838 const base::string16& title) {
[email protected]fcf75d42013-12-03 20:11:264839 base::string16 final_title;
Avi Drissman93002212017-09-27 03:20:524840 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:324841
[email protected]987fc3a2011-05-26 14:18:094842 // If a page is created via window.open and never navigated,
4843 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:554844 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:094845 if (entry) {
[email protected]36fc0392011-12-25 03:59:514846 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:134847 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:324848
[email protected]36fc0392011-12-25 03:59:514849 entry->SetTitle(final_title);
Avi Drissman93002212017-09-27 03:20:524850
4851 // The title for display may differ from the title just set; grab it.
4852 final_title = entry->GetTitleForDisplay();
[email protected]987fc3a2011-05-26 14:18:094853 } else {
4854 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:134855 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:094856
4857 page_title_when_no_navigation_entry_ = final_title;
4858 }
[email protected]420ae012009-04-24 05:16:324859
[email protected]420ae012009-04-24 05:16:324860 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:234861 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:324862
ericwilligersde386342016-10-19 02:35:094863 for (auto& observer : observers_)
Avi Drissman93002212017-09-27 03:20:524864 observer.TitleWasSet(entry);
[email protected]66798902013-10-01 18:40:164865
afakhry6f0c1ec22016-07-14 13:55:134866 // Broadcast notifications when the UI should be updated.
4867 if (entry == controller_.GetEntryAtOffset(0))
4868 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:324869}
4870
fdegansa696e5112015-04-17 01:57:594871void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:004872 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:004873 if (delegate_)
fdegansa696e5112015-04-17 01:57:594874 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:004875}
4876
4877void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:344878 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:004879 loading_weak_factory_.InvalidateWeakPtrs();
4880 loading_last_progress_update_ = base::TimeTicks();
4881}
4882
clamy44e84ce2016-02-22 15:38:254883// Notifies the RenderWidgetHost instance about the fact that the page is
4884// loading, or done loading.
4885void WebContentsImpl::LoadingStateChanged(bool to_different_document,
4886 bool due_to_interstitial,
4887 LoadNotificationDetails* details) {
4888 // Do not send notifications about loading changes in the FrameTree while the
4889 // interstitial page is pausing the throbber.
creisadca9862017-06-16 19:12:114890 if (ShowingInterstitialPage() && interstitial_page_->pause_throbber() &&
clamy44e84ce2016-02-22 15:38:254891 !due_to_interstitial) {
4892 return;
4893 }
4894
4895 bool is_loading = IsLoading();
4896
4897 if (!is_loading) {
4898 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
4899 base::string16());
4900 load_state_host_.clear();
4901 upload_size_ = 0;
4902 upload_position_ = 0;
4903 }
4904
4905 GetRenderManager()->SetIsLoading(is_loading);
4906
4907 waiting_for_response_ = is_loading;
4908 is_load_to_different_document_ = to_different_document;
4909
4910 if (delegate_)
4911 delegate_->LoadingStateChanged(this, to_different_document);
4912 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
4913
4914 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
4915 if (is_loading) {
4916 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
4917 this, "URL", url, "Main FrameTreeNode id",
4918 GetFrameTree()->root()->frame_tree_node_id());
ericwilligersde386342016-10-19 02:35:094919 for (auto& observer : observers_)
4920 observer.DidStartLoading();
clamy44e84ce2016-02-22 15:38:254921 } else {
4922 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
4923 this, "URL", url);
ericwilligersde386342016-10-19 02:35:094924 for (auto& observer : observers_)
4925 observer.DidStopLoading();
clamy44e84ce2016-02-22 15:38:254926 }
4927
4928 // TODO(avi): Remove. http://crbug.com/170921
4929 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
4930 NotificationDetails det = NotificationService::NoDetails();
4931 if (details)
4932 det = Details<LoadNotificationDetails>(details);
4933 NotificationService::current()->Notify(
4934 type, Source<NavigationController>(&controller_), det);
4935}
4936
[email protected]02d7b6e2014-06-24 21:01:504937void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
4938 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:324939 // After sending out a swap notification, we need to send a disconnect
4940 // notification so that clients that pick up a pointer to |this| can NULL the
4941 // pointer. See Bug 1230284.
4942 notify_disconnection_ = true;
ericwilligersde386342016-10-19 02:35:094943 for (auto& observer : observers_)
4944 observer.RenderViewHostChanged(old_host, new_host);
[email protected]da7a7182013-09-06 08:11:114945
Jinsuk Kimdc5284c22018-07-11 02:22:064946 view_->RenderViewHostChanged(old_host, new_host);
4947
Lucas Furukawa Gadanif9ea4fc2018-08-03 23:57:134948 // If this is an inner WebContents that has swapped views, we need to reattach
4949 // it to its outer WebContents.
4950 if (node_.outer_web_contents())
4951 ReattachToOuterWebContentsFrame();
4952
[email protected]7a846df2012-09-20 19:17:394953 // Ensure that the associated embedder gets cleared after a RenderViewHost
4954 // gets swapped, so we don't reuse the same embedder next time a
4955 // RenderViewHost is attached to this WebContents.
4956 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:324957}
4958
[email protected]02d7b6e2014-06-24 21:01:504959void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
Jinsuk Kim895b2c52018-07-03 06:49:164960 RenderFrameHost* new_host,
4961 bool is_main_frame) {
Bo Liu168c8642017-08-28 18:26:024962#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:504963 // Copy importance from |old_host| if |new_host| is a main frame.
4964 if (old_host && !new_host->GetParent()) {
Bo Liu7c6779e92017-08-16 02:02:284965 static_cast<RenderFrameHostImpl*>(new_host)
4966 ->GetRenderWidgetHost()
Bo Liu16dd7b8322018-05-02 21:19:504967 ->SetImportance(static_cast<RenderFrameHostImpl*>(old_host)
4968 ->GetRenderWidgetHost()
4969 ->importance());
Bo Liu7c6779e92017-08-16 02:02:284970 }
Bo Liu168c8642017-08-28 18:26:024971#endif
ericwilligersde386342016-10-19 02:35:094972 for (auto& observer : observers_)
4973 observer.RenderFrameHostChanged(old_host, new_host);
[email protected]02d7b6e2014-06-24 21:01:504974}
4975
[email protected]da7a7182013-09-06 08:11:114976// TODO(avi): Remove this entire function because this notification is already
4977// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:264978void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:324979 if (!notify_disconnection_)
4980 return;
4981
4982 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:214983 NotificationService::current()->Notify(
4984 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
4985 Source<WebContents>(this),
4986 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:324987}
4988
[email protected]cbb1ef592013-06-05 19:49:464989void WebContentsImpl::NotifyNavigationEntryCommitted(
4990 const LoadCommittedDetails& load_details) {
ericwilligersde386342016-10-19 02:35:094991 for (auto& observer : observers_)
4992 observer.NavigationEntryCommitted(load_details);
[email protected]cbb1ef592013-06-05 19:49:464993}
4994
Sam McNally5c087a32017-08-25 01:46:144995void WebContentsImpl::NotifyNavigationEntryChanged(
4996 const EntryChangedDetails& change_details) {
4997 for (auto& observer : observers_)
4998 observer.NavigationEntryChanged(change_details);
4999}
5000
5001void WebContentsImpl::NotifyNavigationListPruned(
5002 const PrunedDetails& pruned_details) {
5003 for (auto& observer : observers_)
5004 observer.NavigationListPruned(pruned_details);
5005}
5006
Christian Dullweber1af31e62018-02-22 11:49:485007void WebContentsImpl::NotifyNavigationEntriesDeleted() {
5008 for (auto& observer : observers_)
5009 observer.NavigationEntriesDeleted();
5010}
5011
rockotf62002a2016-09-15 00:08:595012void WebContentsImpl::OnAssociatedInterfaceRequest(
5013 RenderFrameHost* render_frame_host,
5014 const std::string& interface_name,
5015 mojo::ScopedInterfaceEndpointHandle handle) {
5016 auto it = binding_sets_.find(interface_name);
5017 if (it != binding_sets_.end())
5018 it->second->OnRequestForFrame(render_frame_host, std::move(handle));
5019}
5020
Ben Goodger9e24929e2017-07-21 03:13:405021void WebContentsImpl::OnInterfaceRequest(
5022 RenderFrameHost* render_frame_host,
5023 const std::string& interface_name,
5024 mojo::ScopedMessagePipeHandle* interface_pipe) {
Joel Hockey85b379d2017-12-11 10:42:135025 registry_.TryBindInterface(interface_name, interface_pipe);
Ben Goodger9e24929e2017-07-21 03:13:405026 for (auto& observer : observers_) {
5027 observer.OnInterfaceRequestFromFrame(render_frame_host, interface_name,
5028 interface_pipe);
5029 if (!interface_pipe->is_valid())
5030 break;
5031 }
5032}
5033
Nicolas Dossou-gbetebcab2472017-09-09 12:28:405034void WebContentsImpl::OnDidBlockFramebust(const GURL& url) {
5035 if (delegate_)
5036 delegate_->OnDidBlockFramebust(this, url);
5037}
5038
[email protected]c31a84802014-04-03 15:55:495039const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
5040 return GetLastCommittedURL();
5041}
5042
[email protected]b849847b2013-12-10 21:57:585043void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:095044 for (auto& observer : observers_)
5045 observer.RenderFrameCreated(render_frame_host);
dmazzonif8a31042016-12-03 00:52:135046 UpdateAccessibilityModeOnFrame(render_frame_host);
clamy91b7abf2016-03-24 15:17:455047
Becca Hughesd11d6502018-07-31 17:01:285048 if (display_cutout_host_impl_)
5049 display_cutout_host_impl_->RenderFrameCreated(render_frame_host);
5050
clamy91b7abf2016-03-24 15:17:455051 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
5052 return;
5053
5054 NavigationEntry* entry = controller_.GetPendingEntry();
5055 if (entry && entry->IsViewSourceMode()) {
5056 // Put the renderer in view source mode.
5057 render_frame_host->Send(
5058 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
5059 }
[email protected]b849847b2013-12-10 21:57:585060}
5061
5062void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
creis3638897452017-05-09 22:07:505063 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095064 for (auto& observer : observers_)
5065 observer.RenderFrameDeleted(render_frame_host);
creis3638897452017-05-09 22:07:505066 is_notifying_observers_ = false;
zqzhang7b6f4f02016-12-07 22:10:225067#if BUILDFLAG(ENABLE_PLUGINS)
5068 pepper_playback_observer_->RenderFrameDeleted(render_frame_host);
5069#endif
Becca Hughesfd5d8f892018-06-14 18:23:365070
Becca Hughesd11d6502018-07-31 17:01:285071 if (display_cutout_host_impl_)
5072 display_cutout_host_impl_->RenderFrameDeleted(render_frame_host);
5073
Becca Hughesfd5d8f892018-06-14 18:23:365074 // Remove any fullscreen state that the frame has stored.
5075 FullscreenStateChanged(render_frame_host, false /* is_fullscreen */);
[email protected]b849847b2013-12-10 21:57:585076}
5077
[email protected]a09d53ce2014-01-31 00:46:425078void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
5079 const ContextMenuParams& params) {
avie9fd8722017-04-10 16:17:585080 // If a renderer fires off a second command to show a context menu before the
5081 // first context menu is closed, just ignore it. https://crbug.com/707534
ekaramadf6750aa2017-06-06 18:29:425082 if (showing_context_menu_)
avie9fd8722017-04-10 16:17:585083 return;
5084
[email protected]077e704b2014-05-23 19:24:105085 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:425086 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:105087 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:425088 return;
5089
[email protected]077e704b2014-05-23 19:24:105090 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
5091 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:425092}
5093
Avi Drissman4891b852018-09-25 18:12:585094namespace {
5095// Normalizes the line endings: \r\n -> \n, lone \r -> \n.
5096base::string16 NormalizeLineBreaks(const base::string16& source) {
5097 static const base::NoDestructor<base::string16> kReturnNewline(
5098 base::ASCIIToUTF16("\r\n"));
5099 static const base::NoDestructor<base::string16> kReturn(
5100 base::ASCIIToUTF16("\r"));
5101 static const base::NoDestructor<base::string16> kNewline(
5102 base::ASCIIToUTF16("\n"));
5103
5104 std::vector<base::StringPiece16> pieces;
5105
5106 for (const auto& rn_line : base::SplitStringPieceUsingSubstr(
5107 source, *kReturnNewline, base::KEEP_WHITESPACE,
5108 base::SPLIT_WANT_ALL)) {
5109 auto r_lines = base::SplitStringPieceUsingSubstr(
5110 rn_line, *kReturn, base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
5111 std::move(std::begin(r_lines), std::end(r_lines),
5112 std::back_inserter(pieces));
5113 }
5114
5115 return base::JoinString(pieces, *kNewline);
5116}
5117} // namespace
5118
avi777ff452017-02-09 19:04:485119void WebContentsImpl::RunJavaScriptDialog(RenderFrameHost* render_frame_host,
5120 const base::string16& message,
5121 const base::string16& default_prompt,
avi777ff452017-02-09 19:04:485122 JavaScriptDialogType dialog_type,
5123 IPC::Message* reply_msg) {
Avi Drissman2ccbb402018-03-20 21:11:365124 // Ensure that if showing a dialog is the first thing that a page does, that
5125 // the contents of the previous page aren't shown behind it. This is required
5126 // because showing a dialog freezes the renderer, so no frames will be coming
5127 // from it. https://crbug.com/823353
5128 auto* render_widget_host_impl =
5129 static_cast<RenderFrameHostImpl*>(render_frame_host)
5130 ->GetRenderWidgetHost();
5131 if (render_widget_host_impl)
5132 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5133
avi0720b02e2017-06-13 03:22:135134 // Running a dialog causes an exit to webpage-initiated fullscreen.
5135 // http://crbug.com/728276
Avi Drissmand18c51972018-08-15 18:32:095136 ForSecurityDropFullscreen();
avi0720b02e2017-06-13 03:22:135137
Avi Drissmane04d3992017-10-05 15:11:365138 auto callback =
5139 base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
5140 render_frame_host->GetProcess()->GetID(),
5141 render_frame_host->GetRoutingID(), reply_msg);
Pavel Feldman3c1842b2017-08-02 05:00:165142
Pavel Feldman3c1842b2017-08-02 05:00:165143 std::vector<protocol::PageHandler*> page_handlers =
5144 protocol::PageHandler::EnabledForWebContents(this);
5145
Pavel Feldmanfab3cb62017-10-05 01:02:015146 if (delegate_)
5147 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5148
5149 // Suppress JavaScript dialogs when requested. Also suppress messages when
5150 // showing an interstitial as it's shown over the previous page and we don't
5151 // want the hidden page's dialogs to interfere with the interstitial.
5152 bool should_suppress = ShowingInterstitialPage() ||
5153 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055154 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5155 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015156 bool suppress_this_message = should_suppress || !has_handlers;
5157
5158 if (suppress_this_message) {
Avi Drissmane04d3992017-10-05 15:11:365159 std::move(callback).Run(true, false, base::string16());
Pavel Feldman3c1842b2017-08-02 05:00:165160 return;
5161 }
5162
5163 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365164 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165165
5166 is_showing_javascript_dialog_ = true;
5167
Avi Drissman4891b852018-09-25 18:12:585168 base::string16 normalized_message = NormalizeLineBreaks(message);
5169
Pavel Feldman3c1842b2017-08-02 05:00:165170 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365171 handler->DidRunJavaScriptDialog(
Avi Drissman4891b852018-09-25 18:12:585172 render_frame_host->GetLastCommittedURL(), normalized_message,
5173 default_prompt, dialog_type, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365174 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165175 }
5176
5177 if (dialog_manager_) {
[email protected]87de04b02014-04-08 22:14:495178 dialog_manager_->RunJavaScriptDialog(
Avi Drissman4891b852018-09-25 18:12:585179 this, render_frame_host, dialog_type, normalized_message,
5180 default_prompt,
Avi Drissmane04d3992017-10-05 15:11:365181 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false),
5182 &suppress_this_message);
[email protected]87de04b02014-04-08 22:14:495183 }
5184
5185 if (suppress_this_message) {
5186 // If we are suppressing messages, just reply as if the user immediately
5187 // pressed "Cancel", passing true to |dialog_was_suppressed|.
Avi Drissmane04d3992017-10-05 15:11:365188 wrapper->Run(true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:495189 }
[email protected]87de04b02014-04-08 22:14:495190}
5191
5192void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:015193 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:495194 bool is_reload,
5195 IPC::Message* reply_msg) {
Avi Drissman2ccbb402018-03-20 21:11:365196 // Ensure that if showing a dialog is the first thing that a page does, that
5197 // the contents of the previous page aren't shown behind it. This is required
5198 // because showing a dialog freezes the renderer, so no frames will be coming
5199 // from it. https://crbug.com/823353
5200 auto* render_widget_host_impl =
5201 static_cast<RenderFrameHostImpl*>(render_frame_host)
5202 ->GetRenderWidgetHost();
5203 if (render_widget_host_impl)
5204 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5205
avi0720b02e2017-06-13 03:22:135206 // Running a dialog causes an exit to webpage-initiated fullscreen.
5207 // http://crbug.com/728276
Avi Drissmand18c51972018-08-15 18:32:095208 ForSecurityDropFullscreen();
avi0720b02e2017-06-13 03:22:135209
[email protected]39f2f9252014-05-03 00:54:015210 RenderFrameHostImpl* rfhi =
5211 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:495212 if (delegate_)
5213 delegate_->WillRunBeforeUnloadConfirm();
5214
Avi Drissmane04d3992017-10-05 15:11:365215 auto callback =
5216 base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
5217 render_frame_host->GetProcess()->GetID(),
5218 render_frame_host->GetRoutingID(), reply_msg);
Pavel Feldman3c1842b2017-08-02 05:00:165219
Pavel Feldman3c1842b2017-08-02 05:00:165220 std::vector<protocol::PageHandler*> page_handlers =
5221 protocol::PageHandler::EnabledForWebContents(this);
5222
Pavel Feldmanfab3cb62017-10-05 01:02:015223 if (delegate_)
5224 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5225
5226 bool should_suppress = ShowingInterstitialPage() || !rfhi->is_active() ||
5227 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055228 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5229 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015230 if (should_suppress || !has_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365231 std::move(callback).Run(false, true, base::string16());
[email protected]87de04b02014-04-08 22:14:495232 return;
5233 }
5234
5235 is_showing_before_unload_dialog_ = true;
Pavel Feldman3c1842b2017-08-02 05:00:165236
5237 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365238 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165239
5240 GURL frame_url = rfhi->GetLastCommittedURL();
5241 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365242 handler->DidRunBeforeUnloadConfirm(
Pavel Feldman1c587bc52018-04-04 21:16:055243 frame_url, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365244 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165245 }
5246
5247 if (dialog_manager_) {
Avi Drissmane04d3992017-10-05 15:11:365248 dialog_manager_->RunBeforeUnloadDialog(
Avi Drissmanff9ed752017-11-28 21:18:125249 this, render_frame_host, is_reload,
Avi Drissmane04d3992017-10-05 15:11:365250 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165251 }
[email protected]87de04b02014-04-08 22:14:495252}
5253
Kent Tamurac260c9a2018-09-14 09:10:565254void WebContentsImpl::RunFileChooser(
5255 RenderFrameHost* render_frame_host,
5256 const blink::mojom::FileChooserParams& params) {
Avi Drissman3d41e7712018-08-27 21:18:085257 // Any explicit focusing of another window while this WebContents is in
5258 // fullscreen can be used to confuse the user, so drop fullscreen.
5259 ForSecurityDropFullscreen();
5260
naskoada75b22016-06-11 16:09:465261 if (delegate_)
5262 delegate_->RunFileChooser(render_frame_host, params);
5263}
5264
[email protected]a86c0e962013-12-17 17:10:395265WebContents* WebContentsImpl::GetAsWebContents() {
5266 return this;
5267}
5268
mcnee336ea2c2017-05-23 22:50:595269#if !defined(OS_ANDROID)
akabac6bd1212018-06-25 20:10:485270double WebContentsImpl::GetPendingPageZoomLevel() const {
wjmaclean64951902016-04-29 20:59:125271 NavigationEntry* pending_entry = GetController().GetPendingEntry();
5272 if (!pending_entry)
5273 return HostZoomMap::GetZoomLevel(this);
5274
5275 GURL url = pending_entry->GetURL();
5276 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
5277 url.scheme(), net::GetHostOrSpecFromURL(url));
5278}
mcnee336ea2c2017-05-23 22:50:595279#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:125280
qinmin72e8bd02016-10-21 19:35:375281bool WebContentsImpl::HideDownloadUI() const {
5282 return is_overlay_content_;
5283}
5284
mlamouri5cd9ae82017-02-18 11:05:095285bool WebContentsImpl::HasPersistentVideo() const {
5286 return has_persistent_video_;
5287}
5288
Alex Moshchuk27caae82017-09-11 23:11:185289RenderFrameHost* WebContentsImpl::GetPendingMainFrame() {
clamy610c63b32017-12-22 15:05:185290 return GetRenderManager()->speculative_frame_host();
Alex Moshchuk27caae82017-09-11 23:11:185291}
5292
mlamourie52c1b542017-02-23 14:57:505293bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const {
5294 return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo();
5295}
5296
François Beaufortad6c5232018-02-26 11:00:445297bool WebContentsImpl::IsPictureInPictureAllowedForFullscreenVideo() const {
5298 return media_web_contents_observer_
5299 ->IsPictureInPictureAllowedForFullscreenVideo();
5300}
5301
ekaramada110f642016-12-21 19:47:285302bool WebContentsImpl::IsFocusedElementEditable() {
5303 RenderFrameHostImpl* frame = GetFocusedFrame();
5304 return frame && frame->has_focused_editable_element();
5305}
5306
ekaramadf6750aa2017-06-06 18:29:425307bool WebContentsImpl::IsShowingContextMenu() const {
5308 return showing_context_menu_;
5309}
5310
5311void WebContentsImpl::SetShowingContextMenu(bool showing) {
5312 DCHECK_NE(showing_context_menu_, showing);
5313 showing_context_menu_ = showing;
5314
5315 if (auto* view = GetRenderWidgetHostView()) {
5316 // Notify the main frame's RWHV to run the platform-specific code, if any.
5317 static_cast<RenderWidgetHostViewBase*>(view)->SetShowingContextMenu(
5318 showing);
5319 }
5320}
5321
ekaramada110f642016-12-21 19:47:285322void WebContentsImpl::ClearFocusedElement() {
5323 if (auto* frame = GetFocusedFrame())
5324 frame->ClearFocusedElement();
5325}
5326
[email protected]7912e822014-04-16 02:37:035327bool WebContentsImpl::IsNeverVisible() {
5328 if (!delegate_)
5329 return false;
5330 return delegate_->IsNeverVisible(this);
5331}
5332
[email protected]5a3bdf52012-05-24 15:12:575333RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
5334 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:325335}
5336
[email protected]8ff00d72012-10-23 19:12:215337RendererPreferences WebContentsImpl::GetRendererPrefs(
5338 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:465339 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:515340}
5341
[email protected]7a846df2012-09-20 19:17:395342void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:275343 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:395344 browser_plugin_embedder_.reset();
5345}
5346
avallee0206f782016-07-28 18:55:335347WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
lfg601233692017-03-06 22:45:445348 if (GuestMode::IsCrossProcessFrameGuest(this))
5349 return node_.outer_web_contents();
ekaramad1beabecc2016-09-23 20:18:175350
5351 if (browser_plugin_guest_)
5352 return browser_plugin_guest_->embedder_web_contents();
5353
Lucas Furukawa Gadani105de1e812018-05-31 19:38:395354 return node_.outer_web_contents();
avallee0206f782016-07-28 18:55:335355}
5356
5357WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
lfg601233692017-03-06 22:45:445358 return GetOutermostWebContents()->node_.focused_web_contents();
avallee0206f782016-07-28 18:55:335359}
5360
avallee9993fca2016-11-17 06:16:505361bool WebContentsImpl::ContainsOrIsFocusedWebContents() {
5362 for (WebContentsImpl* focused_contents = GetFocusedWebContents();
5363 focused_contents;
5364 focused_contents = focused_contents->GetOuterWebContents()) {
5365 if (focused_contents == this)
5366 return true;
5367 }
5368
5369 return false;
5370}
5371
avallee0206f782016-07-28 18:55:335372WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
5373 WebContentsImpl* root = this;
5374 while (root->GetOuterWebContents())
5375 root = root->GetOuterWebContents();
5376 return root;
5377}
5378
avalleed68cdd12017-06-21 22:07:275379void WebContentsImpl::FocusOuterAttachmentFrameChain() {
5380 WebContentsImpl* outer_contents = GetOuterWebContents();
5381 if (!outer_contents)
5382 return;
5383
5384 FrameTreeNode* outer_node =
5385 FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId());
5386 outer_contents->frame_tree_.SetFocusedFrame(outer_node, nullptr);
5387
5388 // For a browser initiated focus change, let embedding renderer know of the
5389 // change. Otherwise, if the currently focused element is just across a
5390 // process boundary in focus order, it will not be possible to move across
5391 // that boundary. This is because the target element will already be focused
5392 // (that renderer was not notified) and drop the event.
5393 if (GetRenderManager()->GetProxyToOuterDelegate())
5394 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame();
5395
5396 outer_contents->FocusOuterAttachmentFrameChain();
5397}
5398
[email protected]b172aee2012-04-10 17:05:265399void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]86f98a22013-03-20 14:35:005400 if (delegate_)
[email protected]e85165c642014-06-10 14:34:315401 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:085402
[email protected]8ff00d72012-10-23 19:12:215403 NotificationService::current()->Notify(
5404 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
5405 Source<WebContents>(this),
5406 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:325407
[email protected]60780f412013-02-25 16:34:105408 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:265409
ericwilligersde386342016-10-19 02:35:095410 for (auto& observer : observers_)
5411 observer.RenderViewCreated(render_view_host);
Joel Einbinder848001c2017-09-19 21:39:315412 if (delegate_)
5413 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]420ae012009-04-24 05:16:325414}
5415
[email protected]b172aee2012-04-10 17:05:265416void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:525417 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325418 // Don't notify the world, since this came from a renderer in the
5419 // background.
5420 return;
5421 }
5422
dmazzoni62111452017-04-28 23:46:555423 RenderWidgetHostViewBase* rwhv =
5424 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5425 if (rwhv)
5426 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
5427
[email protected]da7a7182013-09-06 08:11:115428 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:115429
[email protected]be1f56ab2011-12-22 06:55:315430 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:235431 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:305432
5433 // Restore the focus to the tab (otherwise the focus will be on the top
5434 // window).
[email protected]484ae5912010-09-29 19:16:145435 if (was_crashed && !FocusLocationBarByDefault() &&
5436 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:065437 view_->Focus();
[email protected]484ae5912010-09-29 19:16:145438 }
[email protected]32ded2212011-11-10 18:51:435439
ericwilligersde386342016-10-19 02:35:095440 for (auto& observer : observers_)
5441 observer.RenderViewReady();
Jinsuk Kim895b2c52018-07-03 06:49:165442
5443 view_->RenderViewReady();
[email protected]420ae012009-04-24 05:16:325444}
5445
[email protected]ec6a7eb2013-04-22 17:34:225446void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
5447 base::TerminationStatus status,
5448 int error_code) {
[email protected]151a63d2011-12-20 22:32:525449 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325450 // The pending page's RenderViewHost is gone.
5451 return;
5452 }
5453
[email protected]2fcdcc32014-03-05 02:14:075454 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
5455 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:155456 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:465457 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:075458
Jennifer Apacibleb4b972a2018-06-07 04:41:025459 // Ensure any video in Picture-in-Picture is exited in the |delegate_| since
5460 // a crashed renderer may not have made a clean exit.
5461 if (HasPictureInPictureVideo())
5462 ExitPictureInPicture();
5463
[email protected]698191dc2014-02-25 01:06:135464 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:175465 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:135466
dalecurtis3d1e1302017-02-20 22:33:255467 audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID());
5468
[email protected]960b0372014-05-19 18:01:005469 // Reset the loading progress. TODO(avi): What does it mean to have a
5470 // "renderer crash" when there is more than one renderer process serving a
5471 // webpage? Once this function is called at a more granular frame level, we
5472 // probably will need to more granularly reset the state here.
5473 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:255474 NotifyDisconnected();
5475 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:005476
ericwilligersde386342016-10-19 02:35:095477 for (auto& observer : observers_)
5478 observer.RenderProcessGone(GetCrashedStatus());
[email protected]420ae012009-04-24 05:16:325479}
5480
[email protected]b172aee2012-04-10 17:05:265481void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
ericwilligersde386342016-10-19 02:35:095482 for (auto& observer : observers_)
5483 observer.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:065484}
5485
sky8b00392d2015-01-10 00:30:285486void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
5487 const GURL& url) {
5488 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
Lukasz Anforowiczfd707142018-02-07 19:46:135489 // If we're in flash fullscreen (i.e. Pepper plugin fullscreen) only update
5490 // the url if it's from the fullscreen renderer.
sky8b00392d2015-01-10 00:30:285491 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:445492 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:285493 return;
5494 }
Lukasz Anforowiczfd707142018-02-07 19:46:135495
5496 // In case of racey updates from multiple RenderViewHosts, the last URL should
5497 // be shown - see also some discussion in https://crbug.com/807776.
5498 if (!url.is_valid() && render_view_host != view_that_set_last_target_url_)
5499 return;
5500 view_that_set_last_target_url_ = url.is_valid() ? render_view_host : nullptr;
5501
[email protected]6934a702011-12-20 00:04:515502 if (delegate_)
avi450ce00e2014-09-24 01:58:525503 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:325504}
5505
Lukasz Anforowiczfd707142018-02-07 19:46:135506void WebContentsImpl::ClearTargetURL() {
5507 view_that_set_last_target_url_ = nullptr;
5508 if (delegate_)
5509 delegate_->UpdateTargetURL(this, GURL());
5510}
5511
[email protected]b172aee2012-04-10 17:05:265512void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:105513#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:295514 // The UI may be in an event-tracking loop, such as between the
5515 // mouse-down and mouse-up in text selection or a button click.
5516 // Defer the close until after tracking is complete, so that we
5517 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:295518 // TODO(shess): This could get more fine-grained. For instance,
5519 // closing a tab in another window while selecting text in the
5520 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:105521 if (view_->IsEventTracking()) {
5522 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:295523 return;
5524 }
[email protected]60780f412013-02-25 16:34:105525#endif
[email protected]07707302009-11-06 00:50:295526
[email protected]420ae012009-04-24 05:16:325527 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:525528 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:515529 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:325530}
5531
Avi Drissman014dec72018-06-07 02:34:015532void WebContentsImpl::RequestSetBounds(const gfx::Rect& new_bounds) {
5533 if (delegate_)
5534 delegate_->SetContentsBounds(this, new_bounds);
[email protected]420ae012009-04-24 05:16:325535}
5536
fdegansa696e5112015-04-17 01:57:595537void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:095538 bool to_different_document) {
Evan Stadec3b26022017-07-14 19:50:245539 LoadingStateChanged(frame_tree_node->IsMainFrame() && to_different_document,
5540 false, nullptr);
dmazzonibf8cec42015-02-08 08:28:085541
5542 // Notify accessibility that the user is navigating away from the
5543 // current document.
5544 //
5545 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:085546 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:595547 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:085548 if (manager)
5549 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:325550}
5551
fdegansc73eec22015-03-19 14:47:545552void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:085553 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:325554
[email protected]9595fd82013-04-19 21:28:495555 // Use the last committed entry rather than the active one, in case a
5556 // pending entry has been created.
5557 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:205558 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:495559
[email protected]420ae012009-04-24 05:16:325560 // An entry may not exist for a stop when loading an initial blank page or
5561 // if an iframe injected by script into a blank page finishes loading.
5562 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:205563 base::TimeDelta elapsed =
5564 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:325565
5566 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:515567 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:325568 elapsed,
5569 &controller_,
5570 controller_.GetCurrentEntryIndex()));
5571 }
5572
clamy44e84ce2016-02-22 15:38:255573 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:325574}
5575
fdegansa696e5112015-04-17 01:57:595576void WebContentsImpl::DidChangeLoadProgress() {
5577 double load_progress = frame_tree_.load_progress();
5578
5579 // The delegate is notified immediately for the first and last updates. Also,
5580 // since the message loop may be pretty busy when a page is loaded, it might
5581 // not execute a posted task in a timely manner so the progress report is sent
5582 // immediately if enough time has passed.
5583 base::TimeDelta min_delay =
5584 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
5585 bool delay_elapsed = loading_last_progress_update_.is_null() ||
5586 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
5587
5588 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
5589 // If there is a pending task to send progress, it is now obsolete.
5590 loading_weak_factory_.InvalidateWeakPtrs();
5591
5592 // Notify the load progress change.
5593 SendChangeLoadProgress();
5594
5595 // Clean-up the states if needed.
5596 if (load_progress == 1.0)
5597 ResetLoadProgressState();
5598 return;
5599 }
5600
5601 if (loading_weak_factory_.HasWeakPtrs())
5602 return;
5603
skyostil95082a62015-06-05 19:53:075604 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
tzike2aca992017-09-05 08:50:545605 FROM_HERE,
5606 base::BindOnce(&WebContentsImpl::SendChangeLoadProgress,
5607 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:595608 min_delay);
5609}
5610
avid6d88b912017-01-13 00:16:005611std::vector<std::unique_ptr<NavigationThrottle>>
5612WebContentsImpl::CreateThrottlesForNavigation(
clamycbf524d42016-09-27 12:48:355613 NavigationHandle* navigation_handle) {
5614 return GetContentClient()->browser()->CreateThrottlesForNavigation(
5615 navigation_handle);
5616}
5617
clamy1e5574e2016-09-29 16:48:445618std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
5619 NavigationHandle* navigation_handle) {
clamy1e5574e2016-09-29 16:48:445620 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
5621}
5622
pdr15f5b5b2017-06-20 00:58:005623void WebContentsImpl::DidCancelLoading() {
5624 controller_.DiscardNonCommittedEntries();
5625
5626 // Update the URL display.
5627 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
5628}
5629
[email protected]59167c22013-06-03 18:07:325630void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:105631 has_accessed_initial_document_ = true;
5632
[email protected]d1371bf8e2014-04-19 03:26:245633 // We may have left a failed browser-initiated navigation in the address bar
5634 // to let the user edit it and try again. Clear it now that content might
5635 // show up underneath it.
5636 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:455637 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:245638
[email protected]59167c22013-06-03 18:07:325639 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:505640 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:325641}
5642
alexmosbe2f4c32015-03-10 02:30:235643void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
5644 const std::string& name) {
ericwilligersde386342016-10-19 02:35:095645 for (auto& observer : observers_)
5646 observer.FrameNameChanged(render_frame_host, name);
alexmosbe2f4c32015-03-10 02:30:235647}
5648
[email protected]39f2f9252014-05-03 00:54:015649void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:295650 RenderFrameHost* render_frame_host) {
falken52a56e32016-12-08 05:02:405651 ShowInsecureLocalhostWarningIfNeeded();
5652
creis97867aa2017-02-17 18:39:455653 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095654 for (auto& observer : observers_)
5655 observer.DocumentOnLoadCompletedInMainFrame();
creis97867aa2017-02-17 18:39:455656 is_notifying_observers_ = false;
[email protected]6578fef2013-10-14 02:35:095657
5658 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:215659 NotificationService::current()->Notify(
5660 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
5661 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:295662 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:085663}
5664
creis8eb8ef22015-11-04 22:51:385665void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
5666 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:385667 // The state update affects the last NavigationEntry associated with the given
5668 // |render_frame_host|. This may not be the last committed NavigationEntry (as
5669 // in the case of an UpdateState from a frame being swapped out). We track
5670 // which entry this is in the RenderFrameHost's nav_entry_id.
5671 RenderFrameHostImpl* rfhi =
5672 static_cast<RenderFrameHostImpl*>(render_frame_host);
5673 NavigationEntryImpl* entry =
5674 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
5675 if (!entry)
5676 return;
5677
5678 FrameNavigationEntry* frame_entry =
5679 entry->GetFrameEntry(rfhi->frame_tree_node());
5680 if (!frame_entry)
5681 return;
5682
creisd06a9422015-11-11 03:08:455683 // The SiteInstance might not match if we do a cross-process navigation with
5684 // replacement (e.g., auto-subframe), in which case the swap out of the old
5685 // RenderFrameHost runs in the background after the old FrameNavigationEntry
5686 // has already been replaced and destroyed.
5687 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
5688 return;
5689
creis8eb8ef22015-11-04 22:51:385690 if (page_state == frame_entry->page_state())
5691 return; // Nothing to update.
5692
creis0cade2e2017-02-28 06:37:475693 DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState.";
nasko34634672016-07-29 18:46:065694
5695 // The document_sequence_number and item_sequence_number recorded in the
5696 // FrameNavigationEntry should not differ from the one coming with the update,
5697 // since it must come from the same document. Do not update it if a difference
5698 // is detected, as this indicates that |frame_entry| is not the correct one.
5699 ExplodedPageState exploded_state;
5700 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
5701 return;
5702
5703 if (exploded_state.top.document_sequence_number !=
5704 frame_entry->document_sequence_number() ||
5705 exploded_state.top.item_sequence_number !=
5706 frame_entry->item_sequence_number()) {
5707 return;
5708 }
5709
nasko04a322f25a2016-09-01 00:00:345710 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:385711 controller_.NotifyEntryChanged(entry);
5712}
5713
[email protected]ef3adfc2014-05-11 00:04:545714void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
[email protected]ef3adfc2014-05-11 00:04:545715 const base::string16& title,
5716 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:545717 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:585718 // For example, it might be from a recently swapped out RFH.
avi1edc8552016-10-13 21:37:165719 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
creisad8c31a2016-05-24 17:07:045720 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
[email protected]ef3adfc2014-05-11 00:04:545721
5722 // We can handle title updates when we don't have an entry in
5723 // UpdateTitleForEntry, but only if the update is from the current RVH.
5724 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:585725 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:545726 return;
5727
5728 // TODO(evan): make use of title_direction.
5729 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:135730 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:545731}
5732
5733void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
5734 const std::string& encoding) {
5735 SetEncoding(encoding);
5736}
5737
[email protected]39f2f9252014-05-03 00:54:015738void WebContentsImpl::DocumentAvailableInMainFrame(
5739 RenderViewHost* render_view_host) {
ericwilligersde386342016-10-19 02:35:095740 for (auto& observer : observers_)
5741 observer.DocumentAvailableInMainFrame();
[email protected]39f2f9252014-05-03 00:54:015742}
naskoc0fceff2015-04-30 15:53:525743
[email protected]e1c3a552012-05-04 20:51:325744void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
5745 // Tell the active RenderViewHost to run unload handlers and close, as long
5746 // as the request came from a RenderViewHost in the same BrowsingInstance.
5747 // In most cases, we receive this from a swapped out RenderViewHost.
5748 // It is possible to receive it from one that has just been swapped in,
5749 // in which case we might as well deliver the message anyway.
5750 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:525751 ClosePage();
[email protected]e1c3a552012-05-04 20:51:325752}
5753
alexmose7da5a12015-04-09 02:22:165754bool WebContentsImpl::ShouldRouteMessageEvent(
5755 RenderFrameHost* target_rfh,
5756 SiteInstance* source_site_instance) const {
5757 // Allow the message if this WebContents is dedicated to a browser plugin
5758 // guest.
[email protected]0eba810b2012-10-18 03:19:365759 // Note: This check means that an embedder could theoretically receive a
5760 // postMessage from anyone (not just its own guests). However, this is
5761 // probably not a risk for apps since other pages won't have references
5762 // to App windows.
alexmose7da5a12015-04-09 02:22:165763 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
5764}
[email protected]f546640b2012-05-15 00:03:495765
alexmos58729042015-06-18 23:20:005766void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:165767 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
5768 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:495769
alexmose7da5a12015-04-09 02:22:165770 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:145771 // If this message is going to outer WebContents from inner WebContents,
5772 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
5773 // already created a RenderFrameProxyHost for that purpose.
5774 if (GetBrowserPluginEmbedder() &&
ekaramad1beabecc2016-09-23 20:18:175775 GuestMode::IsCrossProcessFrameGuest(source_web_contents)) {
lazyboy6ec48b2a2015-06-29 15:18:145776 return;
5777 }
5778
lfg812874d2016-02-09 22:26:135779 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:065780 // We create a RenderFrameProxyHost for the embedder in the guest's render
5781 // process but we intentionally do not expose the embedder's opener chain
5782 // to it.
5783 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
5784 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:495785 } else {
alexmos58729042015-06-18 23:20:005786 RenderFrameHostImpl* source_rfhi =
5787 static_cast<RenderFrameHostImpl*>(source_rfh);
5788 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:395789 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:495790 }
5791 }
[email protected]f546640b2012-05-15 00:03:495792}
5793
Avi Drissmand18c51972018-08-15 18:32:095794void WebContentsImpl::ForSecurityDropFullscreen() {
5795 WebContentsImpl* web_contents = this;
5796 while (web_contents) {
5797 if (web_contents->IsFullscreenForCurrentTab())
5798 web_contents->ExitFullscreen(true);
5799 web_contents = web_contents->GetOuterWebContents();
5800 }
5801}
5802
avallee9993fca2016-11-17 06:16:505803void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
5804 // Only change focus if we are not currently focused.
5805 WebContentsImpl* old_contents = GetFocusedWebContents();
5806 if (old_contents == this)
5807 return;
5808
paulmeyerfeafc2d2017-04-25 21:46:405809 GetOutermostWebContents()->node_.SetFocusedWebContents(this);
5810
Greg Thompsonfb957602017-09-04 10:25:525811 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
paulmeyerfeafc2d2017-04-25 21:46:405812 return;
5813
avallee9993fca2016-11-17 06:16:505814 // Send a page level blur to the old contents so that it displays inactive UI
5815 // and focus this contents to activate it.
5816 if (old_contents)
5817 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
avalleec2ff1ef2017-01-21 00:12:305818
5819 // Make sure the outer web contents knows our frame is focused. Otherwise, the
5820 // outer renderer could have the element before or after the frame element
5821 // focused which would return early without actually advancing focus.
avalleed68cdd12017-06-21 22:07:275822 FocusOuterAttachmentFrameChain();
avalleec2ff1ef2017-01-21 00:12:305823
lfg1453e412017-04-11 00:48:505824 if (ShowingInterstitialPage()) {
creisadca9862017-06-16 19:12:115825 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:505826 ->GetRenderWidgetHost()
5827 ->SetPageFocus(true);
5828 } else {
5829 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
5830 }
avallee9993fca2016-11-17 06:16:505831}
5832
avallee0206f782016-07-28 18:55:335833void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
5834 SiteInstance* source) {
avallee0206f782016-07-28 18:55:335835 frame_tree_.SetFocusedFrame(node, source);
avalleed68cdd12017-06-21 22:07:275836
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:575837 if (auto* inner_contents = node_.GetInnerWebContentsInFrame(node)) {
5838 // |this| is an outer WebContents and |node| represents an inner
5839 // WebContents. Transfer the focus to the inner contents if |this| is
5840 // focused.
5841 if (GetFocusedWebContents() == this)
5842 inner_contents->SetAsFocusedWebContentsIfNecessary();
5843 } else if (node_.OuterContentsFrameTreeNode() &&
5844 node_.OuterContentsFrameTreeNode()
5845 ->current_frame_host()
5846 ->GetSiteInstance() == source) {
5847 // |this| is an inner WebContents, |node| is its main FrameTreeNode and
5848 // the outer WebContents FrameTreeNode is at |source|'s SiteInstance.
5849 // Transfer the focus to the inner WebContents if the outer WebContents is
5850 // focused. This branch is used when an inner WebContents is focused through
5851 // its RenderFrameProxyHost (via FrameHostMsg_FrameFocused IPC, used to
5852 // implement the window.focus() API).
5853 if (GetFocusedWebContents() == GetOuterWebContents())
5854 SetAsFocusedWebContentsIfNecessary();
5855 } else if (!GetOuterWebContents()) {
5856 // This is an outermost WebContents.
5857 SetAsFocusedWebContentsIfNecessary();
5858 } else if (!GuestMode::IsCrossProcessFrameGuest(this) &&
5859 GetOuterWebContents()) {
5860 // TODO(lfg, paulmeyer): Allows BrowserPlugins to set themselves as the
5861 // focused WebContents. This works around a bug in FindRequestManager that
5862 // doesn't support properly traversing BrowserPlugins.
5863 SetAsFocusedWebContentsIfNecessary();
5864 }
avalleed68cdd12017-06-21 22:07:275865}
5866
Avi Drissman36f801f2018-02-01 20:06:045867void WebContentsImpl::DidCallFocus() {
5868 // Any explicit focusing of another window while this WebContents is in
5869 // fullscreen can be used to confuse the user, so drop fullscreen.
Avi Drissmand18c51972018-08-15 18:32:095870 ForSecurityDropFullscreen();
Avi Drissman36f801f2018-02-01 20:06:045871}
5872
avalleed68cdd12017-06-21 22:07:275873RenderFrameHost* WebContentsImpl::GetFocusedFrameIncludingInnerWebContents() {
5874 WebContentsImpl* contents = this;
5875 FrameTreeNode* focused_node = contents->frame_tree_.GetFocusedFrame();
5876
5877 // If there is no focused frame in the outer WebContents, we need to return
5878 // null.
5879 if (!focused_node)
5880 return nullptr;
5881
5882 // If the focused frame is embedding an inner WebContents, we must descend
5883 // into that contents. If the current WebContents does not have a focused
5884 // frame, return the main frame of this contents instead of the focused empty
5885 // frame embedding this contents.
5886 while (true) {
5887 contents = contents->node_.GetInnerWebContentsInFrame(focused_node);
5888 if (!contents)
5889 return focused_node->current_frame_host();
5890
5891 focused_node = contents->frame_tree_.GetFocusedFrame();
5892 if (!focused_node)
5893 return contents->GetMainFrame();
5894 }
avallee0206f782016-07-28 18:55:335895}
5896
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:575897void WebContentsImpl::OnAdvanceFocus(RenderFrameHostImpl* source_rfh) {
5898 // When a RenderFrame needs to advance focus to a RenderFrameProxy (by hitting
5899 // TAB), the RenderFrameProxy sends an IPC to RenderFrameProxyHost. When this
5900 // RenderFrameProxyHost represents an inner WebContents, the outer WebContents
5901 // needs to focus the inner WebContents.
5902 if (GetOuterWebContents() &&
5903 GetOuterWebContents() == source_rfh->delegate()->GetAsWebContents() &&
5904 GetFocusedWebContents() == GetOuterWebContents()) {
5905 SetAsFocusedWebContentsIfNecessary();
5906 }
5907}
5908
ekaramada110f642016-12-21 19:47:285909void WebContentsImpl::OnFocusedElementChangedInFrame(
5910 RenderFrameHostImpl* frame,
5911 const gfx::Rect& bounds_in_root_view) {
5912 RenderWidgetHostViewBase* root_view =
5913 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5914 if (!root_view || !frame->GetView())
5915 return;
5916
5917 // Converting to screen coordinates.
5918 gfx::Point origin = bounds_in_root_view.origin();
5919 origin += root_view->GetViewBounds().OffsetFromOrigin();
5920 gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size());
5921
5922 root_view->FocusedNodeChanged(frame->has_focused_editable_element(),
5923 bounds_in_screen);
5924
5925 FocusedNodeDetails details = {frame->has_focused_editable_element(),
5926 bounds_in_screen};
5927
5928 // TODO(ekaramad): We should replace this with an observer notification
5929 // (https://crbug.com/675975).
5930 NotificationService::current()->Notify(
5931 NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
5932 Source<RenderViewHost>(GetRenderViewHost()),
5933 Details<FocusedNodeDetails>(&details));
5934}
5935
avia90ae4e2016-11-11 20:49:335936bool WebContentsImpl::DidAddMessageToConsole(int32_t level,
5937 const base::string16& message,
5938 int32_t line_no,
5939 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:255940 if (!delegate_)
5941 return false;
avia90ae4e2016-11-11 20:49:335942 return delegate_->DidAddMessageToConsole(this, level, message, line_no,
5943 source_id);
[email protected]a796f202012-05-30 14:14:255944}
5945
Daniel Cheng90196c82018-04-25 21:49:145946void WebContentsImpl::DidReceiveInputEvent(
dominickn9c7ceaa32016-02-27 01:52:535947 RenderWidgetHostImpl* render_widget_host,
5948 const blink::WebInputEvent::Type type) {
Dominick Ng37a15052018-07-17 23:56:355949 if (!IsUserInteractionInputType(type))
Daniel Cheng90196c82018-04-25 21:49:145950 return;
5951
kenrb19221852016-04-29 17:21:405952 // Ignore unless the widget is currently in the frame tree.
5953 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:225954 return;
5955
Daniel Cheng90196c82018-04-25 21:49:145956 if (type != blink::WebInputEvent::kGestureScrollBegin)
5957 last_interactive_input_event_time_ = ui::EventTimeForNow();
dominickn9c7ceaa32016-02-27 01:52:535958
Dominick Ng37a15052018-07-17 23:56:355959 for (auto& observer : observers_)
5960 observer.DidGetUserInteraction(type);
5961
5962 if (IsResourceLoadUserInteractionInputType(type))
5963 SendUserGestureForResourceDispatchHost();
dominickn2dd142dd2015-10-29 05:30:505964}
5965
Avi Drissman738ea192018-08-29 20:24:165966bool WebContentsImpl::ShouldIgnoreInputEvents() {
5967 WebContentsImpl* web_contents = this;
5968 while (web_contents) {
5969 if (web_contents->ignore_input_events_)
5970 return true;
5971 web_contents = web_contents->GetOuterWebContents();
5972 }
5973
5974 return false;
5975}
5976
avallee9993fca2016-11-17 06:16:505977void WebContentsImpl::FocusOwningWebContents(
5978 RenderWidgetHostImpl* render_widget_host) {
5979 // The PDF plugin still runs as a BrowserPlugin and must go through the
5980 // input redirection mechanism. It must not become focused direcly.
5981 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
5982 return;
5983
5984 RenderWidgetHostImpl* focused_widget =
5985 GetFocusedRenderWidgetHost(render_widget_host);
5986
5987 if (focused_widget != render_widget_host &&
avallee8e881592016-11-19 00:39:305988 (!focused_widget ||
5989 focused_widget->delegate() != render_widget_host->delegate())) {
avallee9993fca2016-11-17 06:16:505990 SetAsFocusedWebContentsIfNecessary();
5991 }
5992}
5993
[email protected]b172aee2012-04-10 17:05:265994void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:445995 // Notify observers.
ericwilligersde386342016-10-19 02:35:095996 for (auto& observer : observers_)
5997 observer.DidGetIgnoredUIEvent();
[email protected]fa1cf0b82010-01-15 21:49:445998}
5999
avic3aa8422015-11-09 20:57:226000void WebContentsImpl::RendererUnresponsive(
Lukasz Anforowicz52b93722018-06-20 16:11:396001 RenderWidgetHostImpl* render_widget_host,
6002 base::RepeatingClosure hang_monitor_restarter) {
avic031d392017-03-03 03:09:426003 if (ShouldIgnoreUnresponsiveRenderer())
[email protected]e5fc1632011-08-08 07:51:536004 return;
6005
Lukasz Anforowicz4f0593d2018-09-21 18:33:546006 // Do not report hangs (to task manager, to hang renderer dialog, etc.) for
6007 // invisible tabs (like extension background page, background tabs). See
6008 // https://crbug.com/881812 for rationale and for choosing the visibility
6009 // (rather than process priority) as the signal here.
6010 if (GetVisibility() != Visibility::VISIBLE)
6011 return;
6012
Avi Drissman8920def2018-01-31 19:53:366013 if (!render_widget_host->renderer_initialized())
[email protected]55452902011-06-01 21:57:476014 return;
6015
Lukasz Anforowicz4f0593d2018-09-21 18:33:546016 for (auto& observer : observers_)
6017 observer.OnRendererUnresponsive(render_widget_host->GetProcess());
6018
Dave Tapuskac6146c52017-12-20 22:48:156019 if (delegate_)
Lukasz Anforowicz52b93722018-06-20 16:11:396020 delegate_->RendererUnresponsive(this, render_widget_host,
6021 std::move(hang_monitor_restarter));
[email protected]420ae012009-04-24 05:16:326022}
6023
avic3aa8422015-11-09 20:57:226024void WebContentsImpl::RendererResponsive(
6025 RenderWidgetHostImpl* render_widget_host) {
[email protected]6934a702011-12-20 00:04:516026 if (delegate_)
Avi Drissman1572e8c3c2018-02-02 19:06:366027 delegate_->RendererResponsive(this, render_widget_host);
[email protected]420ae012009-04-24 05:16:326028}
6029
[email protected]b172aee2012-04-10 17:05:266030void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:556031 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:326032 bool* proceed_to_fire_unload) {
ericwilligersde386342016-10-19 02:35:096033 for (auto& observer : observers_)
Chris Hamilton3b3e315d2018-09-19 13:16:216034 observer.BeforeUnloadFired(proceed, proceed_time);
[email protected]6934a702011-12-20 00:04:516035 if (delegate_)
6036 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:096037 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:326038}
6039
[email protected]58d5cfe2013-07-10 02:40:526040void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:546041 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:236042 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:226043 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:546044}
6045
Jianzhou Fengd8720c72018-01-18 03:06:306046void WebContentsImpl::UpdateRenderViewSizeForRenderManager(bool is_main_frame) {
[email protected]8643e6d2012-01-18 20:26:106047 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
Jianzhou Fengd8720c72018-01-18 03:06:306048 gfx::Size size = GetSizeForNewRenderView(is_main_frame);
[email protected]0323ee42010-02-17 22:03:266049 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
6050 // here during container initialization and normal window size will be set
6051 // later. In case of tab duplication this resizing to 0x0 prevents setting
6052 // normal size later so just ignore it.
6053 if (!size.IsEmpty())
6054 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:326055}
6056
[email protected]af905902013-10-01 21:38:516057void WebContentsImpl::CancelModalDialogsForRenderManager() {
6058 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:546059 // deferrer would prevent us from swapping out. We also clear the state
6060 // because this is a cross-process navigation, which means that it's a new
6061 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:176062 //
6063 // Note that we don't bother telling browser_plugin_embedder_ because the
6064 // cross-process navigation will either destroy the browser plugins or not
6065 // require their dialogs to close.
avi5d3b8692016-10-12 22:00:466066 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:536067 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:466068 }
[email protected]af905902013-10-01 21:38:516069}
6070
[email protected]02d7b6e2014-06-24 21:01:506071void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
6072 RenderFrameHost* new_host,
6073 bool is_main_frame) {
6074 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:056075 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:506076 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:086077
[email protected]02d7b6e2014-06-24 21:01:506078 // Make sure the visible RVH reflects the new delegate's preferences.
6079 if (delegate_)
6080 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:396081
dmazzoni62111452017-04-28 23:46:556082 RenderWidgetHostViewBase* rwhv =
6083 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
6084 if (rwhv)
6085 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
[email protected]02d7b6e2014-06-24 21:01:506086 }
6087
Jinsuk Kim895b2c52018-07-03 06:49:166088 NotifyFrameSwapped(old_host, new_host, is_main_frame);
[email protected]3a3d47472010-07-15 21:03:546089}
6090
naskof5940b9f2015-03-02 23:04:056091void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
Jinsuk Kim895b2c52018-07-03 06:49:166092 RenderFrameHost* old_host,
6093 RenderFrameHost* new_host) {
6094 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
6095 new_host->GetRenderViewHost());
naskof5940b9f2015-03-02 23:04:056096}
6097
[email protected]b172aee2012-04-10 17:05:266098NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:196099 return GetController();
[email protected]3a3d47472010-07-15 21:03:546100}
6101
dcheng59716272016-04-09 05:19:086102std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:296103 const GURL& url) {
Dan Beam055fe8f2017-10-04 23:23:366104 return CreateWebUI(url);
[email protected]420ae012009-04-24 05:16:326105}
6106
[email protected]10f417c52011-12-28 21:04:236107NavigationEntry*
[email protected]b172aee2012-04-10 17:05:266108 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:326109 return controller_.GetLastCommittedEntry();
6110}
6111
creisadca9862017-06-16 19:12:116112InterstitialPageImpl* WebContentsImpl::GetInterstitialForRenderManager() {
6113 return interstitial_page_;
6114}
6115
lfgbede6392015-09-11 21:54:066116void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
6117 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:336118 RenderWidgetHostViewBase* rwh_view =
6119 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:526120
[email protected]420ae012009-04-24 05:16:326121 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:446122 if (rwh_view)
Jianzhou Fengd8720c72018-01-18 03:06:306123 rwh_view->SetSize(GetSizeForNewRenderView(true));
lfgbede6392015-09-11 21:54:066124}
6125
6126bool WebContentsImpl::CreateRenderViewForRenderManager(
6127 RenderViewHost* render_view_host,
6128 int opener_frame_routing_id,
6129 int proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066130 const base::UnguessableToken& devtools_frame_token,
lfgbede6392015-09-11 21:54:066131 const FrameReplicationState& replicated_frame_state) {
6132 TRACE_EVENT0("browser,navigation",
6133 "WebContentsImpl::CreateRenderViewForRenderManager");
6134
piman00cf9402017-04-03 17:09:206135 if (proxy_routing_id == MSG_ROUTING_NONE)
lfg9431efd2016-12-14 14:45:266136 CreateRenderWidgetHostViewForRenderManager(render_view_host);
lfg9431efd2016-12-14 14:45:266137
piman00cf9402017-04-03 17:09:206138 if (!static_cast<RenderViewHostImpl*>(render_view_host)
6139 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066140 devtools_frame_token, replicated_frame_state,
6141 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:526142 return false;
[email protected]14392a52012-05-02 20:28:446143 }
[email protected]a4127722011-04-27 23:13:526144
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:146145 if (proxy_routing_id == MSG_ROUTING_NONE && node_.outer_web_contents())
6146 ReattachToOuterWebContentsFrame();
6147
avi2b177592014-12-10 02:08:026148 SetHistoryOffsetAndLengthForView(render_view_host,
6149 controller_.GetLastCommittedEntryIndex(),
6150 controller_.GetEntryCount());
6151
[email protected]a220b5932013-09-21 03:47:446152#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:506153 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
6154 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:446155 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:446156 if (rwh_view) {
6157 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:166158 render_widget_host->SynchronizeVisualProperties();
[email protected]245f7d52011-11-28 15:36:446159 }
[email protected]f8233cc2011-05-31 20:24:506160#endif
6161
[email protected]420ae012009-04-24 05:16:326162 return true;
6163}
6164
[email protected]82307f6b2014-08-07 03:30:126165bool WebContentsImpl::CreateRenderFrameForRenderManager(
6166 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:046167 int proxy_routing_id,
6168 int opener_routing_id,
japhete6adf142014-10-31 00:01:496169 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:046170 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:436171 TRACE_EVENT0("browser,navigation",
6172 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:126173
6174 RenderFrameHostImpl* rfh =
6175 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:046176 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
6177 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:126178 return false;
6179
6180 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
6181 // RenderFrameHost will have to be associated with the appropriate
6182 // RenderWidgetHostView or a new one should be created here.
6183
6184 return true;
6185}
6186
mfomitchev2b8b066a2016-01-28 19:23:156187#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:456188
[email protected]155c7f22013-12-09 17:07:186189base::android::ScopedJavaLocalRef<jobject>
6190WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:406191 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:566192 return GetWebContentsAndroid()->GetJavaObject();
6193}
[email protected]155c7f22013-12-09 17:07:186194
[email protected]0e813a52014-08-13 10:34:566195WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:186196 WebContentsAndroid* web_contents_android =
6197 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
6198 if (!web_contents_android) {
6199 web_contents_android = new WebContentsAndroid(this);
avicb129c02017-05-03 06:49:296200 SetUserData(kWebContentsAndroidKey, base::WrapUnique(web_contents_android));
[email protected]155c7f22013-12-09 17:07:186201 }
[email protected]0e813a52014-08-13 10:34:566202 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:186203}
6204
paulmeyerc0b762b2016-04-13 11:55:176205void WebContentsImpl::ActivateNearestFindResult(float x,
6206 float y) {
6207 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
6208}
6209
6210void WebContentsImpl::RequestFindMatchRects(int current_version) {
6211 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
6212}
6213
[email protected]7d244f12013-08-22 21:41:516214bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:066215 return CreateRenderViewForRenderManager(
6216 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
Pavel Feldman25234722017-10-11 02:49:066217 frame_tree_.root()->devtools_frame_token(),
lfgbede6392015-09-11 21:54:066218 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:516219}
[email protected]fc2b46b2014-05-03 16:33:456220
rockot400ea35b2016-10-15 19:15:326221service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
sammcf5f1b0f2016-09-20 23:05:116222 if (!java_interfaces_) {
rockot400ea35b2016-10-15 19:15:326223 service_manager::mojom::InterfaceProviderPtr provider;
blundelle0a9f1582016-12-20 11:23:326224 BindInterfaceRegistryForWebContents(mojo::MakeRequest(&provider), this);
rockot400ea35b2016-10-15 19:15:326225 java_interfaces_.reset(new service_manager::InterfaceProvider);
sammcf5f1b0f2016-09-20 23:05:116226 java_interfaces_->Bind(std::move(provider));
6227 }
6228 return java_interfaces_.get();
6229}
6230
[email protected]fc2b46b2014-05-03 16:33:456231#elif defined(OS_MACOSX)
6232
[email protected]75f4df72014-07-16 22:39:426233void WebContentsImpl::SetAllowOtherViews(bool allow) {
6234 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:456235}
6236
[email protected]75f4df72014-07-16 22:39:426237bool WebContentsImpl::GetAllowOtherViews() {
6238 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:456239}
6240
Francois Doray6c26f3342018-08-24 17:17:226241#endif
6242
spqchane72c3cb2017-06-30 23:02:106243bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() const {
6244 return did_first_visually_non_empty_paint_;
6245}
6246
pkotwicz75ca8ffd2016-02-16 23:10:196247void WebContentsImpl::OnDidDownloadImage(
Avi Drissmana5a52dd2018-03-27 03:39:026248 ImageDownloadCallback callback,
pkotwicz75ca8ffd2016-02-16 23:10:196249 int id,
6250 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:526251 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:186252 const std::vector<SkBitmap>& images,
6253 const std::vector<gfx::Size>& original_image_sizes) {
Avi Drissmana5a52dd2018-03-27 03:39:026254 std::move(callback).Run(id, http_status_code, image_url, images,
6255 original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:196256}
6257
[email protected]6fba26d2014-04-29 09:38:286258void WebContentsImpl::OnDialogClosed(int render_process_id,
6259 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:266260 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:496261 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:266262 bool success,
[email protected]fcf75d42013-12-03 20:11:266263 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:286264 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
6265 render_frame_id);
[email protected]87de04b02014-04-08 22:14:496266 last_dialog_suppressed_ = dialog_was_suppressed;
6267
[email protected]beb440c2009-11-06 04:08:546268 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:236269 // It is possible for the current RenderFrameHost to have changed in the
6270 // meantime. Do not reset the navigation state in that case.
6271 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:256272 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:236273 controller_.DiscardNonCommittedEntries();
6274 }
[email protected]ec8e8b02013-06-19 04:57:106275
Charles Reis15d60b132017-11-03 17:43:476276 // Update the URL display either way, to avoid showing a stale URL.
6277 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
6278
ericwilligersde386342016-10-19 02:35:096279 for (auto& observer : observers_)
6280 observer.BeforeUnloadDialogCancelled();
[email protected]beb440c2009-11-06 04:08:546281 }
[email protected]87de04b02014-04-08 22:14:496282
[email protected]6fba26d2014-04-29 09:38:286283 if (rfh) {
avi44acfaa82017-05-03 22:55:356284 rfh->JavaScriptDialogClosed(reply_msg, success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:166285
6286 std::vector<protocol::PageHandler*> page_handlers =
6287 protocol::PageHandler::EnabledForWebContents(this);
6288 for (auto* handler : page_handlers)
6289 handler->DidCloseJavaScriptDialog(success, user_input);
6290
[email protected]6fba26d2014-04-29 09:38:286291 } else {
6292 // Don't leak the sync IPC reply if the RFH or process is gone.
6293 delete reply_msg;
6294 }
avi1c51fb62017-02-27 20:43:036295
6296 is_showing_javascript_dialog_ = false;
6297 is_showing_before_unload_dialog_ = false;
[email protected]beb440c2009-11-06 04:08:546298}
6299
[email protected]b172aee2012-04-10 17:05:266300void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:546301 if (encoding == last_reported_encoding_)
6302 return;
6303 last_reported_encoding_ = encoding;
6304
jinsukkim79df88a2017-01-04 06:26:156305 canonical_encoding_ = base::GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:106306}
[email protected]f45d2a72010-03-08 23:28:356307
[email protected]1ac10dca2013-08-20 20:47:046308bool WebContentsImpl::IsHidden() {
Francois Doraye6161152018-03-27 22:05:376309 return !IsBeingCaptured() && visibility_ != Visibility::VISIBLE;
[email protected]1ac10dca2013-08-20 20:47:046310}
6311
rob97250742015-12-10 17:45:156312int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lfg601233692017-03-06 22:45:446313 return node_.outer_contents_frame_tree_node_id();
lazyboy6ec48b2a2015-06-29 15:18:146314}
6315
ekaramadaeb3c5c2016-11-09 03:22:356316RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const {
6317 return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
6318 fullscreen_widget_routing_id_);
6319}
6320
[email protected]b0936d22013-11-28 06:47:366321RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:216322 return frame_tree_.root()->render_manager();
6323}
6324
[email protected]f8497342013-02-05 22:15:026325BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:396326 return browser_plugin_guest_.get();
6327}
6328
[email protected]738f57a2013-06-29 21:06:546329void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
6330 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:146331 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:546332 browser_plugin_guest_.reset(guest);
6333}
6334
[email protected]f8497342013-02-05 22:15:026335BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:396336 return browser_plugin_embedder_.get();
6337}
[email protected]8ff00d72012-10-23 19:12:216338
fsamuel60b42282015-03-10 03:29:146339void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
6340 if (browser_plugin_embedder_)
6341 return;
6342 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
6343}
6344
Jianzhou Fengd8720c72018-01-18 03:06:306345gfx::Size WebContentsImpl::GetSizeForNewRenderView(bool is_main_frame) {
[email protected]dc0fd432013-08-27 15:29:216346 gfx::Size size;
Jianzhou Fengd8720c72018-01-18 03:06:306347 if (is_main_frame)
6348 size = device_emulation_size_;
6349 if (size.IsEmpty() && delegate_)
[email protected]dc0fd432013-08-27 15:29:216350 size = delegate_->GetSizeForNewRenderView(this);
6351 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:456352 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:216353 return size;
6354}
6355
[email protected]ae7eeda2014-07-04 01:53:266356void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:096357 for (auto& observer : observers_)
6358 observer.FrameDeleted(render_frame_host);
[email protected]9b159a52013-10-03 17:24:556359}
6360
[email protected]222f5822014-02-05 23:40:496361void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
6362 if (!delegate_)
6363 return;
6364 const gfx::Size new_size = GetPreferredSize();
6365 if (new_size != old_size)
6366 delegate_->UpdatePreferredSize(this, new_size);
6367}
6368
Dominick Ng37a15052018-07-17 23:56:356369void WebContentsImpl::SendUserGestureForResourceDispatchHost() {
6370 // This is null in unittests. =(
Daniel Cheng90196c82018-04-25 21:49:146371 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
Dominick Ng37a15052018-07-17 23:56:356372
6373 if (rdh)
Daniel Cheng90196c82018-04-25 21:49:146374 rdh->OnUserGesture();
6375}
6376
Dan Beam055fe8f2017-10-04 23:23:366377std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI(const GURL& url) {
Jeremy Roman04f27c372017-10-27 15:20:556378 std::unique_ptr<WebUIImpl> web_ui = std::make_unique<WebUIImpl>(this);
Lei Zhangee3b63ad2018-06-06 23:25:316379 std::unique_ptr<WebUIController> controller(
avie865b1d2016-10-24 19:42:596380 WebUIControllerFactoryRegistry::GetInstance()
Lei Zhangee3b63ad2018-06-06 23:25:316381 ->CreateWebUIControllerForURL(web_ui.get(), url));
dbeama1b926a2015-08-31 23:17:516382 if (controller) {
Jeremy Roman04f27c372017-10-27 15:20:556383 web_ui->AddMessageHandler(std::make_unique<GenericHandler>());
Lei Zhangee3b63ad2018-06-06 23:25:316384 web_ui->SetController(std::move(controller));
dbeama1b926a2015-08-31 23:17:516385 return web_ui;
6386 }
6387
avie865b1d2016-10-24 19:42:596388 return nullptr;
dbeama1b926a2015-08-31 23:17:516389}
6390
paulmeyerfeafc2d2017-04-25 21:46:406391FindRequestManager* WebContentsImpl::GetFindRequestManager() {
6392 for (WebContentsImpl* contents = this; contents;
6393 contents = contents->GetOuterWebContents()) {
6394 if (contents->find_request_manager_)
6395 return contents->find_request_manager_.get();
6396 }
6397
6398 return nullptr;
6399}
6400
paulmeyerc0b762b2016-04-13 11:55:176401FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
paulmeyerfeafc2d2017-04-25 21:46:406402 if (FindRequestManager* manager = GetFindRequestManager())
6403 return manager;
6404
6405 // No existing FindRequestManager found, so one must be created.
6406 find_request_manager_.reset(new FindRequestManager(this));
6407
6408 // Concurrent find sessions must not overlap, so destroy any existing
6409 // FindRequestManagers in any inner WebContentses.
6410 for (WebContentsImpl* contents : GetWebContentsAndAllInner()) {
6411 if (contents == this)
6412 continue;
6413 if (contents->find_request_manager_) {
6414 contents->find_request_manager_->StopFinding(
6415 content::STOP_FIND_ACTION_CLEAR_SELECTION);
6416 contents->find_request_manager_.release();
6417 }
6418 }
paulmeyerc0b762b2016-04-13 11:55:176419
6420 return find_request_manager_.get();
6421}
6422
6423void WebContentsImpl::NotifyFindReply(int request_id,
6424 int number_of_matches,
6425 const gfx::Rect& selection_rect,
6426 int active_match_ordinal,
6427 bool final_update) {
Sebastien Marchandcf97ed52017-07-24 23:50:346428 if (delegate_ && !is_being_destroyed_ &&
Lukasz Anforowicze9ae3722017-09-29 17:37:386429 !GetMainFrame()->GetProcess()->FastShutdownStarted()) {
paulmeyerc0b762b2016-04-13 11:55:176430 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
6431 active_match_ordinal, final_update);
6432 }
6433}
6434
ortuno467e5792016-06-10 04:32:396435void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
6436 // Trying to invalidate the tab state while being destroyed could result in a
6437 // use after free.
6438 if (IsBeingDestroyed()) {
6439 return;
6440 }
6441 // Notify for UI updates if the state changes.
6442 bluetooth_connected_device_count_++;
6443 if (bluetooth_connected_device_count_ == 1) {
6444 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6445 }
6446}
6447
6448void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
6449 // Trying to invalidate the tab state while being destroyed could result in a
6450 // use after free.
6451 if (IsBeingDestroyed()) {
6452 return;
6453 }
6454 // Notify for UI updates if the state changes.
Lukasz Anforowicze9ae3722017-09-29 17:37:386455 DCHECK_NE(bluetooth_connected_device_count_, 0u);
ortuno467e5792016-06-10 04:32:396456 bluetooth_connected_device_count_--;
6457 if (bluetooth_connected_device_count_ == 0) {
6458 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6459 }
6460}
6461
zqzhang8ac49002017-03-16 21:51:356462void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) {
6463 if (has_persistent_video_ == has_persistent_video)
mlamouri5cd9ae82017-02-18 11:05:096464 return;
6465
zqzhang8ac49002017-03-16 21:51:356466 has_persistent_video_ = has_persistent_video;
mlamouri5cd9ae82017-02-18 11:05:096467 NotifyPreferencesChanged();
zqzhang8ac49002017-03-16 21:51:356468 media_web_contents_observer()->RequestPersistentVideo(has_persistent_video);
mlamouri5cd9ae82017-02-18 11:05:096469}
6470
paulmeyerfeafc2d2017-04-25 21:46:406471void WebContentsImpl::BrowserPluginGuestWillDetach() {
6472 WebContentsImpl* outermost = GetOutermostWebContents();
6473 if (this != outermost && ContainsOrIsFocusedWebContents())
6474 outermost->SetAsFocusedWebContentsIfNecessary();
6475}
6476
Mounir Lamouri11e9ef42018-05-22 03:10:166477gfx::Size WebContentsImpl::EnterPictureInPicture(
6478 const viz::SurfaceId& surface_id,
6479 const gfx::Size& natural_size) {
6480 return delegate_ ? delegate_->EnterPictureInPicture(surface_id, natural_size)
6481 : gfx::Size();
6482}
6483
Mounir Lamouri6d759e12018-05-16 20:01:306484void WebContentsImpl::ExitPictureInPicture() {
6485 if (delegate_)
6486 delegate_->ExitPictureInPicture();
6487}
6488
paulmeyerc0b762b2016-04-13 11:55:176489#if defined(OS_ANDROID)
6490void WebContentsImpl::NotifyFindMatchRectsReply(
6491 int version,
6492 const std::vector<gfx::RectF>& rects,
6493 const gfx::RectF& active_rect) {
6494 if (delegate_)
6495 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
6496}
6497#endif
6498
[email protected]34ff1cfc2014-08-20 06:16:056499void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
6500 force_disable_overscroll_content_ = force_disable;
6501 if (view_)
6502 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
6503}
6504
Jianzhou Fengd8720c72018-01-18 03:06:306505bool WebContentsImpl::SetDeviceEmulationSize(const gfx::Size& new_size) {
6506 device_emulation_size_ = new_size;
6507 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
6508
6509 const gfx::Size current_size = rwhv->GetViewBounds().size();
6510 if (view_size_before_emulation_.IsEmpty())
6511 view_size_before_emulation_ = current_size;
6512
6513 if (current_size != new_size)
6514 rwhv->SetSize(new_size);
6515
6516 return current_size != new_size;
6517}
6518
6519void WebContentsImpl::ClearDeviceEmulationSize() {
6520 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
6521 // WebContentsView could get resized during emulation, which also resizes
6522 // RWHV. If it happens, assume user would like to keep using the size after
6523 // emulation.
6524 // TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when
6525 // WebContentsView size changes).
Dmitry Gozmanc63707182018-03-06 00:09:396526 if (!view_size_before_emulation_.IsEmpty() && rwhv &&
6527 rwhv->GetViewBounds().size() == device_emulation_size_) {
Jianzhou Fengd8720c72018-01-18 03:06:306528 rwhv->SetSize(view_size_before_emulation_);
Dmitry Gozmanc63707182018-03-06 00:09:396529 }
Jianzhou Fengd8720c72018-01-18 03:06:306530 device_emulation_size_ = gfx::Size();
6531 view_size_before_emulation_ = gfx::Size();
6532}
6533
Max Morin5bc74f52018-05-09 07:00:216534ForwardingAudioStreamFactory* WebContentsImpl::GetAudioStreamFactory() {
6535 if (!audio_stream_factory_) {
6536 audio_stream_factory_.emplace(
6537 this,
Max Morinddebb972018-09-20 10:04:146538 // BrowserMainLoop::GetInstance() may be null in unit tests.
6539 BrowserMainLoop::GetInstance()
6540 ? static_cast<media::UserInputMonitorBase*>(
6541 BrowserMainLoop::GetInstance()->user_input_monitor())
6542 : nullptr,
Max Morin5bc74f52018-05-09 07:00:216543 content::ServiceManagerConnection::GetForProcess()
6544 ->GetConnector()
6545 ->Clone(),
6546 AudioStreamBrokerFactory::CreateImpl());
6547 }
6548
6549 return &*audio_stream_factory_;
6550}
6551
dalecurtis88c240072015-12-09 02:11:186552void WebContentsImpl::MediaStartedPlaying(
billorr21c005d2016-11-17 03:57:046553 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:186554 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:046555 if (media_info.has_video)
6556 currently_playing_video_count_++;
6557
ericwilligersde386342016-10-19 02:35:096558 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:046559 observer.MediaStartedPlaying(media_info, id);
dalecurtis88c240072015-12-09 02:11:186560}
6561
6562void WebContentsImpl::MediaStoppedPlaying(
billorr21c005d2016-11-17 03:57:046563 const WebContentsObserver::MediaPlayerInfo& media_info,
Becca Hughes220bfc102017-11-14 18:24:076564 const WebContentsObserver::MediaPlayerId& id,
6565 WebContentsObserver::MediaStoppedReason reason) {
billorr21c005d2016-11-17 03:57:046566 if (media_info.has_video)
6567 currently_playing_video_count_--;
6568
ericwilligersde386342016-10-19 02:35:096569 for (auto& observer : observers_)
Becca Hughes220bfc102017-11-14 18:24:076570 observer.MediaStoppedPlaying(media_info, id, reason);
billorr21c005d2016-11-17 03:57:046571}
6572
peconn257951522017-06-09 18:24:596573void WebContentsImpl::MediaResized(
6574 const gfx::Size& size,
6575 const WebContentsObserver::MediaPlayerId& id) {
6576 cached_video_sizes_[id] = size;
6577
6578 for (auto& observer : observers_)
6579 observer.MediaResized(size, id);
6580}
6581
Peter E Conneccb34c22017-09-08 09:37:586582void WebContentsImpl::MediaEffectivelyFullscreenChanged(bool is_fullscreen) {
6583 for (auto& observer : observers_)
6584 observer.MediaEffectivelyFullscreenChanged(is_fullscreen);
6585}
6586
Peter Conn31c726a2017-08-17 11:07:346587base::Optional<gfx::Size> WebContentsImpl::GetFullscreenVideoSize() {
6588 base::Optional<WebContentsObserver::MediaPlayerId> id =
6589 media_web_contents_observer_->GetFullscreenVideoMediaPlayerId();
6590 if (id && cached_video_sizes_.count(id.value()))
6591 return base::Optional<gfx::Size>(cached_video_sizes_[id.value()]);
6592 return base::Optional<gfx::Size>();
peconn257951522017-06-09 18:24:596593}
6594
billorr21c005d2016-11-17 03:57:046595int WebContentsImpl::GetCurrentlyPlayingVideoCount() {
6596 return currently_playing_video_count_;
dalecurtis88c240072015-12-09 02:11:186597}
6598
Raymond Toye413650c2018-08-31 00:12:476599void WebContentsImpl::AudioContextPlaybackStarted(RenderFrameHost* host,
6600 int context_id) {
6601 WebContentsObserver::AudioContextId audio_context_id(host, context_id);
6602 for (auto& observer : observers_)
6603 observer.AudioContextPlaybackStarted(audio_context_id);
6604}
6605
6606void WebContentsImpl::AudioContextPlaybackStopped(RenderFrameHost* host,
6607 int context_id) {
6608 WebContentsObserver::AudioContextId audio_context_id(host, context_id);
6609 for (auto& observer : observers_)
6610 observer.AudioContextPlaybackStopped(audio_context_id);
6611}
6612
Francois Doraye6161152018-03-27 22:05:376613void WebContentsImpl::UpdateWebContentsVisibility(Visibility visibility) {
Francois Doray3f2afbd2018-04-06 19:18:186614 // Occlusion is disabled when |features::kWebContentsOcclusion| is disabled
6615 // (for power and speed impact assessment) or when
6616 // |switches::kDisableBackgroundingOccludedWindowsForTesting| is specified on
6617 // the command line (to avoid flakiness in browser tests).
6618 const bool occlusion_is_disabled =
6619 !base::FeatureList::IsEnabled(features::kWebContentsOcclusion) ||
Francois Doraye6161152018-03-27 22:05:376620 base::CommandLine::ForCurrentProcess()->HasSwitch(
6621 switches::kDisableBackgroundingOccludedWindowsForTesting);
6622 if (occlusion_is_disabled && visibility == Visibility::OCCLUDED)
6623 visibility = Visibility::VISIBLE;
6624
tapted65ff2ea72016-03-01 23:39:006625 if (!did_first_set_visible_) {
Francois Doraye6161152018-03-27 22:05:376626 if (visibility == Visibility::VISIBLE) {
6627 // A WebContents created with CreateParams::initially_hidden = false
6628 // starts with GetVisibility() == Visibility::VISIBLE even though it is
6629 // not really visible. Call WasShown() when it becomes visible for real as
6630 // the page load mechanism and some WebContentsObserver rely on that.
tapted65ff2ea72016-03-01 23:39:006631 WasShown();
Francois Dorayfe4a1772018-02-17 04:17:096632 did_first_set_visible_ = true;
tapted65ff2ea72016-03-01 23:39:006633 }
Francois Doraye6161152018-03-27 22:05:376634
6635 // Trust the initial visibility of the WebContents and do not switch it to
6636 // HIDDEN or OCCLUDED before it becomes VISIBLE for real. Doing so would
6637 // result in destroying resources that would immediately be recreated (e.g.
6638 // UpdateWebContents(HIDDEN) can be called when a WebContents is added to a
6639 // hidden window that is about to be shown).
6640
tapted65ff2ea72016-03-01 23:39:006641 return;
6642 }
Francois Doraye6161152018-03-27 22:05:376643
6644 if (visibility == visibility_)
tapted65ff2ea72016-03-01 23:39:006645 return;
6646
Francois Doraye6161152018-03-27 22:05:376647 if (visibility == Visibility::VISIBLE)
tapted65ff2ea72016-03-01 23:39:006648 WasShown();
Francois Doraye6161152018-03-27 22:05:376649 else if (visibility == Visibility::OCCLUDED)
6650 WasOccluded();
tapted65ff2ea72016-03-01 23:39:006651 else
6652 WasHidden();
6653}
6654
aelias5252baa2016-04-10 01:18:026655void WebContentsImpl::UpdateOverridingUserAgent() {
mlamouri5cd9ae82017-02-18 11:05:096656 NotifyPreferencesChanged();
aelias5252baa2016-04-10 01:18:026657}
6658
avid53461d2016-02-25 17:15:046659void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
6660 JavaScriptDialogManager* dialog_manager) {
6661 dialog_manager_ = dialog_manager;
6662}
6663
rockotf62002a2016-09-15 00:08:596664void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) {
6665 auto it = binding_sets_.find(interface_name);
6666 if (it != binding_sets_.end())
6667 binding_sets_.erase(it);
6668}
6669
nzolghadrd87a308d2016-12-07 15:45:566670bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) {
nzolghadrbbffc6c2017-05-25 17:56:396671 // Here we associate this metric to the main frame URL regardless of what
6672 // caused it.
nzolghadrd87a308d2016-12-07 15:45:566673 sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL(
6674 GetLastCommittedURL()));
nzolghadrd87a308d2016-12-07 15:45:566675 return true;
6676}
6677
ekaramada110f642016-12-21 19:47:286678void WebContentsImpl::FocusedNodeTouched(bool editable) {
6679#if defined(OS_WIN)
ekaramada110f642016-12-21 19:47:286680 RenderWidgetHostView* view = GetRenderWidgetHostView();
6681 if (!view)
6682 return;
Dave Tapuska2315d8f2018-03-06 17:52:556683 view->FocusedNodeTouched(editable);
ekaramada110f642016-12-21 19:47:286684#endif
6685}
6686
falken52a56e32016-12-08 05:02:406687void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() {
6688 bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch(
6689 switches::kAllowInsecureLocalhost);
6690 if (!allow_localhost)
6691 return;
6692
6693 content::NavigationEntry* entry = GetController().GetLastCommittedEntry();
Rob Wuf79b3ba2018-01-14 01:54:316694 if (!entry || !net::IsLocalhost(entry->GetURL()))
falken52a56e32016-12-08 05:02:406695 return;
6696
6697 content::SSLStatus ssl_status = entry->GetSSL();
6698 bool is_cert_error = net::IsCertStatusError(ssl_status.cert_status) &&
6699 !net::IsCertStatusMinorError(ssl_status.cert_status);
6700 if (!is_cert_error)
6701 return;
6702
6703 GetMainFrame()->AddMessageToConsole(
6704 content::CONSOLE_MESSAGE_LEVEL_WARNING,
6705 base::StringPrintf("This site does not have a valid SSL "
6706 "certificate! Without SSL, your site's and "
6707 "visitors' data is vulnerable to theft and "
6708 "tampering. Get a valid SSL certificate before"
6709 " releasing your website to the public."));
6710}
6711
ekaramadf6750aa2017-06-06 18:29:426712bool WebContentsImpl::IsShowingContextMenuOnPage() const {
6713 return showing_context_menu_;
6714}
6715
Min Qina904f3302018-02-13 23:33:346716download::DownloadUrlParameters::RequestHeadersType
6717WebContentsImpl::ParseDownloadHeaders(const std::string& headers) {
6718 download::DownloadUrlParameters::RequestHeadersType request_headers;
Megan Jablonski2f6a4c52017-07-10 23:01:256719 for (const base::StringPiece& key_value : base::SplitStringPiece(
6720 headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
6721 std::vector<std::string> pair = base::SplitString(
6722 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
6723 if (2ul == pair.size())
6724 request_headers.push_back(make_pair(pair[0], pair[1]));
6725 }
6726 return request_headers;
6727}
6728
lukasza6f8ac622017-06-06 03:10:206729void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener,
6730 bool opener_suppressed) {
6731 if (opener) {
6732 FrameTreeNode* new_root = GetFrameTree()->root();
6733
6734 // For the "original opener", track the opener's main frame instead, because
6735 // if the opener is a subframe, the opener tracking could be easily bypassed
6736 // by spawning from a subframe and deleting the subframe.
6737 // https://crbug.com/705316
6738 new_root->SetOriginalOpener(opener->frame_tree()->root());
6739
6740 if (!opener_suppressed) {
6741 new_root->SetOpener(opener);
6742 created_with_opener_ = true;
6743 }
6744 }
6745}
6746
Becca Hughes9f6fd4b82017-06-15 10:01:406747void WebContentsImpl::MediaMutedStatusChanged(
6748 const WebContentsObserver::MediaPlayerId& id,
6749 bool muted) {
6750 for (auto& observer : observers_)
6751 observer.MediaMutedStatusChanged(id, muted);
6752}
6753
EhsanK2075c7e2017-08-21 02:42:396754void WebContentsImpl::SetVisibilityForChildViews(bool visible) {
6755 GetMainFrame()->SetVisibilityForChildViews(visible);
6756}
6757
[email protected]8ff00d72012-10-23 19:12:216758} // namespace content