blob: c1a8e3e9acfa2b1f052bc8dc8115242dc6cfc246 [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"
[email protected]04cbd3d2013-12-04 04:58:2025#include "base/process/process.h"
skyostil95082a62015-06-05 19:53:0726#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5127#include "base/strings/string16.h"
28#include "base/strings/string_number_conversions.h"
29#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0030#include "base/strings/utf_string_conversions.h"
gab30f26df2016-05-11 19:37:5531#include "base/threading/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3732#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4233#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1034#include "build/build_config.h"
Min Qinda0ed2062018-02-23 22:00:5335#include "components/download/public/common/download_stats.h"
nzolghadrd87a308d2016-12-07 15:45:5636#include "components/rappor/public/rappor_utils.h"
rsleevi24f64dc22015-08-07 21:39:2137#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3038#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1839#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3940#include "content/browser/browser_plugin/browser_plugin_embedder.h"
41#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5942#include "content/browser/child_process_security_policy_impl.h"
Pavel Feldman3c1842b2017-08-02 05:00:1643#include "content/browser/devtools/protocol/page_handler.h"
dgozmanf00c4f72016-10-19 17:45:1544#include "content/browser/devtools/render_frame_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4145#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0446#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]aa4f3972012-03-01 18:12:1247#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1648#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1749#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1650#include "content/browser/frame_host/cross_process_frame_connector.h"
ananta4b7467a52016-09-23 01:42:3851#include "content/browser/frame_host/frame_tree_node.h"
[email protected]d4a8ca482013-10-30 21:06:4052#include "content/browser/frame_host/interstitial_page_impl.h"
53#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3354#include "content/browser/frame_host/navigation_handle_impl.h"
Arthur Hemeryc3380172018-01-22 14:00:1755#include "content/browser/frame_host/navigation_request.h"
[email protected]6ea6bdf2013-12-06 13:35:0156#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1857#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0758#include "content/browser/frame_host/render_frame_proxy_host.h"
Kenneth Russell954ed9ce2018-04-12 23:07:0159#include "content/browser/gpu/gpu_data_manager_impl.h"
csharrison2e8c98e2016-08-01 23:56:2560#include "content/browser/loader/loader_io_thread_notifier.h"
[email protected]678c0362012-12-05 08:02:4461#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4062#include "content/browser/manifest/manifest_manager_host.h"
Max Morin5bc74f52018-05-09 07:00:2163#include "content/browser/media/audio_stream_broker.h"
dalecurtisbc6572e12014-09-12 19:22:3064#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5265#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1866#include "content/browser/media/media_web_contents_observer.h"
zqzhang1adf3cb2016-11-01 11:26:4567#include "content/browser/media/session/media_session_impl.h"
tommyclieb25b2a2014-11-03 19:45:0968#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3069#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5070#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3271#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5072#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5973#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4874#include "content/browser/renderer_host/render_widget_host_view_base.h"
Ken Buchanandaef006b2017-08-17 18:32:1575#include "content/browser/renderer_host/render_widget_host_view_child_frame.h"
ekaramadadd882292016-06-08 15:22:5676#include "content/browser/renderer_host/text_input_manager.h"
leon.han552e9de2017-02-09 14:37:3077#include "content/browser/screen_orientation/screen_orientation_provider.h"
[email protected]b6583592012-01-25 19:52:3378#include "content/browser/site_instance_impl.h"
lfgc740d4b22016-04-15 16:45:3379#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1180#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5881#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0382#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5683#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1484#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4285#include "content/common/browser_plugin/browser_plugin_messages.h"
Paul Meyer0c58c3712016-11-17 22:59:5186#include "content/common/drag_messages.h"
[email protected]f114fa42013-12-06 17:06:4487#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1788#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0789#include "content/common/page_messages.h"
nasko34634672016-07-29 18:46:0690#include "content/common/page_state_serialization.h"
rockot5c478a72016-09-28 23:14:1891#include "content/common/render_message_filter.mojom.h"
[email protected]2c5569662011-03-22 20:45:0292#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3693#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1194#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2895#include "content/public/browser/browser_plugin_guest_manager.h"
Gabriel Charette790754c2018-03-16 21:32:5996#include "content/public/browser/browser_thread.h"
[email protected]87f3c082011-10-19 18:07:4497#include "content/public/browser/content_browser_client.h"
[email protected]e582fdd2011-12-20 16:48:1798#include "content/public/browser/download_manager.h"
ekaramada110f642016-12-21 19:47:2899#include "content/public/browser/focused_node_details.h"
ekaramad1beabecc2016-09-23 20:18:17100#include "content/public/browser/guest_mode.h"
[email protected]d9083482012-01-06 00:38:46101#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:15102#include "content/public/browser/javascript_dialog_manager.h"
skyf65d9bb2017-03-24 02:26:39103#include "content/public/browser/keyboard_event_processing_result.h"
[email protected]09d31d52012-03-11 22:30:27104#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:00105#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:37106#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:14107#include "content/public/browser/notification_service.h"
scottmg011d96e32016-06-29 19:15:08108#include "content/public/browser/notification_types.h"
[email protected]95640212014-07-26 18:14:30109#include "content/public/browser/render_widget_host_iterator.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:06110#include "content/public/browser/restore_type.h"
estark5ea80e52015-06-19 18:43:12111#include "content/public/browser/security_style_explanations.h"
falken52a56e32016-12-08 05:02:40112#include "content/public/browser/ssl_status.h"
[email protected]4c3a23582012-08-18 08:54:34113#include "content/public/browser/storage_partition.h"
rockotf62002a2016-09-15 00:08:59114#include "content/public/browser/web_contents_binding_set.h"
[email protected]674bc592011-12-20 23:00:42115#include "content/public/browser/web_contents_delegate.h"
Lei Zhangee3b63ad2018-06-06 23:25:31116#include "content/public/browser/web_ui_controller.h"
[email protected]e091df82011-10-11 18:13:21117#include "content/public/common/bindings_policy.h"
carloskd80262f52015-12-16 14:40:35118#include "content/public/common/browser_side_navigation_policy.h"
alexmosc9e76ec2016-05-16 22:59:37119#include "content/public/common/child_process_host.h"
[email protected]54087fe2011-10-28 22:02:48120#include "content/public/common/content_constants.h"
Francois Doray3f2afbd2018-04-06 19:18:18121#include "content/public/common/content_features.h"
[email protected]64d69de42012-02-06 00:19:54122#include "content/public/common/content_switches.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:06123#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:49124#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20125#include "content/public/common/result_codes.h"
Ke He7319dbe2017-11-09 05:54:44126#include "content/public/common/service_manager_connection.h"
[email protected]f16cc6782013-12-16 23:42:57127#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05128#include "content/public/common/web_preferences.h"
wjmaclean64951902016-04-29 20:59:12129#include "net/base/url_util.h"
[email protected]8bfc8272013-09-09 20:10:53130#include "net/http/http_cache.h"
131#include "net/http/http_transaction_factory.h"
rhalavati0fbaeef32017-06-01 15:56:30132#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]8bfc8272013-09-09 20:10:53133#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34134#include "net/url_request/url_request_context_getter.h"
Scott Violet02e38b92018-03-27 23:42:14135#include "ppapi/buildflags/buildflags.h"
Ke He31d0bb02018-02-24 07:16:24136#include "services/device/public/mojom/constants.mojom.h"
Mounir Lamourifd9dcefa2017-07-06 10:26:55137#include "services/metrics/public/cpp/ukm_recorder.h"
Ke He7319dbe2017-11-09 05:54:44138#include "services/service_manager/public/cpp/connector.h"
rockot734fb662016-10-15 16:41:30139#include "services/service_manager/public/cpp/interface_provider.h"
Becca Hughes6daf5662018-06-27 16:50:54140#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Blink Reformata30d4232018-04-07 15:31:06141#include "third_party/blink/public/common/frame/sandbox_flags.h"
142#include "third_party/blink/public/common/mime_util/mime_util.h"
143#include "third_party/blink/public/platform/web_security_style.h"
halton.huoca2eabd2015-07-06 08:17:40144#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39145#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56146#include "ui/base/layout.h"
Daniel Cheng90196c82018-04-25 21:49:14147#include "ui/events/base_event_utils.h"
chongz4a9751942016-08-17 17:49:39148#include "ui/events/blink/web_input_event_traits.h"
[email protected]66bd5512012-08-01 02:02:52149#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31150
ekaramada110f642016-12-21 19:47:28151#if defined(OS_WIN)
152#include "content/browser/renderer_host/dip_util.h"
153#include "ui/gfx/geometry/dip_util.h"
154#endif
155
[email protected]583418cc2013-01-17 14:01:10156#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40157#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15158#include "content/browser/android/date_time_chooser_android.h"
sammcf5f1b0f2016-09-20 23:05:11159#include "content/browser/android/java_interfaces_impl.h"
dalecurtisc85ed632016-01-13 00:22:46160#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18161#include "content/browser/web_contents/web_contents_android.h"
Ke He31d0bb02018-02-24 07:16:24162#include "services/device/public/mojom/nfc.mojom.h"
mcnee336ea2c2017-05-23 22:50:59163#else // !OS_ANDROID
164#include "content/browser/host_zoom_map_impl.h"
165#include "content/browser/host_zoom_map_observer.h"
mfomitchev2b8b066a2016-01-28 19:23:15166#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10167
brettw4b461082016-11-19 18:55:16168#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17169#include "content/browser/media/session/pepper_playback_observer.h"
Lei Zhangebcc6302018-01-12 19:46:45170#endif
zqzhang181047e62016-07-01 13:37:17171
[email protected]8ff00d72012-10-23 19:12:21172namespace content {
[email protected]420ae012009-04-24 05:16:32173namespace {
174
[email protected]960b0372014-05-19 18:01:00175const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41176const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05177
[email protected]155c7f22013-12-09 17:07:18178#if defined(OS_ANDROID)
rob.buisf06a8bf2017-03-10 18:11:32179const void* const kWebContentsAndroidKey = &kWebContentsAndroidKey;
Lei Zhangebcc6302018-01-12 19:46:45180#endif
[email protected]155c7f22013-12-09 17:07:18181
Avi Drissmana9114822018-03-23 18:25:55182base::LazyInstance<std::vector<
183 WebContentsImpl::FriendWrapper::CreatedCallback>>::DestructorAtExit
184 g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
[email protected]cbb1ef592013-06-05 19:49:46185
[email protected]8bfc8272013-09-09 20:10:53186void NotifyCacheOnIO(
187 scoped_refptr<net::URLRequestContextGetter> request_context,
188 const GURL& url,
189 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58190 net::HttpCache* cache = request_context->GetURLRequestContext()->
191 http_transaction_factory()->GetCache();
192 if (cache)
193 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53194}
195
dcheng57e39e22016-01-21 00:25:38196bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
197 for (FrameTreeNode* node : tree->Nodes()) {
198 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
199 return true;
alexmos4cf2aa32015-07-15 23:40:43200 }
dcheng57e39e22016-01-21 00:25:38201 return false;
[email protected]95640212014-07-26 18:14:30202}
203
kenrb19221852016-04-29 17:21:40204bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) {
205 // This method scans the frame tree rather than checking whether
206 // host->delegate() == this, which allows it to return false when the host
207 // for a frame that is pending or pending deletion.
208 if (!host)
209 return false;
210
211 for (FrameTreeNode* node : tree->Nodes()) {
212 if (node->current_frame_host()->GetRenderWidgetHost() == host)
213 return true;
214 }
215 return false;
216}
217
dmazzonif8a31042016-12-03 00:52:13218void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) {
219 static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode();
[email protected]95640212014-07-26 18:14:30220}
221
dtseng0dd3fa12015-07-22 19:00:52222void ResetAccessibility(RenderFrameHost* rfh) {
223 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
224}
225
paulmeyerfeafc2d2017-04-25 21:46:40226// Helper for GetInnerWebContents().
227bool GetInnerWebContentsHelper(
228 std::vector<WebContentsImpl*>* all_guest_contents,
229 WebContents* guest_contents) {
230 all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents));
231 return false;
232}
233
Ian Clelland5cbaaf82017-11-27 22:00:03234RenderFrameHostImpl* FindOpenerRFH(const WebContents::CreateParams& params) {
235 RenderFrameHostImpl* opener_rfh = nullptr;
alexmose201c7cd2015-06-10 17:14:21236 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
Ian Clelland5cbaaf82017-11-27 22:00:03237 opener_rfh = RenderFrameHostImpl::FromID(params.opener_render_process_id,
238 params.opener_render_frame_id);
alexmose201c7cd2015-06-10 17:14:21239 }
Ian Clelland5cbaaf82017-11-27 22:00:03240 return opener_rfh;
lukasza6f8ac622017-06-06 03:10:20241}
242
Pavel Feldman3c1842b2017-08-02 05:00:16243// Ensures that OnDialogClosed is only called once.
244class CloseDialogCallbackWrapper
245 : public base::RefCountedThreadSafe<CloseDialogCallbackWrapper> {
246 public:
Avi Drissmane04d3992017-10-05 15:11:36247 using CloseCallback =
248 base::OnceCallback<void(bool, bool, const base::string16&)>;
249
250 explicit CloseDialogCallbackWrapper(CloseCallback callback)
251 : callback_(std::move(callback)) {}
Pavel Feldman3c1842b2017-08-02 05:00:16252
253 void Run(bool dialog_was_suppressed,
254 bool success,
255 const base::string16& user_input) {
Avi Drissmane04d3992017-10-05 15:11:36256 if (callback_.is_null())
Pavel Feldman3c1842b2017-08-02 05:00:16257 return;
Avi Drissmane04d3992017-10-05 15:11:36258 std::move(callback_).Run(dialog_was_suppressed, success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:16259 }
260
261 private:
262 friend class base::RefCountedThreadSafe<CloseDialogCallbackWrapper>;
263 ~CloseDialogCallbackWrapper() {}
Avi Drissmane04d3992017-10-05 15:11:36264
265 CloseCallback callback_;
Pavel Feldman3c1842b2017-08-02 05:00:16266};
267
lukasza6f8ac622017-06-06 03:10:20268} // namespace
269
Erik Chenbb8e738e2018-04-28 14:10:43270std::unique_ptr<WebContents> WebContents::Create(
271 const WebContents::CreateParams& params) {
erikchen50735fd2018-05-05 15:08:33272 return WebContentsImpl::CreateWithOpener(params, FindOpenerRFH(params));
[email protected]d1198fd2012-08-13 22:50:19273}
274
erikchenade1fef2018-05-02 22:07:57275std::unique_ptr<WebContents> WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59276 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30277 const SessionStorageNamespaceMap& session_storage_namespace_map) {
erikchenade1fef2018-05-02 22:07:57278 std::unique_ptr<WebContentsImpl> new_contents(
279 new WebContentsImpl(params.browser_context));
Ian Clelland5cbaaf82017-11-27 22:00:03280 RenderFrameHostImpl* opener_rfh = FindOpenerRFH(params);
281 FrameTreeNode* opener = nullptr;
282 if (opener_rfh)
283 opener = opener_rfh->frame_tree_node();
284 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
[email protected]fdac6ade2013-07-20 01:06:30285
286 for (SessionStorageNamespaceMap::const_iterator it =
287 session_storage_namespace_map.begin();
288 it != session_storage_namespace_map.end();
289 ++it) {
290 new_contents->GetController()
291 .SetSessionStorageNamespace(it->first, it->second.get());
292 }
293
Sam McNally69a33772018-06-27 16:54:12294 if (params.guest_delegate) {
295 // This makes |new_contents| act as a guest.
296 // For more info, see comment above class BrowserPluginGuest.
297 BrowserPluginGuest::Create(new_contents.get(), params.guest_delegate);
298 }
299
[email protected]54944cde2012-12-09 09:24:59300 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19301 return new_contents;
[email protected]a81343d232011-12-27 07:39:20302}
[email protected]746d3052012-05-22 15:15:47303
benwells5e7260d2017-03-20 23:36:33304void WebContentsImpl::FriendWrapper::AddCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37305 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46306 g_created_callbacks.Get().push_back(callback);
307}
308
benwells5e7260d2017-03-20 23:36:33309void WebContentsImpl::FriendWrapper::RemoveCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37310 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46311 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
312 if (g_created_callbacks.Get().at(i).Equals(callback)) {
313 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
314 return;
315 }
316 }
317}
318
avidf38c952015-10-27 13:45:13319WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
320 if (!rvh)
321 return nullptr;
[email protected]746d3052012-05-22 15:15:47322 return rvh->GetDelegate()->GetAsWebContents();
323}
324
[email protected]a86c0e962013-12-17 17:10:39325WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13326 if (!rfh)
327 return nullptr;
328 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39329}
330
ananta4b7467a52016-09-23 01:42:38331WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) {
332 FrameTreeNode* frame_tree_node =
333 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
anantab8cfa3b2016-10-14 22:43:19334 if (!frame_tree_node)
335 return nullptr;
jam8c4edd02017-05-06 18:50:33336 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
ananta4b7467a52016-09-23 01:42:38337}
338
leon.han552e9de2017-02-09 14:37:30339void WebContents::SetScreenOrientationDelegate(
340 ScreenOrientationDelegate* delegate) {
341 ScreenOrientationProvider::SetDelegate(delegate);
342}
343
[email protected]7fff43e2013-05-21 20:21:10344// WebContentsImpl::DestructionObserver ----------------------------------------
345
346class WebContentsImpl::DestructionObserver : public WebContentsObserver {
347 public:
348 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
349 : WebContentsObserver(watched_contents),
350 owner_(owner) {
351 }
352
353 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58354 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58355 owner_->OnWebContentsDestroyed(
356 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10357 }
358
359 private:
360 WebContentsImpl* owner_;
361
362 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
363};
364
Joel Hockey85b379d2017-12-11 10:42:13365// WebContentsImpl::ColorChooser ----------------------------------------------
Joel Hockey163835a2017-12-20 11:51:57366class WebContentsImpl::ColorChooser : public blink::mojom::ColorChooser {
Joel Hockey85b379d2017-12-11 10:42:13367 public:
368 ColorChooser(content::ColorChooser* chooser,
Joel Hockey163835a2017-12-20 11:51:57369 blink::mojom::ColorChooserRequest request,
370 blink::mojom::ColorChooserClientPtr client)
Joel Hockey85b379d2017-12-11 10:42:13371 : chooser_(chooser),
372 binding_(this, std::move(request)),
373 client_(std::move(client)) {
374 binding_.set_connection_error_handler(
375 base::BindOnce([](content::ColorChooser* chooser) { chooser->End(); },
376 base::Unretained(chooser)));
377 }
[email protected]8ed16472014-04-11 19:02:48378
Joel Hockey85b379d2017-12-11 10:42:13379 ~ColorChooser() override { chooser_->End(); }
[email protected]8ed16472014-04-11 19:02:48380
Joel Hockey85b379d2017-12-11 10:42:13381 void SetSelectedColor(SkColor color) override {
382 chooser_->SetSelectedColor(color);
383 }
384
385 void DidChooseColorInColorChooser(SkColor color) {
386 client_->DidChooseColor(color);
387 }
388
389 private:
390 // Color chooser that was opened by this tab.
391 std::unique_ptr<content::ColorChooser> chooser_;
392
393 // mojo bindings.
Joel Hockey163835a2017-12-20 11:51:57394 mojo::Binding<blink::mojom::ColorChooser> binding_;
Joel Hockey85b379d2017-12-11 10:42:13395
396 // mojo renderer client.
Joel Hockey163835a2017-12-20 11:51:57397 blink::mojom::ColorChooserClientPtr client_;
Joel Hockey85b379d2017-12-11 10:42:13398};
nicka0ac8382016-12-15 23:59:23399
Becca Hughes6fe54e432018-06-09 04:18:56400// WebContentsImpl::DisplayCutoutHostImpl --------------------------------------
401
402class WebContentsImpl::DisplayCutoutHostImpl
Becca Hughese9e27952018-06-25 17:08:27403 : public blink::mojom::DisplayCutoutHost,
404 public WebContentsObserver {
Becca Hughes6fe54e432018-06-09 04:18:56405 public:
406 explicit DisplayCutoutHostImpl(WebContentsImpl* web_contents)
Becca Hughese9e27952018-06-25 17:08:27407 : WebContentsObserver(web_contents), bindings_(web_contents, this) {}
Becca Hughes6fe54e432018-06-09 04:18:56408
409 // blink::mojom::DisplayCutoutHost
Becca Hughese9e27952018-06-25 17:08:27410 void NotifyViewportFitChanged(blink::mojom::ViewportFit value) override {
Becca Hughes6fe54e432018-06-09 04:18:56411 ViewportFitChangedForFrame(bindings_.GetCurrentTargetFrame(), value);
412 }
413
Becca Hughese9e27952018-06-25 17:08:27414 // Stores the updated viewport fit value for a |frame| and notifies observers
415 // if it has changed.
Becca Hughes6fe54e432018-06-09 04:18:56416 void ViewportFitChangedForFrame(RenderFrameHost* rfh,
417 blink::mojom::ViewportFit value) {
418 if (GetValueOrDefault(rfh) == value)
419 return;
420
421 values_[rfh] = value;
422
Becca Hughes9ef7f452018-06-27 16:57:31423 // If we are the current |RenderFrameHost| frame then notify
424 // WebContentsObservers about the new value.
425 if (current_rfh_ == rfh)
Becca Hughese9e27952018-06-25 17:08:27426 NotifyObservers(value);
427 }
428
429 // WebContentsObserver override.
430 void DidAcquireFullscreen(RenderFrameHost* rfh) override {
Becca Hughes9ef7f452018-06-27 16:57:31431 SetCurrentRenderFrameHost(rfh);
Becca Hughese9e27952018-06-25 17:08:27432 }
433
434 // WebContentsObserver override.
435 void DidToggleFullscreenModeForTab(bool entered_fullscreen,
436 bool will_cause_resize) override {
437 if (!entered_fullscreen)
Becca Hughes9ef7f452018-06-27 16:57:31438 SetCurrentRenderFrameHost(nullptr);
Becca Hughes6fe54e432018-06-09 04:18:56439 }
440
441 // Removes any state built up by a render frame.
Becca Hughes9ef7f452018-06-27 16:57:31442 void RenderFrameDeleted(RenderFrameHost* rfh) override {
443 values_.erase(rfh);
444
445 // If we were the current |RenderFrameHost| then we should clear that.
446 if (current_rfh_ == rfh)
447 SetCurrentRenderFrameHost(nullptr);
448 }
Becca Hughes6fe54e432018-06-09 04:18:56449
Becca Hughes6daf5662018-06-27 16:50:54450 // Updates the safe area insets on the current frame.
451 void SetDisplayCutoutSafeArea(gfx::Insets insets) {
Becca Hughes9ef7f452018-06-27 16:57:31452 insets_ = insets;
453
454 if (current_rfh_)
455 SendSafeAreaToFrame(current_rfh_, insets);
456 }
457
458 private:
459 // Set the current |RenderFrameHost| that should have control over the
460 // viewport fit value and we should set safe area insets on.
461 void SetCurrentRenderFrameHost(RenderFrameHost* rfh) {
462 if (current_rfh_ == rfh)
463 return;
464
465 // If we had a previous frame then we should clear the insets on that frame.
466 if (current_rfh_)
467 SendSafeAreaToFrame(current_rfh_, gfx::Insets());
468
469 // If the new RenderFrameHost is nullptr we should stop here and notify
470 // observers that the new viewport fit is kAuto (the default).
471 current_rfh_ = rfh;
472 if (!rfh) {
473 NotifyObservers(blink::mojom::ViewportFit::kAuto);
474 return;
475 }
476
477 // Send the current safe area to the new frame.
478 SendSafeAreaToFrame(rfh, insets_);
479
480 // Notify the WebContentsObservers that the viewport fit value has changed.
481 NotifyObservers(GetValueOrDefault(rfh));
482 }
483
484 // Send the safe area insets to a |RenderFrameHost|.
485 void SendSafeAreaToFrame(RenderFrameHost* rfh, gfx::Insets insets) {
Becca Hughes6daf5662018-06-27 16:50:54486 blink::AssociatedInterfaceProvider* provider =
Becca Hughes9ef7f452018-06-27 16:57:31487 rfh->GetRemoteAssociatedInterfaces();
Becca Hughes6daf5662018-06-27 16:50:54488 if (!provider)
489 return;
490
491 blink::mojom::DisplayCutoutClientAssociatedPtr client;
492 provider->GetInterface(&client);
493 client->SetSafeArea(blink::mojom::DisplayCutoutSafeArea::New(
494 insets.top(), insets.left(), insets.bottom(), insets.right()));
495 }
496
Becca Hughes9ef7f452018-06-27 16:57:31497 // Notify WebContentsObservers that the viewport fit value has changed.
Becca Hughese9e27952018-06-25 17:08:27498 void NotifyObservers(blink::mojom::ViewportFit value) {
499 for (auto& observer : web_contents_impl()->observers_)
500 observer.ViewportFitChanged(value);
501 }
502
Becca Hughes6fe54e432018-06-09 04:18:56503 // Get the stored viewport fit value for a frame or kAuto if there is no
504 // stored value.
505 blink::mojom::ViewportFit GetValueOrDefault(RenderFrameHost* rfh) const {
506 auto value = values_.find(rfh);
507 if (value != values_.end())
508 return value->second;
509 return blink::mojom::ViewportFit::kAuto;
510 }
511
Becca Hughese9e27952018-06-25 17:08:27512 WebContentsImpl* web_contents_impl() {
513 return static_cast<WebContentsImpl*>(web_contents());
514 }
515
Becca Hughes9ef7f452018-06-27 16:57:31516 // Stores the current safe area insets.
517 gfx::Insets insets_ = gfx::Insets();
518
519 // Stores the current |RenderFrameHost| that has the applied safe area insets
520 // and is controlling the viewport fit value.
521 RenderFrameHost* current_rfh_ = nullptr;
522
Becca Hughes6fe54e432018-06-09 04:18:56523 // Stores a map of RenderFrameHosts and their current viewport fit values.
524 std::map<RenderFrameHost*, blink::mojom::ViewportFit> values_;
525
Becca Hughes6fe54e432018-06-09 04:18:56526 WebContentsFrameBindingSet<blink::mojom::DisplayCutoutHost> bindings_;
527};
528
lazyboy6ec48b2a2015-06-29 15:18:14529// WebContentsImpl::WebContentsTreeNode ----------------------------------------
lfg601233692017-03-06 22:45:44530WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode(
531 WebContentsImpl* current_web_contents)
532 : current_web_contents_(current_web_contents),
533 outer_web_contents_(nullptr),
lazyboy6ec48b2a2015-06-29 15:18:14534 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33535 FrameTreeNode::kFrameTreeNodeInvalidId),
lfg601233692017-03-06 22:45:44536 focused_web_contents_(current_web_contents) {}
lazyboy6ec48b2a2015-06-29 15:18:14537
538WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
lfga3e2bdc2017-03-07 20:44:01539 if (OuterContentsFrameTreeNode())
540 OuterContentsFrameTreeNode()->RemoveObserver(this);
paulmeyerfeafc2d2017-04-25 21:46:40541
542 if (outer_web_contents_)
543 outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_);
lazyboy6ec48b2a2015-06-29 15:18:14544}
545
546void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
547 WebContentsImpl* outer_web_contents,
548 RenderFrameHostImpl* outer_contents_frame) {
lfg601233692017-03-06 22:45:44549 focused_web_contents_ = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:14550 outer_web_contents_ = outer_web_contents;
551 outer_contents_frame_tree_node_id_ =
552 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
553
paulmeyerfeafc2d2017-04-25 21:46:40554 outer_web_contents_->node_.AttachInnerWebContents(current_web_contents_);
lfga3e2bdc2017-03-07 20:44:01555 outer_contents_frame->frame_tree_node()->AddObserver(this);
lfg601233692017-03-06 22:45:44556}
lazyboy6ec48b2a2015-06-29 15:18:14557
paulmeyerfeafc2d2017-04-25 21:46:40558void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents(
559 WebContentsImpl* inner_web_contents) {
560 inner_web_contents_.push_back(inner_web_contents);
561}
562
563void WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents(
564 WebContentsImpl* inner_web_contents) {
565 DCHECK(std::find(inner_web_contents_.begin(), inner_web_contents_.end(),
566 inner_web_contents) != inner_web_contents_.end());
567 inner_web_contents_.erase(
568 std::remove(inner_web_contents_.begin(), inner_web_contents_.end(),
569 inner_web_contents),
570 inner_web_contents_.end());
571}
572
lfga3e2bdc2017-03-07 20:44:01573FrameTreeNode*
574WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const {
575 return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_);
lfg601233692017-03-06 22:45:44576}
577
lfga3e2bdc2017-03-07 20:44:01578void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed(
579 FrameTreeNode* node) {
580 DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id())
581 << "WebContentsTreeNode should only receive notifications for the "
582 "FrameTreeNode in its outer WebContents that hosts it.";
583 delete current_web_contents_; // deletes |this| too.
lazyboy6ec48b2a2015-06-29 15:18:14584}
585
avallee0206f782016-07-28 18:55:33586void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
587 WebContentsImpl* web_contents) {
588 DCHECK(!outer_web_contents())
589 << "Only the outermost WebContents tracks focus.";
590 focused_web_contents_ = web_contents;
591}
592
paulmeyerfeafc2d2017-04-25 21:46:40593WebContentsImpl*
594WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame(
595 const FrameTreeNode* frame) {
596 auto ftn_id = frame->frame_tree_node_id();
597 for (WebContentsImpl* contents : inner_web_contents_) {
598 if (contents->node_.outer_contents_frame_tree_node_id() == ftn_id) {
599 return contents;
600 }
601 }
602 return nullptr;
603}
604
605const std::vector<WebContentsImpl*>&
606WebContentsImpl::WebContentsTreeNode::inner_web_contents() const {
607 return inner_web_contents_;
608}
609
[email protected]b172aee2012-04-10 17:05:26610// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32611
alexmose201c7cd2015-06-10 17:14:21612WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28613 : delegate_(nullptr),
[email protected]69e797f2013-04-30 01:10:22614 controller_(this, browser_context),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28615 render_view_host_delegate_view_(nullptr),
alexmose201c7cd2015-06-10 17:14:21616 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01617 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57618 this,
619 this,
620 this,
621 this),
lfg601233692017-03-06 22:45:44622 node_(this),
[email protected]6dfed692014-05-22 04:18:03623 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23624 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
625 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34626 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26627 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56628 upload_size_(0),
629 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16630 is_resume_pending_(false),
creisadca9862017-06-16 19:12:11631 interstitial_page_(nullptr),
[email protected]b4c84012014-04-28 19:51:10632 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28633 theme_color_(SK_ColorTRANSPARENT),
634 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29635 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55636 capturer_count_(0),
[email protected]fdd61c62009-04-22 19:22:57637 is_being_destroyed_(false),
creis97867aa2017-02-17 18:39:45638 is_notifying_observers_(false),
[email protected]fdd61c62009-04-22 19:22:57639 notify_disconnection_(false),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28640 dialog_manager_(nullptr),
[email protected]7ab1e7d62009-10-14 23:32:01641 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39642 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38643 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21644 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
645 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22646 zoom_scroll_remainder_(0),
alexmosc9e76ec2016-05-16 22:59:37647 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42648 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03649 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]34ff1cfc2014-08-20 06:16:05650 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30651 last_dialog_suppressed_(false),
waffles1c12bf402016-02-10 17:45:48652 accessibility_mode_(
653 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15654 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35655 bluetooth_connected_device_count_(0),
Guido Urdanetaf4008002018-05-03 10:43:04656 media_device_group_id_salt_base_(
657 BrowserContext::CreateRandomMediaDeviceIDSalt()),
mcnee336ea2c2017-05-23 22:50:59658#if !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:46659 page_scale_factor_is_one_(true),
mcnee336ea2c2017-05-23 22:50:59660#endif // !defined(OS_ANDROID)
qinmin72e8bd02016-10-21 19:35:37661 is_overlay_content_(false),
ekaramadf6750aa2017-06-06 18:29:42662 showing_context_menu_(false),
pkotwicz75ca8ffd2016-02-16 23:10:19663 loading_weak_factory_(this),
664 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55665 frame_tree_.SetFrameRemoveListener(
666 base::Bind(&WebContentsImpl::OnFrameRemoved,
667 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46668#if defined(OS_ANDROID)
669 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
670#else
qinmin58567c82015-01-07 21:00:20671 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46672#endif
brettw4b461082016-11-19 18:55:16673#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17674 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
675#endif
blundelle75a8f92017-03-27 08:11:17676
csharrisona2280cd2016-02-03 23:21:15677 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
mcnee336ea2c2017-05-23 22:50:59678#if !defined(OS_ANDROID)
scottmg276753cf2016-10-27 18:25:22679 host_zoom_map_observer_.reset(new HostZoomMapObserver(this));
mcnee336ea2c2017-05-23 22:50:59680#endif // !defined(OS_ANDROID)
Joel Hockey85b379d2017-12-11 10:42:13681
Becca Hughes86334622018-07-09 21:29:38682#if defined(OS_ANDROID)
683 if (base::FeatureList::IsEnabled(features::kDisplayCutoutAPI))
684 display_cutout_host_impl_ = std::make_unique<DisplayCutoutHostImpl>(this);
685#endif
Becca Hughes6fe54e432018-06-09 04:18:56686
Joel Hockey85b379d2017-12-11 10:42:13687 registry_.AddInterface(base::BindRepeating(
688 &WebContentsImpl::OnColorChooserFactoryRequest, base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35689}
initial.commit09911bf2008-07-26 23:55:29690
[email protected]b172aee2012-04-10 17:05:26691WebContentsImpl::~WebContentsImpl() {
creisba91ba82017-05-12 22:56:19692 // Imperfect sanity check against double free, given some crashes unexpectedly
693 // observed in the wild.
694 CHECK(!is_being_destroyed_);
695
696 // We generally keep track of is_being_destroyed_ to let other features know
697 // to avoid certain actions during destruction.
[email protected]420ae012009-04-24 05:16:32698 is_being_destroyed_ = true;
699
creis97867aa2017-02-17 18:39:45700 // A WebContents should never be deleted while it is notifying observers,
creisba91ba82017-05-12 22:56:19701 // since this will lead to a use-after-free as it continues to notify later
creis97867aa2017-02-17 18:39:45702 // observers.
703 CHECK(!is_notifying_observers_);
704
kenrb2a565f82015-09-02 20:24:59705 rwh_input_event_router_.reset();
706
rockotf62002a2016-09-15 00:08:59707 for (auto& entry : binding_sets_)
708 entry.second->CloseAllBindings();
709
avallee0206f782016-07-28 18:55:33710 WebContentsImpl* outermost = GetOutermostWebContents();
avallee9993fca2016-11-17 06:16:50711 if (this != outermost && ContainsOrIsFocusedWebContents()) {
avallee0206f782016-07-28 18:55:33712 // If the current WebContents is in focus, unset it.
avallee9993fca2016-11-17 06:16:50713 outermost->SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:33714 }
715
Nick Carterd73635b2018-03-13 18:31:41716 if (mouse_lock_widget_)
717 mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary();
718
dcheng72be33c2016-01-21 04:11:31719 for (FrameTreeNode* node : frame_tree_.Nodes()) {
720 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
721 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38722 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38723 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31724 }
carlosk35f35af2015-12-01 10:55:40725
dcheng57e39e22016-01-21 00:25:38726 for (RenderWidgetHostImpl* widget : created_widgets_)
727 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26728 created_widgets_.clear();
729
[email protected]3ab9cb82011-06-03 18:02:07730 // Clear out any JavaScript state.
avi5d3b8692016-10-12 22:00:46731 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:53732 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:46733 }
[email protected]3ab9cb82011-06-03 18:02:07734
Joel Hockey85b379d2017-12-11 10:42:13735 color_chooser_.reset();
[email protected]da8543762012-03-20 08:52:20736
[email protected]420ae012009-04-24 05:16:32737 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32738
[email protected]ca13a442012-04-17 14:00:12739 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21740 NotificationService::current()->Notify(
741 NOTIFICATION_WEB_CONTENTS_DESTROYED,
742 Source<WebContents>(this),
743 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32744
[email protected]df0c843f2014-05-23 20:37:23745 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14746 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23747 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59748
clamy0e119882015-07-31 16:12:33749 // Manually call the observer methods for the root frame tree node. It is
750 // necessary to manually delete all objects tracking navigations
751 // (NavigationHandle, NavigationRequest) for observers to be properly
752 // notified of these navigations stopping before the WebContents is
753 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23754 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56755
naskob21fe4872015-02-24 14:15:56756 root->current_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28757 root->current_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33758
Arthur Hemeryc3380172018-01-22 14:00:17759 // Do not update state as the WebContents is being destroyed.
760 frame_tree_.root()->ResetNavigationRequest(true, true);
761 if (root->speculative_frame_host()) {
762 root->speculative_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28763 root->speculative_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33764 }
[email protected]f273ee52013-10-18 16:05:27765
brettw4b461082016-11-19 18:55:16766#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17767 // Call this before WebContentsDestroyed() is broadcasted since
768 // AudioFocusManager will be destroyed after that.
769 pepper_playback_observer_.reset();
770#endif // defined(ENABLED_PLUGINS)
771
Chris Hamiltondf0d72cd2018-05-29 16:23:53772 // If audio is playing then notify external observers of the audio stream
773 // disappearing.
774 if (is_currently_audible_) {
775 is_currently_audible_ = false;
776 for (auto& observer : observers_)
777 observer.OnAudioStateChanged(false);
778
779 if (GetOuterWebContents())
780 GetOuterWebContents()->OnAudioStateChanged();
781 }
782
ericwilligersde386342016-10-19 02:35:09783 for (auto& observer : observers_)
784 observer.FrameDeleted(root->current_frame_host());
naskoa83483fb2015-02-27 16:57:10785
ericwilligersde386342016-10-19 02:35:09786 for (auto& observer : observers_)
787 observer.RenderViewDeleted(root->current_host());
[email protected]f273ee52013-10-18 16:05:27788
ericwilligersde386342016-10-19 02:35:09789 for (auto& observer : observers_)
790 observer.WebContentsDestroyed();
[email protected]12a46832014-05-09 13:35:58791
ericwilligersde386342016-10-19 02:35:09792 for (auto& observer : observers_)
793 observer.ResetWebContents();
[email protected]232a5812011-03-04 22:42:08794
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28795 SetDelegate(nullptr);
[email protected]b5a1d11c2011-02-17 03:09:42796}
797
erikchen50735fd2018-05-05 15:08:33798std::unique_ptr<WebContentsImpl> WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59799 const WebContents::CreateParams& params,
Ian Clelland5cbaaf82017-11-27 22:00:03800 RenderFrameHostImpl* opener_rfh) {
[email protected]e11f0e92013-06-12 15:12:03801 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
Ian Clelland5cbaaf82017-11-27 22:00:03802 FrameTreeNode* opener = nullptr;
803 if (opener_rfh)
804 opener = opener_rfh->frame_tree_node();
erikchen50735fd2018-05-05 15:08:33805 std::unique_ptr<WebContentsImpl> new_contents(
806 new WebContentsImpl(params.browser_context));
lukasza6f8ac622017-06-06 03:10:20807 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
alexmose201c7cd2015-06-10 17:14:21808
alexmosaedfc6f2016-01-21 23:57:38809 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
810 // flags, and these flags take effect immediately. An exception is if the
811 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
812 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
813 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
lukasza6f8ac622017-06-06 03:10:20814 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
alexmosaedfc6f2016-01-21 23:57:38815 if (opener) {
Ian Clelland5cbaaf82017-11-27 22:00:03816 blink::WebSandboxFlags opener_flags = opener_rfh->active_sandbox_flags();
alexmosaedfc6f2016-01-21 23:57:38817 const blink::WebSandboxFlags inherit_flag =
Blink Reformat1c4d759e2017-04-09 16:34:54818 blink::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts;
alexmosaedfc6f2016-01-21 23:57:38819 if ((opener_flags & inherit_flag) == inherit_flag) {
Ian Clellandcdc4f312017-10-13 22:24:12820 // TODO(iclelland): Transfer correct container policy from opener as well.
821 // https://crbug.com/774620
822 new_root->SetPendingFramePolicy({opener_flags, {}});
alexmosaedfc6f2016-01-21 23:57:38823 }
824 }
825
mark a. foltzef394fce2017-10-21 09:11:02826 // Apply starting sandbox flags.
Luna Luc3fdacdf2017-11-08 04:48:53827 blink::FramePolicy frame_policy(new_root->pending_frame_policy());
mark a. foltzef394fce2017-10-21 09:11:02828 frame_policy.sandbox_flags |= params.starting_sandbox_flags;
829 new_root->SetPendingFramePolicy(frame_policy);
830 new_root->CommitPendingFramePolicy();
831
alexmose201c7cd2015-06-10 17:14:21832 // This may be true even when opener is null, such as when opening blocked
833 // popups.
alexmos090fae8e2015-05-28 17:09:28834 if (params.created_with_opener)
835 new_contents->created_with_opener_ = true;
836
[email protected]4858e432014-06-23 18:14:17837 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06838 // This makes |new_contents| act as a guest.
839 // For more info, see comment above class BrowserPluginGuest.
erikchen50735fd2018-05-05 15:08:33840 BrowserPluginGuest::Create(new_contents.get(), params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06841 }
mark a. foltzef394fce2017-10-21 09:11:02842
[email protected]54944cde2012-12-09 09:24:59843 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19844 return new_contents;
845}
846
[email protected]95640212014-07-26 18:14:30847// static
848std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
849 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08850 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30851 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30852 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30853 RenderViewHost* rvh = RenderViewHost::From(rwh);
854 if (!rvh)
855 continue;
856 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
857 if (!web_contents)
858 continue;
avidf38c952015-10-27 13:45:13859 if (web_contents->GetRenderViewHost() != rvh)
860 continue;
861 // Because a WebContents can only have one current RVH at a time, there will
862 // be no duplicate WebContents here.
863 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30864 }
865 return result;
866}
867
clamya16aa8172015-05-26 13:07:25868// static
869WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
paulmeyerfeafc2d2017-04-25 21:46:40870 const FrameTreeNode* frame_tree_node) {
clamya16aa8172015-05-26 13:07:25871 return static_cast<WebContentsImpl*>(
872 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
873}
874
clamy0d32d6d2015-11-24 11:16:26875// static
876WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
877 int render_frame_host_id) {
878 DCHECK_CURRENTLY_ON(BrowserThread::UI);
879 RenderFrameHost* render_frame_host =
880 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
881 if (!render_frame_host)
882 return nullptr;
883
884 return WebContents::FromRenderFrameHost(render_frame_host);
885}
886
paulmeyerfeafc2d2017-04-25 21:46:40887// static
888WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode(
889 const FrameTreeNode* frame_tree_node) {
890 return WebContentsImpl::FromFrameTreeNode(frame_tree_node)
891 ->node_.GetInnerWebContentsInFrame(frame_tree_node);
892}
893
[email protected]b0936d22013-11-28 06:47:36894RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21895 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28896}
897
nicka0ac8382016-12-15 23:59:23898bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host,
[email protected]7bb761892012-07-20 09:32:47899 const IPC::Message& message) {
nicka0ac8382016-12-15 23:59:23900 for (auto& observer : observers_) {
Lukasz Anforowicz89f2c1b2017-08-30 21:36:46901 // TODO(nick, creis): https://crbug.com/758026: Replace all uses of this
902 // variant of OnMessageReceived with the version that takes a
903 // RenderFrameHost, and then delete it.
nicka0ac8382016-12-15 23:59:23904 if (observer.OnMessageReceived(message))
905 return true;
[email protected]64ffefa2014-05-10 12:06:33906 }
[email protected]403415a2011-01-10 18:57:53907
[email protected]724159a2010-12-30 01:11:18908 bool handled = true;
nicka0ac8382016-12-15 23:59:23909 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host)
910 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
911 OnFirstVisuallyNonEmptyPaint)
912 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
913 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
914 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
915 OnPageScaleFactorChanged)
916 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
917 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
nicka0ac8382016-12-15 23:59:23918#if BUILDFLAG(ENABLE_PLUGINS)
919 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
920 OnRequestPpapiBrokerPermission)
921#endif
nicka0ac8382016-12-15 23:59:23922#if defined(OS_ANDROID)
923 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, OnOpenDateTimeDialog)
924#endif
925 IPC_MESSAGE_UNHANDLED(handled = false)
926 IPC_END_MESSAGE_MAP()
927
928 return handled;
929}
930
931bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host,
932 const IPC::Message& message) {
Lukasz Anforowicz02923102017-10-09 18:11:37933 {
934 WebUIImpl* web_ui = render_frame_host->web_ui();
935 if (web_ui && web_ui->OnMessageReceived(message, render_frame_host))
936 return true;
937 }
938
nicka0ac8382016-12-15 23:59:23939 for (auto& observer : observers_) {
940 if (observer.OnMessageReceived(message, render_frame_host))
941 return true;
942 }
943
944 bool handled = true;
945 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host)
[email protected]cfa856d62014-02-22 07:58:40946 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
947 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05948 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
949 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48950 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
951 OnDocumentLoadedInFrame)
952 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
avi7830c852015-08-31 23:46:25953 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18954 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54955 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18956 OnDidDisplayInsecureContent)
elawrenceb2ac2a232017-03-27 21:46:25957 IPC_MESSAGE_HANDLER(FrameHostMsg_DidContainInsecureFormAction,
958 OnDidContainInsecureFormAction)
avi3a3332622015-09-01 01:18:54959 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18960 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41961 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
962 OnDidDisplayContentWithCertificateErrors)
963 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
964 OnDidRunContentWithCertificateErrors)
avia23e16b2015-07-09 14:18:48965 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
966 OnRegisterProtocolHandler)
967 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
968 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01969 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
970 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52971 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
lukasza178ff092017-06-07 23:39:50972 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
brettw4b461082016-11-19 18:55:16973#if BUILDFLAG(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00974 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
975 OnPepperInstanceCreated)
976 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
977 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42978 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:17979 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
980 OnPepperStartsPlayback)
981 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
982 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:42983 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]c4538072013-03-18 02:17:55984 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40985 OnBrowserPluginMessage(render_frame_host,
986 message))
thestigc4cac8f2014-09-04 21:17:50987#endif
[email protected]724159a2010-12-30 01:11:18988 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33989 IPC_END_MESSAGE_MAP()
[email protected]724159a2010-12-30 01:11:18990
[email protected]724159a2010-12-30 01:11:18991 return handled;
992}
993
[email protected]d1198fd2012-08-13 22:50:19994NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56995 return controller_;
996}
997
[email protected]d1198fd2012-08-13 22:50:19998const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56999 return controller_;
1000}
1001
[email protected]8ff00d72012-10-23 19:12:211002BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:551003 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:301004}
1005
[email protected]b172aee2012-04-10 17:05:261006const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:241007 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:321008 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:511009 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:311010}
1011
[email protected]a093ce02013-07-22 20:53:141012const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:241013 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:321014 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:241015 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
1016}
1017
1018const GURL& WebContentsImpl::GetLastCommittedURL() const {
1019 // We may not have a navigation entry yet.
1020 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1021 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
1022}
1023
[email protected]8ff00d72012-10-23 19:12:211024WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:311025 return delegate_;
1026}
1027
[email protected]8ff00d72012-10-23 19:12:211028void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:311029 // TODO(cbentzel): remove this debugging code?
1030 if (delegate == delegate_)
1031 return;
1032 if (delegate_)
1033 delegate_->Detach(this);
1034 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:081035 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:311036 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:081037 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:001038 if (view_)
[email protected]e85165c642014-06-10 14:34:311039 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
Joel Einbinder848001c2017-09-19 21:39:311040 if (GetRenderViewHost())
1041 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]a6b73c62013-02-11 23:05:081042 }
[email protected]be1f56ab2011-12-22 06:55:311043}
1044
Lukasz Anforowicze9ae3722017-09-29 17:37:381045RenderFrameHostImpl* WebContentsImpl::GetMainFrame() const {
[email protected]94d0cc12013-12-18 00:07:411046 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:161047}
1048
nick53d5cbf2015-04-23 22:50:141049RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
1050 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
1051 if (!focused_node)
1052 return nullptr;
1053 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:071054}
1055
rob3e2a0732016-01-06 21:22:091056RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
creisf71a2632017-05-04 19:03:501057 int frame_tree_node_id,
1058 int process_id) {
1059 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
1060
1061 // Sanity check that this is in the caller's expected process. Otherwise a
1062 // recent cross-process navigation may have led to a privilege change that the
1063 // caller is not expecting.
1064 if (!frame ||
1065 frame->current_frame_host()->GetProcess()->GetID() != process_id)
1066 return nullptr;
1067
1068 return frame->current_frame_host();
1069}
1070
1071RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId(
rob3e2a0732016-01-06 21:22:091072 int frame_tree_node_id) {
creisf71a2632017-05-04 19:03:501073 // Beware using this! The RenderFrameHost may have changed since the caller
1074 // obtained frame_tree_node_id.
rob3e2a0732016-01-06 21:22:091075 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
1076 return frame ? frame->current_frame_host() : nullptr;
1077}
1078
[email protected]a86c0e962013-12-17 17:10:391079void WebContentsImpl::ForEachFrame(
Lei Zhangebcc6302018-01-12 19:46:451080 const base::RepeatingCallback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:381081 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1082 on_frame.Run(node->current_frame_host());
1083 }
[email protected]a86c0e962013-12-17 17:10:391084}
1085
dchengafb53e22016-02-04 08:11:081086std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
1087 std::vector<RenderFrameHost*> frame_hosts;
1088 for (FrameTreeNode* node : frame_tree_.Nodes())
1089 frame_hosts.push_back(node->current_frame_host());
1090 return frame_hosts;
1091}
1092
lukaszacbdf52e2016-01-15 21:19:511093int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
1094 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:081095 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:251096 if (!rfh->IsRenderFrameLive())
1097 continue;
1098
dchengafb53e22016-02-04 08:11:081099 ++number_of_messages;
1100 IPC::Message* message_copy = new IPC::Message(*message);
1101 message_copy->set_routing_id(rfh->GetRoutingID());
1102 rfh->Send(message_copy);
1103 }
[email protected]a86c0e962013-12-17 17:10:391104 delete message;
lukaszacbdf52e2016-01-15 21:19:511105 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:391106}
1107
lfgdb5c4ed2016-03-04 23:09:071108void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:411109 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:071110}
1111
creisc014b402015-04-23 16:41:451112RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:211113 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:311114}
1115
creis89a0f782015-05-27 16:13:171116void WebContentsImpl::CancelActiveAndPendingDialogs() {
avi5d3b8692016-10-12 22:00:461117 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:531118 dialog_manager_->CancelDialogs(this, /*reset_state=*/false);
avi5d3b8692016-10-12 22:00:461119 }
creis89a0f782015-05-27 16:13:171120 if (browser_plugin_embedder_)
1121 browser_plugin_embedder_->CancelGuestDialogs();
1122}
1123
naskoc0fceff2015-04-30 15:53:521124void WebContentsImpl::ClosePage() {
1125 GetRenderViewHost()->ClosePage();
1126}
1127
[email protected]b172aee2012-04-10 17:05:261128RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:211129 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:311130}
1131
lfg265a2672016-04-23 03:11:021132RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
1133 if (GetOuterWebContents())
1134 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
1135 return GetRenderManager()->GetRenderWidgetHostView();
1136}
1137
[email protected]4aebbca2013-09-17 22:26:491138RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
1139 const {
vmpstr6d9996c82017-02-23 00:43:251140 if (auto* widget_host = GetFullscreenRenderWidgetHost())
ekaramadaeb3c5c2016-11-09 03:22:351141 return widget_host->GetView();
1142 return nullptr;
[email protected]4aebbca2013-09-17 22:26:491143}
1144
[email protected]8ff00d72012-10-23 19:12:211145WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:311146 return view_.get();
1147}
1148
leon.han552e9de2017-02-09 14:37:301149void WebContentsImpl::OnScreenOrientationChange() {
1150 DCHECK(screen_orientation_provider_);
Becca Hughese9e27952018-06-25 17:08:271151 screen_orientation_provider_->OnOrientationChange();
leon.hane4db177a2017-02-07 14:19:161152}
1153
yusufod41c5f92015-03-06 00:14:281154SkColor WebContentsImpl::GetThemeColor() const {
1155 return theme_color_;
1156}
1157
Doug Turner63f3c7b2017-07-29 05:10:011158void WebContentsImpl::SetAccessibilityMode(ui::AXMode mode) {
[email protected]95640212014-07-26 18:14:301159 if (mode == accessibility_mode_)
1160 return;
1161
dmazzonif8a31042016-12-03 00:52:131162 // Don't allow accessibility to be enabled for WebContents that are never
1163 // visible, like background pages.
1164 if (IsNeverVisible())
1165 return;
1166
[email protected]95640212014-07-26 18:14:301167 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:381168
1169 for (FrameTreeNode* node : frame_tree_.Nodes()) {
dmazzonif8a31042016-12-03 00:52:131170 UpdateAccessibilityModeOnFrame(node->current_frame_host());
clamy610c63b32017-12-22 15:05:181171 // Also update accessibility mode on the speculative RenderFrameHost for
1172 // this FrameTreeNode, if one exists.
Alex Moshchuk3d8a1f392017-10-24 19:01:261173 RenderFrameHost* speculative_frame_host =
1174 node->render_manager()->speculative_frame_host();
1175 if (speculative_frame_host)
1176 UpdateAccessibilityModeOnFrame(speculative_frame_host);
dcheng57e39e22016-01-21 00:25:381177 }
[email protected]95640212014-07-26 18:14:301178}
1179
Doug Turner63f3c7b2017-07-29 05:10:011180void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) {
1181 ui::AXMode new_mode(accessibility_mode_);
dougtcd3dad732017-03-14 03:26:231182 new_mode |= mode;
1183 SetAccessibilityMode(new_mode);
[email protected]95640212014-07-26 18:14:301184}
1185
Avi Drissman1e620f32018-03-16 13:57:291186// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
1187// Handles the callbacks from parallel snapshot requests to each frame,
1188// and feeds the results to an AXTreeCombiner, which converts them into a
1189// single combined accessibility tree.
1190class WebContentsImpl::AXTreeSnapshotCombiner
1191 : public base::RefCounted<AXTreeSnapshotCombiner> {
1192 public:
1193 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
1194 : callback_(std::move(callback)) {}
1195
1196 AXTreeSnapshotCallback AddFrame(bool is_root) {
1197 // Adds a reference to |this|.
1198 return base::BindOnce(&AXTreeSnapshotCombiner::ReceiveSnapshot, this,
1199 is_root);
1200 }
1201
1202 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
1203 combiner_.AddTree(snapshot, is_root);
1204 }
1205
1206 private:
1207 friend class base::RefCounted<AXTreeSnapshotCombiner>;
1208
1209 // This is called automatically after the last call to ReceiveSnapshot
1210 // when there are no more references to this object.
1211 ~AXTreeSnapshotCombiner() {
1212 combiner_.Combine();
1213 std::move(callback_).Run(combiner_.combined());
1214 }
1215
1216 ui::AXTreeCombiner combiner_;
1217 AXTreeSnapshotCallback callback_;
1218};
1219
1220void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback,
1221 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391222 // Send a request to each of the frames in parallel. Each one will return
1223 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
1224 // them into a single tree and call |callback| with that result, then
1225 // delete |combiner|.
Avi Drissman1e620f32018-03-16 13:57:291226 FrameTreeNode* root_node = frame_tree_.root();
Avi Drissmanb30851c2018-03-08 20:34:331227 AXTreeSnapshotCombiner* combiner =
1228 new AXTreeSnapshotCombiner(std::move(callback));
Avi Drissman1e620f32018-03-16 13:57:291229
1230 RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner, ax_mode);
1231}
1232
1233void WebContentsImpl::RecursiveRequestAXTreeSnapshotOnFrame(
1234 FrameTreeNode* root_node,
1235 AXTreeSnapshotCombiner* combiner,
1236 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391237 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
Avi Drissman1e620f32018-03-16 13:57:291238 WebContentsImpl* inner_contents =
1239 node_.GetInnerWebContentsInFrame(frame_tree_node);
1240 if (inner_contents) {
1241 inner_contents->RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner,
1242 ax_mode);
1243 } else {
1244 bool is_root = frame_tree_node == root_node;
1245 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
1246 combiner->AddFrame(is_root), ax_mode);
1247 }
dmazzonid95ae842016-04-12 21:17:391248 }
dmazzoni83ba5c82015-04-14 07:11:511249}
1250
mcnee336ea2c2017-05-23 22:50:591251#if !defined(OS_ANDROID)
akabac6bd1212018-06-25 20:10:481252
1253void WebContentsImpl::UpdateZoom() {
1254 RenderWidgetHostImpl* rwh = GetRenderViewHost()->GetWidget();
1255 if (rwh->GetView())
1256 rwh->SynchronizeVisualProperties();
wjmaclean64951902016-04-29 20:59:121257}
1258
akabac6bd1212018-06-25 20:10:481259bool WebContentsImpl::UsesTemporaryZoomLevel() const {
1260 return HostZoomMap::GetForWebContents(this)->UsesTemporaryZoomLevel(
1261 GetMainFrame()->GetProcess()->GetID(),
1262 GetRenderViewHost()->GetRoutingID());
wjmaclean64951902016-04-29 20:59:121263}
1264
1265void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
akabac6bd1212018-06-25 20:10:481266 const std::string& host) {
wjmaclean64951902016-04-29 20:59:121267 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1268 if (!entry)
1269 return;
1270
1271 GURL url = HostZoomMap::GetURLFromEntry(entry);
1272 if (host != net::GetHostOrSpecFromURL(url) ||
1273 (!scheme.empty() && !url.SchemeIs(scheme))) {
1274 return;
1275 }
1276
akabac6bd1212018-06-25 20:10:481277 UpdateZoom();
wjmaclean64951902016-04-29 20:59:121278}
mcnee336ea2c2017-05-23 22:50:591279#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:121280
rockotf62002a2016-09-15 00:08:591281base::Closure WebContentsImpl::AddBindingSet(
1282 const std::string& interface_name,
1283 WebContentsBindingSet* binding_set) {
1284 auto result =
1285 binding_sets_.insert(std::make_pair(interface_name, binding_set));
1286 DCHECK(result.second);
1287 return base::Bind(&WebContentsImpl::RemoveBindingSet,
1288 weak_factory_.GetWeakPtr(), interface_name);
1289}
1290
rockot8bbad222017-03-22 04:34:051291WebContentsBindingSet* WebContentsImpl::GetBindingSet(
1292 const std::string& interface_name) {
1293 auto it = binding_sets_.find(interface_name);
1294 if (it == binding_sets_.end())
1295 return nullptr;
1296 return it->second;
1297}
1298
paulmeyerfeafc2d2017-04-25 21:46:401299std::vector<WebContentsImpl*> WebContentsImpl::GetInnerWebContents() {
1300 if (browser_plugin_embedder_) {
1301 std::vector<WebContentsImpl*> inner_contents;
1302 GetBrowserContext()->GetGuestManager()->ForEachGuest(
Mark Pilgrimd84121732018-03-22 14:12:121303 this, base::BindRepeating(&GetInnerWebContentsHelper, &inner_contents));
paulmeyerfeafc2d2017-04-25 21:46:401304 return inner_contents;
1305 }
1306
1307 return node_.inner_web_contents();
1308}
1309
1310std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() {
1311 std::vector<WebContentsImpl*> all_contents(1, this);
1312
1313 for (size_t i = 0; i != all_contents.size(); ++i) {
1314 for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) {
1315 all_contents.push_back(inner_contents);
1316 }
1317 }
1318
1319 return all_contents;
1320}
1321
Sam McNally145fb172017-05-10 00:13:231322void WebContentsImpl::NotifyManifestUrlChanged(
1323 const base::Optional<GURL>& manifest_url) {
1324 for (auto& observer : observers_)
1325 observer.DidUpdateWebManifestURL(manifest_url);
1326}
1327
[email protected]8ff00d72012-10-23 19:12:211328WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:401329 WebUI* commited_web_ui = GetCommittedWebUI();
1330 return commited_web_ui ? commited_web_ui
1331 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:311332}
1333
[email protected]8ff00d72012-10-23 19:12:211334WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:401335 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341336}
1337
Changwan Ryuc1134a82018-03-07 02:10:141338void WebContentsImpl::SetUserAgentOverride(const std::string& override,
1339 bool override_in_new_tabs) {
[email protected]bf70edce2012-06-20 22:32:221340 if (GetUserAgentOverride() == override)
1341 return;
1342
Changwan Ryuc1134a82018-03-07 02:10:141343 should_override_user_agent_in_new_tabs_ = override_in_new_tabs;
1344
[email protected]bf70edce2012-06-20 22:32:221345 renderer_preferences_.user_agent_override = override;
1346
1347 // Send the new override string to the renderer.
1348 RenderViewHost* host = GetRenderViewHost();
1349 if (host)
1350 host->SyncRendererPrefs();
1351
1352 // Reload the page if a load is currently in progress to avoid having
1353 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271354 NavigationEntry* entry = controller_.GetVisibleEntry();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281355 if (IsLoading() && entry != nullptr && entry->GetIsOverridingUserAgent())
toyoshim6142d96f2016-12-19 09:07:251356 controller_.Reload(ReloadType::BYPASSING_CACHE, true);
[email protected]8d0f3312012-08-18 01:47:531357
ericwilligersde386342016-10-19 02:35:091358 for (auto& observer : observers_)
1359 observer.UserAgentOverrideSet(override);
[email protected]86ef6a392012-05-11 22:03:111360}
1361
1362const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:221363 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111364}
1365
Changwan Ryuc1134a82018-03-07 02:10:141366bool WebContentsImpl::ShouldOverrideUserAgentInNewTabs() {
1367 return should_override_user_agent_in_new_tabs_;
1368}
1369
dmazzonidd3d51a72016-12-14 18:41:011370void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() {
dougtcd3dad732017-03-14 03:26:231371 if (!GetAccessibilityMode().is_mode_off()) {
dchengafb53e22016-02-04 08:11:081372 for (RenderFrameHost* rfh : GetAllFrames())
1373 ResetAccessibility(rfh);
1374 } else {
Doug Turner63f3c7b2017-07-29 05:10:011375 AddAccessibilityMode(ui::kAXModeWebContentsOnly);
dchengafb53e22016-02-04 08:11:081376 }
[email protected]95640212014-07-26 18:14:301377}
1378
dmazzonidd3d51a72016-12-14 18:41:011379bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011380 return accessibility_mode_ == ui::kAXModeWebContentsOnly;
[email protected]95640212014-07-26 18:14:301381}
1382
1383bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011384 return accessibility_mode_ == ui::kAXModeComplete;
[email protected]95640212014-07-26 18:14:301385}
1386
kouhei40f03cb2015-09-24 07:47:011387const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
1388 return page_importance_signals_;
1389}
1390
Guido Urdanetaf4008002018-05-03 10:43:041391const std::string& WebContentsImpl::GetMediaDeviceGroupIDSaltBase() const {
1392 return media_device_group_id_salt_base_;
1393}
1394
Becca Hughes6daf5662018-06-27 16:50:541395#if defined(OS_ANDROID)
1396
1397void WebContentsImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) {
Becca Hughes86334622018-07-09 21:29:381398 if (display_cutout_host_impl_)
1399 display_cutout_host_impl_->SetDisplayCutoutSafeArea(insets);
Becca Hughes6daf5662018-06-27 16:50:541400}
1401
1402#endif
1403
[email protected]fcf75d42013-12-03 20:11:261404const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:551405 // Transient entries take precedence. They are used for interstitial pages
1406 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231407 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231408 if (entry) {
jshin1fb76462016-04-05 22:13:031409 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231410 }
carlosk35f35af2015-12-01 10:55:401411
1412 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
1413 WebUI* our_web_ui = navigating_web_ui
1414 ? navigating_web_ui
1415 : GetRenderManager()->current_frame_host()->web_ui();
1416
[email protected]7ade2732011-02-10 00:13:581417 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541418 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321419 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541420 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351421 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261422 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541423 if (!title.empty())
1424 return title;
1425 }
1426 }
1427
1428 // We use the title for the last committed entry rather than a pending
1429 // navigation entry. For example, when the user types in a URL, we want to
1430 // keep the old page's title until the new load has committed and we get a new
1431 // title.
[email protected]96d185d2009-04-24 03:28:541432 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321433
creis072b61f2015-09-28 20:52:241434 // We make an exception for initial navigations. We only want to use the title
1435 // from the visible entry if:
1436 // 1. The pending entry has been explicitly assigned a title to display.
1437 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1438 // which case there is a pending entry index other than -1.
1439 //
1440 // Otherwise, we want to stick with the last committed entry's title during
1441 // new navigations, which have pending entries at index -1 with no title.
1442 if (controller_.IsInitialNavigation() &&
1443 ((controller_.GetVisibleEntry() &&
1444 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1445 controller_.GetPendingEntryIndex() != -1)) {
1446 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471447 }
[email protected]59167c22013-06-03 18:07:321448
[email protected]45d0ef7f2011-01-05 13:46:231449 if (entry) {
jshin1fb76462016-04-05 22:13:031450 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231451 }
[email protected]987fc3a2011-05-26 14:18:091452
1453 // |page_title_when_no_navigation_entry_| is finally used
1454 // if no title cannot be retrieved.
1455 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541456}
1457
creiscce56cd2014-09-29 22:45:221458SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211459 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541460}
1461
[email protected]b172aee2012-04-10 17:05:261462bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251463 return frame_tree_.IsLoading() &&
creisadca9862017-06-16 19:12:111464 !(ShowingInterstitialPage() && interstitial_page_->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491465}
1466
[email protected]6dfed692014-05-22 04:18:031467bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251468 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031469}
1470
[email protected]b172aee2012-04-10 17:05:261471bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031472 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311473}
1474
[email protected]b172aee2012-04-10 17:05:261475const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311476 return load_state_;
1477}
1478
[email protected]fcf75d42013-12-03 20:11:261479const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311480 return load_state_host_;
1481}
1482
avib7348942015-12-25 20:57:101483uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311484 return upload_size_;
1485}
1486
avib7348942015-12-25 20:57:101487uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311488 return upload_position_;
1489}
1490
[email protected]b172aee2012-04-10 17:05:261491const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541492 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311493}
1494
Shubhie Panickerddf2a4e2018-03-06 00:09:061495void WebContentsImpl::SetWasDiscarded(bool was_discarded) {
1496 GetFrameTree()->root()->set_was_discarded();
1497}
1498
[email protected]222f5822014-02-05 23:40:491499void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251500 DCHECK(!is_being_destroyed_);
Francois Doraye6161152018-03-27 22:05:371501 const bool was_captured = IsBeingCaptured();
[email protected]54597982013-02-06 01:59:551502 ++capturer_count_;
1503 DVLOG(1) << "There are now " << capturer_count_
1504 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491505
1506 // Note: This provides a hint to upstream code to size the views optimally
1507 // for quality (e.g., to avoid scaling).
1508 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1509 preferred_size_for_capture_ = capture_size;
1510 OnPreferredSizeChanged(preferred_size_);
1511 }
ccameron8807c38f2015-01-17 00:29:191512
Francois Doraye6161152018-03-27 22:05:371513 if (GetVisibility() != Visibility::VISIBLE && !was_captured) {
1514 // Ensure that all views act as if they were visible before capture begins.
1515 // TODO(fdoray): Replace RenderWidgetHostView::WasUnOccluded() with a method
1516 // to explicitly notify the RenderWidgetHostView that capture began.
1517 // https://crbug.com/668690
1518 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1519 view->WasUnOccluded();
1520 }
[email protected]54597982013-02-06 01:59:551521}
1522
1523void WebContentsImpl::DecrementCapturerCount() {
1524 --capturer_count_;
1525 DVLOG(1) << "There are now " << capturer_count_
1526 << " capturing(s) of WebContentsImpl@" << this;
1527 DCHECK_LE(0, capturer_count_);
1528
[email protected]5a652232013-02-12 06:15:251529 if (is_being_destroyed_)
1530 return;
1531
Francois Doray24fc62c2017-12-11 17:27:331532 if (!IsBeingCaptured()) {
[email protected]222f5822014-02-05 23:40:491533 const gfx::Size old_size = preferred_size_for_capture_;
1534 preferred_size_for_capture_ = gfx::Size();
1535 OnPreferredSizeChanged(old_size);
[email protected]222f5822014-02-05 23:40:491536
Francois Doraye6161152018-03-27 22:05:371537 if (visibility_ == Visibility::HIDDEN) {
Francois Doray18800972017-08-25 22:38:581538 DVLOG(1) << "Executing delayed WasHidden().";
1539 WasHidden();
Francois Doraye6161152018-03-27 22:05:371540 } else if (visibility_ == Visibility::OCCLUDED) {
Mitsuru Oshima04a80242018-03-03 03:06:151541 WasOccluded();
Francois Doraye6161152018-03-27 22:05:371542 }
[email protected]54597982013-02-06 01:59:551543 }
[email protected]be1f56ab2011-12-22 06:55:311544}
1545
Francois Doray24fc62c2017-12-11 17:27:331546bool WebContentsImpl::IsBeingCaptured() const {
1547 return capturer_count_ > 0;
[email protected]f2bd40812013-07-20 04:30:441548}
1549
miu50f97892014-09-22 22:49:521550bool WebContentsImpl::IsAudioMuted() const {
Max Morinb5506f72018-05-16 07:33:101551 if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) {
1552 return audio_stream_factory_ && audio_stream_factory_->IsMuted();
1553 }
miu50f97892014-09-22 22:49:521554 return audio_muter_.get() && audio_muter_->is_muting();
1555}
1556
1557void WebContentsImpl::SetAudioMuted(bool mute) {
1558 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1559 << " for WebContentsImpl@" << this;
1560
1561 if (mute == IsAudioMuted())
1562 return;
1563
Max Morinb5506f72018-05-16 07:33:101564 if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) {
1565 GetAudioStreamFactory()->SetMuted(mute);
miu50f97892014-09-22 22:49:521566 } else {
Max Morinb5506f72018-05-16 07:33:101567 if (mute) {
1568 if (!audio_muter_)
1569 audio_muter_.reset(new WebContentsAudioMuter(this));
1570 audio_muter_->StartMuting();
1571 } else {
1572 DCHECK(audio_muter_);
1573 audio_muter_->StopMuting();
1574 }
miu50f97892014-09-22 22:49:521575 }
1576
ericwilligersde386342016-10-19 02:35:091577 for (auto& observer : observers_)
1578 observer.DidUpdateAudioMutingState(mute);
wjmaclean2f797c782016-01-07 14:52:031579
Jan Rucka442c83f2017-08-08 13:27:541580 // Notification for UI updates in response to the changed muting state.
1581 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1582}
1583
1584bool WebContentsImpl::IsCurrentlyAudible() {
Chris Hamiltondf0d72cd2018-05-29 16:23:531585 return is_currently_audible_;
miu50f97892014-09-22 22:49:521586}
1587
ortunodf4d7982016-04-08 02:33:351588bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1589 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201590}
1591
sawtellea7333a82018-05-31 02:36:361592bool WebContentsImpl::HasPictureInPictureVideo() const {
1593 return has_picture_in_picture_video_;
1594}
1595
1596void WebContentsImpl::SetHasPictureInPictureVideo(
1597 bool has_picture_in_picture_video) {
1598 // If status of |this| is already accurate, there is no need to update.
1599 if (has_picture_in_picture_video == has_picture_in_picture_video_)
1600 return;
1601 has_picture_in_picture_video_ = has_picture_in_picture_video;
1602 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1603}
1604
[email protected]b172aee2012-04-10 17:05:261605bool WebContentsImpl::IsCrashed() const {
Dominic Mazzoni73a48322018-05-25 18:14:071606 switch (crashed_status_) {
1607 case base::TERMINATION_STATUS_PROCESS_CRASHED:
1608 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
1609 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
1610 case base::TERMINATION_STATUS_OOM:
1611 case base::TERMINATION_STATUS_LAUNCH_FAILED:
oshima620225722015-06-04 19:45:271612#if defined(OS_CHROMEOS)
Dominic Mazzoni73a48322018-05-25 18:14:071613 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM:
oshima620225722015-06-04 19:45:271614#endif
Dominic Mazzoni73a48322018-05-25 18:14:071615#if defined(OS_ANDROID)
1616 case base::TERMINATION_STATUS_OOM_PROTECTED:
1617#endif
1618 return true;
1619 case base::TERMINATION_STATUS_NORMAL_TERMINATION:
1620 case base::TERMINATION_STATUS_STILL_RUNNING:
1621 return false;
1622 case base::TERMINATION_STATUS_MAX_ENUM:
1623 NOTREACHED();
1624 return false;
1625 }
1626
1627 NOTREACHED();
1628 return false;
[email protected]3c9e1872010-11-18 16:17:491629}
1630
[email protected]b172aee2012-04-10 17:05:261631void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1632 int error_code) {
[email protected]443b80e2010-12-14 00:42:231633 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341634 return;
1635
[email protected]443b80e2010-12-14 00:42:231636 crashed_status_ = status;
1637 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211638 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341639}
1640
[email protected]b172aee2012-04-10 17:05:261641base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311642 return crashed_status_;
1643}
1644
afakhry98241832016-03-11 19:27:471645int WebContentsImpl::GetCrashedErrorCode() const {
1646 return crashed_error_code_;
1647}
1648
[email protected]b172aee2012-04-10 17:05:261649bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311650 return is_being_destroyed_;
1651}
1652
[email protected]7f924832014-08-09 05:57:221653void WebContentsImpl::NotifyNavigationStateChanged(
1654 InvalidateTypes changed_flags) {
dalecurtis88c240072015-12-09 02:11:181655 // Notify the media observer of potential audibility changes.
1656 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271657 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301658 }
1659
[email protected]d5f942ba2008-09-26 19:30:341660 if (delegate_)
1661 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441662
1663 if (GetOuterWebContents())
1664 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341665}
1666
Chris Hamiltondf0d72cd2018-05-29 16:23:531667void WebContentsImpl::OnAudioStateChanged() {
1668 // This notification can come from any embedded contents or from this
1669 // WebContents' stream monitor. Aggregate these signals to get the actual
1670 // state.
1671 bool is_currently_audible =
1672 audio_stream_monitor_.IsCurrentlyAudible() ||
1673 (browser_plugin_embedder_ &&
1674 browser_plugin_embedder_->AreAnyGuestsCurrentlyAudible());
1675 if (is_currently_audible == is_currently_audible_)
1676 return;
1677
1678 // Update internal state.
1679 is_currently_audible_ = is_currently_audible;
1680 was_ever_audible_ = was_ever_audible_ || is_currently_audible_;
1681
1682 SendPageMessage(
1683 new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_currently_audible_));
altimind8bd26c2016-11-04 11:44:541684
altiminec87fd1f2016-11-17 20:22:491685 // Notification for UI updates in response to the changed audio state.
altimind8bd26c2016-11-04 11:44:541686 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
Jan Rucka442c83f2017-08-08 13:27:541687
Chris Hamiltondf0d72cd2018-05-29 16:23:531688 // Ensure that audio state changes propagate from innermost to outermost
1689 // WebContents.
1690 if (GetOuterWebContents())
1691 GetOuterWebContents()->OnAudioStateChanged();
Tommy Steimel18360512017-11-01 00:38:191692
Chris Hamiltoneb41198f2018-05-24 18:41:261693 for (auto& observer : observers_)
Chris Hamiltondf0d72cd2018-05-29 16:23:531694 observer.OnAudioStateChanged(is_currently_audible_);
altimind8bd26c2016-11-04 11:44:541695}
1696
gab0dccfef2015-05-20 18:43:391697base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021698 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331699}
1700
[email protected]9e2e4632012-07-27 16:38:411701void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541702 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591703
EhsanK2075c7e2017-08-21 02:42:391704 if (auto* view = GetRenderWidgetHostView()) {
lfgf949e0e2017-05-10 22:18:111705 view->Show();
[email protected]789e9152009-08-04 21:59:431706#if defined(OS_MACOSX)
lfgf949e0e2017-05-10 22:18:111707 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431708#endif
1709 }
[email protected]96d185d2009-04-24 03:28:541710
EhsanK2075c7e2017-08-21 02:42:391711 if (!ShowingInterstitialPage())
1712 SetVisibilityForChildViews(true);
1713
lfg717154072016-06-30 15:04:161714 SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE));
1715
gab0dccfef2015-05-20 18:43:391716 last_active_time_ = base::TimeTicks::Now();
Francois Doraye6161152018-03-27 22:05:371717 SetVisibility(Visibility::VISIBLE);
Lukasz Anforowicz873e6082018-05-17 00:12:331718
1719 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1720 RenderFrameProxyHost* parent = node->render_manager()->GetProxyToParent();
1721 if (!parent)
1722 continue;
1723
1724 if (parent->cross_process_frame_connector()->IsVisible()) {
1725 // MaybeLogCrash will check 1) if there was a crash or not and 2) if the
1726 // crash might have been already logged earlier as kCrashedWhileVisible.
1727 parent->cross_process_frame_connector()->MaybeLogCrash(
1728 CrossProcessFrameConnector::CrashVisibility::kShownAfterCrashing);
1729 }
1730 }
[email protected]be1f56ab2011-12-22 06:55:311731}
1732
[email protected]b172aee2012-04-10 17:05:261733void WebContentsImpl::WasHidden() {
Jennifer Apacible72c31412018-06-19 16:52:241734 // If there are entities capturing screenshots or video (e.g. mirroring),
1735 // or in Picture-in-Picture mode, don't activate the "disable rendering"
1736 // optimization.
1737 if (!IsBeingCaptured() && !HasPictureInPictureVideo()) {
[email protected]151a63d2011-12-20 22:32:521738 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551739 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261740 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521741 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331742 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521743 // calls us).
EhsanK2075c7e2017-08-21 02:42:391744 if (auto* view = GetRenderWidgetHostView())
lfgf949e0e2017-05-10 22:18:111745 view->Hide();
lfg717154072016-06-30 15:04:161746
EhsanK2075c7e2017-08-21 02:42:391747 if (!ShowingInterstitialPage())
Igor Eremeevef59187a2017-09-29 00:25:421748 SetVisibilityForChildViews(false);
EhsanK2075c7e2017-08-21 02:42:391749
lfg717154072016-06-30 15:04:161750 SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
[email protected]96d185d2009-04-24 03:28:541751 }
1752
Francois Doraye6161152018-03-27 22:05:371753 SetVisibility(Visibility::HIDDEN);
[email protected]375fa1b2012-05-22 22:05:371754}
1755
Daniel Cheng90196c82018-04-25 21:49:141756bool WebContentsImpl::HasRecentInteractiveInputEvent() const {
1757 static constexpr base::TimeDelta kMaxInterval =
1758 base::TimeDelta::FromSeconds(5);
1759 base::TimeDelta delta =
1760 ui::EventTimeForNow() - last_interactive_input_event_time_;
1761 // Note: the expectation is that the caller is typically expecting an input
1762 // event, e.g. validating that a WebUI message that requires a gesture is
1763 // actually attached to a gesture. Logging to UMA here should hopefully give
1764 // sufficient data if 5 seconds is actually sufficient (or even too high a
1765 // threshhold).
1766 UMA_HISTOGRAM_TIMES("Tabs.TimeSinceLastInteraction", delta);
1767 return delta <= kMaxInterval;
1768}
1769
Bo Liu168c8642017-08-28 18:26:021770#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:501771void WebContentsImpl::SetMainFrameImportance(
1772 ChildProcessImportance importance) {
1773 GetMainFrame()->GetRenderWidgetHost()->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281774 if (ShowingInterstitialPage()) {
Bo Liu16dd7b8322018-05-02 21:19:501775 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
1776 ->GetRenderWidgetHost()
1777 ->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281778 }
Bo Liu7c6779e92017-08-16 02:02:281779}
Bo Liu168c8642017-08-28 18:26:021780#endif
Bo Liu7c6779e92017-08-16 02:02:281781
ccameron8807c38f2015-01-17 00:29:191782void WebContentsImpl::WasOccluded() {
Francois Doray24fc62c2017-12-11 17:27:331783 if (!IsBeingCaptured()) {
Francois Doray18800972017-08-25 22:38:581784 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1785 view->WasOccluded();
1786 }
Francois Doraye6161152018-03-27 22:05:371787 SetVisibility(Visibility::OCCLUDED);
ccameron8807c38f2015-01-17 00:29:191788}
1789
Francois Dorayfe4a1772018-02-17 04:17:091790Visibility WebContentsImpl::GetVisibility() const {
Francois Doraye6161152018-03-27 22:05:371791 return visibility_;
Francois Dorayfe4a1772018-02-17 04:17:091792}
1793
[email protected]b172aee2012-04-10 17:05:261794bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311795 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451796 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
jam40444982017-04-11 03:01:411797 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311798}
1799
nasko148bb0b92016-05-10 21:03:191800void WebContentsImpl::DispatchBeforeUnload() {
1801 bool for_cross_site_transition = false;
clamybfd6a812016-05-30 16:25:171802 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false);
[email protected]1c3f80bd2014-04-08 23:02:061803}
1804
lazyboy6ec48b2a2015-06-29 15:18:141805void WebContentsImpl::AttachToOuterWebContentsFrame(
1806 WebContents* outer_web_contents,
1807 RenderFrameHost* outer_contents_frame) {
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391808 DCHECK(!node_.outer_web_contents());
1809
lfg91a79e12016-04-01 23:52:191810 RenderFrameHostManager* render_manager = GetRenderManager();
1811
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391812 // When attaching a WebContents as an inner WebContents, we need to replace
1813 // the Webcontents' view with a WebContentsViewChildFrame.
1814 view_.reset(new WebContentsViewChildFrame(
1815 this, GetContentClient()->browser()->GetWebContentsViewDelegate(this),
1816 &render_view_host_delegate_view_));
1817
lfg91a79e12016-04-01 23:52:191818 // When the WebContents being initialized has an opener, the browser side
1819 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1820 // created. This is needed because the usual initialization happens during
1821 // the first navigation, but when attaching a new window we don't navigate
1822 // before attaching. If the browser side is already initialized, the calls
1823 // below will just early return.
1824 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1825 GetMainFrame()->Init();
1826 if (!render_manager->GetRenderWidgetHostView())
1827 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1828
avallee7529b2a2017-04-26 11:37:511829 auto* outer_web_contents_impl =
1830 static_cast<WebContentsImpl*>(outer_web_contents);
1831 auto* outer_contents_frame_impl =
1832 static_cast<RenderFrameHostImpl*>(outer_contents_frame);
lazyboy6ec48b2a2015-06-29 15:18:141833 // Create a link to our outer WebContents.
avallee7529b2a2017-04-26 11:37:511834 node_.ConnectToOuterWebContents(outer_web_contents_impl,
1835 outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141836
1837 DCHECK(outer_contents_frame);
1838
1839 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1840 // SiteInstance of the outer WebContents. The proxy will be used to send
1841 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191842 render_manager->CreateOuterDelegateProxy(
avallee7529b2a2017-04-26 11:37:511843 outer_contents_frame->GetSiteInstance(), outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141844
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141845 ReattachToOuterWebContentsFrame();
ekaramadadd882292016-06-08 15:22:561846
avallee7529b2a2017-04-26 11:37:511847 if (outer_web_contents_impl->frame_tree_.GetFocusedFrame() ==
1848 outer_contents_frame_impl->frame_tree_node()) {
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:571849 SetFocusedFrame(frame_tree_.root(),
1850 outer_contents_frame->GetSiteInstance());
avallee7529b2a2017-04-26 11:37:511851 }
1852
ekaramadadd882292016-06-08 15:22:561853 // At this point, we should destroy the TextInputManager which will notify all
1854 // the RWHV in this WebContents. The RWHV in this WebContents should use the
1855 // TextInputManager owned by the outer WebContents.
1856 // TODO(ekaramad): Is it possible to have TextInputState before attaching to
1857 // outer WebContents? In such a case, is this still the right way to hand off
1858 // state tracking from inner WebContents's TextInputManager to that of the
1859 // outer WebContent (crbug.com/609846)?
1860 text_input_manager_.reset(nullptr);
lazyboy6ec48b2a2015-06-29 15:18:141861}
1862
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141863void WebContentsImpl::ReattachToOuterWebContentsFrame() {
1864 DCHECK(node_.outer_web_contents());
1865 auto* render_manager = GetRenderManager();
1866 auto* parent_frame =
1867 node_.OuterContentsFrameTreeNode()->current_frame_host()->GetParent();
1868 render_manager->SetRWHViewForInnerContents(
1869 render_manager->GetRenderWidgetHostView());
1870
1871 static_cast<RenderWidgetHostViewChildFrame*>(
1872 render_manager->GetRenderWidgetHostView())
1873 ->RegisterFrameSinkId();
1874
1875 // Set up the the guest's AX tree to point back at the embedder's AX tree.
1876 GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(
1877 parent_frame->GetAXTreeID());
1878 GetMainFrame()->UpdateAXTreeData();
1879}
1880
dalecurtis6c58ed02016-10-28 23:02:371881void WebContentsImpl::DidChangeVisibleSecurityState() {
1882 if (delegate_) {
1883 delegate_->VisibleSecurityStateChanged(this);
cjgrant6d1d727a2016-12-09 21:16:571884 for (auto& observer : observers_)
1885 observer.DidChangeVisibleSecurityState();
dalecurtis6c58ed02016-10-28 23:02:371886 }
1887}
1888
Ahmed Fakhryd70bf37b2018-04-04 17:07:241889void WebContentsImpl::NotifyPreferencesChanged() {
1890 std::set<RenderViewHost*> render_view_host_set;
1891 for (FrameTreeNode* node : frame_tree_.Nodes()) {
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531892 render_view_host_set.insert(
1893 node->current_frame_host()->GetRenderViewHost());
Ahmed Fakhryd70bf37b2018-04-04 17:07:241894 }
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531895
Ahmed Fakhryd70bf37b2018-04-04 17:07:241896 for (RenderViewHost* render_view_host : render_view_host_set)
1897 render_view_host->OnWebkitPreferencesChanged();
1898}
1899
[email protected]b172aee2012-04-10 17:05:261900void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381901 for (FrameTreeNode* node : frame_tree_.Nodes())
1902 node->StopLoading();
ericwilligersde386342016-10-19 02:35:091903 for (auto& observer : observers_)
1904 observer.NavigationStopped();
[email protected]0bfbf882011-12-22 18:19:271905}
1906
Francois Doray47f759d2018-06-11 18:13:511907void WebContentsImpl::SetPageFrozen(bool frozen) {
1908 // A visible page is never frozen.
1909 DCHECK_NE(Visibility::VISIBLE, GetVisibility());
1910
1911 SendPageMessage(new PageMsg_SetPageFrozen(MSG_ROUTING_NONE, frozen));
Fadi Meawada6573e02018-03-10 00:52:111912}
1913
erikchen6c7df7f7a2018-05-03 18:13:591914std::unique_ptr<WebContents> WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441915 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211916 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451917 // before.
[email protected]54944cde2012-12-09 09:24:591918 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451919 create_params.initial_size = GetContainerBounds().size();
Ian Clelland5cbaaf82017-11-27 22:00:031920 FrameTreeNode* opener = frame_tree_.root()->opener();
1921 RenderFrameHostImpl* opener_rfh = nullptr;
1922 if (opener)
1923 opener_rfh = opener->current_frame_host();
erikchen6c7df7f7a2018-05-03 18:13:591924 std::unique_ptr<WebContentsImpl> tc =
erikchen50735fd2018-05-05 15:08:331925 CreateWithOpener(create_params, opener_rfh);
Francois Dorayeaace782017-06-21 16:37:241926 tc->GetController().CopyStateFrom(controller_, true);
ericwilligersde386342016-10-19 02:35:091927 for (auto& observer : observers_)
erikchen6c7df7f7a2018-05-03 18:13:591928 observer.DidCloneToNewWebContents(this, tc.get());
[email protected]0bfbf882011-12-22 18:19:271929 return tc;
1930}
1931
[email protected]14392a52012-05-02 20:28:441932void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211933 const NotificationSource& source,
1934 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441935 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211936 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1937 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031938 RenderWidgetHostView* view = host->GetView();
1939 if (view == GetFullscreenRenderWidgetHostView()) {
1940 // We cannot just call view_->RestoreFocus() here. On some platforms,
1941 // attempting to focus the currently-invisible WebContentsView will be
1942 // flat-out ignored. Therefore, this boolean is used to track whether
1943 // we will request focus after the fullscreen widget has been
1944 // destroyed.
1945 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1946 } else {
alexmosc2a8cec2016-05-23 22:19:531947 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:031948 i != pending_widget_views_.end(); ++i) {
1949 if (host->GetView() == i->second) {
1950 pending_widget_views_.erase(i);
1951 break;
1952 }
[email protected]bafe6cd2012-05-23 23:09:501953 }
1954 }
1955 break;
1956 }
[email protected]14392a52012-05-02 20:28:441957 default:
1958 NOTREACHED();
1959 }
1960}
1961
[email protected]ec6c05f2013-10-23 18:41:571962WebContents* WebContentsImpl::GetWebContents() {
1963 return this;
1964}
1965
[email protected]54944cde2012-12-09 09:24:591966void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211967 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361968 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211969 // it should be hidden.
Francois Doraye6161152018-03-27 22:05:371970 visibility_ =
1971 params.initially_hidden ? Visibility::HIDDEN : Visibility::VISIBLE;
[email protected]d6fa88f2013-10-18 16:00:431972
Sebastien Marchand28cf23182018-06-20 02:39:351973 if (!params.last_active_time.is_null())
1974 last_active_time_ = params.last_active_time;
1975
dcheng3ce04b62015-10-26 23:30:551976 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541977 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551978 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1979 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541980 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551981 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1982 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1983
1984 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1985 if (!site_instance)
1986 site_instance = SiteInstance::Create(params.browser_context);
Lukasz Anforowicz3caa8372018-06-05 17:22:071987 if (params.desired_renderer_state == CreateParams::kNoRendererProcess) {
1988 static_cast<SiteInstanceImpl*>(site_instance.get())
1989 ->PreventAssociationWithSpareProcess();
1990 }
dcheng3ce04b62015-10-26 23:30:551991
1992 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1993 // local root by definition.
1994 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1995 // longer be necessary to eagerly grab a routing ID for the view.
1996 // https://crbug.com/545684
1997 int32_t view_routing_id = params.routing_id;
1998 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1999 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
2000 view_routing_id = main_frame_widget_routing_id =
2001 site_instance->GetProcess()->GetNextRoutingID();
2002 }
2003
Dave Tapuska485aca92017-08-08 00:47:582004 GetRenderManager()->Init(
2005 site_instance.get(), view_routing_id, params.main_frame_routing_id,
2006 main_frame_widget_routing_id, params.renderer_initiated_creation);
lukasza464d8692016-02-22 19:26:322007
lukasza5140a412016-09-15 21:12:302008 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
2009 // main frame - let's do the same thing here.
2010 std::string unique_name;
lukasza464d8692016-02-22 19:26:322011 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:192012
[email protected]fc2b46b2014-05-03 16:33:452013 WebContentsViewDelegate* delegate =
2014 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
2015
sky52a39e342016-12-17 17:23:222016 if (GuestMode::IsCrossProcessFrameGuest(this)) {
2017 view_.reset(new WebContentsViewChildFrame(
2018 this, delegate, &render_view_host_delegate_view_));
2019 } else {
2020 view_.reset(CreateWebContentsView(this, delegate,
2021 &render_view_host_delegate_view_));
Scott Violetc884c7fd2017-11-03 23:51:012022 if (browser_plugin_guest_) {
2023 view_ = std::make_unique<WebContentsViewGuest>(
2024 this, browser_plugin_guest_.get(), std::move(view_),
2025 &render_view_host_delegate_view_);
2026 }
[email protected]d1198fd2012-08-13 22:50:192027 }
[email protected]fc2b46b2014-05-03 16:33:452028 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:192029 CHECK(view_.get());
2030
[email protected]ed245db2012-12-18 08:00:452031 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:592032 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:192033
brettw4b461082016-11-19 18:55:162034#if BUILDFLAG(ENABLE_PLUGINS)
tommyclieb25b2a2014-11-03 19:45:092035 plugin_content_origin_whitelist_.reset(
2036 new PluginContentOriginWhitelist(this));
2037#endif
2038
[email protected]d1198fd2012-08-13 22:50:192039 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:212040 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
2041 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:102042
leon.hane4db177a2017-02-07 14:19:162043 screen_orientation_provider_.reset(new ScreenOrientationProvider(this));
[email protected]01f83f92014-06-17 14:41:542044
mlamouriefdca9d2014-09-16 16:55:402045 manifest_manager_host_.reset(new ManifestManagerHost(this));
2046
mfomitchev2b8b066a2016-01-28 19:23:152047#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:102048 date_time_chooser_.reset(new DateTimeChooserAndroid());
2049#endif
fsamuel7310a4262014-12-05 05:06:442050
2051 // BrowserPluginGuest::Init needs to be called after this WebContents has
2052 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
2053 if (browser_plugin_guest_)
2054 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:372055
2056 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
2057 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:562058
2059 // If the WebContents creation was renderer-initiated, it means that the
2060 // corresponding RenderView and main RenderFrame have already been created.
2061 // Ensure observers are notified about this.
2062 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:432063 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
Alex Moshchuk27caae82017-09-11 23:11:182064 GetRenderViewHost()->DispatchRenderViewCreated();
naskob21fe4872015-02-24 14:15:562065 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
2066 }
naskof5940b9f2015-03-02 23:04:052067
lof84501da082016-05-23 21:22:542068 // Create the renderer process in advance if requested.
Lukasz Anforowicz3caa8372018-06-05 17:22:072069 if (params.desired_renderer_state ==
2070 CreateParams::kInitializeAndWarmupRendererProcess) {
lof84501da082016-05-23 21:22:542071 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
2072 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
2073 }
2074 }
2075
naskof5940b9f2015-03-02 23:04:052076 // Ensure that observers are notified of the creation of this WebContents's
2077 // main RenderFrameHost. It must be done here for main frames, since the
2078 // NotifySwappedFromRenderManager expects view_ to already be created and that
2079 // happens after RenderFrameHostManager::Init.
2080 NotifySwappedFromRenderManager(
2081 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:192082}
2083
[email protected]7fff43e2013-05-21 20:21:102084void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
2085 RemoveDestructionObserver(web_contents);
2086
[email protected]ceee8cd2013-03-08 04:59:512087 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:532088 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:512089 ++iter) {
erikchenbee5c9622018-04-27 19:30:252090 if (iter->second.get() != web_contents)
[email protected]ceee8cd2013-03-08 04:59:512091 continue;
erikchenbee5c9622018-04-27 19:30:252092
2093 // Someone else has deleted the WebContents. That should never happen!
2094 // TODO(erikchen): Fix semantics here. https://crbug.com/832879.
2095 iter->second.release();
[email protected]ceee8cd2013-03-08 04:59:512096 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:512097 return;
2098 }
2099 NOTREACHED();
[email protected]14392a52012-05-02 20:28:442100}
2101
[email protected]7fff43e2013-05-21 20:21:102102void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
2103 if (!ContainsKey(destruction_observers_, web_contents)) {
2104 destruction_observers_[web_contents] =
Jeremy Roman04f27c372017-10-27 15:20:552105 std::make_unique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:102106 }
2107}
2108
2109void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:462110 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:102111}
2112
[email protected]b172aee2012-04-10 17:05:262113void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312114 observers_.AddObserver(observer);
2115}
2116
[email protected]b172aee2012-04-10 17:05:262117void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312118 observers_.RemoveObserver(observer);
2119}
2120
[email protected]948481d2014-06-11 18:32:222121std::set<RenderWidgetHostView*>
2122WebContentsImpl::GetRenderWidgetHostViewsInTree() {
2123 std::set<RenderWidgetHostView*> set;
2124 if (ShowingInterstitialPage()) {
lfgf949e0e2017-05-10 22:18:112125 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView())
2126 set.insert(rwhv);
[email protected]948481d2014-06-11 18:32:222127 } else {
dchengafb53e22016-02-04 08:11:082128 for (RenderFrameHost* rfh : GetAllFrames()) {
lfgf949e0e2017-05-10 22:18:112129 if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
2130 ->frame_tree_node()
2131 ->render_manager()
2132 ->GetRenderWidgetHostView()) {
2133 set.insert(rwhv);
2134 }
dchengafb53e22016-02-04 08:11:082135 }
[email protected]948481d2014-06-11 18:32:222136 }
[email protected]de3c5d82014-05-28 22:12:592137 return set;
2138}
2139
[email protected]b172aee2012-04-10 17:05:262140void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:342141 if (delegate_)
2142 delegate_->ActivateContents(this);
2143}
2144
avi3e4b8512015-11-11 01:55:492145void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
2146 if (!RenderViewHostImpl::From(render_widget_host))
2147 return;
2148
[email protected]63954792011-07-11 04:17:482149 if (delegate_)
2150 delegate_->LostCapture();
2151}
2152
Steven Holte38041342018-06-22 22:00:572153ukm::SourceId WebContentsImpl::GetUkmSourceIdForLastCommittedSource() const {
2154 return last_committed_source_id_;
2155}
2156
lazyboy63f5b312015-11-23 20:19:522157void WebContentsImpl::RenderWidgetCreated(
2158 RenderWidgetHostImpl* render_widget_host) {
2159 created_widgets_.insert(render_widget_host);
2160}
2161
[email protected]b24b68a2012-09-24 21:57:262162void WebContentsImpl::RenderWidgetDeleted(
2163 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:522164 // Note that |is_being_destroyed_| can be true at this point as
2165 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
2166 // us here.
2167 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262168
lazyboy63f5b312015-11-23 20:19:522169 if (is_being_destroyed_)
2170 return;
[email protected]44470a22013-01-24 01:21:542171
2172 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:372173 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
2174 render_widget_host->GetProcess()->GetID() ==
2175 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:492176 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:532177 delegate_->ExitFullscreenModeForTab(this);
ericwilligersde386342016-10-19 02:35:092178 for (auto& observer : observers_)
2179 observer.DidDestroyFullscreenWidget();
alexmosc9e76ec2016-05-16 22:59:372180 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:542181 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:032182 if (fullscreen_widget_had_focus_at_shutdown_)
2183 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:542184 }
lfgbee1e0a2016-06-08 21:24:212185
lfg7d4caad2017-03-22 09:01:452186 if (render_widget_host == mouse_lock_widget_)
lfgff8dfc8d2016-10-21 17:42:322187 LostMouseLock(mouse_lock_widget_);
Joe Downing192998b22018-03-22 15:51:362188
Joe Downingc1a57efe2018-05-09 18:23:542189 CancelKeyboardLock(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262190}
2191
miu9e14e492014-10-25 02:39:042192void WebContentsImpl::RenderWidgetGotFocus(
2193 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:372194 // Notify the observers if an embedded fullscreen widget was focused.
2195 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2196 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
Michael Thiessen896405db2017-07-20 17:52:322197 NotifyWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:372198 }
miu9e14e492014-10-25 02:39:042199}
2200
zijiehe3bee08e22017-05-17 04:14:462201void WebContentsImpl::RenderWidgetLostFocus(
2202 RenderWidgetHostImpl* render_widget_host) {
Michael Thiessen896405db2017-07-20 17:52:322203 // Notify the observers if an embedded fullscreen widget lost focus.
2204 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2205 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
2206 NotifyWebContentsLostFocus(render_widget_host);
2207 }
zijiehe3bee08e22017-05-17 04:14:462208}
2209
estaded0a0c992015-01-21 14:12:062210void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:312211 RenderWidgetHostImpl* render_widget_host,
Christopher Cameron07f666b2018-02-13 23:41:192212 const ScreenInfo& screen_info,
rouslan2f5993f2015-01-29 00:18:312213 bool width_changed) {
creisc014b402015-04-23 16:41:452214 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:292215 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:062216 return;
estaded0a0c992015-01-21 14:12:062217
lfg8d649cc2017-04-28 18:04:302218 SendPageMessage(new PageMsg_UpdateScreenInfo(MSG_ROUTING_NONE, screen_info));
2219
ericwilligersde386342016-10-19 02:35:092220 for (auto& observer : observers_)
2221 observer.MainFrameWasResized(width_changed);
estaded0a0c992015-01-21 14:12:062222}
2223
skyf65d9bb2017-03-24 02:26:392224KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(
2225 const NativeWebKeyboardEvent& event) {
2226 return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event)
2227 : KeyboardEventProcessingResult::NOT_HANDLED;
[email protected]63954792011-07-11 04:17:482228}
2229
[email protected]b172aee2012-04-10 17:05:262230void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:102231 if (browser_plugin_embedder_ &&
2232 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
2233 return;
2234 }
[email protected]63954792011-07-11 04:17:482235 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132236 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:482237}
2238
[email protected]d92026ef2014-03-03 21:04:132239bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:462240 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:192241#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:332242 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
2243 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:192244 // -the OS already has a gesture to do this through pinch-zoom
2245 // -if a user starts an inertial scroll, let's go, and presses control
2246 // (i.e. control+tab) then the OS's buffered scroll events will come in
2247 // with control key set which isn't what the user wants
Blink Reformat1c4d759e2017-04-09 16:34:542248 if (delegate_ && event.wheel_ticks_y &&
chongz4a9751942016-08-17 17:49:392249 !ui::WebInputEventTraits::CanCauseScroll(event)) {
w.shackleton49bcd392016-01-06 17:38:222250 // Count only integer cumulative scrolls as zoom events; this handles
2251 // smooth scroll and regular scroll device behavior.
Blink Reformat1c4d759e2017-04-09 16:34:542252 zoom_scroll_remainder_ += event.wheel_ticks_y;
w.shackleton49bcd392016-01-06 17:38:222253 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
2254 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
2255 if (whole_zoom_scroll_remainder_ != 0) {
2256 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
2257 }
[email protected]fb3f066e2013-02-12 19:12:522258 return true;
2259 }
[email protected]bccc4472013-04-18 16:37:192260#endif
[email protected]fb3f066e2013-02-12 19:12:522261 return false;
2262}
2263
[email protected]04bce562014-01-30 05:34:542264bool WebContentsImpl::PreHandleGestureEvent(
2265 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:032266 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:542267}
2268
kenrb2a565f82015-09-02 20:24:592269RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:452270 if (!is_being_destroyed_ && GetOuterWebContents())
2271 return GetOuterWebContents()->GetInputEventRouter();
2272
2273 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:592274 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
2275 return rwh_input_event_router_.get();
2276}
2277
alexmos3fcd0ca2015-10-23 18:18:332278void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
2279 // Focus loss may occur while this WebContents is being destroyed. Don't
2280 // send the message in this case, as the main frame's RenderFrameHost and
2281 // other state has already been cleared.
2282 if (is_being_destroyed_)
2283 return;
2284
2285 frame_tree_.ReplicatePageFocus(is_focused);
2286}
2287
alexmosc4cbacb2015-11-21 01:29:222288RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
2289 RenderWidgetHostImpl* receiving_widget) {
alexmosc4cbacb2015-11-21 01:29:222290 // Events for widgets other than the main frame (e.g., popup menus) should be
2291 // forwarded directly to the widget they arrived on.
2292 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
2293 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522294
lfg1453e412017-04-11 00:48:502295 WebContentsImpl* focused_contents = GetFocusedWebContents();
2296
2297 // If the focused WebContents is showing an interstitial, return the
2298 // interstitial's widget.
2299 if (focused_contents->ShowingInterstitialPage()) {
2300 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112301 focused_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502302 ->GetRenderWidgetHost();
2303 }
2304
paulmeyerfeafc2d2017-04-25 21:46:402305 // If the focused WebContents is a guest WebContents, then get the focused
2306 // frame in the embedder WebContents instead.
2307 FrameTreeNode* focused_frame = nullptr;
2308 if (focused_contents->browser_plugin_guest_ &&
2309 !GuestMode::IsCrossProcessFrameGuest(focused_contents)) {
2310 focused_frame = frame_tree_.GetFocusedFrame();
2311 } else {
2312 focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
2313 }
lfg1453e412017-04-11 00:48:502314
alexmosc4d183e2015-11-06 00:46:522315 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:222316 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522317
alexmos732ca3a2015-12-08 02:01:022318 // The view may be null if a subframe's renderer process has crashed while
2319 // the subframe has focus. Drop the event in that case. Do not give
2320 // it to the main frame, so that the user doesn't unexpectedly type into the
2321 // wrong frame if a focused subframe renderer crashes while they type.
2322 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
2323 if (!view)
2324 return nullptr;
2325
2326 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:522327}
2328
avallee9993fca2016-11-17 06:16:502329RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
lfg1453e412017-04-11 00:48:502330 WebContentsImpl* focused_web_contents = GetFocusedWebContents();
2331
2332 if (focused_web_contents->ShowingInterstitialPage()) {
2333 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112334 focused_web_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502335 ->GetRenderWidgetHost();
2336 }
Alex Valléedc80ae2ed2017-09-06 21:55:442337 if (!GuestMode::IsCrossProcessFrameGuest(focused_web_contents) &&
2338 focused_web_contents->browser_plugin_guest_) {
2339 // If this is a guest, we need to be controlled by our embedder.
2340 return focused_web_contents->GetOuterWebContents()
2341 ->GetMainFrame()
2342 ->GetRenderWidgetHost();
2343 }
lfg1453e412017-04-11 00:48:502344
2345 return focused_web_contents->GetMainFrame()->GetRenderWidgetHost();
avallee9993fca2016-11-17 06:16:502346}
2347
Dave Tapuska3ed44192018-05-01 18:53:302348void WebContentsImpl::EnterFullscreenMode(
2349 const GURL& origin,
2350 const blink::WebFullscreenOptions& options) {
mlamouri7a78d6fd2015-01-17 13:23:532351 // This method is being called to enter renderer-initiated fullscreen mode.
2352 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:492353 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372354 if (widget_view) {
2355 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2356 ->ShutdownAndDestroyWidget(true);
2357 }
[email protected]4aebbca2013-09-17 22:26:492358
Joe Downing13dd76b2018-04-09 18:32:152359 if (delegate_) {
Dave Tapuska3ed44192018-05-01 18:53:302360 delegate_->EnterFullscreenModeForTab(this, origin, options);
mlamouri7a78d6fd2015-01-17 13:23:532361
Joe Downing13dd76b2018-04-09 18:32:152362 if (keyboard_lock_widget_)
2363 delegate_->RequestKeyboardLock(this, esc_key_locked_);
2364 }
2365
ericwilligersde386342016-10-19 02:35:092366 for (auto& observer : observers_)
2367 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false);
mlamouri7a78d6fd2015-01-17 13:23:532368}
2369
bokanece34a82016-01-28 19:49:462370void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532371 // This method is being called to leave renderer-initiated fullscreen mode.
2372 // Make sure any existing fullscreen widget is shut down first.
2373 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372374 if (widget_view) {
2375 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2376 ->ShutdownAndDestroyWidget(true);
2377 }
mlamouri7a78d6fd2015-01-17 13:23:532378
hugo.holgersson61288e6c2015-01-28 17:04:402379#if defined(OS_ANDROID)
2380 ContentVideoView* video_view = ContentVideoView::GetInstance();
2381 if (video_view != NULL)
watk98292292016-01-19 22:24:082382 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:402383#endif
2384
Joe Downing13dd76b2018-04-09 18:32:152385 if (delegate_) {
mlamouri7a78d6fd2015-01-17 13:23:532386 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:372387
Joe Downing13dd76b2018-04-09 18:32:152388 if (keyboard_lock_widget_)
2389 delegate_->CancelKeyboardLockRequest(this);
2390 }
2391
bokanece34a82016-01-28 19:49:462392 // The fullscreen state is communicated to the renderer through a resize
2393 // message. If the change in fullscreen state doesn't cause a view resize
2394 // then we must ensure web contents exit the fullscreen state by explicitly
2395 // sending a resize message. This is required for the situation of the browser
2396 // moving the view into a "browser fullscreen" state and then the contents
2397 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
2398 // have the side effect of the view resizing, hence the explicit call here is
2399 // required.
2400 if (!will_cause_resize) {
2401 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
2402 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:162403 render_widget_host->SynchronizeVisualProperties();
bokanece34a82016-01-28 19:49:462404 }
scheib3dcb6c932015-02-23 10:55:582405 }
2406
Becca Hughese9e27952018-06-25 17:08:272407 // Clear the current fullscreen frame ID.
2408 current_fullscreen_frame_tree_node_id_ = RenderFrameHost::kNoFrameTreeNodeId;
2409
ericwilligersde386342016-10-19 02:35:092410 for (auto& observer : observers_) {
2411 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
2412 will_cause_resize);
2413 }
[email protected]8a5e0ca2011-08-25 06:30:472414}
2415
Becca Hughesfd5d8f892018-06-14 18:23:362416void WebContentsImpl::FullscreenStateChanged(RenderFrameHost* rfh,
2417 bool is_fullscreen) {
2418 int frame_tree_node_id = rfh->GetFrameTreeNodeId();
2419 auto it = fullscreen_frame_tree_nodes_.find(frame_tree_node_id);
2420 bool changed = false;
2421
2422 if (is_fullscreen) {
2423 // If we are fullscreen then add the FrameTreeNode ID to the set.
2424 if (it == fullscreen_frame_tree_nodes_.end()) {
2425 fullscreen_frame_tree_nodes_.insert(frame_tree_node_id);
2426 changed = true;
2427 }
2428 } else {
2429 FrameTreeNode* ancestor =
2430 static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node();
2431 DCHECK(ancestor);
2432
2433 // If we are not fullscreen then remove this frame and any descendants
2434 // from the set.
2435 for (it = fullscreen_frame_tree_nodes_.begin();
2436 it != fullscreen_frame_tree_nodes_.end();) {
2437 FrameTreeNode* node = FrameTreeNode::GloballyFindByID(*it);
2438
2439 if (!node || frame_tree_node_id == *it ||
2440 node->IsDescendantOf(ancestor)) {
2441 it = fullscreen_frame_tree_nodes_.erase(it);
2442 changed = true;
2443 } else {
2444 ++it;
2445 }
2446 }
2447 }
2448
2449 // If we have changed then find the current fullscreen FrameTreeNode
2450 // and call the observers. If we have exited fullscreen then this
2451 // will be the last frame that was fullscreen.
2452 if (changed && fullscreen_frame_tree_nodes_.size() > 0) {
2453 unsigned int max_depth = 0;
2454 RenderFrameHost* max_depth_rfh = nullptr;
2455
2456 for (auto node_id : fullscreen_frame_tree_nodes_) {
2457 FrameTreeNode* fullscreen_node = FrameTreeNode::GloballyFindByID(node_id);
2458 DCHECK(fullscreen_node);
2459
2460 if (max_depth_rfh == nullptr || fullscreen_node->depth() > max_depth) {
2461 max_depth = fullscreen_node->depth();
2462 max_depth_rfh = fullscreen_node->current_frame_host();
2463 }
2464 }
2465
2466 // If we have already notified observers about this frame then we should not
2467 // fire the observers again.
2468 DCHECK(max_depth_rfh);
2469 if (max_depth_rfh->GetFrameTreeNodeId() ==
2470 current_fullscreen_frame_tree_node_id_)
2471 return;
2472
2473 current_fullscreen_frame_tree_node_id_ =
2474 max_depth_rfh->GetFrameTreeNodeId();
2475
2476 for (auto& observer : observers_)
2477 observer.DidAcquireFullscreen(max_depth_rfh);
2478 } else if (fullscreen_frame_tree_nodes_.size() == 0) {
2479 current_fullscreen_frame_tree_node_id_ =
2480 RenderFrameHost::kNoFrameTreeNodeId;
2481 }
2482}
2483
alexmos5dd617d2016-06-07 04:21:152484bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:382485 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:122486}
2487
billorr21c005d2016-11-17 03:57:042488bool WebContentsImpl::IsFullscreen() {
2489 return IsFullscreenForCurrentTab();
2490}
2491
avibf58fa0c2015-11-11 01:45:522492blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
2493 RenderWidgetHostImpl* render_widget_host) const {
2494 if (!RenderViewHostImpl::From(render_widget_host))
Blink Reformat1c4d759e2017-04-09 16:34:542495 return blink::kWebDisplayModeBrowser;
avibf58fa0c2015-11-11 01:45:522496
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122497 return delegate_ ? delegate_->GetDisplayMode(this)
Blink Reformat1c4d759e2017-04-09 16:34:542498 : blink::kWebDisplayModeBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122499}
2500
avic3aa8422015-11-09 20:57:222501void WebContentsImpl::RequestToLockMouse(
2502 RenderWidgetHostImpl* render_widget_host,
2503 bool user_gesture,
lfgad8244352016-07-13 16:55:512504 bool last_unlocked_by_target,
2505 bool privileged) {
lfgf0cd46e2017-01-04 00:05:232506 for (WebContentsImpl* current = this; current;
2507 current = current->GetOuterWebContents()) {
2508 if (current->mouse_lock_widget_) {
2509 render_widget_host->GotResponseToLockMouseRequest(false);
2510 return;
2511 }
[email protected]e9621112011-10-17 05:38:372512 }
avic3aa8422015-11-09 20:57:222513
lfgad8244352016-07-13 16:55:512514 if (privileged) {
lfgf0cd46e2017-01-04 00:05:232515 DCHECK(!GetOuterWebContents());
lfgad8244352016-07-13 16:55:512516 mouse_lock_widget_ = render_widget_host;
2517 render_widget_host->GotResponseToLockMouseRequest(true);
2518 return;
2519 }
2520
lfgbee1e0a2016-06-08 21:24:212521 bool widget_in_frame_tree = false;
2522 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2523 if (node->current_frame_host()->GetRenderWidgetHost() ==
2524 render_widget_host) {
2525 widget_in_frame_tree = true;
2526 break;
2527 }
2528 }
2529
2530 if (widget_in_frame_tree && delegate_) {
lfgf0cd46e2017-01-04 00:05:232531 for (WebContentsImpl* current = this; current;
2532 current = current->GetOuterWebContents()) {
2533 current->mouse_lock_widget_ = render_widget_host;
2534 }
2535
avic3aa8422015-11-09 20:57:222536 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:212537 } else {
2538 render_widget_host->GotResponseToLockMouseRequest(false);
2539 }
[email protected]e9621112011-10-17 05:38:372540}
2541
avi3e4b8512015-11-11 01:55:492542void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:212543 CHECK(mouse_lock_widget_);
lfgf0cd46e2017-01-04 00:05:232544
2545 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this)
2546 return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host);
2547
lfgbee1e0a2016-06-08 21:24:212548 mouse_lock_widget_->SendMouseLockLost();
lfgf0cd46e2017-01-04 00:05:232549 for (WebContentsImpl* current = this; current;
2550 current = current->GetOuterWebContents()) {
2551 current->mouse_lock_widget_ = nullptr;
2552 }
avi3e4b8512015-11-11 01:55:492553
[email protected]e9621112011-10-17 05:38:372554 if (delegate_)
2555 delegate_->LostMouseLock();
2556}
2557
lfgad8244352016-07-13 16:55:512558bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
2559 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
2560 // assigned to the widget that requested the mouse lock, and the top-level
2561 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
2562 return mouse_lock_widget_ == render_widget_host &&
2563 GetTopLevelRenderWidgetHostView()->IsMouseLocked();
2564}
2565
lfg84763c92017-02-16 18:55:152566RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() {
lfge2176fb2017-03-26 00:45:472567 if (GetTopLevelRenderWidgetHostView()->IsMouseLocked() ||
2568 (GetFullscreenRenderWidgetHostView() &&
2569 GetFullscreenRenderWidgetHostView()->IsMouseLocked()))
lfg84763c92017-02-16 18:55:152570 return mouse_lock_widget_;
2571
2572 return nullptr;
2573}
2574
Joe Downing192998b22018-03-22 15:51:362575bool WebContentsImpl::RequestKeyboardLock(
Joe Downing13dd76b2018-04-09 18:32:152576 RenderWidgetHostImpl* render_widget_host,
2577 bool esc_key_locked) {
Joe Downing192998b22018-03-22 15:51:362578 DCHECK(render_widget_host);
Joe Downing192998b22018-03-22 15:51:362579 if (render_widget_host->delegate()->GetAsWebContents() != this) {
2580 NOTREACHED();
2581 return false;
2582 }
2583
2584 // KeyboardLock is only supported when called by the top-level browsing
2585 // context and is not supported in embedded content scenarios.
2586 if (GetOuterWebContents())
2587 return false;
2588
Joe Downing13dd76b2018-04-09 18:32:152589 esc_key_locked_ = esc_key_locked;
Joe Downing192998b22018-03-22 15:51:362590 keyboard_lock_widget_ = render_widget_host;
2591
Joe Downing13dd76b2018-04-09 18:32:152592 if (delegate_)
2593 delegate_->RequestKeyboardLock(this, esc_key_locked_);
Joe Downing192998b22018-03-22 15:51:362594 return true;
2595}
2596
2597void WebContentsImpl::CancelKeyboardLock(
2598 RenderWidgetHostImpl* render_widget_host) {
2599 if (!keyboard_lock_widget_ || render_widget_host != keyboard_lock_widget_)
2600 return;
2601
2602 RenderWidgetHostImpl* old_keyboard_lock_widget = keyboard_lock_widget_;
2603 keyboard_lock_widget_ = nullptr;
2604
Joe Downing13dd76b2018-04-09 18:32:152605 if (delegate_)
2606 delegate_->CancelKeyboardLockRequest(this);
2607
Joe Downing192998b22018-03-22 15:51:362608 old_keyboard_lock_widget->CancelKeyboardLock();
2609}
2610
2611RenderWidgetHostImpl* WebContentsImpl::GetKeyboardLockWidget() {
2612 return keyboard_lock_widget_;
2613}
2614
ekaramada4f42692016-02-11 19:48:372615void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
lfg9462cef2016-07-18 23:51:062616 if (visible && !GetOuterWebContents()->IsHidden())
ekaramada4f42692016-02-11 19:48:372617 WasShown();
lfg9462cef2016-07-18 23:51:062618 else if (!visible)
ekaramada4f42692016-02-11 19:48:372619 WasHidden();
2620}
2621
[email protected]bafe6cd2012-05-23 23:09:502622void WebContentsImpl::CreateNewWindow(
csharrison95f01e922017-04-24 18:52:352623 RenderFrameHost* opener,
nick5ae4d2d2017-01-06 01:18:352624 int32_t render_view_route_id,
dcheng3ce04b62015-10-26 23:30:552625 int32_t main_frame_route_id,
2626 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:182627 const mojom::CreateNewWindowParams& params,
[email protected]97714c82012-06-06 10:15:132628 SessionStorageNamespace* session_storage_namespace) {
nick5ae4d2d2017-01-06 01:18:352629 // We should have zero valid routing ids, or three valid routing IDs.
2630 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2631 (main_frame_route_id == MSG_ROUTING_NONE));
2632 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2633 (main_frame_widget_route_id == MSG_ROUTING_NONE));
csharrison95f01e922017-04-24 18:52:352634 DCHECK(opener);
nick5ae4d2d2017-01-06 01:18:352635
csharrison95f01e922017-04-24 18:52:352636 int render_process_id = opener->GetProcess()->GetID();
2637 SiteInstance* source_site_instance = opener->GetSiteInstance();
2638
2639 // The route IDs passed into this function can be trusted not to already
2640 // be in use; they were allocated by the RenderWidgetHelper by the caller.
nick5ae4d2d2017-01-06 01:18:352641 DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id));
2642
[email protected]bafe6cd2012-05-23 23:09:502643 // We usually create the new window in the same BrowsingInstance (group of
2644 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:552645 // if the opener is being suppressed (in a non-guest), we create a new
2646 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:252647 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:552648
[email protected]04cbd3d2013-12-04 04:58:202649 // If the opener is to be suppressed, the new window can be in any process.
2650 // Since routing ids are process specific, we must not have one passed in
2651 // as argument here.
nick5ae4d2d2017-01-06 01:18:352652 DCHECK(!params.opener_suppressed || render_view_route_id == MSG_ROUTING_NONE);
[email protected]04cbd3d2013-12-04 04:58:202653
[email protected]bafe6cd2012-05-23 23:09:502654 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:432655 params.opener_suppressed && !is_guest
2656 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
2657 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:502658
[email protected]d1198fd2012-08-13 22:50:192659 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:342660 //
2661 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:302662 const std::string& partition_id =
2663 GetContentClient()->browser()->
2664 GetStoragePartitionIdForSite(GetBrowserContext(),
2665 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:462666 StoragePartition* partition = BrowserContext::GetStoragePartition(
2667 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:412668 DOMStorageContextWrapper* dom_storage_context =
2669 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:192670 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2671 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2672 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:372673
2674 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:552675 !delegate_->ShouldCreateWebContents(
lukasza6f8ac622017-06-06 03:10:202676 this, opener, source_site_instance, render_view_route_id,
2677 main_frame_route_id, main_frame_widget_route_id,
2678 params.window_container_type, opener->GetLastCommittedURL(),
2679 params.frame_name, params.target_url, partition_id,
2680 session_storage_namespace)) {
jambaaab3a2016-11-05 00:46:182681 // Note: even though we're not creating a WebContents here, it could have
2682 // been created by the embedder so ensure that the RenderFrameHost is
2683 // properly initialized.
csharrisona2280cd2016-02-03 23:21:152684 // It's safe to only target the frame because the render process will not
2685 // have a chance to create more frames at this point.
jambaaab3a2016-11-05 00:46:182686 RenderFrameHostImpl* rfh =
2687 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id);
nick5ae4d2d2017-01-06 01:18:352688 if (rfh) {
2689 DCHECK(rfh->IsRenderFrameLive());
jambaaab3a2016-11-05 00:46:182690 rfh->Init();
nick5ae4d2d2017-01-06 01:18:352691 }
[email protected]dd6730412013-08-14 15:03:372692 return;
2693 }
2694
2695 // Create the new web contents. This will automatically create the new
2696 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462697 CreateParams create_params(GetBrowserContext(), site_instance.get());
nick5ae4d2d2017-01-06 01:18:352698 create_params.routing_id = render_view_route_id;
[email protected]227692c52013-05-31 22:43:042699 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:552700 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:122701 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432702 create_params.opener_render_process_id = render_process_id;
csharrison95f01e922017-04-24 18:52:352703 create_params.opener_render_frame_id = opener->GetRoutingID();
[email protected]50d326e2014-05-20 17:59:062704 create_params.opener_suppressed = params.opener_suppressed;
nick3b04f322016-08-31 19:29:192705 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
[email protected]50d326e2014-05-20 17:59:062706 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:192707 create_params.renderer_initiated_creation =
2708 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:062709
erikchenbee5c9622018-04-27 19:30:252710 std::unique_ptr<WebContents> new_contents;
[email protected]c4538072013-03-18 02:17:552711 if (!is_guest) {
2712 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:452713 create_params.initial_size = GetContainerBounds().size();
Erik Chenbb8e738e2018-04-28 14:10:432714 new_contents = WebContents::Create(create_params);
[email protected]4858e432014-06-23 18:14:172715 } else {
erikchenbee5c9622018-04-27 19:30:252716 new_contents = base::WrapUnique(
2717 GetBrowserPluginGuest()->CreateNewGuestWindow(create_params));
[email protected]c4538072013-03-18 02:17:552718 }
erikchenbee5c9622018-04-27 19:30:252719 WebContentsImpl* raw_new_contents =
2720 static_cast<WebContentsImpl*>(new_contents.get());
2721 raw_new_contents->GetController().SetSessionStorageNamespace(
2722 partition_id, session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192723
alexmos646fec02015-07-25 00:11:492724 // If the new frame has a name, make sure any SiteInstances that can find
2725 // this named frame have proxies for it. Must be called after
2726 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2727 // GetSessionStorageNamespace.
2728 if (!params.frame_name.empty())
erikchenbee5c9622018-04-27 19:30:252729 raw_new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
alexmos646fec02015-07-25 00:11:492730
[email protected]c4538072013-03-18 02:17:552731 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342732 // will be shown immediately).
2733 if (!params.opener_suppressed) {
2734 if (!is_guest) {
erikchenbee5c9622018-04-27 19:30:252735 WebContentsView* new_view = raw_new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502736
[email protected]d70bea92013-04-05 04:23:342737 // TODO(brettw): It seems bogus that we have to call this function on the
2738 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:432739 new_view->CreateViewForWidget(
2740 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:342741 }
[email protected]bafe6cd2012-05-23 23:09:502742 // Save the created window associated with the route so we can show it
2743 // later.
nick5ae4d2d2017-01-06 01:18:352744 DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id);
erikchenbee5c9622018-04-27 19:30:252745 pending_contents_[std::make_pair(render_process_id,
2746 main_frame_widget_route_id)] =
2747 std::move(new_contents);
2748 AddDestructionObserver(raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502749 }
2750
2751 if (delegate_) {
Bryan McQuaded2b93c02017-07-14 22:26:312752 delegate_->WebContentsCreated(this, render_process_id,
2753 opener->GetRoutingID(), params.frame_name,
erikchenbee5c9622018-04-27 19:30:252754 params.target_url, raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502755 }
2756
csharrison95f01e922017-04-24 18:52:352757 if (opener) {
pnolandaae574e2017-03-06 21:04:212758 for (auto& observer : observers_) {
erikchenbee5c9622018-04-27 19:30:252759 observer.DidOpenRequestedURL(raw_new_contents, opener, params.target_url,
csharrison95f01e922017-04-24 18:52:352760 params.referrer, params.disposition,
2761 ui::PAGE_TRANSITION_LINK,
pnolandaae574e2017-03-06 21:04:212762 false, // started_from_context_menu
2763 true); // renderer_initiated
2764 }
2765 }
2766
Avi Drissmanba3b1b342017-08-29 18:16:132767 // Any new WebContents opened while this WebContents is in fullscreen can be
2768 // used to confuse the user, so drop fullscreen.
2769 if (IsFullscreenForCurrentTab())
2770 ExitFullscreen(true);
2771
[email protected]bafe6cd2012-05-23 23:09:502772 if (params.opener_suppressed) {
2773 // When the opener is suppressed, the original renderer cannot access the
2774 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002775 bool was_blocked = false;
erikchenbee5c9622018-04-27 19:30:252776
2777 base::WeakPtr<WebContentsImpl> weak_new_contents =
2778 raw_new_contents->weak_factory_.GetWeakPtr();
[email protected]eda238a12012-09-07 23:44:002779 if (delegate_) {
bokan107a47f2015-02-03 23:23:392780 gfx::Rect initial_rect;
nick0d558482017-02-13 22:27:222781
erikchenbee5c9622018-04-27 19:30:252782 delegate_->AddNewContents(this, std::move(new_contents),
2783 params.disposition, initial_rect,
Mustaq Ahmedc4cb7162018-06-05 16:28:362784 params.mimic_user_gesture, &was_blocked);
nick0d558482017-02-13 22:27:222785 if (!weak_new_contents)
2786 return; // The delegate deleted |new_contents| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002787 }
erikchenbee5c9622018-04-27 19:30:252788
[email protected]eda238a12012-09-07 23:44:002789 if (!was_blocked) {
nick3b04f322016-08-31 19:29:192790 OpenURLParams open_params(params.target_url, params.referrer,
2791 WindowOpenDisposition::CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352792 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212793 true /* is_renderer_initiated */);
Mustaq Ahmedc4cb7162018-06-05 16:28:362794 open_params.user_gesture = params.mimic_user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372795
2796 if (delegate_ && !is_guest &&
2797 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
erikchenbee5c9622018-04-27 19:30:252798 DCHECK(weak_new_contents);
mariakhomenkoa4971c12015-07-21 19:04:372799 // We are in asynchronous add new contents path, delay opening url
erikchenbee5c9622018-04-27 19:30:252800 weak_new_contents->delayed_open_url_params_.reset(
mariakhomenkoa4971c12015-07-21 19:04:372801 new OpenURLParams(open_params));
2802 } else {
erikchenbee5c9622018-04-27 19:30:252803 weak_new_contents->OpenURL(open_params);
mariakhomenkoa4971c12015-07-21 19:04:372804 }
[email protected]eda238a12012-09-07 23:44:002805 }
[email protected]bafe6cd2012-05-23 23:09:502806 }
2807}
2808
avib7348942015-12-25 20:57:102809void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2810 int32_t route_id,
Dave Tapuska1bdf1832017-07-07 18:07:192811 mojom::WidgetPtr widget,
[email protected]180ef242013-11-07 06:50:462812 blink::WebPopupType popup_type) {
Dave Tapuska1bdf1832017-07-07 18:07:192813 CreateNewWidget(render_process_id, route_id, false, std::move(widget),
2814 popup_type);
[email protected]bafe6cd2012-05-23 23:09:502815}
2816
avib7348942015-12-25 20:57:102817void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
Dave Tapuska1bdf1832017-07-07 18:07:192818 int32_t route_id,
2819 mojom::WidgetPtr widget) {
2820 CreateNewWidget(render_process_id, route_id, true, std::move(widget),
2821 blink::kWebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502822}
2823
avib7348942015-12-25 20:57:102824void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2825 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502826 bool is_fullscreen,
Dave Tapuska1bdf1832017-07-07 18:07:192827 mojom::WidgetPtr widget,
[email protected]180ef242013-11-07 06:50:462828 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252829 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232830 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512831 // this WebContentsImpl instance. If any other process sends the request,
2832 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382833 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
Lukasz Anforowicz6f746282018-01-04 23:24:512834 ReceivedBadMessage(process, bad_message::WCI_NEW_WIDGET_PROCESS_MISMATCH);
[email protected]a8504022013-12-04 20:23:512835 return;
2836 }
2837
Dave Tapuska485aca92017-08-08 00:47:582838 RenderWidgetHostImpl* widget_host = new RenderWidgetHostImpl(
2839 this, process, route_id, std::move(widget), IsHidden());
[email protected]b24b68a2012-09-24 21:57:262840
[email protected]cfd80b02014-05-01 17:46:482841 RenderWidgetHostViewBase* widget_view =
2842 static_cast<RenderWidgetHostViewBase*>(
2843 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192844 if (!widget_view)
2845 return;
[email protected]bafe6cd2012-05-23 23:09:502846 if (!is_fullscreen) {
2847 // Popups should not get activated.
2848 widget_view->SetPopupType(popup_type);
2849 }
2850 // Save the created widget associated with the route so we can show it later.
alexmosc2a8cec2016-05-23 22:19:532851 pending_widget_views_[std::make_pair(render_process_id, route_id)] =
2852 widget_view;
[email protected]bafe6cd2012-05-23 23:09:502853}
2854
alexmosc2a8cec2016-05-23 22:19:532855void WebContentsImpl::ShowCreatedWindow(int process_id,
nick5ae4d2d2017-01-06 01:18:352856 int main_frame_widget_route_id,
[email protected]bafe6cd2012-05-23 23:09:502857 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392858 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502859 bool user_gesture) {
erikchenbee5c9622018-04-27 19:30:252860 std::unique_ptr<WebContents> popup =
nick5ae4d2d2017-01-06 01:18:352861 GetCreatedWindow(process_id, main_frame_widget_route_id);
nick0d558482017-02-13 22:27:222862 if (popup) {
erikchenbee5c9622018-04-27 19:30:252863 WebContentsImpl* raw_popup = static_cast<WebContentsImpl*>(popup.get());
[email protected]eda238a12012-09-07 23:44:002864 WebContentsDelegate* delegate = GetDelegate();
erikchenbee5c9622018-04-27 19:30:252865 raw_popup->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382866 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
erikchenbee5c9622018-04-27 19:30:252867 raw_popup->ResumeLoadingCreatedWebContents();
mariakhomenko44bdc4732015-04-29 01:55:382868
erikchenbee5c9622018-04-27 19:30:252869 base::WeakPtr<WebContentsImpl> weak_popup =
2870 raw_popup->weak_factory_.GetWeakPtr();
[email protected]eda238a12012-09-07 23:44:002871 if (delegate) {
erikchenbee5c9622018-04-27 19:30:252872 delegate->AddNewContents(this, std::move(popup), disposition,
2873 initial_rect, user_gesture, nullptr);
nick0d558482017-02-13 22:27:222874 if (!weak_popup)
2875 return; // The delegate deleted |popup| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002876 }
nick5ae4d2d2017-01-06 01:18:352877
erikchenbee5c9622018-04-27 19:30:252878 RenderWidgetHostImpl* rwh =
2879 weak_popup->GetMainFrame()->GetRenderWidgetHost();
nick0d558482017-02-13 22:27:222880 DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID());
Avi Drissman014dec72018-06-07 02:34:012881 rwh->Send(new ViewMsg_SetBounds_ACK(rwh->GetRoutingID()));
[email protected]eda238a12012-09-07 23:44:002882 }
[email protected]bafe6cd2012-05-23 23:09:502883}
2884
alexmosc2a8cec2016-05-23 22:19:532885void WebContentsImpl::ShowCreatedWidget(int process_id,
2886 int route_id,
bokan107a47f2015-02-03 23:23:392887 const gfx::Rect& initial_rect) {
alexmosc2a8cec2016-05-23 22:19:532888 ShowCreatedWidget(process_id, route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502889}
2890
alexmosc2a8cec2016-05-23 22:19:532891void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
2892 int route_id) {
2893 ShowCreatedWidget(process_id, route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:502894}
2895
alexmosc2a8cec2016-05-23 22:19:532896void WebContentsImpl::ShowCreatedWidget(int process_id,
2897 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502898 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392899 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482900 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:532901 static_cast<RenderWidgetHostViewBase*>(
2902 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502903 if (!widget_host_view)
2904 return;
[email protected]cfd80b02014-05-01 17:46:482905
Ivan Kotenkov2c0d2bb32017-11-01 15:41:282906 RenderWidgetHostView* view = nullptr;
lfgc740d4b22016-04-15 16:45:332907 if (GetOuterWebContents()) {
2908 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482909 } else {
2910 view = GetRenderWidgetHostView();
2911 }
2912
[email protected]4aebbca2013-09-17 22:26:492913 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312914 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032915 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:372916 fullscreen_widget_process_id_ =
2917 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:312918 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492919 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2920 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
Dave Tapuska3ed44192018-05-01 18:53:302921 delegate_->EnterFullscreenModeForTab(this, GURL(),
2922 blink::WebFullscreenOptions());
[email protected]4aebbca2013-09-17 22:26:492923 } else {
[email protected]cfd80b02014-05-01 17:46:482924 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492925 }
ericwilligersde386342016-10-19 02:35:092926 for (auto& observer : observers_)
2927 observer.DidShowFullscreenWidget();
[email protected]4aebbca2013-09-17 22:26:492928 if (!widget_host_view->HasFocus())
2929 widget_host_view->Focus();
2930 } else {
bokan107a47f2015-02-03 23:23:392931 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492932 }
[email protected]89054502012-06-03 10:29:242933
yiyixcb1fbc4f2018-03-16 19:54:082934 RenderWidgetHostImpl* render_widget_host_impl = widget_host_view->host();
[email protected]89054502012-06-03 10:29:242935 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312936 // Only allow privileged mouse lock for fullscreen render widget, which is
2937 // used to implement Pepper Flash fullscreen.
2938 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502939}
2940
erikchenbee5c9622018-04-27 19:30:252941std::unique_ptr<WebContents> WebContentsImpl::GetCreatedWindow(
nick5ae4d2d2017-01-06 01:18:352942 int process_id,
2943 int main_frame_widget_route_id) {
2944 auto key = std::make_pair(process_id, main_frame_widget_route_id);
2945 auto iter = pending_contents_.find(key);
[email protected]bafe6cd2012-05-23 23:09:502946
2947 // Certain systems can block the creation of new windows. If we didn't succeed
2948 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:532949 if (iter == pending_contents_.end())
2950 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502951
erikchenbee5c9622018-04-27 19:30:252952 std::unique_ptr<WebContents> new_contents = std::move(iter->second);
nick5ae4d2d2017-01-06 01:18:352953 pending_contents_.erase(key);
erikchenbee5c9622018-04-27 19:30:252954 WebContentsImpl* raw_new_contents =
2955 static_cast<WebContentsImpl*>(new_contents.get());
2956 RemoveDestructionObserver(raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502957
[email protected]d70bea92013-04-05 04:23:342958 // Don't initialize the guest WebContents immediately.
erikchenbee5c9622018-04-27 19:30:252959 if (BrowserPluginGuest::IsGuest(raw_new_contents))
[email protected]d70bea92013-04-05 04:23:342960 return new_contents;
2961
Lukasz Anforowicz5510ed652018-06-06 16:16:192962 if (!new_contents->GetMainFrame()->GetProcess()->IsInitializedAndNotDead() ||
nick5ae4d2d2017-01-06 01:18:352963 !new_contents->GetMainFrame()->GetView()) {
alexmosc2a8cec2016-05-23 22:19:532964 return nullptr;
nick5ae4d2d2017-01-06 01:18:352965 }
[email protected]bafe6cd2012-05-23 23:09:502966
[email protected]bafe6cd2012-05-23 23:09:502967 return new_contents;
2968}
2969
alexmosc2a8cec2016-05-23 22:19:532970RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
2971 int route_id) {
2972 auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502973 if (iter == pending_widget_views_.end()) {
2974 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:532975 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502976 }
2977
2978 RenderWidgetHostView* widget_host_view = iter->second;
alexmosc2a8cec2016-05-23 22:19:532979 pending_widget_views_.erase(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502980
2981 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
Lukasz Anforowicz5510ed652018-06-06 16:16:192982 if (!widget_host->GetProcess()->IsInitializedAndNotDead()) {
[email protected]bafe6cd2012-05-23 23:09:502983 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:532984 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502985 }
2986
2987 return widget_host_view;
2988}
2989
[email protected]f13b4202012-06-12 23:53:232990void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092991 const MediaStreamRequest& request,
Mark Pilgrim57499082018-06-12 12:38:302992 MediaResponseCallback callback) {
[email protected]d19b84b2014-03-14 11:52:372993 if (delegate_) {
Mark Pilgrim57499082018-06-12 12:38:302994 delegate_->RequestMediaAccessPermission(this, request, std::move(callback));
[email protected]d19b84b2014-03-14 11:52:372995 } else {
Mark Pilgrim57499082018-06-12 12:38:302996 std::move(callback).Run(MediaStreamDevices(),
2997 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2998 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372999 }
[email protected]f13b4202012-06-12 23:53:233000}
3001
Chandan Padhia4b8bcb72017-09-12 16:41:043002bool WebContentsImpl::CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:583003 RenderFrameHost* render_frame_host,
Chandan Padhia4b8bcb72017-09-12 16:41:043004 const url::Origin& security_origin,
3005 MediaStreamType type) {
grunell657d4d82014-09-18 00:09:433006 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
3007 type == MEDIA_DEVICE_VIDEO_CAPTURE);
Chandan Padhia4b8bcb72017-09-12 16:41:043008 return delegate_ && delegate_->CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:583009 render_frame_host, security_origin.GetURL(), type);
grunell657d4d82014-09-18 00:09:433010}
3011
guidou8a440b842017-01-30 13:58:433012std::string WebContentsImpl::GetDefaultMediaDeviceID(MediaStreamType type) {
3013 if (!delegate_)
3014 return std::string();
3015 return delegate_->GetDefaultMediaDeviceID(this, type);
3016}
3017
[email protected]cc9200432013-07-23 23:02:403018SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
3019 SiteInstance* instance) {
3020 return controller_.GetSessionStorageNamespace(instance);
3021}
3022
[email protected]6de7fc482014-06-06 10:46:443023SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
3024 return controller_.GetSessionStorageNamespaceMap();
3025}
3026
[email protected]9b159a52013-10-03 17:24:553027FrameTree* WebContentsImpl::GetFrameTree() {
3028 return &frame_tree_;
3029}
3030
aelias5252baa2016-04-10 01:18:023031bool WebContentsImpl::IsOverridingUserAgent() {
3032 return GetController().GetVisibleEntry() &&
3033 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
3034}
3035
avi85ee8362016-10-08 02:09:083036bool WebContentsImpl::IsJavaScriptDialogShowing() const {
3037 return is_showing_javascript_dialog_;
3038}
3039
avic031d392017-03-03 03:09:423040bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() {
3041 // Ignore unresponsive renderers if the debugger is attached to them since the
3042 // unresponsiveness might be a result of the renderer sitting on a breakpoint.
3043 //
3044 // TODO(pfeldman): Fix this to only return true if the renderer is *actually*
3045 // sitting on a breakpoint. https://crbug.com/684202
3046 return DevToolsAgentHost::IsDebuggerAttached(this);
3047}
3048
Doug Turner63f3c7b2017-07-29 05:10:013049ui::AXMode WebContentsImpl::GetAccessibilityMode() const {
[email protected]95640212014-07-26 18:14:303050 return accessibility_mode_;
3051}
3052
Dominic Mazzonia7b0edb22017-08-09 16:32:513053void WebContentsImpl::AccessibilityEventReceived(
Dominic Mazzoniccbaa9b2018-06-06 07:44:233054 const AXEventNotificationDetails& details) {
ericwilligersde386342016-10-19 02:35:093055 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513056 observer.AccessibilityEventReceived(details);
[email protected]31a71eaf2014-03-13 01:47:363057}
3058
dmazzoni2400c462016-08-23 15:07:133059void WebContentsImpl::AccessibilityLocationChangesReceived(
3060 const std::vector<AXLocationChangeNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:093061 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513062 observer.AccessibilityLocationChangesReceived(details);
dmazzoni2400c462016-08-23 15:07:133063}
3064
dmazzonia656928e2014-09-15 20:28:543065RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:403066 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:543067 int browser_plugin_instance_id) {
3068 BrowserPluginGuestManager* guest_manager =
3069 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:203070 if (!guest_manager)
3071 return nullptr;
3072
dmazzonia656928e2014-09-15 20:28:543073 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:443074 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:543075 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:203076 return nullptr;
3077
dmazzonia656928e2014-09-15 20:28:543078 return guest->GetMainFrame();
3079}
3080
Ke He7319dbe2017-11-09 05:54:443081device::mojom::GeolocationContext* WebContentsImpl::GetGeolocationContext() {
3082 if (geolocation_context_)
3083 return geolocation_context_.get();
3084
3085 auto request = mojo::MakeRequest(&geolocation_context_);
3086 if (!ServiceManagerConnection::GetForProcess())
3087 return geolocation_context_.get();
3088
3089 service_manager::Connector* connector =
3090 ServiceManagerConnection::GetForProcess()->GetConnector();
3091 connector->BindInterface(device::mojom::kServiceName, std::move(request));
Conley Owens6894c4f2017-07-10 19:29:133092 return geolocation_context_.get();
blundellc57b93f2014-10-29 13:19:573093}
3094
ke.he98b761e2017-05-09 05:59:173095device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() {
blundelld8cd72b2017-03-28 07:18:383096 if (!wake_lock_context_host_)
3097 wake_lock_context_host_.reset(new WakeLockContextHost(this));
blundelle75a8f92017-03-27 08:11:173098 return wake_lock_context_host_->GetWakeLockContext();
alogvinovf50445a2015-10-30 13:00:123099}
3100
juncai8e8d6ec2017-06-06 20:48:183101device::mojom::WakeLock* WebContentsImpl::GetRendererWakeLock() {
3102 // WebContents creates a long-lived connection to one WakeLock.
ke.he98b761e2017-05-09 05:59:173103 // All the frames' requests will be added into the BindingSet of
juncai8e8d6ec2017-06-06 20:48:183104 // WakeLock via this connection.
ke.he98b761e2017-05-09 05:59:173105 if (!renderer_wake_lock_) {
3106 device::mojom::WakeLockContext* wake_lock_context = GetWakeLockContext();
3107 if (!wake_lock_context) {
3108 return nullptr;
3109 }
ke.hef435c1e82017-05-11 04:09:103110 wake_lock_context->GetWakeLock(
Daniel Erat28922ba2017-11-08 16:18:263111 device::mojom::WakeLockType::kPreventDisplaySleep,
3112 device::mojom::WakeLockReason::kOther, "Wake Lock API",
ke.hef435c1e82017-05-11 04:09:103113 mojo::MakeRequest(&renderer_wake_lock_));
ke.he98b761e2017-05-09 05:59:173114 }
3115 return renderer_wake_lock_.get();
3116}
3117
blundellf5316fc2017-05-15 11:49:033118#if defined(OS_ANDROID)
Han Leonf6a2e5f2017-05-23 13:40:473119void WebContentsImpl::GetNFC(device::mojom::NFCRequest request) {
blundellf5316fc2017-05-15 11:49:033120 if (!nfc_host_)
3121 nfc_host_.reset(new NFCHost(this));
3122 nfc_host_->GetNFC(std::move(request));
3123}
3124#endif
3125
Evan Stade5e750ad02017-08-07 21:59:273126void WebContentsImpl::SetNotWaitingForResponse() {
3127 if (waiting_for_response_ == false)
3128 return;
3129
3130 waiting_for_response_ = false;
3131 if (delegate_)
3132 delegate_->LoadingStateChanged(this, is_load_to_different_document_);
Chris Hamiltonf82f2a702018-02-15 19:37:293133 for (auto& observer : observers_)
3134 observer.DidReceiveResponse();
Evan Stade5e750ad02017-08-07 21:59:273135}
3136
lfgbb9c28a2016-03-01 03:19:493137void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:373138 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:403139 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:373140 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
3141 }
lfgbb9c28a2016-03-01 03:19:493142
lfgdb5c4ed2016-03-04 23:09:073143 RenderWidgetHostViewBase* rwhv =
3144 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3145 if (rwhv) {
3146 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
3147 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
3148 }
3149
avallee9f43b012016-11-26 07:02:103150 if (browser_plugin_embedder_ && !is_being_destroyed_)
[email protected]a7568e62013-06-14 07:50:443151 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:043152}
3153
ekaramadadd882292016-06-08 15:22:563154TextInputManager* WebContentsImpl::GetTextInputManager() {
3155 if (GetOuterWebContents())
3156 return GetOuterWebContents()->GetTextInputManager();
3157
Darren Shenca53d5f2018-05-15 04:56:013158 if (!text_input_manager_) {
3159 text_input_manager_.reset(new TextInputManager(
3160 GetBrowserContext() &&
3161 !GetBrowserContext()->IsOffTheRecord()) /* should_do_learning */);
3162 }
ekaramadadd882292016-06-08 15:22:563163
3164 return text_input_manager_.get();
3165}
3166
paulmeyer7f6f1d4f2016-11-15 00:00:273167bool WebContentsImpl::OnUpdateDragCursor() {
3168 if (browser_plugin_embedder_)
3169 return browser_plugin_embedder_->OnUpdateDragCursor();
3170 return false;
3171}
3172
kenrb11f213a2017-03-24 18:12:063173bool WebContentsImpl::IsWidgetForMainFrame(
3174 RenderWidgetHostImpl* render_widget_host) {
3175 return render_widget_host == GetMainFrame()->GetRenderWidgetHost();
3176}
3177
[email protected]95640212014-07-26 18:14:303178BrowserAccessibilityManager*
3179 WebContentsImpl::GetRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223180 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3181 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3182 : GetMainFrame());
creisc014b402015-04-23 16:41:453183 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:303184}
3185
3186BrowserAccessibilityManager*
3187 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223188 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3189 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3190 : GetMainFrame());
creisc014b402015-04-23 16:41:453191 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:303192}
3193
Dave Tapuskab336b922017-07-06 19:24:053194void WebContentsImpl::ExecuteEditCommand(
3195 const std::string& command,
3196 const base::Optional<base::string16>& value) {
3197 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
3198 if (!focused_frame)
3199 return;
3200
3201 focused_frame->GetFrameInputHandler()->ExecuteEditCommand(command, value);
3202}
3203
mohsen7ab1ec16ec2015-07-02 18:26:233204void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:053205 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:233206 if (!focused_frame)
3207 return;
3208
dtapuska9d46ef7d2017-05-26 19:06:063209 focused_frame->GetFrameInputHandler()->MoveRangeSelectionExtent(extent);
mohsen7ab1ec16ec2015-07-02 18:26:233210}
3211
3212void WebContentsImpl::SelectRange(const gfx::Point& base,
3213 const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:053214 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:233215 if (!focused_frame)
3216 return;
3217
dtapuska9d46ef7d2017-05-26 19:06:063218 focused_frame->GetFrameInputHandler()->SelectRange(base, extent);
mohsen7ab1ec16ec2015-07-02 18:26:233219}
3220
Tessa Nijssenc4b101232018-06-25 20:28:083221#if defined(OS_MACOSX)
Tessa Nijssendbef4742018-06-29 21:02:083222void WebContentsImpl::DidChangeTextSelection(const base::string16& text,
3223 const gfx::Range& range) {
3224 for (auto& observer : observers_)
3225 observer.DidChangeTextSelection(text, range);
Tessa Nijssenc4b101232018-06-25 20:28:083226}
3227#endif
3228
Dave Tapuskab336b922017-07-06 19:24:053229void WebContentsImpl::MoveCaret(const gfx::Point& extent) {
3230 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
3231 if (!focused_frame)
3232 return;
3233
3234 focused_frame->GetFrameInputHandler()->MoveCaret(extent);
3235}
3236
Shimi Zhang37deeb22017-09-28 00:59:013237void WebContentsImpl::AdjustSelectionByCharacterOffset(
3238 int start_adjust,
3239 int end_adjust,
3240 bool show_selection_menu) {
Dave Tapuskab336b922017-07-06 19:24:053241 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
aurimasab0319022015-07-10 21:57:383242 if (!focused_frame)
3243 return;
3244
Shimi Zhang37deeb22017-09-28 00:59:013245 using blink::mojom::SelectionMenuBehavior;
dtapuska9d46ef7d2017-05-26 19:06:063246 focused_frame->GetFrameInputHandler()->AdjustSelectionByCharacterOffset(
Shimi Zhang37deeb22017-09-28 00:59:013247 start_adjust, end_adjust,
3248 show_selection_menu ? SelectionMenuBehavior::kShow
3249 : SelectionMenuBehavior::kHide);
aurimasab0319022015-07-10 21:57:383250}
3251
[email protected]b172aee2012-04-10 17:05:263252void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:493253 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:233254 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:493255 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:333256}
3257
avic3aa8422015-11-09 20:57:223258void WebContentsImpl::ResizeDueToAutoResize(
3259 RenderWidgetHostImpl* render_widget_host,
Fady Samuel97947112018-05-05 16:24:543260 const gfx::Size& new_size) {
avic3aa8422015-11-09 20:57:223261 if (render_widget_host != GetRenderViewHost()->GetWidget())
3262 return;
3263
kenrbe4f91082017-06-02 20:32:083264 auto_resize_size_ = new_size;
3265
3266 // Out-of-process iframe visible viewport sizes usually come from the
3267 // top-level RenderWidgetHostView, but when auto-resize is enabled on the
3268 // top frame then that size is used instead.
3269 for (FrameTreeNode* node : frame_tree_.Nodes()) {
3270 if (node->current_frame_host()->is_local_root()) {
3271 RenderWidgetHostImpl* host =
3272 node->current_frame_host()->GetRenderWidgetHost();
3273 if (host != render_widget_host)
Fady Samuel0b911822018-04-25 13:22:163274 host->SynchronizeVisualProperties();
kenrbe4f91082017-06-02 20:32:083275 }
3276 }
3277
[email protected]61e2b3cc2012-03-02 16:13:343278 if (delegate_)
3279 delegate_->ResizeDueToAutoResize(this, new_size);
3280}
3281
kenrbe4f91082017-06-02 20:32:083282gfx::Size WebContentsImpl::GetAutoResizeSize() {
3283 return auto_resize_size_;
3284}
3285
3286void WebContentsImpl::ResetAutoResizeSize() {
3287 auto_resize_size_ = gfx::Size();
3288}
3289
[email protected]b172aee2012-04-10 17:05:263290WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
Bo Liu300c6052018-06-12 04:46:073291 if (!delegate_) {
3292 // Embedder can delay setting a delegate on new WebContents with
3293 // WebContentsDelegate::ShouldResumeRequestsForCreatedWindow. In the mean
3294 // time, navigations, including the initial one, that goes through OpenURL
3295 // should be delayed until embedder is ready to resume loading.
3296 delayed_open_url_params_ = std::make_unique<OpenURLParams>(params);
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283297 return nullptr;
Bo Liu300c6052018-06-12 04:46:073298 }
[email protected]00c37fc2011-08-02 00:22:503299
[email protected]e5d549d2011-12-28 01:29:203300 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
pnoland488944652017-02-22 18:58:543301
3302 RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID(
3303 params.source_render_process_id, params.source_render_frame_id);
3304
3305 if (source_render_frame_host && params.source_site_instance) {
3306 CHECK_EQ(source_render_frame_host->GetSiteInstance(),
3307 params.source_site_instance.get());
3308 }
3309
3310 if (new_contents && source_render_frame_host && new_contents != this) {
3311 for (auto& observer : observers_) {
3312 observer.DidOpenRequestedURL(new_contents, source_render_frame_host,
3313 params.url, params.referrer,
3314 params.disposition, params.transition,
pnolandaae574e2017-03-06 21:04:213315 params.started_from_context_menu, false);
pnoland488944652017-02-22 18:58:543316 }
3317 }
3318
[email protected]e5d549d2011-12-28 01:29:203319 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:343320}
3321
[email protected]a86c0e962013-12-17 17:10:393322void WebContentsImpl::RenderFrameForInterstitialPageCreated(
3323 RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:093324 for (auto& observer : observers_)
3325 observer.RenderFrameForInterstitialPageCreated(render_frame_host);
[email protected]ba45bfd2012-05-22 21:51:443326}
3327
[email protected]20ca0382013-02-28 19:50:073328void WebContentsImpl::AttachInterstitialPage(
3329 InterstitialPageImpl* interstitial_page) {
creisadca9862017-06-16 19:12:113330 DCHECK(!interstitial_page_ && interstitial_page);
3331 interstitial_page_ = interstitial_page;
[email protected]90fb08ed2013-09-24 17:43:293332
3333 // Cancel any visible dialogs so that they don't interfere with the
3334 // interstitial.
creis89a0f782015-05-27 16:13:173335 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:293336
ericwilligersde386342016-10-19 02:35:093337 for (auto& observer : observers_)
3338 observer.DidAttachInterstitialPage();
clamy44e84ce2016-02-22 15:38:253339
3340 // Stop the throbber if needed while the interstitial page is shown.
3341 if (frame_tree_.IsLoading())
3342 LoadingStateChanged(true, true, nullptr);
lfg1453e412017-04-11 00:48:503343
3344 // Connect to outer WebContents if necessary.
3345 if (node_.OuterContentsFrameTreeNode()) {
3346 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3347 DCHECK(
3348 static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView())
3349 ->IsRenderWidgetHostViewChildFrame());
3350 RenderWidgetHostViewChildFrame* view =
3351 static_cast<RenderWidgetHostViewChildFrame*>(
3352 interstitial_page->GetView());
3353 GetRenderManager()->SetRWHViewForInnerContents(view);
3354 }
3355 }
Bo Liu7c6779e92017-08-16 02:02:283356
Bo Liu168c8642017-08-28 18:26:023357#if defined(OS_ANDROID)
Bo Liu7c6779e92017-08-16 02:02:283358 // Update importance of the interstitial.
3359 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
3360 ->GetRenderWidgetHost()
3361 ->SetImportance(GetMainFrame()->GetRenderWidgetHost()->importance());
Bo Liu168c8642017-08-28 18:26:023362#endif
Dominic Mazzoniefb5f9e32017-12-21 01:08:223363
3364 if (accessibility_mode_.has_mode(ui::AXMode::kNativeAPIs)) {
3365 // Make sure that the main page's accessibility tree is hidden and the
3366 // interstitial gets focus.
3367 RenderFrameHostImpl* rfh =
3368 static_cast<RenderFrameHostImpl*>(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(true);
3374 }
3375 rfh = static_cast<RenderFrameHostImpl*>(
3376 GetInterstitialPage()->GetMainFrame());
3377 if (rfh) {
3378 BrowserAccessibilityManager* accessibility_manager =
3379 rfh->GetOrCreateBrowserAccessibilityManager();
3380 if (accessibility_manager)
3381 accessibility_manager->OnWindowFocused();
3382 }
3383 }
clamy44e84ce2016-02-22 15:38:253384}
3385
3386void WebContentsImpl::DidProceedOnInterstitial() {
3387 // The interstitial page should no longer be pausing the throbber.
creisadca9862017-06-16 19:12:113388 DCHECK(!(ShowingInterstitialPage() && interstitial_page_->pause_throbber()));
clamy44e84ce2016-02-22 15:38:253389
3390 // Restart the throbber now that the interstitial page no longer pauses it.
3391 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
3392 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073393}
3394
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043395void WebContentsImpl::DetachInterstitialPage(bool has_focus) {
Lucas Furukawa Gadani69b609192017-07-10 17:08:343396 bool interstitial_pausing_throbber =
3397 ShowingInterstitialPage() && interstitial_page_->pause_throbber();
3398 if (ShowingInterstitialPage())
3399 interstitial_page_ = nullptr;
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043400
Dominic Mazzoniefb5f9e32017-12-21 01:08:223401 // Make sure that the main page's accessibility tree is no longer
3402 // suppressed.
3403 RenderFrameHostImpl* rfh = GetMainFrame();
3404 if (rfh) {
3405 BrowserAccessibilityManager* accessibility_manager =
3406 rfh->browser_accessibility_manager();
3407 if (accessibility_manager)
3408 accessibility_manager->set_hidden_by_interstitial_page(false);
3409 }
3410
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043411 // If the focus was on the interstitial, let's keep it to the page.
3412 // (Note that in unit-tests the RVH may not have a view).
3413 if (has_focus && GetRenderViewHost()->GetWidget()->GetView())
3414 GetRenderViewHost()->GetWidget()->GetView()->Focus();
3415
Lucas Furukawa Gadani69b609192017-07-10 17:08:343416 for (auto& observer : observers_)
3417 observer.DidDetachInterstitialPage();
3418
3419 // Disconnect from outer WebContents if necessary. This must happen after the
3420 // interstitial page is cleared above, since the call to
3421 // SetRWHViewForInnerContents below may loop over all the
3422 // RenderWidgetHostViews in the tree (otherwise, including the now-deleted
3423 // view for the interstitial).
lfg1453e412017-04-11 00:48:503424 if (node_.OuterContentsFrameTreeNode()) {
3425 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3426 DCHECK(static_cast<RenderWidgetHostViewBase*>(
3427 GetRenderManager()->current_frame_host()->GetView())
3428 ->IsRenderWidgetHostViewChildFrame());
3429 RenderWidgetHostViewChildFrame* view =
3430 static_cast<RenderWidgetHostViewChildFrame*>(
3431 GetRenderManager()->current_frame_host()->GetView());
3432 GetRenderManager()->SetRWHViewForInnerContents(view);
3433 }
3434 }
3435
clamy44e84ce2016-02-22 15:38:253436 // Restart the throbber if needed now that the interstitial page is going
3437 // away.
3438 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
3439 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073440}
3441
avi2b177592014-12-10 02:08:023442void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
3443 int history_length) {
alexmos136fd6e62016-08-15 20:58:413444 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
3445 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:023446}
3447
3448void WebContentsImpl::SetHistoryOffsetAndLengthForView(
3449 RenderViewHost* render_view_host,
3450 int history_offset,
3451 int history_length) {
alexmos136fd6e62016-08-15 20:58:413452 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:023453 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:143454}
3455
toyoshim24a4c7ab2016-04-05 09:24:143456void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:173457 RenderFrameHost* focused_frame = GetFocusedFrame();
3458 if (!focused_frame)
3459 return;
3460
[email protected]959be4c2014-04-08 15:01:333461 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:143462 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:333463}
3464
megjablon3f5941072016-02-04 23:27:523465void WebContentsImpl::ReloadLoFiImages() {
3466 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
3467}
3468
Ryan Sturmc65dbe42018-05-31 20:37:043469std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr>
3470WebContentsImpl::PauseSubresourceLoading() {
3471 std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr> handles;
3472 for (RenderFrameHost* rfh : GetAllFrames()) {
3473 if (!rfh->IsRenderFrameLive())
3474 continue;
3475 handles.push_back(rfh->PauseSubresourceLoading());
3476 }
3477 return handles;
3478}
3479
[email protected]959be4c2014-04-08 15:01:333480void WebContentsImpl::Undo() {
Dave Tapuskab336b922017-07-06 19:24:053481 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333482 if (!focused_frame)
3483 return;
3484
dtapuska9d46ef7d2017-05-26 19:06:063485 focused_frame->GetFrameInputHandler()->Undo();
[email protected]959be4c2014-04-08 15:01:333486 RecordAction(base::UserMetricsAction("Undo"));
3487}
3488
3489void WebContentsImpl::Redo() {
Dave Tapuskab336b922017-07-06 19:24:053490 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333491 if (!focused_frame)
3492 return;
dtapuska9d46ef7d2017-05-26 19:06:063493 focused_frame->GetFrameInputHandler()->Redo();
[email protected]959be4c2014-04-08 15:01:333494 RecordAction(base::UserMetricsAction("Redo"));
3495}
3496
3497void WebContentsImpl::Cut() {
Dave Tapuskab336b922017-07-06 19:24:053498 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333499 if (!focused_frame)
3500 return;
3501
dtapuska9d46ef7d2017-05-26 19:06:063502 focused_frame->GetFrameInputHandler()->Cut();
[email protected]959be4c2014-04-08 15:01:333503 RecordAction(base::UserMetricsAction("Cut"));
3504}
3505
3506void WebContentsImpl::Copy() {
Dave Tapuskab336b922017-07-06 19:24:053507 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333508 if (!focused_frame)
3509 return;
3510
dtapuska9d46ef7d2017-05-26 19:06:063511 focused_frame->GetFrameInputHandler()->Copy();
[email protected]959be4c2014-04-08 15:01:333512 RecordAction(base::UserMetricsAction("Copy"));
3513}
3514
3515void WebContentsImpl::CopyToFindPboard() {
3516#if defined(OS_MACOSX)
Dave Tapuskab336b922017-07-06 19:24:053517 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333518 if (!focused_frame)
3519 return;
3520
3521 // Windows/Linux don't have the concept of a find pasteboard.
dtapuska9d46ef7d2017-05-26 19:06:063522 focused_frame->GetFrameInputHandler()->CopyToFindPboard();
[email protected]959be4c2014-04-08 15:01:333523 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
3524#endif
3525}
3526
3527void WebContentsImpl::Paste() {
Dave Tapuskab336b922017-07-06 19:24:053528 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333529 if (!focused_frame)
3530 return;
3531
dtapuska9d46ef7d2017-05-26 19:06:063532 focused_frame->GetFrameInputHandler()->Paste();
[email protected]959be4c2014-04-08 15:01:333533 RecordAction(base::UserMetricsAction("Paste"));
3534}
3535
3536void WebContentsImpl::PasteAndMatchStyle() {
Dave Tapuskab336b922017-07-06 19:24:053537 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333538 if (!focused_frame)
3539 return;
3540
dtapuska9d46ef7d2017-05-26 19:06:063541 focused_frame->GetFrameInputHandler()->PasteAndMatchStyle();
[email protected]959be4c2014-04-08 15:01:333542 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
3543}
3544
3545void WebContentsImpl::Delete() {
Dave Tapuskab336b922017-07-06 19:24:053546 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333547 if (!focused_frame)
3548 return;
3549
dtapuska9d46ef7d2017-05-26 19:06:063550 focused_frame->GetFrameInputHandler()->Delete();
[email protected]959be4c2014-04-08 15:01:333551 RecordAction(base::UserMetricsAction("DeleteSelection"));
3552}
3553
3554void WebContentsImpl::SelectAll() {
Dave Tapuskab336b922017-07-06 19:24:053555 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333556 if (!focused_frame)
3557 return;
3558
dtapuska9d46ef7d2017-05-26 19:06:063559 focused_frame->GetFrameInputHandler()->SelectAll();
[email protected]959be4c2014-04-08 15:01:333560 RecordAction(base::UserMetricsAction("SelectAll"));
3561}
3562
yabinh351e7ec2017-03-10 02:43:243563void WebContentsImpl::CollapseSelection() {
Dave Tapuskab336b922017-07-06 19:24:053564 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333565 if (!focused_frame)
3566 return;
3567
dtapuska9d46ef7d2017-05-26 19:06:063568 focused_frame->GetFrameInputHandler()->CollapseSelection();
[email protected]1f3fc1d2014-04-03 14:50:173569}
3570
3571void WebContentsImpl::Replace(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053572 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173573 if (!focused_frame)
3574 return;
3575
dtapuska9d46ef7d2017-05-26 19:06:063576 focused_frame->GetFrameInputHandler()->Replace(word);
[email protected]1f3fc1d2014-04-03 14:50:173577}
3578
3579void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053580 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173581 if (!focused_frame)
3582 return;
3583
dtapuska9d46ef7d2017-05-26 19:06:063584 focused_frame->GetFrameInputHandler()->ReplaceMisspelling(word);
[email protected]959be4c2014-04-08 15:01:333585}
3586
3587void WebContentsImpl::NotifyContextMenuClosed(
3588 const CustomContextMenuContext& context) {
3589 RenderFrameHost* focused_frame = GetFocusedFrame();
3590 if (!focused_frame)
3591 return;
3592
3593 focused_frame->Send(new FrameMsg_ContextMenuClosed(
3594 focused_frame->GetRoutingID(), context));
3595}
3596
3597void WebContentsImpl::ExecuteCustomContextMenuCommand(
3598 int action, const CustomContextMenuContext& context) {
3599 RenderFrameHost* focused_frame = GetFocusedFrame();
3600 if (!focused_frame)
3601 return;
3602
3603 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
3604 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:003605}
3606
[email protected]fc2b46b2014-05-03 16:33:453607gfx::NativeView WebContentsImpl::GetNativeView() {
3608 return view_->GetNativeView();
3609}
3610
3611gfx::NativeView WebContentsImpl::GetContentNativeView() {
3612 return view_->GetContentNativeView();
3613}
3614
3615gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
3616 return view_->GetTopLevelNativeWindow();
3617}
3618
3619gfx::Rect WebContentsImpl::GetViewBounds() {
3620 return view_->GetViewBounds();
3621}
3622
3623gfx::Rect WebContentsImpl::GetContainerBounds() {
3624 gfx::Rect rv;
3625 view_->GetContainerBounds(&rv);
3626 return rv;
3627}
3628
3629DropData* WebContentsImpl::GetDropData() {
3630 return view_->GetDropData();
3631}
3632
3633void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:043634 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:453635}
3636
3637void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:043638 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:453639}
3640
3641void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:043642 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453643}
3644
3645void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:043646 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453647}
3648
[email protected]b172aee2012-04-10 17:05:263649void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
Maxim Podgorodskiya926c4ff2017-11-20 02:06:393650 view_->FocusThroughTabTraversal(reverse);
[email protected]96d185d2009-04-24 03:28:543651}
3652
[email protected]b172aee2012-04-10 17:05:263653bool WebContentsImpl::ShowingInterstitialPage() const {
creisadca9862017-06-16 19:12:113654 return interstitial_page_ != nullptr;
[email protected]96d185d2009-04-24 03:28:543655}
3656
Pete Williamson89aa1402017-07-07 19:58:413657void WebContentsImpl::AdjustPreviewsStateForNavigation(
3658 PreviewsState* previews_state) {
3659 if (delegate_)
Doug Arnettc681bbe2018-04-06 04:04:463660 delegate_->AdjustPreviewsStateForNavigation(this, previews_state);
Pete Williamson89aa1402017-07-07 19:58:413661}
3662
Maxim Podgorodskiya926c4ff2017-11-20 02:06:393663InterstitialPageImpl* WebContentsImpl::GetInterstitialPage() const {
creisadca9862017-06-16 19:12:113664 return interstitial_page_;
[email protected]686493142011-07-15 21:47:223665}
3666
Gyuyoung Kim80143f5e2018-04-02 02:40:253667void WebContentsImpl::PausePageScheduledTasks(bool paused) {
3668 SendPageMessage(
3669 new PageMsg_PausePageScheduledTasks(MSG_ROUTING_NONE, paused));
3670}
3671
[email protected]b172aee2012-04-10 17:05:263672bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:163673 // WebKit creates Document object when MIME type is application/xhtml+xml,
3674 // so we also support this MIME type.
3675 return contents_mime_type_ == "text/html" ||
3676 contents_mime_type_ == "text/xml" ||
3677 contents_mime_type_ == "application/xhtml+xml" ||
3678 contents_mime_type_ == "text/plain" ||
3679 contents_mime_type_ == "text/css" ||
Kinuko Yasuda74702f92017-07-31 03:27:533680 blink::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:163681}
3682
[email protected]b172aee2012-04-10 17:05:263683void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:593684 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:163685 if (!IsSavable()) {
Min Qinda0ed2062018-02-23 22:00:533686 download::RecordSavePackageEvent(
3687 download::SAVE_PACKAGE_DOWNLOAD_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:193688 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:143689 return;
[email protected]c7dd2f62011-07-18 15:57:593690 }
3691
3692 Stop();
3693
3694 // Create the save package and possibly prompt the user for the name to save
3695 // the page as. The user prompt is an asynchronous operation that runs on
3696 // another thread.
3697 save_package_ = new SavePackage(this);
3698 save_package_->GetSaveInfo();
3699}
3700
3701// Used in automated testing to bypass prompting the user for file names.
3702// Instead, the names and paths are hard coded rather than running them through
3703// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:343704bool WebContentsImpl::SavePage(const base::FilePath& main_file,
3705 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:213706 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:593707 // Stop the page from navigating.
3708 Stop();
3709
3710 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:213711 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:593712}
3713
[email protected]3c71576ce2013-07-23 02:00:013714void WebContentsImpl::SaveFrame(const GURL& url,
3715 const Referrer& referrer) {
Xing Liu10329bf2018-03-20 19:22:143716 SaveFrameWithHeaders(url, referrer, std::string(), base::string16());
kundaji6c7f9692015-03-09 18:00:373717}
3718
Xing Liu10329bf2018-03-20 19:22:143719void WebContentsImpl::SaveFrameWithHeaders(
3720 const GURL& url,
3721 const Referrer& referrer,
3722 const std::string& headers,
3723 const base::string16& suggested_filename) {
nasko89ad7742015-03-05 22:14:193724 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:013725 return;
sammc92af61552014-11-19 23:27:403726 if (delegate_ && delegate_->SaveFrame(url, referrer))
3727 return;
3728
nasko89ad7742015-03-05 22:14:193729 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:223730 // by explicitly passing in which frame this method should target. This would
3731 // indicate whether it's the main frame, and also tell us the frame pointer
3732 // to use for routing.
nasko89ad7742015-03-05 22:14:193733 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:223734 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:013735
brettw760f7442016-05-23 21:19:223736 StoragePartition* storage_partition = BrowserContext::GetStoragePartition(
3737 GetBrowserContext(), frame_host->GetSiteInstance());
avib7348942015-12-25 20:57:103738 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:013739 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:273740 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:013741 if (entry)
3742 post_id = entry->GetPostID();
3743 }
Ramin Halavati24e21012017-07-10 12:56:063744 net::NetworkTrafficAnnotationTag traffic_annotation =
3745 net::DefineNetworkTrafficAnnotation("download_web_contents_frame", R"(
3746 semantics {
3747 sender: "Save Page Action"
3748 description:
3749 "Saves the given frame's URL to the local file system."
3750 trigger:
3751 "The user has triggered a save operation on the frame through a "
3752 "context menu or other mechanism."
3753 data: "None."
3754 destination: WEBSITE
3755 }
3756 policy {
Ramin Halavati3b979782017-07-21 11:40:263757 cookies_allowed: YES
Ramin Halavati24e21012017-07-10 12:56:063758 cookies_store: "user"
3759 setting:
3760 "This feature cannot be disabled by settings, but it's is only "
3761 "triggered by user request."
3762 policy_exception_justification: "Not implemented."
3763 })");
Min Qina904f3302018-02-13 23:33:343764 auto params = std::make_unique<download::DownloadUrlParameters>(
brettw760f7442016-05-23 21:19:223765 url, frame_host->GetProcess()->GetID(),
3766 frame_host->GetRenderViewHost()->GetRoutingID(),
Ramin Halavati03efa732017-06-12 09:28:203767 frame_host->GetRoutingID(), storage_partition->GetURLRequestContext(),
Ramin Halavati24e21012017-07-10 12:56:063768 traffic_annotation);
Min Qina904f3302018-02-13 23:33:343769 params->set_referrer(referrer.url);
3770 params->set_referrer_policy(
3771 Referrer::ReferrerPolicyForUrlRequest(referrer.policy));
[email protected]3c71576ce2013-07-23 02:00:013772 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:013773 if (post_id >= 0)
3774 params->set_method("POST");
3775 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:373776
3777 if (headers.empty()) {
3778 params->set_prefer_cache(true);
3779 } else {
Min Qina904f3302018-02-13 23:33:343780 for (download::DownloadUrlParameters::RequestHeadersNameValuePair
3781 key_value : ParseDownloadHeaders(headers)) {
Megan Jablonski2f6a4c52017-07-10 23:01:253782 params->add_request_header(key_value.first, key_value.second);
kundaji6c7f9692015-03-09 18:00:373783 }
3784 }
Xing Liu10329bf2018-03-20 19:22:143785 params->set_suggested_name(suggested_filename);
Min Qin0ca8e1ee2018-01-31 00:49:353786 params->set_download_source(download::DownloadSource::WEB_CONTENTS_API);
thestig859c78892017-05-15 21:17:063787 BrowserContext::GetDownloadManager(GetBrowserContext())
Ramin Halavati03efa732017-06-12 09:28:203788 ->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:013789}
3790
[email protected]b172aee2012-04-10 17:05:263791void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:473792 const MHTMLGenerationParams& params,
Avi Drissman149b7832018-03-23 14:31:493793 base::OnceCallback<void(int64_t)> callback) {
3794 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params,
3795 std::move(callback));
[email protected]aa4f3972012-03-01 18:12:123796}
3797
[email protected]b172aee2012-04-10 17:05:263798const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:273799 return contents_mime_type_;
3800}
3801
[email protected]b172aee2012-04-10 17:05:263802bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:273803 return notify_disconnection_;
3804}
3805
[email protected]8ff00d72012-10-23 19:12:213806RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:273807 return &renderer_preferences_;
3808}
3809
[email protected]e35ccd52012-05-23 16:22:473810void WebContentsImpl::Close() {
3811 Close(GetRenderViewHost());
3812}
3813
Ella Ge80a52dce2017-11-15 18:01:523814void WebContentsImpl::DragSourceEndedAt(float client_x,
3815 float client_y,
3816 float screen_x,
3817 float screen_y,
Paul Meyer0c58c3712016-11-17 22:59:513818 blink::WebDragOperation operation,
3819 RenderWidgetHost* source_rwh) {
[email protected]cf200a562013-05-03 16:24:293820 if (browser_plugin_embedder_.get())
paulmeyer8fc8ea92016-11-15 05:12:213821 browser_plugin_embedder_->DragSourceEndedAt(
3822 client_x, client_y, screen_x, screen_y, operation);
Paul Meyer0c58c3712016-11-17 22:59:513823 if (source_rwh) {
Ella Ge80a52dce2017-11-15 18:01:523824 source_rwh->DragSourceEndedAt(gfx::PointF(client_x, client_y),
3825 gfx::PointF(screen_x, screen_y), operation);
Paul Meyer0c58c3712016-11-17 22:59:513826 }
[email protected]cf200a562013-05-03 16:24:293827}
3828
jam73f892642016-09-11 06:04:063829void WebContentsImpl::LoadStateChanged(
Charles Harrison911fa062018-03-06 21:01:463830 const std::string& host,
jam73f892642016-09-11 06:04:063831 const net::LoadStateWithParam& load_state,
3832 uint64_t upload_position,
3833 uint64_t upload_size) {
Charles Harrison911fa062018-03-06 21:01:463834 base::string16 host16 = url_formatter::IDNToUnicode(host);
Elly Fong-Jonescad9c3d12018-01-31 17:26:103835 // Drop no-op updates.
3836 if (load_state_.state == load_state.state &&
3837 load_state_.param == load_state.param &&
3838 upload_position_ == upload_position && upload_size_ == upload_size &&
Charles Harrison911fa062018-03-06 21:01:463839 load_state_host_ == host16) {
Elly Fong-Jonescad9c3d12018-01-31 17:26:103840 return;
3841 }
jam73f892642016-09-11 06:04:063842 load_state_ = load_state;
3843 upload_position_ = upload_position;
3844 upload_size_ = upload_size;
Charles Harrison911fa062018-03-06 21:01:463845 load_state_host_ = host16;
jam73f892642016-09-11 06:04:063846 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
3847 SetNotWaitingForResponse();
3848 if (IsLoading()) {
3849 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
3850 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
3851 }
3852}
3853
Francois Doraye6161152018-03-27 22:05:373854void WebContentsImpl::SetVisibility(Visibility visibility) {
3855 const Visibility previous_visibility = visibility_;
3856 visibility_ = visibility;
3857
Francois Dorayfe4a1772018-02-17 04:17:093858 // Notify observers if the visibility changed or if WasShown() is being called
3859 // for the first time.
Francois Dorayfe4a1772018-02-17 04:17:093860 if (visibility != previous_visibility ||
3861 (visibility == Visibility::VISIBLE && !did_first_set_visible_)) {
3862 for (auto& observer : observers_)
3863 observer.OnVisibilityChanged(visibility);
3864 }
3865}
3866
Michael Thiessen896405db2017-07-20 17:52:323867void WebContentsImpl::NotifyWebContentsFocused(
3868 RenderWidgetHost* render_widget_host) {
ericwilligersde386342016-10-19 02:35:093869 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323870 observer.OnWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:373871}
3872
Michael Thiessen896405db2017-07-20 17:52:323873void WebContentsImpl::NotifyWebContentsLostFocus(
3874 RenderWidgetHost* render_widget_host) {
zijiehe3bee08e22017-05-17 04:14:463875 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323876 observer.OnWebContentsLostFocus(render_widget_host);
zijiehe3bee08e22017-05-17 04:14:463877}
3878
Paul Meyer0c58c3712016-11-17 22:59:513879void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) {
3880 if (source_rwh)
3881 source_rwh->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:293882 if (browser_plugin_embedder_.get())
3883 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:343884}
3885
Daniel Cheng90196c82018-04-25 21:49:143886void WebContentsImpl::NavigatedByUser() {
3887 OnUserInteraction(blink::WebInputEvent::kUndefined);
[email protected]e35ccd52012-05-23 16:22:473888}
3889
[email protected]b172aee2012-04-10 17:05:263890void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:273891 closed_by_user_gesture_ = value;
3892}
3893
[email protected]b172aee2012-04-10 17:05:263894bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:273895 return closed_by_user_gesture_;
3896}
3897
[email protected]b172aee2012-04-10 17:05:263898int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273899 return minimum_zoom_percent_;
3900}
3901
[email protected]b172aee2012-04-10 17:05:263902int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273903 return maximum_zoom_percent_;
3904}
3905
mcnee432e47d2015-11-09 19:37:463906void WebContentsImpl::SetPageScale(float page_scale_factor) {
Lukasz Anforowiczf4357ca2017-09-07 01:43:323907 GetRenderViewHost()->Send(new ViewMsg_SetPageScale(
3908 GetRenderViewHost()->GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:243909}
3910
[email protected]b172aee2012-04-10 17:05:263911gfx::Size WebContentsImpl::GetPreferredSize() const {
Francois Doray24fc62c2017-12-11 17:27:333912 return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_;
[email protected]bcd2815602012-01-14 18:17:233913}
3914
[email protected]b172aee2012-04-10 17:05:263915bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
lfgf0cd46e2017-01-04 00:05:233916 if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) &&
3917 GetBrowserPluginGuest())
[email protected]660f18e2014-05-15 20:53:053918 return GetBrowserPluginGuest()->LockMouse(allowed);
3919
lfgf0cd46e2017-01-04 00:05:233920 if (mouse_lock_widget_) {
3921 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
3922 return mouse_lock_widget_->delegate()
3923 ->GetAsWebContents()
3924 ->GotResponseToLockMouseRequest(allowed);
3925 }
lfgad8244352016-07-13 16:55:513926
lfgf0cd46e2017-01-04 00:05:233927 if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3928 return true;
3929 }
3930
3931 for (WebContentsImpl* current = this; current;
3932 current = current->GetOuterWebContents()) {
3933 current->mouse_lock_widget_ = nullptr;
3934 }
3935
lfgbee1e0a2016-06-08 21:24:213936 return false;
[email protected]0bfbf882011-12-22 18:19:273937}
3938
Joe Downing13dd76b2018-04-09 18:32:153939bool WebContentsImpl::GotResponseToKeyboardLockRequest(bool allowed) {
3940 if (!keyboard_lock_widget_)
3941 return false;
3942
3943 if (keyboard_lock_widget_->delegate()->GetAsWebContents() != this) {
3944 NOTREACHED();
3945 return false;
3946 }
3947
3948 // KeyboardLock is only supported when called by the top-level browsing
3949 // context and is not supported in embedded content scenarios.
3950 if (GetOuterWebContents())
3951 return false;
3952
3953 keyboard_lock_widget_->GotResponseToKeyboardLockRequest(allowed);
3954 return true;
3955}
3956
[email protected]b172aee2012-04-10 17:05:263957bool WebContentsImpl::HasOpener() const {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283958 return GetOpener() != nullptr;
[email protected]a0358d72012-03-09 14:06:503959}
3960
lukasza6f8ac622017-06-06 03:10:203961RenderFrameHostImpl* WebContentsImpl::GetOpener() const {
alexmose201c7cd2015-06-10 17:14:213962 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
lukasza6f8ac622017-06-06 03:10:203963 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen55ff3502014-12-18 20:52:573964}
3965
jochen6004a362017-02-04 00:11:403966bool WebContentsImpl::HasOriginalOpener() const {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283967 return GetOriginalOpener() != nullptr;
jochen6004a362017-02-04 00:11:403968}
3969
lukasza6f8ac622017-06-06 03:10:203970RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() const {
jochen6004a362017-02-04 00:11:403971 FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener();
lukasza6f8ac622017-06-06 03:10:203972 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen6004a362017-02-04 00:11:403973}
3974
[email protected]cb805452013-05-22 15:16:213975void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
Joel Hockey85b379d2017-12-11 10:42:133976 color_chooser_->DidChooseColorInColorChooser(color);
[email protected]da8543762012-03-20 08:52:203977}
3978
[email protected]cb805452013-05-22 15:16:213979void WebContentsImpl::DidEndColorChooser() {
Joel Hockey85b379d2017-12-11 10:42:133980 color_chooser_.reset();
[email protected]da8543762012-03-20 08:52:203981}
3982
halton.huoca2eabd2015-07-06 08:17:403983int WebContentsImpl::DownloadImage(
3984 const GURL& url,
3985 bool is_favicon,
3986 uint32_t max_bitmap_size,
3987 bool bypass_cache,
Avi Drissmana5a52dd2018-03-27 03:39:023988 WebContents::ImageDownloadCallback callback) {
amistry9f01b772015-07-29 01:54:553989 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:403990 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:063991 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:403992 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:553993 const int download_id = ++next_image_download_id;
3994 if (!mojo_image_downloader) {
3995 // If the renderer process is dead (i.e. crash, or memory pressure on
3996 // Android), the downloader service will be invalid. Pre-Mojo, this would
Avi Drissmana5a52dd2018-03-27 03:39:023997 // hang the callback indefinitely since the IPC would be dropped. Now,
amistry9f01b772015-07-29 01:54:553998 // respond with a 400 HTTP error code to indicate that something went wrong.
3999 BrowserThread::PostTask(
4000 BrowserThread::UI, FROM_HERE,
tzike2aca992017-09-05 08:50:544001 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:024002 weak_factory_.GetWeakPtr(), std::move(callback),
4003 download_id, url, 400, std::vector<SkBitmap>(),
4004 std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:554005 return download_id;
4006 }
4007
halton.huoca2eabd2015-07-06 08:17:404008 mojo_image_downloader->DownloadImage(
sammcf6f4fcf2016-06-21 05:39:394009 url, is_favicon, max_bitmap_size, bypass_cache,
tzike2aca992017-09-05 08:50:544010 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:024011 weak_factory_.GetWeakPtr(), std::move(callback),
4012 download_id, url));
amistry9f01b772015-07-29 01:54:554013 return download_id;
[email protected]795c28972012-12-06 06:13:394014}
4015
[email protected]36ec24f2014-01-09 00:32:084016void WebContentsImpl::Find(int request_id,
4017 const base::string16& search_text,
4018 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:334019 // Cowardly refuse to search for no text.
4020 if (search_text.empty()) {
4021 NOTREACHED();
4022 return;
4023 }
4024
paulmeyerc0b762b2016-04-13 11:55:174025 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:084026}
4027
4028void WebContentsImpl::StopFinding(StopFindAction action) {
paulmeyerfeafc2d2017-04-25 21:46:404029 if (FindRequestManager* manager = GetFindRequestManager())
4030 manager->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:084031}
4032
Tommy Steimel18360512017-11-01 00:38:194033bool WebContentsImpl::WasEverAudible() {
4034 return was_ever_audible_;
4035}
4036
Avi Drissmana5a52dd2018-03-27 03:39:024037void WebContentsImpl::GetManifest(GetManifestCallback callback) {
4038 manifest_manager_host_->GetManifest(std::move(callback));
mlamouriefdca9d2014-09-16 16:55:404039}
4040
bokanece34a82016-01-28 19:49:464041void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:534042 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:434043 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:464044 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:534045}
4046
mariakhomenko44bdc4732015-04-29 01:55:384047void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:374048 if (delayed_open_url_params_.get()) {
4049 OpenURL(*delayed_open_url_params_.get());
4050 delayed_open_url_params_.reset(nullptr);
4051 return;
4052 }
4053
mariakhomenko44bdc4732015-04-29 01:55:384054 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
4055 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:164056 if (is_resume_pending_) {
4057 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:134058 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:164059 GetMainFrame()->Init();
4060 }
mariakhomenko44bdc4732015-04-29 01:55:384061}
4062
[email protected]b172aee2012-04-10 17:05:264063bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:264064 // When the browser is started with about:blank as the startup URL, focus
4065 // the location bar (which will also select its contents) so people can
4066 // simply begin typing to navigate elsewhere.
4067 //
4068 // We need to be careful not to trigger this for anything other than the
4069 // startup navigation. In particular, if we allow an attacker to open a
4070 // popup to about:blank, then navigate, focusing the Omnibox will cause the
4071 // end of the new URL to be scrolled into view instead of the start,
4072 // allowing the attacker to spoof other URLs. The conditions checked here
4073 // are all aimed at ensuring no such attacker-controlled navigation can
4074 // trigger this.
4075 //
4076 // Note that we check the pending entry instead of the visible one; for the
4077 // startup URL case these are the same, but for the attacker-controlled
4078 // navigation case the visible entry is the committed "about:blank" URL and
4079 // the pending entry is the problematic navigation elsewhere.
4080 NavigationEntryImpl* entry = controller_.GetPendingEntry();
4081 if (controller_.IsInitialNavigation() && entry &&
4082 !entry->is_renderer_initiated() &&
csharrisona3bd0b32016-10-19 18:40:484083 entry->GetURL() == url::kAboutBlankURL) {
[email protected]0c9406632013-02-08 01:13:334084 return true;
palmerc70cb1f2016-03-04 23:41:264085 }
[email protected]0c9406632013-02-08 01:13:334086 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:274087}
4088
[email protected]b172aee2012-04-10 17:05:264089void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:274090 if (delegate_)
4091 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:214092}
4093
clamy0e119882015-07-31 16:12:334094void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484095 TRACE_EVENT1("navigation", "WebContentsImpl::DidStartNavigation",
4096 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094097 for (auto& observer : observers_)
4098 observer.DidStartNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:334099}
4100
4101void WebContentsImpl::DidRedirectNavigation(
4102 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484103 TRACE_EVENT1("navigation", "WebContentsImpl::DidRedirectNavigation",
4104 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094105 for (auto& observer : observers_)
4106 observer.DidRedirectNavigation(navigation_handle);
jam5f358e52017-02-13 16:37:034107
4108 // Notify accessibility if this is a reload. This has to called on the
4109 // BrowserAccessibilityManager associated with the old RFHI.
4110 if (navigation_handle->GetReloadType() != ReloadType::NONE) {
4111 NavigationHandleImpl* nhi =
4112 static_cast<NavigationHandleImpl*>(navigation_handle);
4113 BrowserAccessibilityManager* manager =
4114 nhi->frame_tree_node()
4115 ->current_frame_host()
4116 ->browser_accessibility_manager();
4117 if (manager)
4118 manager->UserIsReloading();
4119 }
clamy0e119882015-07-31 16:12:334120}
4121
clamyefca29e2015-09-17 00:22:114122void WebContentsImpl::ReadyToCommitNavigation(
4123 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484124 TRACE_EVENT1("navigation", "WebContentsImpl::ReadyToCommitNavigation",
4125 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094126 for (auto& observer : observers_)
4127 observer.ReadyToCommitNavigation(navigation_handle);
John Abd-El-Malekd4882642017-12-04 21:45:194128
Kenneth Russell954ed9ce2018-04-12 23:07:014129 // If any domains are blocked from accessing 3D APIs because they may
4130 // have caused the GPU to reset recently, unblock them here if the user
4131 // initiated this navigation. This implies that the user was involved in
4132 // the decision to navigate, so there's no concern about
4133 // denial-of-service issues. Want to do this as early as
4134 // possible to avoid race conditions with pages attempting to access
4135 // WebGL early on.
4136 //
4137 // TODO(crbug.com/617904): currently navigations initiated by the browser
4138 // (reload button, reload menu option, pressing return in the Omnibox)
4139 // return false from HasUserGesture(). If or when that is addressed,
4140 // remove the check for IsRendererInitiated() below.
4141 //
4142 // TODO(crbug.com/832180): HasUserGesture comes from the renderer
4143 // process and isn't validated. Until it is, don't trust it.
4144 if (!navigation_handle->IsRendererInitiated()) {
4145 GpuDataManagerImpl::GetInstance()->UnblockDomainFrom3DAPIs(
4146 navigation_handle->GetURL());
4147 }
4148
John Abd-El-Malekfde08e6da2017-12-05 04:06:244149 if (navigation_handle->IsSameDocument())
4150 return;
4151
John Abd-El-Malekd4882642017-12-04 21:45:194152 controller_.ssl_manager()->DidStartResourceResponse(
4153 navigation_handle->GetURL(),
4154 net::IsCertStatusError(navigation_handle->GetSSLInfo().cert_status));
John Abd-El-Malekfde08e6da2017-12-05 04:06:244155
4156 SetNotWaitingForResponse();
Becca Hughes6fe54e432018-06-09 04:18:564157
4158 // Reset the viewport fit
Becca Hughes86334622018-07-09 21:29:384159 if (display_cutout_host_impl_) {
4160 display_cutout_host_impl_->ViewportFitChangedForFrame(
4161 navigation_handle->GetRenderFrameHost(),
4162 blink::mojom::ViewportFit::kAuto);
4163 }
clamyefca29e2015-09-17 00:22:114164}
4165
clamy0e119882015-07-31 16:12:334166void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484167 TRACE_EVENT1("navigation", "WebContentsImpl::DidFinishNavigation",
4168 "navigation_handle", navigation_handle);
Steven Holte38041342018-06-22 22:00:574169
ericwilligersde386342016-10-19 02:35:094170 for (auto& observer : observers_)
4171 observer.DidFinishNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:334172
jam5f358e52017-02-13 16:37:034173 if (navigation_handle->HasCommitted()) {
dmazzonibf8cec42015-02-08 08:28:084174 BrowserAccessibilityManager* manager =
jam5f358e52017-02-13 16:37:034175 static_cast<RenderFrameHostImpl*>(
4176 navigation_handle->GetRenderFrameHost())
4177 ->browser_accessibility_manager();
4178 if (manager) {
4179 if (navigation_handle->IsErrorPage()) {
4180 manager->NavigationFailed();
4181 } else {
4182 manager->NavigationSucceeded();
4183 }
4184 }
Tommy Steimel18360512017-11-01 00:38:194185
4186 if (navigation_handle->IsInMainFrame() &&
4187 !navigation_handle->IsSameDocument()) {
4188 was_ever_audible_ = false;
Steven Holte38041342018-06-22 22:00:574189 last_committed_source_id_ =
4190 ukm::ConvertToSourceId(navigation_handle->GetNavigationId(),
4191 ukm::SourceIdType::NAVIGATION_ID);
Tommy Steimel18360512017-11-01 00:38:194192 }
dmazzonibf8cec42015-02-08 08:28:084193 }
[email protected]400992b2012-06-14 00:03:544194}
4195
[email protected]b80624c2014-02-09 02:46:554196void WebContentsImpl::DidFailLoadWithError(
4197 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:554198 const GURL& url,
[email protected]b80624c2014-02-09 02:46:554199 int error_code,
Yutaka Hirano16d3c5d2017-07-31 06:17:304200 const base::string16& error_description) {
ericwilligersde386342016-10-19 02:35:094201 for (auto& observer : observers_) {
Yutaka Hirano16d3c5d2017-07-31 06:17:304202 observer.DidFailLoad(render_frame_host, url, error_code, error_description);
ericwilligersde386342016-10-19 02:35:094203 }
[email protected]b80624c2014-02-09 02:46:554204}
4205
[email protected]52913802013-12-10 05:52:184206void WebContentsImpl::NotifyChangedNavigationState(
4207 InvalidateTypes changed_flags) {
4208 NotifyNavigationStateChanged(changed_flags);
4209}
4210
toyoshim0df1d3a2016-09-09 09:52:484211void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
4212 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:204213 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094214 for (auto& observer : observers_)
4215 observer.DidStartNavigationToPendingEntry(url, reload_type);
[email protected]3691e5cf2014-01-22 10:16:204216}
4217
lukasza1d025732016-09-28 21:36:084218bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:224219 if (!delegate_)
4220 return true;
lukasza1d025732016-09-28 21:36:084221 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:224222}
4223
[email protected]aa62afd2014-04-22 19:22:464224bool WebContentsImpl::ShouldPreserveAbortedURLs() {
4225 if (!delegate_)
4226 return false;
4227 return delegate_->ShouldPreserveAbortedURLs(this);
4228}
4229
[email protected]0d0f4c492014-04-02 06:42:574230void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:234231 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:574232 // Ensure fullscreen mode is exited before committing the navigation to a
4233 // different page. The next page will not start out assuming it is in
4234 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:234235 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:194236 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:574237 return;
4238 }
alexmos5dd617d2016-06-07 04:21:154239 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464240 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:154241 DCHECK(!IsFullscreenForCurrentTab());
Joe Downingc1a57efe2018-05-09 18:23:544242
4243 // Clean up keyboard lock state when navigating.
4244 CancelKeyboardLock(keyboard_lock_widget_);
[email protected]0d0f4c492014-04-02 06:42:574245}
4246
[email protected]37567b432014-02-12 01:12:224247void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:284248 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:224249 const LoadCommittedDetails& details,
4250 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
4251 if (details.is_navigation_to_different_page()) {
4252 // Clear the status bubble. This is a workaround for a bug where WebKit
4253 // doesn't let us know that the cursor left an element during a
4254 // transition (this is also why the mouse cursor remains as a hand after
4255 // clicking on a link); see bugs 1184641 and 980803. We don't want to
4256 // clear the bubble when a user navigates to a named anchor in the same
4257 // page.
Lukasz Anforowiczfd707142018-02-07 19:46:134258 ClearTargetURL();
lanwei9d343ad22015-02-11 01:46:004259
4260 RenderWidgetHostViewBase* rwhvb =
4261 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
4262 if (rwhvb)
4263 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:284264
peter90afaba2015-06-01 12:05:294265 did_first_visually_non_empty_paint_ = false;
4266
yusufod41c5f92015-03-06 00:14:284267 // Reset theme color on navigation to new page.
4268 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:224269 }
4270
[email protected]e85165c642014-06-10 14:34:314271 if (delegate_)
[email protected]37567b432014-02-12 01:12:224272 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:314273 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:224274}
4275
4276void WebContentsImpl::DidNavigateAnyFramePostCommit(
4277 RenderFrameHostImpl* render_frame_host,
4278 const LoadCommittedDetails& details,
4279 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:104280 // Now that something has committed, we don't need to track whether the
4281 // initial page has been accessed.
4282 has_accessed_initial_document_ = false;
4283
[email protected]37567b432014-02-12 01:12:224284 // If we navigate off the page, close all JavaScript dialogs.
eugenebutee08663a2017-04-27 17:43:124285 if (!details.is_same_document)
creis89a0f782015-05-27 16:13:174286 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:224287
avid53461d2016-02-25 17:15:044288 // If this is a user-initiated navigation, start allowing JavaScript dialogs
4289 // again.
avi5d3b8692016-10-12 22:00:464290 if (params.gesture == NavigationGestureUser && dialog_manager_) {
avi6879fcf2017-01-21 05:27:534291 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:464292 }
[email protected]37567b432014-02-12 01:12:224293}
4294
4295void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
4296 contents_mime_type_ = mime_type;
4297}
4298
[email protected]277857a2014-06-03 10:38:014299bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:314300 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:054301 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:314302 return false;
4303
[email protected]37567b432014-02-12 01:12:224304 if (delegate_)
4305 return delegate_->CanOverscrollContent();
4306
4307 return false;
4308}
4309
nicka0ac8382016-12-15 23:59:234310void WebContentsImpl::OnThemeColorChanged(RenderFrameHostImpl* source,
4311 SkColor theme_color) {
4312 if (source != GetMainFrame()) {
4313 // Only the main frame may control the theme.
4314 return;
4315 }
4316
peter90afaba2015-06-01 12:05:294317 // Update the theme color. This is to be published to observers after the
4318 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:284319 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:294320
4321 if (did_first_visually_non_empty_paint_ &&
4322 last_sent_theme_color_ != theme_color_) {
ericwilligersde386342016-10-19 02:35:094323 for (auto& observer : observers_)
4324 observer.DidChangeThemeColor(theme_color_);
peter90afaba2015-06-01 12:05:294325 last_sent_theme_color_ = theme_color_;
4326 }
[email protected]e7104762014-06-20 19:17:254327}
4328
[email protected]b172aee2012-04-10 17:05:264329void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
nicka0ac8382016-12-15 23:59:234330 RenderFrameHostImpl* source,
[email protected]724159a2010-12-30 01:11:184331 const GURL& url,
[email protected]70435962011-08-02 20:13:284332 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:184333 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:404334 ResourceType resource_type) {
ericwilligersde386342016-10-19 02:35:094335 for (auto& observer : observers_)
4336 observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type);
[email protected]b0f724c2013-09-05 04:21:134337
[email protected]8bfc8272013-09-09 20:10:534338 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
nicka0ac8382016-12-15 23:59:234339 StoragePartition* partition = source->GetProcess()->GetStoragePartition();
[email protected]8bfc8272013-09-09 20:10:534340 scoped_refptr<net::URLRequestContextGetter> request_context(
nicka0ac8382016-12-15 23:59:234341 resource_type == RESOURCE_TYPE_MEDIA
4342 ? partition->GetMediaURLRequestContext()
4343 : partition->GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:534344 BrowserThread::PostTask(
nicka0ac8382016-12-15 23:59:234345 BrowserThread::IO, FROM_HERE,
tzike2aca992017-09-05 08:50:544346 base::BindOnce(&NotifyCacheOnIO, request_context, url, http_method));
[email protected]8bfc8272013-09-09 20:10:534347 }
[email protected]724159a2010-12-30 01:11:184348}
4349
nicka0ac8382016-12-15 23:59:234350void WebContentsImpl::OnDidDisplayInsecureContent(RenderFrameHostImpl* source) {
4351 // Any frame can trigger display of insecure content, so we don't check
4352 // |source| here.
carloskd9d97942017-02-16 08:58:094353 DidDisplayInsecureContent();
4354}
4355
4356void WebContentsImpl::DidDisplayInsecureContent() {
estarkc2273502016-10-12 22:03:024357 controller_.ssl_manager()->DidDisplayMixedContent();
[email protected]724159a2010-12-30 01:11:184358}
4359
elawrenceb2ac2a232017-03-27 21:46:254360void WebContentsImpl::OnDidContainInsecureFormAction(
4361 RenderFrameHostImpl* source) {
4362 controller_.ssl_manager()->DidContainInsecureFormAction();
4363}
4364
nicka0ac8382016-12-15 23:59:234365void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source,
4366 const GURL& security_origin,
estark910b4572015-12-09 20:55:414367 const GURL& target_url) {
nicka0ac8382016-12-15 23:59:234368 // TODO(nick, estark): Should we call FilterURL using |source|'s process on
4369 // these parameters? |target_url| seems unused, except for a log message. And
4370 // |security_origin| might be replaceable with the origin of the main frame.
carloskd9d97942017-02-16 08:58:094371 DidRunInsecureContent(security_origin, target_url);
4372}
4373
4374void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin,
4375 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:584376 LOG(WARNING) << security_origin << " ran insecure content from "
4377 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:394378 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:414379 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:294380 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:394381 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
estarkc2273502016-10-12 22:03:024382 controller_.ssl_manager()->DidRunMixedContent(security_origin);
[email protected]724159a2010-12-30 01:11:184383}
4384
carloskd9d97942017-02-16 08:58:094385void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364386 if (delegate_) {
4387 delegate_->PassiveInsecureContentFound(resource_url);
4388 }
carloskd9d97942017-02-16 08:58:094389}
4390
4391bool WebContentsImpl::ShouldAllowRunningInsecureContent(
4392 WebContents* web_contents,
4393 bool allowed_per_prefs,
4394 const url::Origin& origin,
4395 const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364396 if (delegate_) {
4397 return delegate_->ShouldAllowRunningInsecureContent(
4398 web_contents, allowed_per_prefs, origin, resource_url);
4399 }
4400
4401 return allowed_per_prefs;
carloskd9d97942017-02-16 08:58:094402}
4403
Lukasz Anforowicze1b954d92017-10-30 21:28:064404void WebContentsImpl::ViewSource(RenderFrameHostImpl* frame) {
4405 DCHECK_EQ(this, WebContents::FromRenderFrameHost(frame));
4406
4407 // Don't do anything if there is no |delegate_| that could accept and show the
4408 // new WebContents containing the view-source.
4409 if (!delegate_)
4410 return;
4411
4412 // Use the last committed entry, since the pending entry hasn't loaded yet and
4413 // won't be copied into the cloned tab.
4414 NavigationEntryImpl* last_committed_entry =
4415 static_cast<NavigationEntryImpl*>(frame->frame_tree_node()
4416 ->navigator()
4417 ->GetController()
4418 ->GetLastCommittedEntry());
4419 if (!last_committed_entry)
4420 return;
4421
4422 FrameNavigationEntry* frame_entry =
4423 last_committed_entry->GetFrameEntry(frame->frame_tree_node());
4424 if (!frame_entry)
4425 return;
4426
4427 // Any new WebContents opened while this WebContents is in fullscreen can be
4428 // used to confuse the user, so drop fullscreen.
4429 if (IsFullscreenForCurrentTab())
4430 ExitFullscreen(true);
4431
4432 // We intentionally don't share the SiteInstance with the original frame so
4433 // that view source has a consistent process model and always ends up in a new
4434 // process (https://crbug.com/699493).
4435 scoped_refptr<SiteInstanceImpl> site_instance_for_view_source = nullptr;
4436 // Referrer is not important, because view-source should not hit the network,
4437 // but should be served from the cache instead.
4438 Referrer referrer_for_view_source;
4439 // Do not restore title, derive it from the url.
4440 base::string16 title_for_view_source;
4441 auto navigation_entry = std::make_unique<NavigationEntryImpl>(
4442 site_instance_for_view_source, frame_entry->url(),
4443 referrer_for_view_source, title_for_view_source, ui::PAGE_TRANSITION_LINK,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:094444 /* is_renderer_initiated = */ false,
4445 /* blob_url_loader_factory = */ nullptr);
Lukasz Anforowicze1b954d92017-10-30 21:28:064446 navigation_entry->SetVirtualURL(GURL(content::kViewSourceScheme +
4447 std::string(":") +
4448 frame_entry->url().spec()));
4449
4450 // Do not restore scroller position.
4451 // TODO(creis, lukasza, arthursonzogni): Do not reuse the original PageState,
4452 // but start from a new one and only copy the needed data.
4453 const PageState& new_page_state =
4454 frame_entry->page_state().RemoveScrollOffset();
4455
4456 scoped_refptr<FrameNavigationEntry> new_frame_entry =
4457 navigation_entry->root_node()->frame_entry;
4458 new_frame_entry->set_method(frame_entry->method());
4459 new_frame_entry->SetPageState(new_page_state);
4460
4461 // Create a new WebContents, which is used to display the source code.
erikchenbee5c9622018-04-27 19:30:254462 std::unique_ptr<WebContents> view_source_contents =
Erik Chenbb8e738e2018-04-28 14:10:434463 Create(CreateParams(GetBrowserContext()));
Lukasz Anforowicze1b954d92017-10-30 21:28:064464
4465 // Restore the previously created NavigationEntry.
4466 std::vector<std::unique_ptr<NavigationEntry>> navigation_entries;
4467 navigation_entries.push_back(std::move(navigation_entry));
4468 view_source_contents->GetController().Restore(0, RestoreType::CURRENT_SESSION,
4469 &navigation_entries);
4470
4471 // Add |view_source_contents| as a new tab.
4472 gfx::Rect initial_rect;
4473 constexpr bool kUserGesture = true;
4474 bool ignored_was_blocked;
erikchenbee5c9622018-04-27 19:30:254475 delegate_->AddNewContents(this, std::move(view_source_contents),
Lukasz Anforowicze1b954d92017-10-30 21:28:064476 WindowOpenDisposition::NEW_FOREGROUND_TAB,
4477 initial_rect, kUserGesture, &ignored_was_blocked);
4478 // Note that the |delegate_| could have deleted |view_source_contents| during
4479 // AddNewContents method call.
4480}
4481
Jay Civellid5904f02018-03-23 19:43:574482void WebContentsImpl::SubresourceResponseStarted(const GURL& url,
4483 net::CertStatus cert_status) {
4484 controller_.ssl_manager()->DidStartResourceResponse(url, cert_status);
4485 SetNotWaitingForResponse();
4486}
4487
Jay Civelli116683f2018-03-27 19:56:234488void WebContentsImpl::ResourceLoadComplete(
Jay Civelli52a63302018-04-30 22:39:554489 RenderFrameHost* render_frame_host,
Jay Civelli116683f2018-03-27 19:56:234490 mojom::ResourceLoadInfoPtr resource_load_info) {
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254491 for (auto& observer : observers_) {
Jay Civelli718fd6c02018-05-11 21:04:274492 observer.ResourceLoadComplete(render_frame_host, *resource_load_info);
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254493 }
John Abd-El-Malekd4882642017-12-04 21:45:194494}
4495
Wei Li5bb659742018-02-14 03:07:584496void WebContentsImpl::PrintCrossProcessSubframe(
4497 const gfx::Rect& rect,
4498 int document_cookie,
4499 RenderFrameHost* subframe_host) {
Wei Li5c0b4d12018-03-22 15:05:224500 auto* outer_contents = GetOuterWebContents();
4501 if (outer_contents) {
4502 // When an extension or app page is printed, the content should be
4503 // composited with outer content, so the outer contents should handle the
4504 // print request.
4505 outer_contents->PrintCrossProcessSubframe(rect, document_cookie,
4506 subframe_host);
4507 return;
4508 }
4509
Wei Li5bb659742018-02-14 03:07:584510 // If there is no delegate such as in tests or during deletion, do nothing.
4511 if (!delegate_)
4512 return;
4513
4514 delegate_->PrintCrossProcessSubframe(this, rect, document_cookie,
4515 subframe_host);
4516}
4517
rob.buis300b0872017-03-10 20:43:584518#if defined(OS_ANDROID)
4519base::android::ScopedJavaLocalRef<jobject>
4520WebContentsImpl::GetJavaRenderFrameHostDelegate() {
4521 return GetJavaWebContents();
4522}
4523#endif
4524
estark910b4572015-12-09 20:55:414525void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004526 RenderFrameHostImpl* source) {
estarkc2273502016-10-12 22:03:024527 controller_.ssl_manager()->DidDisplayContentWithCertErrors();
estark910b4572015-12-09 20:55:414528}
4529
4530void WebContentsImpl::OnDidRunContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004531 RenderFrameHostImpl* source) {
nicka0ac8382016-12-15 23:59:234532 // TODO(nick, estark): Do we need to consider |source| here somehow?
estarkcd2e30c2016-08-12 06:51:154533 NavigationEntry* entry = controller_.GetVisibleEntry();
4534 if (!entry)
estarkaeda1422016-05-10 02:31:124535 return;
4536
estarkaeda1422016-05-10 02:31:124537 // TODO(estark): check that this does something reasonable for
4538 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:154539 controller_.ssl_manager()->DidRunContentWithCertErrors(
4540 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:414541}
4542
nicka0ac8382016-12-15 23:59:234543void WebContentsImpl::OnDocumentLoadedInFrame(RenderFrameHostImpl* source) {
ericwilligersde386342016-10-19 02:35:094544 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:234545 observer.DocumentLoadedInFrame(source);
[email protected]724159a2010-12-30 01:11:184546}
4547
nicka0ac8382016-12-15 23:59:234548void WebContentsImpl::OnDidFinishLoad(RenderFrameHostImpl* source,
4549 const GURL& url) {
[email protected]8b3af1e2014-01-24 13:29:124550 GURL validated_url(url);
nicka0ac8382016-12-15 23:59:234551 source->GetProcess()->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:374552
ericwilligersde386342016-10-19 02:35:094553 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:234554 observer.DidFinishLoad(source, validated_url);
[email protected]1a55c5be2011-11-29 11:36:314555}
4556
nicka0ac8382016-12-15 23:59:234557void WebContentsImpl::OnGoToEntryAtOffset(RenderViewHostImpl* source,
4558 int offset) {
4559 // All frames are allowed to navigate the global history.
avi6ddfcae2015-06-30 15:50:574560 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
4561 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:264562}
4563
nicka0ac8382016-12-15 23:59:234564void WebContentsImpl::OnUpdateZoomLimits(RenderViewHostImpl* source,
4565 int minimum_percent,
[email protected]fce823222014-05-30 16:24:304566 int maximum_percent) {
[email protected]216813952011-05-19 22:21:264567 minimum_zoom_percent_ = minimum_percent;
4568 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:264569}
4570
nicka0ac8382016-12-15 23:59:234571void WebContentsImpl::OnPageScaleFactorChanged(RenderViewHostImpl* source,
4572 float page_scale_factor) {
mcnee336ea2c2017-05-23 22:50:594573#if !defined(OS_ANDROID)
4574 // While page scale factor is used on mobile, this PageScaleFactorIsOne logic
4575 // is only needed on desktop.
mcnee432e47d2015-11-09 19:37:464576 bool is_one = page_scale_factor == 1.f;
4577 if (is_one != page_scale_factor_is_one_) {
4578 page_scale_factor_is_one_ = is_one;
4579
4580 HostZoomMapImpl* host_zoom_map =
4581 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
4582
nicka0ac8382016-12-15 23:59:234583 if (host_zoom_map) {
mcnee432e47d2015-11-09 19:37:464584 host_zoom_map->SetPageScaleFactorIsOneForView(
nicka0ac8382016-12-15 23:59:234585 source->GetProcess()->GetID(), source->GetRoutingID(),
mcnee432e47d2015-11-09 19:37:464586 page_scale_factor_is_one_);
4587 }
4588 }
mcnee336ea2c2017-05-23 22:50:594589#endif // !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:464590
ericwilligersde386342016-10-19 02:35:094591 for (auto& observer : observers_)
4592 observer.OnPageScaleFactorChanged(page_scale_factor);
mcnee432e47d2015-11-09 19:37:464593}
4594
nicka0ac8382016-12-15 23:59:234595void WebContentsImpl::OnEnumerateDirectory(RenderViewHostImpl* source,
4596 int request_id,
[email protected]2dec8ec2013-02-07 19:20:344597 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:434598 if (!delegate_)
4599 return;
4600
[email protected]b9535422012-02-09 01:47:594601 ChildProcessSecurityPolicyImpl* policy =
4602 ChildProcessSecurityPolicyImpl::GetInstance();
nicka0ac8382016-12-15 23:59:234603 if (policy->CanReadFile(source->GetProcess()->GetID(), path)) {
4604 // TODO(nick): |this| param in the call below ought to be a RenderFrameHost.
[email protected]b9535422012-02-09 01:47:594605 delegate_->EnumerateDirectory(this, request_id, path);
nicka0ac8382016-12-15 23:59:234606 }
[email protected]3a29a6e2011-08-24 18:26:214607}
4608
nicka0ac8382016-12-15 23:59:234609void WebContentsImpl::OnRegisterProtocolHandler(RenderFrameHostImpl* source,
4610 const std::string& protocol,
[email protected]b172aee2012-04-10 17:05:264611 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:264612 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:364613 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234614 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4615 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]e5f2de02012-07-20 22:15:434616 if (!delegate_)
4617 return;
4618
[email protected]b9535422012-02-09 01:47:594619 ChildProcessSecurityPolicyImpl* policy =
4620 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:324621 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:594622 return;
[email protected]8f810632013-06-06 22:33:324623
[email protected]c125e532014-05-10 20:39:064624 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:204625}
4626
nicka0ac8382016-12-15 23:59:234627void WebContentsImpl::OnUnregisterProtocolHandler(RenderFrameHostImpl* source,
4628 const std::string& protocol,
[email protected]f5273e52014-07-14 16:30:204629 const GURL& url,
4630 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234631 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4632 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]f5273e52014-07-14 16:30:204633 if (!delegate_)
4634 return;
4635
4636 ChildProcessSecurityPolicyImpl* policy =
4637 ChildProcessSecurityPolicyImpl::GetInstance();
4638 if (policy->IsPseudoScheme(protocol))
4639 return;
4640
4641 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
4642}
4643
kouhei40f03cb2015-09-24 07:47:014644void WebContentsImpl::OnUpdatePageImportanceSignals(
nicka0ac8382016-12-15 23:59:234645 RenderFrameHostImpl* source,
kouhei40f03cb2015-09-24 07:47:014646 const PageImportanceSignals& signals) {
nicka0ac8382016-12-15 23:59:234647 // TODO(nick, kouhei): Fix this for oopifs; currently all frames' state gets
4648 // written to this one field.
kouhei40f03cb2015-09-24 07:47:014649 page_importance_signals_ = signals;
4650}
4651
nicka0ac8382016-12-15 23:59:234652void WebContentsImpl::OnFindReply(RenderFrameHostImpl* source,
4653 int request_id,
[email protected]b172aee2012-04-10 17:05:264654 int number_of_matches,
4655 const gfx::Rect& selection_rect,
4656 int active_match_ordinal,
4657 bool final_update) {
paulmeyerfeafc2d2017-04-25 21:46:404658 if (active_match_ordinal > 0)
4659 SetFocusedFrame(source->frame_tree_node(), source->GetSiteInstance());
4660
paulmeyerc0b762b2016-04-13 11:55:174661 // Forward the find reply to the FindRequestManager, along with the
4662 // RenderFrameHost associated with the frame that the reply came from.
nicka0ac8382016-12-15 23:59:234663 GetOrCreateFindRequestManager()->OnFindReply(
4664 source, request_id, number_of_matches, selection_rect,
4665 active_match_ordinal, final_update);
[email protected]b888919c2011-09-02 00:32:164666}
4667
mfomitchev2b8b066a2016-01-28 19:23:154668#if defined(OS_ANDROID)
[email protected]1ff427972013-02-07 21:14:074669void WebContentsImpl::OnOpenDateTimeDialog(
nicka0ac8382016-12-15 23:59:234670 RenderViewHostImpl* source,
[email protected]1ff427972013-02-07 21:14:074671 const ViewHostMsg_DateTimeDialogValue_Params& value) {
nicka0ac8382016-12-15 23:59:234672 date_time_chooser_->ShowDialog(
4673 GetTopLevelNativeWindow(), source, value.dialog_type, value.dialog_value,
4674 value.minimum, value.maximum, value.step, value.suggestions);
[email protected]583418cc2013-01-17 14:01:104675}
[email protected]59363fc92012-09-05 03:46:314676#endif
4677
nicka0ac8382016-12-15 23:59:234678void WebContentsImpl::OnDomOperationResponse(RenderFrameHostImpl* source,
4679 const std::string& json_string) {
4680 // TODO(nick, lukasza): The notification below should probably be updated to
4681 // include |source|.
avi60bd4902015-09-23 20:39:244682 std::string json = json_string;
4683 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
4684 Source<WebContents>(this),
4685 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:404686}
4687
nicka0ac8382016-12-15 23:59:234688void WebContentsImpl::OnAppCacheAccessed(RenderViewHostImpl* source,
4689 const GURL& manifest_url,
[email protected]b172aee2012-04-10 17:05:264690 bool blocked_by_policy) {
nicka0ac8382016-12-15 23:59:234691 // TODO(nick): Should we consider |source| here? Should we call FilterURL on
4692 // |manifest_url|?
4693
[email protected]7fc4bbb2011-09-08 21:23:104694 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094695 for (auto& observer : observers_)
4696 observer.AppCacheAccessed(manifest_url, blocked_by_policy);
[email protected]7fc4bbb2011-09-08 21:23:104697}
4698
Joel Hockey85b379d2017-12-11 10:42:134699void WebContentsImpl::OnColorChooserFactoryRequest(
Joel Hockey163835a2017-12-20 11:51:574700 blink::mojom::ColorChooserFactoryRequest request) {
Joel Hockey85b379d2017-12-11 10:42:134701 color_chooser_factory_bindings_.AddBinding(this, std::move(request));
4702}
4703
4704void WebContentsImpl::OpenColorChooser(
Joel Hockey163835a2017-12-20 11:51:574705 blink::mojom::ColorChooserRequest chooser_request,
4706 blink::mojom::ColorChooserClientPtr client,
[email protected]8ed16472014-04-11 19:02:484707 SkColor color,
Joel Hockey163835a2017-12-20 11:51:574708 std::vector<blink::mojom::ColorSuggestionPtr> suggestions) {
Joel Hockey85b379d2017-12-11 10:42:134709 content::ColorChooser* new_color_chooser =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:284710 delegate_ ? delegate_->OpenColorChooser(this, color, suggestions)
4711 : nullptr;
[email protected]820957a2014-01-14 14:56:304712 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:214713 return;
[email protected]8ed16472014-04-11 19:02:484714
Joel Hockey85b379d2017-12-11 10:42:134715 color_chooser_.reset();
4716 color_chooser_ = std::make_unique<ColorChooser>(
4717 new_color_chooser, std::move(chooser_request), std::move(client));
[email protected]da8543762012-03-20 08:52:204718}
4719
brettw4b461082016-11-19 18:55:164720#if BUILDFLAG(ENABLE_PLUGINS)
nicka0ac8382016-12-15 23:59:234721void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source,
4722 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094723 for (auto& observer : observers_)
4724 observer.PepperInstanceCreated();
nicka0ac8382016-12-15 23:59:234725 pepper_playback_observer_->PepperInstanceCreated(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004726}
4727
nicka0ac8382016-12-15 23:59:234728void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source,
4729 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094730 for (auto& observer : observers_)
4731 observer.PepperInstanceDeleted();
nicka0ac8382016-12-15 23:59:234732 pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004733}
4734
nicka0ac8382016-12-15 23:59:234735void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source,
4736 int plugin_child_id,
tommyclie6633ca72014-10-31 00:40:424737 const base::FilePath& path,
4738 bool is_hung) {
4739 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
4740
ericwilligersde386342016-10-19 02:35:094741 for (auto& observer : observers_)
4742 observer.PluginHungStatusChanged(plugin_child_id, path, is_hung);
tommyclie6633ca72014-10-31 00:40:424743}
4744
nicka0ac8382016-12-15 23:59:234745void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source,
4746 int32_t pp_instance) {
4747 pepper_playback_observer_->PepperStartsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174748}
4749
nicka0ac8382016-12-15 23:59:234750void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source,
4751 int32_t pp_instance) {
4752 pepper_playback_observer_->PepperStopsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174753}
4754
nicka0ac8382016-12-15 23:59:234755void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source,
4756 const base::FilePath& plugin_path,
tommyclie6633ca72014-10-31 00:40:424757 base::ProcessId plugin_pid) {
nicka0ac8382016-12-15 23:59:234758 // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted,
4759 // and is only used by BlinkTestController.
ericwilligersde386342016-10-19 02:35:094760 for (auto& observer : observers_)
4761 observer.PluginCrashed(plugin_path, plugin_pid);
tommyclie6633ca72014-10-31 00:40:424762}
4763
[email protected]d8415ad92012-08-23 14:40:504764void WebContentsImpl::OnRequestPpapiBrokerPermission(
nicka0ac8382016-12-15 23:59:234765 RenderViewHostImpl* source,
4766 int ppb_broker_route_id,
[email protected]d8415ad92012-08-23 14:40:504767 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:344768 const base::FilePath& plugin_path) {
nicka0ac8382016-12-15 23:59:234769 base::Callback<void(bool)> permission_result_callback = base::Bind(
4770 &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this),
4771 source->GetProcess()->GetID(), ppb_broker_route_id);
[email protected]8c8fc292012-11-23 18:57:164772 if (!delegate_) {
Tommy Nyquist4b749d02018-03-20 21:46:294773 std::move(permission_result_callback).Run(false);
[email protected]8c8fc292012-11-23 18:57:164774 return;
[email protected]d8415ad92012-08-23 14:40:504775 }
4776
nicka0ac8382016-12-15 23:59:234777 if (!delegate_->RequestPpapiBrokerPermission(this, url, plugin_path,
4778 permission_result_callback)) {
[email protected]8c8fc292012-11-23 18:57:164779 NOTIMPLEMENTED();
Tommy Nyquist4b749d02018-03-20 21:46:294780 std::move(permission_result_callback).Run(false);
[email protected]8c8fc292012-11-23 18:57:164781 }
[email protected]d8415ad92012-08-23 14:40:504782}
4783
nicka0ac8382016-12-15 23:59:234784void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id,
4785 int ppb_broker_route_id,
4786 bool result) {
4787 RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
4788 if (rph) {
4789 // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it
4790 // is not routed to a RenderView.
4791 rph->Send(
4792 new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result));
4793 }
[email protected]d8415ad92012-08-23 14:40:504794}
4795
fsamuel833ee7c2015-02-13 23:40:404796void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
4797 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:394798 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:144799 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:404800 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:374801}
brettw4b461082016-11-19 18:55:164802#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:374803
[email protected]795c28972012-12-06 06:13:394804void WebContentsImpl::OnUpdateFaviconURL(
lukasza178ff092017-06-07 23:39:504805 RenderFrameHostImpl* source,
[email protected]795c28972012-12-06 06:13:394806 const std::vector<FaviconURL>& candidates) {
lukasza178ff092017-06-07 23:39:504807 // Ignore favicons for non-main frame.
4808 if (source->GetParent()) {
4809 NOTREACHED();
4810 return;
4811 }
4812
pkotwiczf9bc20592015-04-21 18:57:064813 // We get updated favicon URLs after the page stops loading. If a cross-site
4814 // navigation occurs while a page is still loading, the initial page
4815 // may stop loading and send us updated favicon URLs after the navigation
4816 // for the new page has committed.
lukasza178ff092017-06-07 23:39:504817 if (!source->IsCurrent())
pkotwiczf9bc20592015-04-21 18:57:064818 return;
4819
ericwilligersde386342016-10-19 02:35:094820 for (auto& observer : observers_)
4821 observer.DidUpdateFaviconURL(candidates);
[email protected]795c28972012-12-06 06:13:394822}
4823
qinmin72e8bd02016-10-21 19:35:374824void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) {
4825 is_overlay_content_ = is_overlay_content;
4826}
4827
nicka0ac8382016-12-15 23:59:234828void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(RenderViewHostImpl* source) {
4829 // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if
4830 // |source| is the main frame.
ericwilligersde386342016-10-19 02:35:094831 for (auto& observer : observers_)
4832 observer.DidFirstVisuallyNonEmptyPaint();
yusufod41c5f92015-03-06 00:14:284833
peter90afaba2015-06-01 12:05:294834 did_first_visually_non_empty_paint_ = true;
4835
yusufod41c5f92015-03-06 00:14:284836 if (theme_color_ != last_sent_theme_color_) {
4837 // Theme color should have updated by now if there was one.
ericwilligersde386342016-10-19 02:35:094838 for (auto& observer : observers_)
4839 observer.DidChangeThemeColor(theme_color_);
yusufod41c5f92015-03-06 00:14:284840 last_sent_theme_color_ = theme_color_;
4841 }
[email protected]9f268072013-11-07 00:02:154842}
[email protected]d9030b82013-07-19 08:26:064843
[email protected]17e286e2013-03-01 23:29:394844void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
ericwilligersde386342016-10-19 02:35:094845 for (auto& observer : observers_)
4846 observer.BeforeFormRepostWarningShow();
[email protected]17e286e2013-03-01 23:29:394847}
4848
[email protected]ec6c05f2013-10-23 18:41:574849void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
4850 Activate();
4851 if (delegate_)
4852 delegate_->ShowRepostFormWarningDialog(this);
4853}
4854
[email protected]b4c84012014-04-28 19:51:104855bool WebContentsImpl::HasAccessedInitialDocument() {
4856 return has_accessed_initial_document_;
4857}
4858
afakhry6f0c1ec22016-07-14 13:55:134859void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:264860 const base::string16& title) {
[email protected]fcf75d42013-12-03 20:11:264861 base::string16 final_title;
Avi Drissman93002212017-09-27 03:20:524862 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:324863
[email protected]987fc3a2011-05-26 14:18:094864 // If a page is created via window.open and never navigated,
4865 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:554866 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:094867 if (entry) {
[email protected]36fc0392011-12-25 03:59:514868 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:134869 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:324870
[email protected]36fc0392011-12-25 03:59:514871 entry->SetTitle(final_title);
Avi Drissman93002212017-09-27 03:20:524872
4873 // The title for display may differ from the title just set; grab it.
4874 final_title = entry->GetTitleForDisplay();
[email protected]987fc3a2011-05-26 14:18:094875 } else {
4876 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:134877 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:094878
4879 page_title_when_no_navigation_entry_ = final_title;
4880 }
[email protected]420ae012009-04-24 05:16:324881
[email protected]420ae012009-04-24 05:16:324882 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:234883 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:324884
ericwilligersde386342016-10-19 02:35:094885 for (auto& observer : observers_)
Avi Drissman93002212017-09-27 03:20:524886 observer.TitleWasSet(entry);
[email protected]66798902013-10-01 18:40:164887
afakhry6f0c1ec22016-07-14 13:55:134888 // Broadcast notifications when the UI should be updated.
4889 if (entry == controller_.GetEntryAtOffset(0))
4890 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:324891}
4892
fdegansa696e5112015-04-17 01:57:594893void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:004894 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:004895 if (delegate_)
fdegansa696e5112015-04-17 01:57:594896 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:004897}
4898
4899void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:344900 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:004901 loading_weak_factory_.InvalidateWeakPtrs();
4902 loading_last_progress_update_ = base::TimeTicks();
4903}
4904
clamy44e84ce2016-02-22 15:38:254905// Notifies the RenderWidgetHost instance about the fact that the page is
4906// loading, or done loading.
4907void WebContentsImpl::LoadingStateChanged(bool to_different_document,
4908 bool due_to_interstitial,
4909 LoadNotificationDetails* details) {
4910 // Do not send notifications about loading changes in the FrameTree while the
4911 // interstitial page is pausing the throbber.
creisadca9862017-06-16 19:12:114912 if (ShowingInterstitialPage() && interstitial_page_->pause_throbber() &&
clamy44e84ce2016-02-22 15:38:254913 !due_to_interstitial) {
4914 return;
4915 }
4916
4917 bool is_loading = IsLoading();
4918
4919 if (!is_loading) {
4920 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
4921 base::string16());
4922 load_state_host_.clear();
4923 upload_size_ = 0;
4924 upload_position_ = 0;
4925 }
4926
4927 GetRenderManager()->SetIsLoading(is_loading);
4928
4929 waiting_for_response_ = is_loading;
4930 is_load_to_different_document_ = to_different_document;
4931
4932 if (delegate_)
4933 delegate_->LoadingStateChanged(this, to_different_document);
4934 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
4935
4936 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
4937 if (is_loading) {
4938 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
4939 this, "URL", url, "Main FrameTreeNode id",
4940 GetFrameTree()->root()->frame_tree_node_id());
ericwilligersde386342016-10-19 02:35:094941 for (auto& observer : observers_)
4942 observer.DidStartLoading();
clamy44e84ce2016-02-22 15:38:254943 } else {
4944 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
4945 this, "URL", url);
ericwilligersde386342016-10-19 02:35:094946 for (auto& observer : observers_)
4947 observer.DidStopLoading();
clamy44e84ce2016-02-22 15:38:254948 }
4949
4950 // TODO(avi): Remove. http://crbug.com/170921
4951 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
4952 NotificationDetails det = NotificationService::NoDetails();
4953 if (details)
4954 det = Details<LoadNotificationDetails>(details);
4955 NotificationService::current()->Notify(
4956 type, Source<NavigationController>(&controller_), det);
4957}
4958
[email protected]02d7b6e2014-06-24 21:01:504959void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
4960 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:324961 // After sending out a swap notification, we need to send a disconnect
4962 // notification so that clients that pick up a pointer to |this| can NULL the
4963 // pointer. See Bug 1230284.
4964 notify_disconnection_ = true;
ericwilligersde386342016-10-19 02:35:094965 for (auto& observer : observers_)
4966 observer.RenderViewHostChanged(old_host, new_host);
[email protected]da7a7182013-09-06 08:11:114967
[email protected]7a846df2012-09-20 19:17:394968 // Ensure that the associated embedder gets cleared after a RenderViewHost
4969 // gets swapped, so we don't reuse the same embedder next time a
4970 // RenderViewHost is attached to this WebContents.
4971 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:324972}
4973
[email protected]02d7b6e2014-06-24 21:01:504974void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
Jinsuk Kim895b2c52018-07-03 06:49:164975 RenderFrameHost* new_host,
4976 bool is_main_frame) {
Bo Liu168c8642017-08-28 18:26:024977#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:504978 // Copy importance from |old_host| if |new_host| is a main frame.
4979 if (old_host && !new_host->GetParent()) {
Bo Liu7c6779e92017-08-16 02:02:284980 static_cast<RenderFrameHostImpl*>(new_host)
4981 ->GetRenderWidgetHost()
Bo Liu16dd7b8322018-05-02 21:19:504982 ->SetImportance(static_cast<RenderFrameHostImpl*>(old_host)
4983 ->GetRenderWidgetHost()
4984 ->importance());
Bo Liu7c6779e92017-08-16 02:02:284985 }
Bo Liu168c8642017-08-28 18:26:024986#endif
ericwilligersde386342016-10-19 02:35:094987 for (auto& observer : observers_)
4988 observer.RenderFrameHostChanged(old_host, new_host);
Jinsuk Kim895b2c52018-07-03 06:49:164989
4990 view_->RenderFrameSwappedIn(old_host, new_host, is_main_frame);
[email protected]02d7b6e2014-06-24 21:01:504991}
4992
[email protected]da7a7182013-09-06 08:11:114993// TODO(avi): Remove this entire function because this notification is already
4994// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:264995void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:324996 if (!notify_disconnection_)
4997 return;
4998
4999 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:215000 NotificationService::current()->Notify(
5001 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
5002 Source<WebContents>(this),
5003 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:325004}
5005
[email protected]cbb1ef592013-06-05 19:49:465006void WebContentsImpl::NotifyNavigationEntryCommitted(
5007 const LoadCommittedDetails& load_details) {
ericwilligersde386342016-10-19 02:35:095008 for (auto& observer : observers_)
5009 observer.NavigationEntryCommitted(load_details);
[email protected]cbb1ef592013-06-05 19:49:465010}
5011
Sam McNally5c087a32017-08-25 01:46:145012void WebContentsImpl::NotifyNavigationEntryChanged(
5013 const EntryChangedDetails& change_details) {
5014 for (auto& observer : observers_)
5015 observer.NavigationEntryChanged(change_details);
5016}
5017
5018void WebContentsImpl::NotifyNavigationListPruned(
5019 const PrunedDetails& pruned_details) {
5020 for (auto& observer : observers_)
5021 observer.NavigationListPruned(pruned_details);
5022}
5023
Christian Dullweber1af31e62018-02-22 11:49:485024void WebContentsImpl::NotifyNavigationEntriesDeleted() {
5025 for (auto& observer : observers_)
5026 observer.NavigationEntriesDeleted();
5027}
5028
rockotf62002a2016-09-15 00:08:595029void WebContentsImpl::OnAssociatedInterfaceRequest(
5030 RenderFrameHost* render_frame_host,
5031 const std::string& interface_name,
5032 mojo::ScopedInterfaceEndpointHandle handle) {
5033 auto it = binding_sets_.find(interface_name);
5034 if (it != binding_sets_.end())
5035 it->second->OnRequestForFrame(render_frame_host, std::move(handle));
5036}
5037
Ben Goodger9e24929e2017-07-21 03:13:405038void WebContentsImpl::OnInterfaceRequest(
5039 RenderFrameHost* render_frame_host,
5040 const std::string& interface_name,
5041 mojo::ScopedMessagePipeHandle* interface_pipe) {
Joel Hockey85b379d2017-12-11 10:42:135042 registry_.TryBindInterface(interface_name, interface_pipe);
Ben Goodger9e24929e2017-07-21 03:13:405043 for (auto& observer : observers_) {
5044 observer.OnInterfaceRequestFromFrame(render_frame_host, interface_name,
5045 interface_pipe);
5046 if (!interface_pipe->is_valid())
5047 break;
5048 }
5049}
5050
Nicolas Dossou-gbetebcab2472017-09-09 12:28:405051void WebContentsImpl::OnDidBlockFramebust(const GURL& url) {
5052 if (delegate_)
5053 delegate_->OnDidBlockFramebust(this, url);
5054}
5055
[email protected]c31a84802014-04-03 15:55:495056const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
5057 return GetLastCommittedURL();
5058}
5059
[email protected]b849847b2013-12-10 21:57:585060void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:095061 for (auto& observer : observers_)
5062 observer.RenderFrameCreated(render_frame_host);
dmazzonif8a31042016-12-03 00:52:135063 UpdateAccessibilityModeOnFrame(render_frame_host);
clamy91b7abf2016-03-24 15:17:455064
5065 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
5066 return;
5067
5068 NavigationEntry* entry = controller_.GetPendingEntry();
5069 if (entry && entry->IsViewSourceMode()) {
5070 // Put the renderer in view source mode.
5071 render_frame_host->Send(
5072 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
5073 }
[email protected]b849847b2013-12-10 21:57:585074}
5075
5076void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
creis3638897452017-05-09 22:07:505077 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095078 for (auto& observer : observers_)
5079 observer.RenderFrameDeleted(render_frame_host);
creis3638897452017-05-09 22:07:505080 is_notifying_observers_ = false;
zqzhang7b6f4f02016-12-07 22:10:225081#if BUILDFLAG(ENABLE_PLUGINS)
5082 pepper_playback_observer_->RenderFrameDeleted(render_frame_host);
5083#endif
Becca Hughesfd5d8f892018-06-14 18:23:365084
5085 // Remove any fullscreen state that the frame has stored.
5086 FullscreenStateChanged(render_frame_host, false /* is_fullscreen */);
[email protected]b849847b2013-12-10 21:57:585087}
5088
[email protected]a09d53ce2014-01-31 00:46:425089void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
5090 const ContextMenuParams& params) {
avie9fd8722017-04-10 16:17:585091 // If a renderer fires off a second command to show a context menu before the
5092 // first context menu is closed, just ignore it. https://crbug.com/707534
ekaramadf6750aa2017-06-06 18:29:425093 if (showing_context_menu_)
avie9fd8722017-04-10 16:17:585094 return;
5095
[email protected]077e704b2014-05-23 19:24:105096 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:425097 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:105098 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:425099 return;
5100
[email protected]077e704b2014-05-23 19:24:105101 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
5102 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:425103}
5104
avi777ff452017-02-09 19:04:485105void WebContentsImpl::RunJavaScriptDialog(RenderFrameHost* render_frame_host,
5106 const base::string16& message,
5107 const base::string16& default_prompt,
avi777ff452017-02-09 19:04:485108 JavaScriptDialogType dialog_type,
5109 IPC::Message* reply_msg) {
Avi Drissman2ccbb402018-03-20 21:11:365110 // Ensure that if showing a dialog is the first thing that a page does, that
5111 // the contents of the previous page aren't shown behind it. This is required
5112 // because showing a dialog freezes the renderer, so no frames will be coming
5113 // from it. https://crbug.com/823353
5114 auto* render_widget_host_impl =
5115 static_cast<RenderFrameHostImpl*>(render_frame_host)
5116 ->GetRenderWidgetHost();
5117 if (render_widget_host_impl)
5118 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5119
avi0720b02e2017-06-13 03:22:135120 // Running a dialog causes an exit to webpage-initiated fullscreen.
5121 // http://crbug.com/728276
5122 if (IsFullscreenForCurrentTab())
5123 ExitFullscreen(true);
5124
Avi Drissmane04d3992017-10-05 15:11:365125 auto callback =
5126 base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
5127 render_frame_host->GetProcess()->GetID(),
5128 render_frame_host->GetRoutingID(), reply_msg);
Pavel Feldman3c1842b2017-08-02 05:00:165129
Pavel Feldman3c1842b2017-08-02 05:00:165130 std::vector<protocol::PageHandler*> page_handlers =
5131 protocol::PageHandler::EnabledForWebContents(this);
5132
Pavel Feldmanfab3cb62017-10-05 01:02:015133 if (delegate_)
5134 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5135
5136 // Suppress JavaScript dialogs when requested. Also suppress messages when
5137 // showing an interstitial as it's shown over the previous page and we don't
5138 // want the hidden page's dialogs to interfere with the interstitial.
5139 bool should_suppress = ShowingInterstitialPage() ||
5140 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055141 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5142 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015143 bool suppress_this_message = should_suppress || !has_handlers;
5144
5145 if (suppress_this_message) {
Avi Drissmane04d3992017-10-05 15:11:365146 std::move(callback).Run(true, false, base::string16());
Pavel Feldman3c1842b2017-08-02 05:00:165147 return;
5148 }
5149
5150 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365151 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165152
5153 is_showing_javascript_dialog_ = true;
5154
5155 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365156 handler->DidRunJavaScriptDialog(
Avi Drissman2fefc4b2018-02-22 20:41:015157 render_frame_host->GetLastCommittedURL(), message, default_prompt,
Pavel Feldman1c587bc52018-04-04 21:16:055158 dialog_type, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365159 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165160 }
5161
5162 if (dialog_manager_) {
[email protected]87de04b02014-04-08 22:14:495163 dialog_manager_->RunJavaScriptDialog(
Avi Drissman2fefc4b2018-02-22 20:41:015164 this, render_frame_host, dialog_type, message, default_prompt,
Avi Drissmane04d3992017-10-05 15:11:365165 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false),
5166 &suppress_this_message);
[email protected]87de04b02014-04-08 22:14:495167 }
5168
5169 if (suppress_this_message) {
5170 // If we are suppressing messages, just reply as if the user immediately
5171 // pressed "Cancel", passing true to |dialog_was_suppressed|.
Avi Drissmane04d3992017-10-05 15:11:365172 wrapper->Run(true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:495173 }
[email protected]87de04b02014-04-08 22:14:495174}
5175
5176void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:015177 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:495178 bool is_reload,
5179 IPC::Message* reply_msg) {
Avi Drissman2ccbb402018-03-20 21:11:365180 // Ensure that if showing a dialog is the first thing that a page does, that
5181 // the contents of the previous page aren't shown behind it. This is required
5182 // because showing a dialog freezes the renderer, so no frames will be coming
5183 // from it. https://crbug.com/823353
5184 auto* render_widget_host_impl =
5185 static_cast<RenderFrameHostImpl*>(render_frame_host)
5186 ->GetRenderWidgetHost();
5187 if (render_widget_host_impl)
5188 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5189
avi0720b02e2017-06-13 03:22:135190 // Running a dialog causes an exit to webpage-initiated fullscreen.
5191 // http://crbug.com/728276
5192 if (IsFullscreenForCurrentTab())
5193 ExitFullscreen(true);
5194
[email protected]39f2f9252014-05-03 00:54:015195 RenderFrameHostImpl* rfhi =
5196 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:495197 if (delegate_)
5198 delegate_->WillRunBeforeUnloadConfirm();
5199
Avi Drissmane04d3992017-10-05 15:11:365200 auto callback =
5201 base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
5202 render_frame_host->GetProcess()->GetID(),
5203 render_frame_host->GetRoutingID(), reply_msg);
Pavel Feldman3c1842b2017-08-02 05:00:165204
Pavel Feldman3c1842b2017-08-02 05:00:165205 std::vector<protocol::PageHandler*> page_handlers =
5206 protocol::PageHandler::EnabledForWebContents(this);
5207
Pavel Feldmanfab3cb62017-10-05 01:02:015208 if (delegate_)
5209 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5210
5211 bool should_suppress = ShowingInterstitialPage() || !rfhi->is_active() ||
5212 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055213 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5214 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015215 if (should_suppress || !has_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365216 std::move(callback).Run(false, true, base::string16());
[email protected]87de04b02014-04-08 22:14:495217 return;
5218 }
5219
5220 is_showing_before_unload_dialog_ = true;
Pavel Feldman3c1842b2017-08-02 05:00:165221
5222 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365223 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165224
5225 GURL frame_url = rfhi->GetLastCommittedURL();
5226 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365227 handler->DidRunBeforeUnloadConfirm(
Pavel Feldman1c587bc52018-04-04 21:16:055228 frame_url, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365229 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165230 }
5231
5232 if (dialog_manager_) {
Avi Drissmane04d3992017-10-05 15:11:365233 dialog_manager_->RunBeforeUnloadDialog(
Avi Drissmanff9ed752017-11-28 21:18:125234 this, render_frame_host, is_reload,
Avi Drissmane04d3992017-10-05 15:11:365235 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165236 }
[email protected]87de04b02014-04-08 22:14:495237}
5238
naskoada75b22016-06-11 16:09:465239void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host,
5240 const FileChooserParams& params) {
5241 if (delegate_)
5242 delegate_->RunFileChooser(render_frame_host, params);
5243}
5244
[email protected]a86c0e962013-12-17 17:10:395245WebContents* WebContentsImpl::GetAsWebContents() {
5246 return this;
5247}
5248
mcnee336ea2c2017-05-23 22:50:595249#if !defined(OS_ANDROID)
akabac6bd1212018-06-25 20:10:485250double WebContentsImpl::GetPendingPageZoomLevel() const {
wjmaclean64951902016-04-29 20:59:125251 NavigationEntry* pending_entry = GetController().GetPendingEntry();
5252 if (!pending_entry)
5253 return HostZoomMap::GetZoomLevel(this);
5254
5255 GURL url = pending_entry->GetURL();
5256 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
5257 url.scheme(), net::GetHostOrSpecFromURL(url));
5258}
mcnee336ea2c2017-05-23 22:50:595259#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:125260
qinmin72e8bd02016-10-21 19:35:375261bool WebContentsImpl::HideDownloadUI() const {
5262 return is_overlay_content_;
5263}
5264
mlamouri5cd9ae82017-02-18 11:05:095265bool WebContentsImpl::HasPersistentVideo() const {
5266 return has_persistent_video_;
5267}
5268
Alex Moshchuk27caae82017-09-11 23:11:185269RenderFrameHost* WebContentsImpl::GetPendingMainFrame() {
clamy610c63b32017-12-22 15:05:185270 return GetRenderManager()->speculative_frame_host();
Alex Moshchuk27caae82017-09-11 23:11:185271}
5272
mlamourie52c1b542017-02-23 14:57:505273bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const {
5274 return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo();
5275}
5276
François Beaufortad6c5232018-02-26 11:00:445277bool WebContentsImpl::IsPictureInPictureAllowedForFullscreenVideo() const {
5278 return media_web_contents_observer_
5279 ->IsPictureInPictureAllowedForFullscreenVideo();
5280}
5281
ekaramada110f642016-12-21 19:47:285282bool WebContentsImpl::IsFocusedElementEditable() {
5283 RenderFrameHostImpl* frame = GetFocusedFrame();
5284 return frame && frame->has_focused_editable_element();
5285}
5286
ekaramadf6750aa2017-06-06 18:29:425287bool WebContentsImpl::IsShowingContextMenu() const {
5288 return showing_context_menu_;
5289}
5290
5291void WebContentsImpl::SetShowingContextMenu(bool showing) {
5292 DCHECK_NE(showing_context_menu_, showing);
5293 showing_context_menu_ = showing;
5294
5295 if (auto* view = GetRenderWidgetHostView()) {
5296 // Notify the main frame's RWHV to run the platform-specific code, if any.
5297 static_cast<RenderWidgetHostViewBase*>(view)->SetShowingContextMenu(
5298 showing);
5299 }
5300}
5301
ekaramada110f642016-12-21 19:47:285302void WebContentsImpl::ClearFocusedElement() {
5303 if (auto* frame = GetFocusedFrame())
5304 frame->ClearFocusedElement();
5305}
5306
[email protected]7912e822014-04-16 02:37:035307bool WebContentsImpl::IsNeverVisible() {
5308 if (!delegate_)
5309 return false;
5310 return delegate_->IsNeverVisible(this);
5311}
5312
[email protected]5a3bdf52012-05-24 15:12:575313RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
5314 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:325315}
5316
[email protected]8ff00d72012-10-23 19:12:215317RendererPreferences WebContentsImpl::GetRendererPrefs(
5318 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:465319 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:515320}
5321
[email protected]7a846df2012-09-20 19:17:395322void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:275323 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:395324 browser_plugin_embedder_.reset();
5325}
5326
avallee0206f782016-07-28 18:55:335327WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
lfg601233692017-03-06 22:45:445328 if (GuestMode::IsCrossProcessFrameGuest(this))
5329 return node_.outer_web_contents();
ekaramad1beabecc2016-09-23 20:18:175330
5331 if (browser_plugin_guest_)
5332 return browser_plugin_guest_->embedder_web_contents();
5333
Lucas Furukawa Gadani105de1e812018-05-31 19:38:395334 return node_.outer_web_contents();
avallee0206f782016-07-28 18:55:335335}
5336
5337WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
lfg601233692017-03-06 22:45:445338 return GetOutermostWebContents()->node_.focused_web_contents();
avallee0206f782016-07-28 18:55:335339}
5340
avallee9993fca2016-11-17 06:16:505341bool WebContentsImpl::ContainsOrIsFocusedWebContents() {
5342 for (WebContentsImpl* focused_contents = GetFocusedWebContents();
5343 focused_contents;
5344 focused_contents = focused_contents->GetOuterWebContents()) {
5345 if (focused_contents == this)
5346 return true;
5347 }
5348
5349 return false;
5350}
5351
avallee0206f782016-07-28 18:55:335352WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
5353 WebContentsImpl* root = this;
5354 while (root->GetOuterWebContents())
5355 root = root->GetOuterWebContents();
5356 return root;
5357}
5358
avalleed68cdd12017-06-21 22:07:275359void WebContentsImpl::FocusOuterAttachmentFrameChain() {
5360 WebContentsImpl* outer_contents = GetOuterWebContents();
5361 if (!outer_contents)
5362 return;
5363
5364 FrameTreeNode* outer_node =
5365 FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId());
5366 outer_contents->frame_tree_.SetFocusedFrame(outer_node, nullptr);
5367
5368 // For a browser initiated focus change, let embedding renderer know of the
5369 // change. Otherwise, if the currently focused element is just across a
5370 // process boundary in focus order, it will not be possible to move across
5371 // that boundary. This is because the target element will already be focused
5372 // (that renderer was not notified) and drop the event.
5373 if (GetRenderManager()->GetProxyToOuterDelegate())
5374 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame();
5375
5376 outer_contents->FocusOuterAttachmentFrameChain();
5377}
5378
[email protected]b172aee2012-04-10 17:05:265379void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]86f98a22013-03-20 14:35:005380 if (delegate_)
[email protected]e85165c642014-06-10 14:34:315381 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:085382
[email protected]8ff00d72012-10-23 19:12:215383 NotificationService::current()->Notify(
5384 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
5385 Source<WebContents>(this),
5386 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:325387
[email protected]60780f412013-02-25 16:34:105388 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:265389
ericwilligersde386342016-10-19 02:35:095390 for (auto& observer : observers_)
5391 observer.RenderViewCreated(render_view_host);
Joel Einbinder848001c2017-09-19 21:39:315392 if (delegate_)
5393 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]420ae012009-04-24 05:16:325394}
5395
[email protected]b172aee2012-04-10 17:05:265396void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:525397 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325398 // Don't notify the world, since this came from a renderer in the
5399 // background.
5400 return;
5401 }
5402
dmazzoni62111452017-04-28 23:46:555403 RenderWidgetHostViewBase* rwhv =
5404 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5405 if (rwhv)
5406 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
5407
[email protected]da7a7182013-09-06 08:11:115408 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:115409
[email protected]be1f56ab2011-12-22 06:55:315410 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:235411 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:305412
5413 // Restore the focus to the tab (otherwise the focus will be on the top
5414 // window).
[email protected]484ae5912010-09-29 19:16:145415 if (was_crashed && !FocusLocationBarByDefault() &&
5416 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:065417 view_->Focus();
[email protected]484ae5912010-09-29 19:16:145418 }
[email protected]32ded2212011-11-10 18:51:435419
ericwilligersde386342016-10-19 02:35:095420 for (auto& observer : observers_)
5421 observer.RenderViewReady();
Jinsuk Kim895b2c52018-07-03 06:49:165422
5423 view_->RenderViewReady();
[email protected]420ae012009-04-24 05:16:325424}
5425
[email protected]ec6a7eb2013-04-22 17:34:225426void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
5427 base::TerminationStatus status,
5428 int error_code) {
[email protected]151a63d2011-12-20 22:32:525429 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325430 // The pending page's RenderViewHost is gone.
5431 return;
5432 }
5433
[email protected]2fcdcc32014-03-05 02:14:075434 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
5435 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:155436 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:465437 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:075438
Jennifer Apacibleb4b972a2018-06-07 04:41:025439 // Ensure any video in Picture-in-Picture is exited in the |delegate_| since
5440 // a crashed renderer may not have made a clean exit.
5441 if (HasPictureInPictureVideo())
5442 ExitPictureInPicture();
5443
[email protected]698191dc2014-02-25 01:06:135444 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:175445 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:135446
dalecurtis3d1e1302017-02-20 22:33:255447 audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID());
5448
[email protected]960b0372014-05-19 18:01:005449 // Reset the loading progress. TODO(avi): What does it mean to have a
5450 // "renderer crash" when there is more than one renderer process serving a
5451 // webpage? Once this function is called at a more granular frame level, we
5452 // probably will need to more granularly reset the state here.
5453 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:255454 NotifyDisconnected();
5455 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:005456
ericwilligersde386342016-10-19 02:35:095457 for (auto& observer : observers_)
5458 observer.RenderProcessGone(GetCrashedStatus());
[email protected]420ae012009-04-24 05:16:325459}
5460
[email protected]b172aee2012-04-10 17:05:265461void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
ericwilligersde386342016-10-19 02:35:095462 for (auto& observer : observers_)
5463 observer.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:065464}
5465
sky8b00392d2015-01-10 00:30:285466void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
5467 const GURL& url) {
5468 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
Lukasz Anforowiczfd707142018-02-07 19:46:135469 // If we're in flash fullscreen (i.e. Pepper plugin fullscreen) only update
5470 // the url if it's from the fullscreen renderer.
sky8b00392d2015-01-10 00:30:285471 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:445472 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:285473 return;
5474 }
Lukasz Anforowiczfd707142018-02-07 19:46:135475
5476 // In case of racey updates from multiple RenderViewHosts, the last URL should
5477 // be shown - see also some discussion in https://crbug.com/807776.
5478 if (!url.is_valid() && render_view_host != view_that_set_last_target_url_)
5479 return;
5480 view_that_set_last_target_url_ = url.is_valid() ? render_view_host : nullptr;
5481
[email protected]6934a702011-12-20 00:04:515482 if (delegate_)
avi450ce00e2014-09-24 01:58:525483 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:325484}
5485
Lukasz Anforowiczfd707142018-02-07 19:46:135486void WebContentsImpl::ClearTargetURL() {
5487 view_that_set_last_target_url_ = nullptr;
5488 if (delegate_)
5489 delegate_->UpdateTargetURL(this, GURL());
5490}
5491
[email protected]b172aee2012-04-10 17:05:265492void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:105493#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:295494 // The UI may be in an event-tracking loop, such as between the
5495 // mouse-down and mouse-up in text selection or a button click.
5496 // Defer the close until after tracking is complete, so that we
5497 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:295498 // TODO(shess): This could get more fine-grained. For instance,
5499 // closing a tab in another window while selecting text in the
5500 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:105501 if (view_->IsEventTracking()) {
5502 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:295503 return;
5504 }
[email protected]60780f412013-02-25 16:34:105505#endif
[email protected]07707302009-11-06 00:50:295506
[email protected]420ae012009-04-24 05:16:325507 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:525508 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:515509 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:325510}
5511
Avi Drissman014dec72018-06-07 02:34:015512void WebContentsImpl::RequestSetBounds(const gfx::Rect& new_bounds) {
5513 if (delegate_)
5514 delegate_->SetContentsBounds(this, new_bounds);
[email protected]420ae012009-04-24 05:16:325515}
5516
fdegansa696e5112015-04-17 01:57:595517void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:095518 bool to_different_document) {
Evan Stadec3b26022017-07-14 19:50:245519 LoadingStateChanged(frame_tree_node->IsMainFrame() && to_different_document,
5520 false, nullptr);
dmazzonibf8cec42015-02-08 08:28:085521
5522 // Notify accessibility that the user is navigating away from the
5523 // current document.
5524 //
5525 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:085526 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:595527 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:085528 if (manager)
5529 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:325530}
5531
fdegansc73eec22015-03-19 14:47:545532void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:085533 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:325534
[email protected]9595fd82013-04-19 21:28:495535 // Use the last committed entry rather than the active one, in case a
5536 // pending entry has been created.
5537 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:205538 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:495539
[email protected]420ae012009-04-24 05:16:325540 // An entry may not exist for a stop when loading an initial blank page or
5541 // if an iframe injected by script into a blank page finishes loading.
5542 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:205543 base::TimeDelta elapsed =
5544 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:325545
5546 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:515547 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:325548 elapsed,
5549 &controller_,
5550 controller_.GetCurrentEntryIndex()));
5551 }
5552
clamy44e84ce2016-02-22 15:38:255553 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:325554}
5555
fdegansa696e5112015-04-17 01:57:595556void WebContentsImpl::DidChangeLoadProgress() {
5557 double load_progress = frame_tree_.load_progress();
5558
5559 // The delegate is notified immediately for the first and last updates. Also,
5560 // since the message loop may be pretty busy when a page is loaded, it might
5561 // not execute a posted task in a timely manner so the progress report is sent
5562 // immediately if enough time has passed.
5563 base::TimeDelta min_delay =
5564 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
5565 bool delay_elapsed = loading_last_progress_update_.is_null() ||
5566 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
5567
5568 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
5569 // If there is a pending task to send progress, it is now obsolete.
5570 loading_weak_factory_.InvalidateWeakPtrs();
5571
5572 // Notify the load progress change.
5573 SendChangeLoadProgress();
5574
5575 // Clean-up the states if needed.
5576 if (load_progress == 1.0)
5577 ResetLoadProgressState();
5578 return;
5579 }
5580
5581 if (loading_weak_factory_.HasWeakPtrs())
5582 return;
5583
skyostil95082a62015-06-05 19:53:075584 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
tzike2aca992017-09-05 08:50:545585 FROM_HERE,
5586 base::BindOnce(&WebContentsImpl::SendChangeLoadProgress,
5587 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:595588 min_delay);
5589}
5590
avid6d88b912017-01-13 00:16:005591std::vector<std::unique_ptr<NavigationThrottle>>
5592WebContentsImpl::CreateThrottlesForNavigation(
clamycbf524d42016-09-27 12:48:355593 NavigationHandle* navigation_handle) {
5594 return GetContentClient()->browser()->CreateThrottlesForNavigation(
5595 navigation_handle);
5596}
5597
clamy1e5574e2016-09-29 16:48:445598std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
5599 NavigationHandle* navigation_handle) {
5600 DCHECK(IsBrowserSideNavigationEnabled());
5601 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
5602}
5603
pdr15f5b5b2017-06-20 00:58:005604void WebContentsImpl::DidCancelLoading() {
5605 controller_.DiscardNonCommittedEntries();
5606
5607 // Update the URL display.
5608 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
5609}
5610
[email protected]59167c22013-06-03 18:07:325611void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:105612 has_accessed_initial_document_ = true;
5613
[email protected]d1371bf8e2014-04-19 03:26:245614 // We may have left a failed browser-initiated navigation in the address bar
5615 // to let the user edit it and try again. Clear it now that content might
5616 // show up underneath it.
5617 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:455618 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:245619
[email protected]59167c22013-06-03 18:07:325620 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:505621 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:325622}
5623
alexmosbe2f4c32015-03-10 02:30:235624void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
5625 const std::string& name) {
ericwilligersde386342016-10-19 02:35:095626 for (auto& observer : observers_)
5627 observer.FrameNameChanged(render_frame_host, name);
alexmosbe2f4c32015-03-10 02:30:235628}
5629
[email protected]39f2f9252014-05-03 00:54:015630void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:295631 RenderFrameHost* render_frame_host) {
falken52a56e32016-12-08 05:02:405632 ShowInsecureLocalhostWarningIfNeeded();
5633
creis97867aa2017-02-17 18:39:455634 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095635 for (auto& observer : observers_)
5636 observer.DocumentOnLoadCompletedInMainFrame();
creis97867aa2017-02-17 18:39:455637 is_notifying_observers_ = false;
[email protected]6578fef2013-10-14 02:35:095638
5639 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:215640 NotificationService::current()->Notify(
5641 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
5642 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:295643 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:085644}
5645
creis8eb8ef22015-11-04 22:51:385646void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
5647 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:385648 // The state update affects the last NavigationEntry associated with the given
5649 // |render_frame_host|. This may not be the last committed NavigationEntry (as
5650 // in the case of an UpdateState from a frame being swapped out). We track
5651 // which entry this is in the RenderFrameHost's nav_entry_id.
5652 RenderFrameHostImpl* rfhi =
5653 static_cast<RenderFrameHostImpl*>(render_frame_host);
5654 NavigationEntryImpl* entry =
5655 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
5656 if (!entry)
5657 return;
5658
5659 FrameNavigationEntry* frame_entry =
5660 entry->GetFrameEntry(rfhi->frame_tree_node());
5661 if (!frame_entry)
5662 return;
5663
creisd06a9422015-11-11 03:08:455664 // The SiteInstance might not match if we do a cross-process navigation with
5665 // replacement (e.g., auto-subframe), in which case the swap out of the old
5666 // RenderFrameHost runs in the background after the old FrameNavigationEntry
5667 // has already been replaced and destroyed.
5668 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
5669 return;
5670
creis8eb8ef22015-11-04 22:51:385671 if (page_state == frame_entry->page_state())
5672 return; // Nothing to update.
5673
creis0cade2e2017-02-28 06:37:475674 DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState.";
nasko34634672016-07-29 18:46:065675
5676 // The document_sequence_number and item_sequence_number recorded in the
5677 // FrameNavigationEntry should not differ from the one coming with the update,
5678 // since it must come from the same document. Do not update it if a difference
5679 // is detected, as this indicates that |frame_entry| is not the correct one.
5680 ExplodedPageState exploded_state;
5681 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
5682 return;
5683
5684 if (exploded_state.top.document_sequence_number !=
5685 frame_entry->document_sequence_number() ||
5686 exploded_state.top.item_sequence_number !=
5687 frame_entry->item_sequence_number()) {
5688 return;
5689 }
5690
nasko04a322f25a2016-09-01 00:00:345691 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:385692 controller_.NotifyEntryChanged(entry);
5693}
5694
[email protected]ef3adfc2014-05-11 00:04:545695void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
[email protected]ef3adfc2014-05-11 00:04:545696 const base::string16& title,
5697 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:545698 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:585699 // For example, it might be from a recently swapped out RFH.
avi1edc8552016-10-13 21:37:165700 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
creisad8c31a2016-05-24 17:07:045701 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
[email protected]ef3adfc2014-05-11 00:04:545702
5703 // We can handle title updates when we don't have an entry in
5704 // UpdateTitleForEntry, but only if the update is from the current RVH.
5705 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:585706 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:545707 return;
5708
5709 // TODO(evan): make use of title_direction.
5710 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:135711 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:545712}
5713
5714void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
5715 const std::string& encoding) {
5716 SetEncoding(encoding);
5717}
5718
[email protected]39f2f9252014-05-03 00:54:015719void WebContentsImpl::DocumentAvailableInMainFrame(
5720 RenderViewHost* render_view_host) {
ericwilligersde386342016-10-19 02:35:095721 for (auto& observer : observers_)
5722 observer.DocumentAvailableInMainFrame();
[email protected]39f2f9252014-05-03 00:54:015723}
naskoc0fceff2015-04-30 15:53:525724
[email protected]e1c3a552012-05-04 20:51:325725void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
5726 // Tell the active RenderViewHost to run unload handlers and close, as long
5727 // as the request came from a RenderViewHost in the same BrowsingInstance.
5728 // In most cases, we receive this from a swapped out RenderViewHost.
5729 // It is possible to receive it from one that has just been swapped in,
5730 // in which case we might as well deliver the message anyway.
5731 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:525732 ClosePage();
[email protected]e1c3a552012-05-04 20:51:325733}
5734
alexmose7da5a12015-04-09 02:22:165735bool WebContentsImpl::ShouldRouteMessageEvent(
5736 RenderFrameHost* target_rfh,
5737 SiteInstance* source_site_instance) const {
5738 // Allow the message if this WebContents is dedicated to a browser plugin
5739 // guest.
[email protected]0eba810b2012-10-18 03:19:365740 // Note: This check means that an embedder could theoretically receive a
5741 // postMessage from anyone (not just its own guests). However, this is
5742 // probably not a risk for apps since other pages won't have references
5743 // to App windows.
alexmose7da5a12015-04-09 02:22:165744 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
5745}
[email protected]f546640b2012-05-15 00:03:495746
alexmos58729042015-06-18 23:20:005747void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:165748 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
5749 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:495750
alexmose7da5a12015-04-09 02:22:165751 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:145752 // If this message is going to outer WebContents from inner WebContents,
5753 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
5754 // already created a RenderFrameProxyHost for that purpose.
5755 if (GetBrowserPluginEmbedder() &&
ekaramad1beabecc2016-09-23 20:18:175756 GuestMode::IsCrossProcessFrameGuest(source_web_contents)) {
lazyboy6ec48b2a2015-06-29 15:18:145757 return;
5758 }
5759
lfg812874d2016-02-09 22:26:135760 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:065761 // We create a RenderFrameProxyHost for the embedder in the guest's render
5762 // process but we intentionally do not expose the embedder's opener chain
5763 // to it.
5764 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
5765 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:495766 } else {
alexmos58729042015-06-18 23:20:005767 RenderFrameHostImpl* source_rfhi =
5768 static_cast<RenderFrameHostImpl*>(source_rfh);
5769 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:395770 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:495771 }
5772 }
[email protected]f546640b2012-05-15 00:03:495773}
5774
avallee9993fca2016-11-17 06:16:505775void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
5776 // Only change focus if we are not currently focused.
5777 WebContentsImpl* old_contents = GetFocusedWebContents();
5778 if (old_contents == this)
5779 return;
5780
paulmeyerfeafc2d2017-04-25 21:46:405781 GetOutermostWebContents()->node_.SetFocusedWebContents(this);
5782
Greg Thompsonfb957602017-09-04 10:25:525783 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
paulmeyerfeafc2d2017-04-25 21:46:405784 return;
5785
avallee9993fca2016-11-17 06:16:505786 // Send a page level blur to the old contents so that it displays inactive UI
5787 // and focus this contents to activate it.
5788 if (old_contents)
5789 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
avalleec2ff1ef2017-01-21 00:12:305790
5791 // Make sure the outer web contents knows our frame is focused. Otherwise, the
5792 // outer renderer could have the element before or after the frame element
5793 // focused which would return early without actually advancing focus.
avalleed68cdd12017-06-21 22:07:275794 FocusOuterAttachmentFrameChain();
avalleec2ff1ef2017-01-21 00:12:305795
lfg1453e412017-04-11 00:48:505796 if (ShowingInterstitialPage()) {
creisadca9862017-06-16 19:12:115797 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:505798 ->GetRenderWidgetHost()
5799 ->SetPageFocus(true);
5800 } else {
5801 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
5802 }
avallee9993fca2016-11-17 06:16:505803}
5804
avallee0206f782016-07-28 18:55:335805void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
5806 SiteInstance* source) {
avallee0206f782016-07-28 18:55:335807 frame_tree_.SetFocusedFrame(node, source);
avalleed68cdd12017-06-21 22:07:275808
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:575809 if (auto* inner_contents = node_.GetInnerWebContentsInFrame(node)) {
5810 // |this| is an outer WebContents and |node| represents an inner
5811 // WebContents. Transfer the focus to the inner contents if |this| is
5812 // focused.
5813 if (GetFocusedWebContents() == this)
5814 inner_contents->SetAsFocusedWebContentsIfNecessary();
5815 } else if (node_.OuterContentsFrameTreeNode() &&
5816 node_.OuterContentsFrameTreeNode()
5817 ->current_frame_host()
5818 ->GetSiteInstance() == source) {
5819 // |this| is an inner WebContents, |node| is its main FrameTreeNode and
5820 // the outer WebContents FrameTreeNode is at |source|'s SiteInstance.
5821 // Transfer the focus to the inner WebContents if the outer WebContents is
5822 // focused. This branch is used when an inner WebContents is focused through
5823 // its RenderFrameProxyHost (via FrameHostMsg_FrameFocused IPC, used to
5824 // implement the window.focus() API).
5825 if (GetFocusedWebContents() == GetOuterWebContents())
5826 SetAsFocusedWebContentsIfNecessary();
5827 } else if (!GetOuterWebContents()) {
5828 // This is an outermost WebContents.
5829 SetAsFocusedWebContentsIfNecessary();
5830 } else if (!GuestMode::IsCrossProcessFrameGuest(this) &&
5831 GetOuterWebContents()) {
5832 // TODO(lfg, paulmeyer): Allows BrowserPlugins to set themselves as the
5833 // focused WebContents. This works around a bug in FindRequestManager that
5834 // doesn't support properly traversing BrowserPlugins.
5835 SetAsFocusedWebContentsIfNecessary();
5836 }
avalleed68cdd12017-06-21 22:07:275837}
5838
Avi Drissman36f801f2018-02-01 20:06:045839void WebContentsImpl::DidCallFocus() {
5840 // Any explicit focusing of another window while this WebContents is in
5841 // fullscreen can be used to confuse the user, so drop fullscreen.
5842 if (IsFullscreenForCurrentTab())
5843 ExitFullscreen(true);
5844}
5845
avalleed68cdd12017-06-21 22:07:275846RenderFrameHost* WebContentsImpl::GetFocusedFrameIncludingInnerWebContents() {
5847 WebContentsImpl* contents = this;
5848 FrameTreeNode* focused_node = contents->frame_tree_.GetFocusedFrame();
5849
5850 // If there is no focused frame in the outer WebContents, we need to return
5851 // null.
5852 if (!focused_node)
5853 return nullptr;
5854
5855 // If the focused frame is embedding an inner WebContents, we must descend
5856 // into that contents. If the current WebContents does not have a focused
5857 // frame, return the main frame of this contents instead of the focused empty
5858 // frame embedding this contents.
5859 while (true) {
5860 contents = contents->node_.GetInnerWebContentsInFrame(focused_node);
5861 if (!contents)
5862 return focused_node->current_frame_host();
5863
5864 focused_node = contents->frame_tree_.GetFocusedFrame();
5865 if (!focused_node)
5866 return contents->GetMainFrame();
5867 }
avallee0206f782016-07-28 18:55:335868}
5869
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:575870void WebContentsImpl::OnAdvanceFocus(RenderFrameHostImpl* source_rfh) {
5871 // When a RenderFrame needs to advance focus to a RenderFrameProxy (by hitting
5872 // TAB), the RenderFrameProxy sends an IPC to RenderFrameProxyHost. When this
5873 // RenderFrameProxyHost represents an inner WebContents, the outer WebContents
5874 // needs to focus the inner WebContents.
5875 if (GetOuterWebContents() &&
5876 GetOuterWebContents() == source_rfh->delegate()->GetAsWebContents() &&
5877 GetFocusedWebContents() == GetOuterWebContents()) {
5878 SetAsFocusedWebContentsIfNecessary();
5879 }
5880}
5881
ekaramada110f642016-12-21 19:47:285882void WebContentsImpl::OnFocusedElementChangedInFrame(
5883 RenderFrameHostImpl* frame,
5884 const gfx::Rect& bounds_in_root_view) {
5885 RenderWidgetHostViewBase* root_view =
5886 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5887 if (!root_view || !frame->GetView())
5888 return;
5889
5890 // Converting to screen coordinates.
5891 gfx::Point origin = bounds_in_root_view.origin();
5892 origin += root_view->GetViewBounds().OffsetFromOrigin();
5893 gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size());
5894
5895 root_view->FocusedNodeChanged(frame->has_focused_editable_element(),
5896 bounds_in_screen);
5897
5898 FocusedNodeDetails details = {frame->has_focused_editable_element(),
5899 bounds_in_screen};
5900
5901 // TODO(ekaramad): We should replace this with an observer notification
5902 // (https://crbug.com/675975).
5903 NotificationService::current()->Notify(
5904 NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
5905 Source<RenderViewHost>(GetRenderViewHost()),
5906 Details<FocusedNodeDetails>(&details));
5907}
5908
avia90ae4e2016-11-11 20:49:335909bool WebContentsImpl::DidAddMessageToConsole(int32_t level,
5910 const base::string16& message,
5911 int32_t line_no,
5912 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:255913 if (!delegate_)
5914 return false;
avia90ae4e2016-11-11 20:49:335915 return delegate_->DidAddMessageToConsole(this, level, message, line_no,
5916 source_id);
[email protected]a796f202012-05-30 14:14:255917}
5918
Daniel Cheng90196c82018-04-25 21:49:145919void WebContentsImpl::DidReceiveInputEvent(
dominickn9c7ceaa32016-02-27 01:52:535920 RenderWidgetHostImpl* render_widget_host,
5921 const blink::WebInputEvent::Type type) {
Daniel Cheng90196c82018-04-25 21:49:145922 // Ideally, this list would be based more off of
5923 // https://whatwg.org/C/interaction.html#triggered-by-user-activation.
5924 if (type != blink::WebInputEvent::kMouseDown &&
5925 type != blink::WebInputEvent::kGestureScrollBegin &&
5926 type != blink::WebInputEvent::kTouchStart &&
5927 type != blink::WebInputEvent::kRawKeyDown)
5928 return;
5929
kenrb19221852016-04-29 17:21:405930 // Ignore unless the widget is currently in the frame tree.
5931 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:225932 return;
5933
Daniel Cheng90196c82018-04-25 21:49:145934 if (type != blink::WebInputEvent::kGestureScrollBegin)
5935 last_interactive_input_event_time_ = ui::EventTimeForNow();
dominickn9c7ceaa32016-02-27 01:52:535936
Daniel Cheng90196c82018-04-25 21:49:145937 OnUserInteraction(type);
dominickn2dd142dd2015-10-29 05:30:505938}
5939
avallee9993fca2016-11-17 06:16:505940void WebContentsImpl::FocusOwningWebContents(
5941 RenderWidgetHostImpl* render_widget_host) {
5942 // The PDF plugin still runs as a BrowserPlugin and must go through the
5943 // input redirection mechanism. It must not become focused direcly.
5944 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
5945 return;
5946
5947 RenderWidgetHostImpl* focused_widget =
5948 GetFocusedRenderWidgetHost(render_widget_host);
5949
5950 if (focused_widget != render_widget_host &&
avallee8e881592016-11-19 00:39:305951 (!focused_widget ||
5952 focused_widget->delegate() != render_widget_host->delegate())) {
avallee9993fca2016-11-17 06:16:505953 SetAsFocusedWebContentsIfNecessary();
5954 }
5955}
5956
[email protected]b172aee2012-04-10 17:05:265957void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:445958 // Notify observers.
ericwilligersde386342016-10-19 02:35:095959 for (auto& observer : observers_)
5960 observer.DidGetIgnoredUIEvent();
[email protected]fa1cf0b82010-01-15 21:49:445961}
5962
avic3aa8422015-11-09 20:57:225963void WebContentsImpl::RendererUnresponsive(
Lukasz Anforowicz52b93722018-06-20 16:11:395964 RenderWidgetHostImpl* render_widget_host,
5965 base::RepeatingClosure hang_monitor_restarter) {
ericwilligersde386342016-10-19 02:35:095966 for (auto& observer : observers_)
Avi Drissman1572e8c3c2018-02-02 19:06:365967 observer.OnRendererUnresponsive(render_widget_host->GetProcess());
afakhry98241832016-03-11 19:27:475968
avic031d392017-03-03 03:09:425969 if (ShouldIgnoreUnresponsiveRenderer())
[email protected]e5fc1632011-08-08 07:51:535970 return;
5971
Avi Drissman8920def2018-01-31 19:53:365972 if (!render_widget_host->renderer_initialized())
[email protected]55452902011-06-01 21:57:475973 return;
5974
Dave Tapuskac6146c52017-12-20 22:48:155975 if (delegate_)
Lukasz Anforowicz52b93722018-06-20 16:11:395976 delegate_->RendererUnresponsive(this, render_widget_host,
5977 std::move(hang_monitor_restarter));
[email protected]420ae012009-04-24 05:16:325978}
5979
avic3aa8422015-11-09 20:57:225980void WebContentsImpl::RendererResponsive(
5981 RenderWidgetHostImpl* render_widget_host) {
[email protected]6934a702011-12-20 00:04:515982 if (delegate_)
Avi Drissman1572e8c3c2018-02-02 19:06:365983 delegate_->RendererResponsive(this, render_widget_host);
[email protected]420ae012009-04-24 05:16:325984}
5985
[email protected]b172aee2012-04-10 17:05:265986void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:555987 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:325988 bool* proceed_to_fire_unload) {
ericwilligersde386342016-10-19 02:35:095989 for (auto& observer : observers_)
5990 observer.BeforeUnloadFired(proceed_time);
[email protected]6934a702011-12-20 00:04:515991 if (delegate_)
5992 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:095993 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:325994}
5995
[email protected]58d5cfe2013-07-10 02:40:525996void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:545997 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:235998 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:225999 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:546000}
6001
Jianzhou Fengd8720c72018-01-18 03:06:306002void WebContentsImpl::UpdateRenderViewSizeForRenderManager(bool is_main_frame) {
[email protected]8643e6d2012-01-18 20:26:106003 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
Jianzhou Fengd8720c72018-01-18 03:06:306004 gfx::Size size = GetSizeForNewRenderView(is_main_frame);
[email protected]0323ee42010-02-17 22:03:266005 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
6006 // here during container initialization and normal window size will be set
6007 // later. In case of tab duplication this resizing to 0x0 prevents setting
6008 // normal size later so just ignore it.
6009 if (!size.IsEmpty())
6010 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:326011}
6012
[email protected]af905902013-10-01 21:38:516013void WebContentsImpl::CancelModalDialogsForRenderManager() {
6014 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:546015 // deferrer would prevent us from swapping out. We also clear the state
6016 // because this is a cross-process navigation, which means that it's a new
6017 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:176018 //
6019 // Note that we don't bother telling browser_plugin_embedder_ because the
6020 // cross-process navigation will either destroy the browser plugins or not
6021 // require their dialogs to close.
avi5d3b8692016-10-12 22:00:466022 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:536023 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:466024 }
[email protected]af905902013-10-01 21:38:516025}
6026
[email protected]02d7b6e2014-06-24 21:01:506027void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
6028 RenderFrameHost* new_host,
6029 bool is_main_frame) {
6030 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:056031 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:506032 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:086033
[email protected]02d7b6e2014-06-24 21:01:506034 // Make sure the visible RVH reflects the new delegate's preferences.
6035 if (delegate_)
6036 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:396037
dmazzoni62111452017-04-28 23:46:556038 RenderWidgetHostViewBase* rwhv =
6039 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
6040 if (rwhv)
6041 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
[email protected]02d7b6e2014-06-24 21:01:506042 }
6043
Jinsuk Kim895b2c52018-07-03 06:49:166044 NotifyFrameSwapped(old_host, new_host, is_main_frame);
[email protected]3a3d47472010-07-15 21:03:546045}
6046
naskof5940b9f2015-03-02 23:04:056047void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
Jinsuk Kim895b2c52018-07-03 06:49:166048 RenderFrameHost* old_host,
6049 RenderFrameHost* new_host) {
6050 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
6051 new_host->GetRenderViewHost());
naskof5940b9f2015-03-02 23:04:056052}
6053
[email protected]b172aee2012-04-10 17:05:266054NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:196055 return GetController();
[email protected]3a3d47472010-07-15 21:03:546056}
6057
dcheng59716272016-04-09 05:19:086058std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:296059 const GURL& url) {
Dan Beam055fe8f2017-10-04 23:23:366060 return CreateWebUI(url);
[email protected]420ae012009-04-24 05:16:326061}
6062
[email protected]10f417c52011-12-28 21:04:236063NavigationEntry*
[email protected]b172aee2012-04-10 17:05:266064 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:326065 return controller_.GetLastCommittedEntry();
6066}
6067
creisadca9862017-06-16 19:12:116068InterstitialPageImpl* WebContentsImpl::GetInterstitialForRenderManager() {
6069 return interstitial_page_;
6070}
6071
lfgbede6392015-09-11 21:54:066072void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
6073 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:336074 RenderWidgetHostViewBase* rwh_view =
6075 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:526076
[email protected]420ae012009-04-24 05:16:326077 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:446078 if (rwh_view)
Jianzhou Fengd8720c72018-01-18 03:06:306079 rwh_view->SetSize(GetSizeForNewRenderView(true));
lfgbede6392015-09-11 21:54:066080}
6081
6082bool WebContentsImpl::CreateRenderViewForRenderManager(
6083 RenderViewHost* render_view_host,
6084 int opener_frame_routing_id,
6085 int proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066086 const base::UnguessableToken& devtools_frame_token,
lfgbede6392015-09-11 21:54:066087 const FrameReplicationState& replicated_frame_state) {
6088 TRACE_EVENT0("browser,navigation",
6089 "WebContentsImpl::CreateRenderViewForRenderManager");
6090
piman00cf9402017-04-03 17:09:206091 if (proxy_routing_id == MSG_ROUTING_NONE)
lfg9431efd2016-12-14 14:45:266092 CreateRenderWidgetHostViewForRenderManager(render_view_host);
lfg9431efd2016-12-14 14:45:266093
piman00cf9402017-04-03 17:09:206094 if (!static_cast<RenderViewHostImpl*>(render_view_host)
6095 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066096 devtools_frame_token, replicated_frame_state,
6097 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:526098 return false;
[email protected]14392a52012-05-02 20:28:446099 }
[email protected]a4127722011-04-27 23:13:526100
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:146101 if (proxy_routing_id == MSG_ROUTING_NONE && node_.outer_web_contents())
6102 ReattachToOuterWebContentsFrame();
6103
avi2b177592014-12-10 02:08:026104 SetHistoryOffsetAndLengthForView(render_view_host,
6105 controller_.GetLastCommittedEntryIndex(),
6106 controller_.GetEntryCount());
6107
[email protected]a220b5932013-09-21 03:47:446108#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:506109 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
6110 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:446111 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:446112 if (rwh_view) {
6113 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:166114 render_widget_host->SynchronizeVisualProperties();
[email protected]245f7d52011-11-28 15:36:446115 }
[email protected]f8233cc2011-05-31 20:24:506116#endif
6117
[email protected]420ae012009-04-24 05:16:326118 return true;
6119}
6120
[email protected]82307f6b2014-08-07 03:30:126121bool WebContentsImpl::CreateRenderFrameForRenderManager(
6122 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:046123 int proxy_routing_id,
6124 int opener_routing_id,
japhete6adf142014-10-31 00:01:496125 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:046126 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:436127 TRACE_EVENT0("browser,navigation",
6128 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:126129
6130 RenderFrameHostImpl* rfh =
6131 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:046132 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
6133 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:126134 return false;
6135
6136 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
6137 // RenderFrameHost will have to be associated with the appropriate
6138 // RenderWidgetHostView or a new one should be created here.
6139
6140 return true;
6141}
6142
mfomitchev2b8b066a2016-01-28 19:23:156143#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:456144
[email protected]155c7f22013-12-09 17:07:186145base::android::ScopedJavaLocalRef<jobject>
6146WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:406147 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:566148 return GetWebContentsAndroid()->GetJavaObject();
6149}
[email protected]155c7f22013-12-09 17:07:186150
[email protected]0e813a52014-08-13 10:34:566151WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:186152 WebContentsAndroid* web_contents_android =
6153 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
6154 if (!web_contents_android) {
6155 web_contents_android = new WebContentsAndroid(this);
avicb129c02017-05-03 06:49:296156 SetUserData(kWebContentsAndroidKey, base::WrapUnique(web_contents_android));
[email protected]155c7f22013-12-09 17:07:186157 }
[email protected]0e813a52014-08-13 10:34:566158 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:186159}
6160
paulmeyerc0b762b2016-04-13 11:55:176161void WebContentsImpl::ActivateNearestFindResult(float x,
6162 float y) {
6163 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
6164}
6165
6166void WebContentsImpl::RequestFindMatchRects(int current_version) {
6167 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
6168}
6169
[email protected]7d244f12013-08-22 21:41:516170bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:066171 return CreateRenderViewForRenderManager(
6172 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
Pavel Feldman25234722017-10-11 02:49:066173 frame_tree_.root()->devtools_frame_token(),
lfgbede6392015-09-11 21:54:066174 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:516175}
[email protected]fc2b46b2014-05-03 16:33:456176
rockot400ea35b2016-10-15 19:15:326177service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
sammcf5f1b0f2016-09-20 23:05:116178 if (!java_interfaces_) {
rockot400ea35b2016-10-15 19:15:326179 service_manager::mojom::InterfaceProviderPtr provider;
blundelle0a9f1582016-12-20 11:23:326180 BindInterfaceRegistryForWebContents(mojo::MakeRequest(&provider), this);
rockot400ea35b2016-10-15 19:15:326181 java_interfaces_.reset(new service_manager::InterfaceProvider);
sammcf5f1b0f2016-09-20 23:05:116182 java_interfaces_->Bind(std::move(provider));
6183 }
6184 return java_interfaces_.get();
6185}
6186
[email protected]fc2b46b2014-05-03 16:33:456187#elif defined(OS_MACOSX)
6188
[email protected]75f4df72014-07-16 22:39:426189void WebContentsImpl::SetAllowOtherViews(bool allow) {
6190 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:456191}
6192
[email protected]75f4df72014-07-16 22:39:426193bool WebContentsImpl::GetAllowOtherViews() {
6194 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:456195}
6196
spqchane72c3cb2017-06-30 23:02:106197bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() const {
6198 return did_first_visually_non_empty_paint_;
6199}
6200
[email protected]7d244f12013-08-22 21:41:516201#endif
6202
pkotwicz75ca8ffd2016-02-16 23:10:196203void WebContentsImpl::OnDidDownloadImage(
Avi Drissmana5a52dd2018-03-27 03:39:026204 ImageDownloadCallback callback,
pkotwicz75ca8ffd2016-02-16 23:10:196205 int id,
6206 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:526207 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:186208 const std::vector<SkBitmap>& images,
6209 const std::vector<gfx::Size>& original_image_sizes) {
Avi Drissmana5a52dd2018-03-27 03:39:026210 std::move(callback).Run(id, http_status_code, image_url, images,
6211 original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:196212}
6213
[email protected]6fba26d2014-04-29 09:38:286214void WebContentsImpl::OnDialogClosed(int render_process_id,
6215 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:266216 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:496217 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:266218 bool success,
[email protected]fcf75d42013-12-03 20:11:266219 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:286220 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
6221 render_frame_id);
[email protected]87de04b02014-04-08 22:14:496222 last_dialog_suppressed_ = dialog_was_suppressed;
6223
[email protected]beb440c2009-11-06 04:08:546224 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:236225 // It is possible for the current RenderFrameHost to have changed in the
6226 // meantime. Do not reset the navigation state in that case.
6227 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:256228 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:236229 controller_.DiscardNonCommittedEntries();
6230 }
[email protected]ec8e8b02013-06-19 04:57:106231
Charles Reis15d60b132017-11-03 17:43:476232 // Update the URL display either way, to avoid showing a stale URL.
6233 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
6234
ericwilligersde386342016-10-19 02:35:096235 for (auto& observer : observers_)
6236 observer.BeforeUnloadDialogCancelled();
[email protected]beb440c2009-11-06 04:08:546237 }
[email protected]87de04b02014-04-08 22:14:496238
[email protected]6fba26d2014-04-29 09:38:286239 if (rfh) {
avi44acfaa82017-05-03 22:55:356240 rfh->JavaScriptDialogClosed(reply_msg, success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:166241
6242 std::vector<protocol::PageHandler*> page_handlers =
6243 protocol::PageHandler::EnabledForWebContents(this);
6244 for (auto* handler : page_handlers)
6245 handler->DidCloseJavaScriptDialog(success, user_input);
6246
[email protected]6fba26d2014-04-29 09:38:286247 } else {
6248 // Don't leak the sync IPC reply if the RFH or process is gone.
6249 delete reply_msg;
6250 }
avi1c51fb62017-02-27 20:43:036251
6252 is_showing_javascript_dialog_ = false;
6253 is_showing_before_unload_dialog_ = false;
[email protected]beb440c2009-11-06 04:08:546254}
6255
[email protected]b172aee2012-04-10 17:05:266256void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:546257 if (encoding == last_reported_encoding_)
6258 return;
6259 last_reported_encoding_ = encoding;
6260
jinsukkim79df88a2017-01-04 06:26:156261 canonical_encoding_ = base::GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:106262}
[email protected]f45d2a72010-03-08 23:28:356263
[email protected]1ac10dca2013-08-20 20:47:046264bool WebContentsImpl::IsHidden() {
Francois Doraye6161152018-03-27 22:05:376265 return !IsBeingCaptured() && visibility_ != Visibility::VISIBLE;
[email protected]1ac10dca2013-08-20 20:47:046266}
6267
rob97250742015-12-10 17:45:156268int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lfg601233692017-03-06 22:45:446269 return node_.outer_contents_frame_tree_node_id();
lazyboy6ec48b2a2015-06-29 15:18:146270}
6271
ekaramadaeb3c5c2016-11-09 03:22:356272RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const {
6273 return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
6274 fullscreen_widget_routing_id_);
6275}
6276
[email protected]b0936d22013-11-28 06:47:366277RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:216278 return frame_tree_.root()->render_manager();
6279}
6280
[email protected]f8497342013-02-05 22:15:026281BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:396282 return browser_plugin_guest_.get();
6283}
6284
[email protected]738f57a2013-06-29 21:06:546285void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
6286 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:146287 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:546288 browser_plugin_guest_.reset(guest);
6289}
6290
[email protected]f8497342013-02-05 22:15:026291BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:396292 return browser_plugin_embedder_.get();
6293}
[email protected]8ff00d72012-10-23 19:12:216294
fsamuel60b42282015-03-10 03:29:146295void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
6296 if (browser_plugin_embedder_)
6297 return;
6298 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
6299}
6300
Jianzhou Fengd8720c72018-01-18 03:06:306301gfx::Size WebContentsImpl::GetSizeForNewRenderView(bool is_main_frame) {
[email protected]dc0fd432013-08-27 15:29:216302 gfx::Size size;
Jianzhou Fengd8720c72018-01-18 03:06:306303 if (is_main_frame)
6304 size = device_emulation_size_;
6305 if (size.IsEmpty() && delegate_)
[email protected]dc0fd432013-08-27 15:29:216306 size = delegate_->GetSizeForNewRenderView(this);
6307 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:456308 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:216309 return size;
6310}
6311
[email protected]ae7eeda2014-07-04 01:53:266312void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:096313 for (auto& observer : observers_)
6314 observer.FrameDeleted(render_frame_host);
[email protected]9b159a52013-10-03 17:24:556315}
6316
[email protected]222f5822014-02-05 23:40:496317void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
6318 if (!delegate_)
6319 return;
6320 const gfx::Size new_size = GetPreferredSize();
6321 if (new_size != old_size)
6322 delegate_->UpdatePreferredSize(this, new_size);
6323}
6324
Daniel Cheng90196c82018-04-25 21:49:146325void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) {
6326 for (auto& observer : observers_)
6327 observer.DidGetUserInteraction(type);
6328
6329 // TODO(https://crbug.com/827659): This used to check if type != kMouseWheel.
6330 // However, due to the caller already filtering event types, this would never
6331 // be called with type == kMouseWheel so checking for that here is pointless.
6332 // However, mouse wheel events *also* generate a kGestureScrollBegin event...
6333 // which is *not* filtered out. Maybe they should be?
6334 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
6335 if (rdh) // null in unittests. =(
6336 rdh->OnUserGesture();
6337}
6338
Dan Beam055fe8f2017-10-04 23:23:366339std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI(const GURL& url) {
Jeremy Roman04f27c372017-10-27 15:20:556340 std::unique_ptr<WebUIImpl> web_ui = std::make_unique<WebUIImpl>(this);
Lei Zhangee3b63ad2018-06-06 23:25:316341 std::unique_ptr<WebUIController> controller(
avie865b1d2016-10-24 19:42:596342 WebUIControllerFactoryRegistry::GetInstance()
Lei Zhangee3b63ad2018-06-06 23:25:316343 ->CreateWebUIControllerForURL(web_ui.get(), url));
dbeama1b926a2015-08-31 23:17:516344 if (controller) {
Jeremy Roman04f27c372017-10-27 15:20:556345 web_ui->AddMessageHandler(std::make_unique<GenericHandler>());
Lei Zhangee3b63ad2018-06-06 23:25:316346 web_ui->SetController(std::move(controller));
dbeama1b926a2015-08-31 23:17:516347 return web_ui;
6348 }
6349
avie865b1d2016-10-24 19:42:596350 return nullptr;
dbeama1b926a2015-08-31 23:17:516351}
6352
paulmeyerfeafc2d2017-04-25 21:46:406353FindRequestManager* WebContentsImpl::GetFindRequestManager() {
6354 for (WebContentsImpl* contents = this; contents;
6355 contents = contents->GetOuterWebContents()) {
6356 if (contents->find_request_manager_)
6357 return contents->find_request_manager_.get();
6358 }
6359
6360 return nullptr;
6361}
6362
paulmeyerc0b762b2016-04-13 11:55:176363FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
paulmeyerfeafc2d2017-04-25 21:46:406364 if (FindRequestManager* manager = GetFindRequestManager())
6365 return manager;
6366
6367 // No existing FindRequestManager found, so one must be created.
6368 find_request_manager_.reset(new FindRequestManager(this));
6369
6370 // Concurrent find sessions must not overlap, so destroy any existing
6371 // FindRequestManagers in any inner WebContentses.
6372 for (WebContentsImpl* contents : GetWebContentsAndAllInner()) {
6373 if (contents == this)
6374 continue;
6375 if (contents->find_request_manager_) {
6376 contents->find_request_manager_->StopFinding(
6377 content::STOP_FIND_ACTION_CLEAR_SELECTION);
6378 contents->find_request_manager_.release();
6379 }
6380 }
paulmeyerc0b762b2016-04-13 11:55:176381
6382 return find_request_manager_.get();
6383}
6384
6385void WebContentsImpl::NotifyFindReply(int request_id,
6386 int number_of_matches,
6387 const gfx::Rect& selection_rect,
6388 int active_match_ordinal,
6389 bool final_update) {
Sebastien Marchandcf97ed52017-07-24 23:50:346390 if (delegate_ && !is_being_destroyed_ &&
Lukasz Anforowicze9ae3722017-09-29 17:37:386391 !GetMainFrame()->GetProcess()->FastShutdownStarted()) {
paulmeyerc0b762b2016-04-13 11:55:176392 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
6393 active_match_ordinal, final_update);
6394 }
6395}
6396
ortuno467e5792016-06-10 04:32:396397void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
6398 // Trying to invalidate the tab state while being destroyed could result in a
6399 // use after free.
6400 if (IsBeingDestroyed()) {
6401 return;
6402 }
6403 // Notify for UI updates if the state changes.
6404 bluetooth_connected_device_count_++;
6405 if (bluetooth_connected_device_count_ == 1) {
6406 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6407 }
6408}
6409
6410void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
6411 // Trying to invalidate the tab state while being destroyed could result in a
6412 // use after free.
6413 if (IsBeingDestroyed()) {
6414 return;
6415 }
6416 // Notify for UI updates if the state changes.
Lukasz Anforowicze9ae3722017-09-29 17:37:386417 DCHECK_NE(bluetooth_connected_device_count_, 0u);
ortuno467e5792016-06-10 04:32:396418 bluetooth_connected_device_count_--;
6419 if (bluetooth_connected_device_count_ == 0) {
6420 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6421 }
6422}
6423
zqzhang8ac49002017-03-16 21:51:356424void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) {
6425 if (has_persistent_video_ == has_persistent_video)
mlamouri5cd9ae82017-02-18 11:05:096426 return;
6427
zqzhang8ac49002017-03-16 21:51:356428 has_persistent_video_ = has_persistent_video;
mlamouri5cd9ae82017-02-18 11:05:096429 NotifyPreferencesChanged();
zqzhang8ac49002017-03-16 21:51:356430 media_web_contents_observer()->RequestPersistentVideo(has_persistent_video);
mlamouri5cd9ae82017-02-18 11:05:096431}
6432
paulmeyerfeafc2d2017-04-25 21:46:406433void WebContentsImpl::BrowserPluginGuestWillDetach() {
6434 WebContentsImpl* outermost = GetOutermostWebContents();
6435 if (this != outermost && ContainsOrIsFocusedWebContents())
6436 outermost->SetAsFocusedWebContentsIfNecessary();
6437}
6438
Mounir Lamouri11e9ef42018-05-22 03:10:166439gfx::Size WebContentsImpl::EnterPictureInPicture(
6440 const viz::SurfaceId& surface_id,
6441 const gfx::Size& natural_size) {
6442 return delegate_ ? delegate_->EnterPictureInPicture(surface_id, natural_size)
6443 : gfx::Size();
6444}
6445
Mounir Lamouri6d759e12018-05-16 20:01:306446void WebContentsImpl::ExitPictureInPicture() {
6447 if (delegate_)
6448 delegate_->ExitPictureInPicture();
6449}
6450
paulmeyerc0b762b2016-04-13 11:55:176451#if defined(OS_ANDROID)
6452void WebContentsImpl::NotifyFindMatchRectsReply(
6453 int version,
6454 const std::vector<gfx::RectF>& rects,
6455 const gfx::RectF& active_rect) {
6456 if (delegate_)
6457 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
6458}
6459#endif
6460
[email protected]34ff1cfc2014-08-20 06:16:056461void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
6462 force_disable_overscroll_content_ = force_disable;
6463 if (view_)
6464 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
6465}
6466
Jianzhou Fengd8720c72018-01-18 03:06:306467bool WebContentsImpl::SetDeviceEmulationSize(const gfx::Size& new_size) {
6468 device_emulation_size_ = new_size;
6469 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
6470
6471 const gfx::Size current_size = rwhv->GetViewBounds().size();
6472 if (view_size_before_emulation_.IsEmpty())
6473 view_size_before_emulation_ = current_size;
6474
6475 if (current_size != new_size)
6476 rwhv->SetSize(new_size);
6477
6478 return current_size != new_size;
6479}
6480
6481void WebContentsImpl::ClearDeviceEmulationSize() {
6482 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
6483 // WebContentsView could get resized during emulation, which also resizes
6484 // RWHV. If it happens, assume user would like to keep using the size after
6485 // emulation.
6486 // TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when
6487 // WebContentsView size changes).
Dmitry Gozmanc63707182018-03-06 00:09:396488 if (!view_size_before_emulation_.IsEmpty() && rwhv &&
6489 rwhv->GetViewBounds().size() == device_emulation_size_) {
Jianzhou Fengd8720c72018-01-18 03:06:306490 rwhv->SetSize(view_size_before_emulation_);
Dmitry Gozmanc63707182018-03-06 00:09:396491 }
Jianzhou Fengd8720c72018-01-18 03:06:306492 device_emulation_size_ = gfx::Size();
6493 view_size_before_emulation_ = gfx::Size();
6494}
6495
Max Morin5bc74f52018-05-09 07:00:216496ForwardingAudioStreamFactory* WebContentsImpl::GetAudioStreamFactory() {
6497 if (!audio_stream_factory_) {
6498 audio_stream_factory_.emplace(
6499 this,
6500 content::ServiceManagerConnection::GetForProcess()
6501 ->GetConnector()
6502 ->Clone(),
6503 AudioStreamBrokerFactory::CreateImpl());
6504 }
6505
6506 return &*audio_stream_factory_;
6507}
6508
dalecurtis88c240072015-12-09 02:11:186509void WebContentsImpl::MediaStartedPlaying(
billorr21c005d2016-11-17 03:57:046510 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:186511 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:046512 if (media_info.has_video)
6513 currently_playing_video_count_++;
6514
ericwilligersde386342016-10-19 02:35:096515 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:046516 observer.MediaStartedPlaying(media_info, id);
dalecurtis88c240072015-12-09 02:11:186517}
6518
6519void WebContentsImpl::MediaStoppedPlaying(
billorr21c005d2016-11-17 03:57:046520 const WebContentsObserver::MediaPlayerInfo& media_info,
Becca Hughes220bfc102017-11-14 18:24:076521 const WebContentsObserver::MediaPlayerId& id,
6522 WebContentsObserver::MediaStoppedReason reason) {
billorr21c005d2016-11-17 03:57:046523 if (media_info.has_video)
6524 currently_playing_video_count_--;
6525
ericwilligersde386342016-10-19 02:35:096526 for (auto& observer : observers_)
Becca Hughes220bfc102017-11-14 18:24:076527 observer.MediaStoppedPlaying(media_info, id, reason);
billorr21c005d2016-11-17 03:57:046528}
6529
peconn257951522017-06-09 18:24:596530void WebContentsImpl::MediaResized(
6531 const gfx::Size& size,
6532 const WebContentsObserver::MediaPlayerId& id) {
6533 cached_video_sizes_[id] = size;
6534
6535 for (auto& observer : observers_)
6536 observer.MediaResized(size, id);
6537}
6538
Peter E Conneccb34c22017-09-08 09:37:586539void WebContentsImpl::MediaEffectivelyFullscreenChanged(bool is_fullscreen) {
6540 for (auto& observer : observers_)
6541 observer.MediaEffectivelyFullscreenChanged(is_fullscreen);
6542}
6543
Peter Conn31c726a2017-08-17 11:07:346544base::Optional<gfx::Size> WebContentsImpl::GetFullscreenVideoSize() {
6545 base::Optional<WebContentsObserver::MediaPlayerId> id =
6546 media_web_contents_observer_->GetFullscreenVideoMediaPlayerId();
6547 if (id && cached_video_sizes_.count(id.value()))
6548 return base::Optional<gfx::Size>(cached_video_sizes_[id.value()]);
6549 return base::Optional<gfx::Size>();
peconn257951522017-06-09 18:24:596550}
6551
billorr21c005d2016-11-17 03:57:046552int WebContentsImpl::GetCurrentlyPlayingVideoCount() {
6553 return currently_playing_video_count_;
dalecurtis88c240072015-12-09 02:11:186554}
6555
Francois Doraye6161152018-03-27 22:05:376556void WebContentsImpl::UpdateWebContentsVisibility(Visibility visibility) {
Francois Doray3f2afbd2018-04-06 19:18:186557 // Occlusion is disabled when |features::kWebContentsOcclusion| is disabled
6558 // (for power and speed impact assessment) or when
6559 // |switches::kDisableBackgroundingOccludedWindowsForTesting| is specified on
6560 // the command line (to avoid flakiness in browser tests).
6561 const bool occlusion_is_disabled =
6562 !base::FeatureList::IsEnabled(features::kWebContentsOcclusion) ||
Francois Doraye6161152018-03-27 22:05:376563 base::CommandLine::ForCurrentProcess()->HasSwitch(
6564 switches::kDisableBackgroundingOccludedWindowsForTesting);
6565 if (occlusion_is_disabled && visibility == Visibility::OCCLUDED)
6566 visibility = Visibility::VISIBLE;
6567
tapted65ff2ea72016-03-01 23:39:006568 if (!did_first_set_visible_) {
Francois Doraye6161152018-03-27 22:05:376569 if (visibility == Visibility::VISIBLE) {
6570 // A WebContents created with CreateParams::initially_hidden = false
6571 // starts with GetVisibility() == Visibility::VISIBLE even though it is
6572 // not really visible. Call WasShown() when it becomes visible for real as
6573 // the page load mechanism and some WebContentsObserver rely on that.
tapted65ff2ea72016-03-01 23:39:006574 WasShown();
Francois Dorayfe4a1772018-02-17 04:17:096575 did_first_set_visible_ = true;
tapted65ff2ea72016-03-01 23:39:006576 }
Francois Doraye6161152018-03-27 22:05:376577
6578 // Trust the initial visibility of the WebContents and do not switch it to
6579 // HIDDEN or OCCLUDED before it becomes VISIBLE for real. Doing so would
6580 // result in destroying resources that would immediately be recreated (e.g.
6581 // UpdateWebContents(HIDDEN) can be called when a WebContents is added to a
6582 // hidden window that is about to be shown).
6583
tapted65ff2ea72016-03-01 23:39:006584 return;
6585 }
Francois Doraye6161152018-03-27 22:05:376586
6587 if (visibility == visibility_)
tapted65ff2ea72016-03-01 23:39:006588 return;
6589
Francois Doraye6161152018-03-27 22:05:376590 if (visibility == Visibility::VISIBLE)
tapted65ff2ea72016-03-01 23:39:006591 WasShown();
Francois Doraye6161152018-03-27 22:05:376592 else if (visibility == Visibility::OCCLUDED)
6593 WasOccluded();
tapted65ff2ea72016-03-01 23:39:006594 else
6595 WasHidden();
6596}
6597
aelias5252baa2016-04-10 01:18:026598void WebContentsImpl::UpdateOverridingUserAgent() {
mlamouri5cd9ae82017-02-18 11:05:096599 NotifyPreferencesChanged();
aelias5252baa2016-04-10 01:18:026600}
6601
avid53461d2016-02-25 17:15:046602void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
6603 JavaScriptDialogManager* dialog_manager) {
6604 dialog_manager_ = dialog_manager;
6605}
6606
rockotf62002a2016-09-15 00:08:596607void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) {
6608 auto it = binding_sets_.find(interface_name);
6609 if (it != binding_sets_.end())
6610 binding_sets_.erase(it);
6611}
6612
nzolghadrd87a308d2016-12-07 15:45:566613bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) {
nzolghadrbbffc6c2017-05-25 17:56:396614 // Here we associate this metric to the main frame URL regardless of what
6615 // caused it.
nzolghadrd87a308d2016-12-07 15:45:566616 sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL(
6617 GetLastCommittedURL()));
nzolghadrd87a308d2016-12-07 15:45:566618 return true;
6619}
6620
ekaramada110f642016-12-21 19:47:286621void WebContentsImpl::FocusedNodeTouched(bool editable) {
6622#if defined(OS_WIN)
ekaramada110f642016-12-21 19:47:286623 RenderWidgetHostView* view = GetRenderWidgetHostView();
6624 if (!view)
6625 return;
Dave Tapuska2315d8f2018-03-06 17:52:556626 view->FocusedNodeTouched(editable);
ekaramada110f642016-12-21 19:47:286627#endif
6628}
6629
samans90fb8162017-04-04 22:30:456630void WebContentsImpl::DidReceiveCompositorFrame() {
6631 for (auto& observer : observers_)
6632 observer.DidReceiveCompositorFrame();
6633}
6634
falken52a56e32016-12-08 05:02:406635void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() {
6636 bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch(
6637 switches::kAllowInsecureLocalhost);
6638 if (!allow_localhost)
6639 return;
6640
6641 content::NavigationEntry* entry = GetController().GetLastCommittedEntry();
Rob Wuf79b3ba2018-01-14 01:54:316642 if (!entry || !net::IsLocalhost(entry->GetURL()))
falken52a56e32016-12-08 05:02:406643 return;
6644
6645 content::SSLStatus ssl_status = entry->GetSSL();
6646 bool is_cert_error = net::IsCertStatusError(ssl_status.cert_status) &&
6647 !net::IsCertStatusMinorError(ssl_status.cert_status);
6648 if (!is_cert_error)
6649 return;
6650
6651 GetMainFrame()->AddMessageToConsole(
6652 content::CONSOLE_MESSAGE_LEVEL_WARNING,
6653 base::StringPrintf("This site does not have a valid SSL "
6654 "certificate! Without SSL, your site's and "
6655 "visitors' data is vulnerable to theft and "
6656 "tampering. Get a valid SSL certificate before"
6657 " releasing your website to the public."));
6658}
6659
ekaramadf6750aa2017-06-06 18:29:426660bool WebContentsImpl::IsShowingContextMenuOnPage() const {
6661 return showing_context_menu_;
6662}
6663
Min Qina904f3302018-02-13 23:33:346664download::DownloadUrlParameters::RequestHeadersType
6665WebContentsImpl::ParseDownloadHeaders(const std::string& headers) {
6666 download::DownloadUrlParameters::RequestHeadersType request_headers;
Megan Jablonski2f6a4c52017-07-10 23:01:256667 for (const base::StringPiece& key_value : base::SplitStringPiece(
6668 headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
6669 std::vector<std::string> pair = base::SplitString(
6670 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
6671 if (2ul == pair.size())
6672 request_headers.push_back(make_pair(pair[0], pair[1]));
6673 }
6674 return request_headers;
6675}
6676
lukasza6f8ac622017-06-06 03:10:206677void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener,
6678 bool opener_suppressed) {
6679 if (opener) {
6680 FrameTreeNode* new_root = GetFrameTree()->root();
6681
6682 // For the "original opener", track the opener's main frame instead, because
6683 // if the opener is a subframe, the opener tracking could be easily bypassed
6684 // by spawning from a subframe and deleting the subframe.
6685 // https://crbug.com/705316
6686 new_root->SetOriginalOpener(opener->frame_tree()->root());
6687
6688 if (!opener_suppressed) {
6689 new_root->SetOpener(opener);
6690 created_with_opener_ = true;
6691 }
6692 }
6693}
6694
Becca Hughes9f6fd4b82017-06-15 10:01:406695void WebContentsImpl::MediaMutedStatusChanged(
6696 const WebContentsObserver::MediaPlayerId& id,
6697 bool muted) {
6698 for (auto& observer : observers_)
6699 observer.MediaMutedStatusChanged(id, muted);
6700}
6701
EhsanK2075c7e2017-08-21 02:42:396702void WebContentsImpl::SetVisibilityForChildViews(bool visible) {
6703 GetMainFrame()->SetVisibilityForChildViews(visible);
6704}
6705
[email protected]8ff00d72012-10-23 19:12:216706} // namespace content