blob: c6c9a6e179f5b168379d6a0ad89fa71532b2ac9b [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
Becca Hughesbda2c4d2018-07-10 00:54:12441 // WebContentsObserver override.
442 void DidFinishNavigation(NavigationHandle* navigation_handle) override {
443 // If the navigation is not in the main frame or if we are a same document
444 // navigation then we should stop now.
445 if (!navigation_handle->IsInMainFrame() ||
446 navigation_handle->IsSameDocument()) {
447 return;
448 }
449
450 // If we finish a main frame navigation and the |WebDisplayMode| is
451 // fullscreen or standalone then we should make the main frame the
452 // current |RenderFrameHost|.
453 RenderWidgetHostImpl* rwh =
454 web_contents_impl()->GetRenderViewHost()->GetWidget();
455 blink::WebDisplayMode mode = web_contents_impl()->GetDisplayMode(rwh);
456 if (mode == blink::WebDisplayMode::kWebDisplayModeFullscreen ||
457 mode == blink::WebDisplayMode::kWebDisplayModeStandalone) {
458 SetCurrentRenderFrameHost(web_contents_impl()->GetMainFrame());
459 }
460 }
461
462 // WebContentsObserver override. Removes any state built up by a render frame.
Becca Hughes9ef7f452018-06-27 16:57:31463 void RenderFrameDeleted(RenderFrameHost* rfh) override {
464 values_.erase(rfh);
465
466 // If we were the current |RenderFrameHost| then we should clear that.
467 if (current_rfh_ == rfh)
468 SetCurrentRenderFrameHost(nullptr);
469 }
Becca Hughes6fe54e432018-06-09 04:18:56470
Becca Hughesbda2c4d2018-07-10 00:54:12471 // WebContentsObserver override.
472 void RenderFrameCreated(RenderFrameHost* rfh) override {
473 ViewportFitChangedForFrame(rfh, blink::mojom::ViewportFit::kAuto);
474 }
475
Becca Hughes6daf5662018-06-27 16:50:54476 // Updates the safe area insets on the current frame.
477 void SetDisplayCutoutSafeArea(gfx::Insets insets) {
Becca Hughes9ef7f452018-06-27 16:57:31478 insets_ = insets;
479
480 if (current_rfh_)
481 SendSafeAreaToFrame(current_rfh_, insets);
482 }
483
484 private:
485 // Set the current |RenderFrameHost| that should have control over the
486 // viewport fit value and we should set safe area insets on.
487 void SetCurrentRenderFrameHost(RenderFrameHost* rfh) {
488 if (current_rfh_ == rfh)
489 return;
490
491 // If we had a previous frame then we should clear the insets on that frame.
492 if (current_rfh_)
493 SendSafeAreaToFrame(current_rfh_, gfx::Insets());
494
495 // If the new RenderFrameHost is nullptr we should stop here and notify
496 // observers that the new viewport fit is kAuto (the default).
497 current_rfh_ = rfh;
498 if (!rfh) {
499 NotifyObservers(blink::mojom::ViewportFit::kAuto);
500 return;
501 }
502
503 // Send the current safe area to the new frame.
504 SendSafeAreaToFrame(rfh, insets_);
505
506 // Notify the WebContentsObservers that the viewport fit value has changed.
507 NotifyObservers(GetValueOrDefault(rfh));
508 }
509
510 // Send the safe area insets to a |RenderFrameHost|.
511 void SendSafeAreaToFrame(RenderFrameHost* rfh, gfx::Insets insets) {
Becca Hughes6daf5662018-06-27 16:50:54512 blink::AssociatedInterfaceProvider* provider =
Becca Hughes9ef7f452018-06-27 16:57:31513 rfh->GetRemoteAssociatedInterfaces();
Becca Hughes6daf5662018-06-27 16:50:54514 if (!provider)
515 return;
516
517 blink::mojom::DisplayCutoutClientAssociatedPtr client;
518 provider->GetInterface(&client);
519 client->SetSafeArea(blink::mojom::DisplayCutoutSafeArea::New(
520 insets.top(), insets.left(), insets.bottom(), insets.right()));
521 }
522
Becca Hughes9ef7f452018-06-27 16:57:31523 // Notify WebContentsObservers that the viewport fit value has changed.
Becca Hughese9e27952018-06-25 17:08:27524 void NotifyObservers(blink::mojom::ViewportFit value) {
525 for (auto& observer : web_contents_impl()->observers_)
526 observer.ViewportFitChanged(value);
527 }
528
Becca Hughes6fe54e432018-06-09 04:18:56529 // Get the stored viewport fit value for a frame or kAuto if there is no
530 // stored value.
531 blink::mojom::ViewportFit GetValueOrDefault(RenderFrameHost* rfh) const {
532 auto value = values_.find(rfh);
533 if (value != values_.end())
534 return value->second;
535 return blink::mojom::ViewportFit::kAuto;
536 }
537
Becca Hughese9e27952018-06-25 17:08:27538 WebContentsImpl* web_contents_impl() {
539 return static_cast<WebContentsImpl*>(web_contents());
540 }
541
Becca Hughes9ef7f452018-06-27 16:57:31542 // Stores the current safe area insets.
543 gfx::Insets insets_ = gfx::Insets();
544
545 // Stores the current |RenderFrameHost| that has the applied safe area insets
546 // and is controlling the viewport fit value.
547 RenderFrameHost* current_rfh_ = nullptr;
548
Becca Hughes6fe54e432018-06-09 04:18:56549 // Stores a map of RenderFrameHosts and their current viewport fit values.
550 std::map<RenderFrameHost*, blink::mojom::ViewportFit> values_;
551
Becca Hughes6fe54e432018-06-09 04:18:56552 WebContentsFrameBindingSet<blink::mojom::DisplayCutoutHost> bindings_;
553};
554
lazyboy6ec48b2a2015-06-29 15:18:14555// WebContentsImpl::WebContentsTreeNode ----------------------------------------
lfg601233692017-03-06 22:45:44556WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode(
557 WebContentsImpl* current_web_contents)
558 : current_web_contents_(current_web_contents),
559 outer_web_contents_(nullptr),
lazyboy6ec48b2a2015-06-29 15:18:14560 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33561 FrameTreeNode::kFrameTreeNodeInvalidId),
lfg601233692017-03-06 22:45:44562 focused_web_contents_(current_web_contents) {}
lazyboy6ec48b2a2015-06-29 15:18:14563
564WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
lfga3e2bdc2017-03-07 20:44:01565 if (OuterContentsFrameTreeNode())
566 OuterContentsFrameTreeNode()->RemoveObserver(this);
paulmeyerfeafc2d2017-04-25 21:46:40567
568 if (outer_web_contents_)
569 outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_);
lazyboy6ec48b2a2015-06-29 15:18:14570}
571
572void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
573 WebContentsImpl* outer_web_contents,
574 RenderFrameHostImpl* outer_contents_frame) {
lfg601233692017-03-06 22:45:44575 focused_web_contents_ = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:14576 outer_web_contents_ = outer_web_contents;
577 outer_contents_frame_tree_node_id_ =
578 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
579
paulmeyerfeafc2d2017-04-25 21:46:40580 outer_web_contents_->node_.AttachInnerWebContents(current_web_contents_);
lfga3e2bdc2017-03-07 20:44:01581 outer_contents_frame->frame_tree_node()->AddObserver(this);
lfg601233692017-03-06 22:45:44582}
lazyboy6ec48b2a2015-06-29 15:18:14583
paulmeyerfeafc2d2017-04-25 21:46:40584void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents(
585 WebContentsImpl* inner_web_contents) {
586 inner_web_contents_.push_back(inner_web_contents);
587}
588
589void WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents(
590 WebContentsImpl* inner_web_contents) {
591 DCHECK(std::find(inner_web_contents_.begin(), inner_web_contents_.end(),
592 inner_web_contents) != inner_web_contents_.end());
593 inner_web_contents_.erase(
594 std::remove(inner_web_contents_.begin(), inner_web_contents_.end(),
595 inner_web_contents),
596 inner_web_contents_.end());
597}
598
lfga3e2bdc2017-03-07 20:44:01599FrameTreeNode*
600WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const {
601 return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_);
lfg601233692017-03-06 22:45:44602}
603
lfga3e2bdc2017-03-07 20:44:01604void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed(
605 FrameTreeNode* node) {
606 DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id())
607 << "WebContentsTreeNode should only receive notifications for the "
608 "FrameTreeNode in its outer WebContents that hosts it.";
609 delete current_web_contents_; // deletes |this| too.
lazyboy6ec48b2a2015-06-29 15:18:14610}
611
avallee0206f782016-07-28 18:55:33612void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
613 WebContentsImpl* web_contents) {
614 DCHECK(!outer_web_contents())
615 << "Only the outermost WebContents tracks focus.";
616 focused_web_contents_ = web_contents;
617}
618
paulmeyerfeafc2d2017-04-25 21:46:40619WebContentsImpl*
620WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame(
621 const FrameTreeNode* frame) {
622 auto ftn_id = frame->frame_tree_node_id();
623 for (WebContentsImpl* contents : inner_web_contents_) {
624 if (contents->node_.outer_contents_frame_tree_node_id() == ftn_id) {
625 return contents;
626 }
627 }
628 return nullptr;
629}
630
631const std::vector<WebContentsImpl*>&
632WebContentsImpl::WebContentsTreeNode::inner_web_contents() const {
633 return inner_web_contents_;
634}
635
[email protected]b172aee2012-04-10 17:05:26636// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32637
alexmose201c7cd2015-06-10 17:14:21638WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28639 : delegate_(nullptr),
[email protected]69e797f2013-04-30 01:10:22640 controller_(this, browser_context),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28641 render_view_host_delegate_view_(nullptr),
alexmose201c7cd2015-06-10 17:14:21642 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01643 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57644 this,
645 this,
646 this,
647 this),
lfg601233692017-03-06 22:45:44648 node_(this),
[email protected]6dfed692014-05-22 04:18:03649 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23650 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
651 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34652 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26653 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56654 upload_size_(0),
655 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16656 is_resume_pending_(false),
creisadca9862017-06-16 19:12:11657 interstitial_page_(nullptr),
[email protected]b4c84012014-04-28 19:51:10658 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28659 theme_color_(SK_ColorTRANSPARENT),
660 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29661 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55662 capturer_count_(0),
[email protected]fdd61c62009-04-22 19:22:57663 is_being_destroyed_(false),
creis97867aa2017-02-17 18:39:45664 is_notifying_observers_(false),
[email protected]fdd61c62009-04-22 19:22:57665 notify_disconnection_(false),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28666 dialog_manager_(nullptr),
[email protected]7ab1e7d62009-10-14 23:32:01667 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39668 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38669 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21670 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
671 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22672 zoom_scroll_remainder_(0),
alexmosc9e76ec2016-05-16 22:59:37673 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42674 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03675 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]34ff1cfc2014-08-20 06:16:05676 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30677 last_dialog_suppressed_(false),
waffles1c12bf402016-02-10 17:45:48678 accessibility_mode_(
679 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15680 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35681 bluetooth_connected_device_count_(0),
Guido Urdanetaf4008002018-05-03 10:43:04682 media_device_group_id_salt_base_(
683 BrowserContext::CreateRandomMediaDeviceIDSalt()),
mcnee336ea2c2017-05-23 22:50:59684#if !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:46685 page_scale_factor_is_one_(true),
mcnee336ea2c2017-05-23 22:50:59686#endif // !defined(OS_ANDROID)
qinmin72e8bd02016-10-21 19:35:37687 is_overlay_content_(false),
ekaramadf6750aa2017-06-06 18:29:42688 showing_context_menu_(false),
pkotwicz75ca8ffd2016-02-16 23:10:19689 loading_weak_factory_(this),
690 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55691 frame_tree_.SetFrameRemoveListener(
692 base::Bind(&WebContentsImpl::OnFrameRemoved,
693 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46694#if defined(OS_ANDROID)
695 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
696#else
qinmin58567c82015-01-07 21:00:20697 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46698#endif
brettw4b461082016-11-19 18:55:16699#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17700 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
701#endif
blundelle75a8f92017-03-27 08:11:17702
csharrisona2280cd2016-02-03 23:21:15703 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
mcnee336ea2c2017-05-23 22:50:59704#if !defined(OS_ANDROID)
scottmg276753cf2016-10-27 18:25:22705 host_zoom_map_observer_.reset(new HostZoomMapObserver(this));
mcnee336ea2c2017-05-23 22:50:59706#endif // !defined(OS_ANDROID)
Joel Hockey85b379d2017-12-11 10:42:13707
Becca Hughes86334622018-07-09 21:29:38708#if defined(OS_ANDROID)
709 if (base::FeatureList::IsEnabled(features::kDisplayCutoutAPI))
710 display_cutout_host_impl_ = std::make_unique<DisplayCutoutHostImpl>(this);
711#endif
Becca Hughes6fe54e432018-06-09 04:18:56712
Joel Hockey85b379d2017-12-11 10:42:13713 registry_.AddInterface(base::BindRepeating(
714 &WebContentsImpl::OnColorChooserFactoryRequest, base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35715}
initial.commit09911bf2008-07-26 23:55:29716
[email protected]b172aee2012-04-10 17:05:26717WebContentsImpl::~WebContentsImpl() {
creisba91ba82017-05-12 22:56:19718 // Imperfect sanity check against double free, given some crashes unexpectedly
719 // observed in the wild.
720 CHECK(!is_being_destroyed_);
721
722 // We generally keep track of is_being_destroyed_ to let other features know
723 // to avoid certain actions during destruction.
[email protected]420ae012009-04-24 05:16:32724 is_being_destroyed_ = true;
725
creis97867aa2017-02-17 18:39:45726 // A WebContents should never be deleted while it is notifying observers,
creisba91ba82017-05-12 22:56:19727 // since this will lead to a use-after-free as it continues to notify later
creis97867aa2017-02-17 18:39:45728 // observers.
729 CHECK(!is_notifying_observers_);
730
kenrb2a565f82015-09-02 20:24:59731 rwh_input_event_router_.reset();
732
rockotf62002a2016-09-15 00:08:59733 for (auto& entry : binding_sets_)
734 entry.second->CloseAllBindings();
735
avallee0206f782016-07-28 18:55:33736 WebContentsImpl* outermost = GetOutermostWebContents();
avallee9993fca2016-11-17 06:16:50737 if (this != outermost && ContainsOrIsFocusedWebContents()) {
avallee0206f782016-07-28 18:55:33738 // If the current WebContents is in focus, unset it.
avallee9993fca2016-11-17 06:16:50739 outermost->SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:33740 }
741
Nick Carterd73635b2018-03-13 18:31:41742 if (mouse_lock_widget_)
743 mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary();
744
dcheng72be33c2016-01-21 04:11:31745 for (FrameTreeNode* node : frame_tree_.Nodes()) {
746 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
747 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38748 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38749 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31750 }
carlosk35f35af2015-12-01 10:55:40751
dcheng57e39e22016-01-21 00:25:38752 for (RenderWidgetHostImpl* widget : created_widgets_)
753 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26754 created_widgets_.clear();
755
[email protected]3ab9cb82011-06-03 18:02:07756 // Clear out any JavaScript state.
avi5d3b8692016-10-12 22:00:46757 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:53758 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:46759 }
[email protected]3ab9cb82011-06-03 18:02:07760
Joel Hockey85b379d2017-12-11 10:42:13761 color_chooser_.reset();
[email protected]da8543762012-03-20 08:52:20762
[email protected]420ae012009-04-24 05:16:32763 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32764
[email protected]ca13a442012-04-17 14:00:12765 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21766 NotificationService::current()->Notify(
767 NOTIFICATION_WEB_CONTENTS_DESTROYED,
768 Source<WebContents>(this),
769 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32770
[email protected]df0c843f2014-05-23 20:37:23771 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14772 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23773 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59774
clamy0e119882015-07-31 16:12:33775 // Manually call the observer methods for the root frame tree node. It is
776 // necessary to manually delete all objects tracking navigations
777 // (NavigationHandle, NavigationRequest) for observers to be properly
778 // notified of these navigations stopping before the WebContents is
779 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23780 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56781
naskob21fe4872015-02-24 14:15:56782 root->current_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28783 root->current_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33784
Arthur Hemeryc3380172018-01-22 14:00:17785 // Do not update state as the WebContents is being destroyed.
786 frame_tree_.root()->ResetNavigationRequest(true, true);
787 if (root->speculative_frame_host()) {
788 root->speculative_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28789 root->speculative_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33790 }
[email protected]f273ee52013-10-18 16:05:27791
brettw4b461082016-11-19 18:55:16792#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17793 // Call this before WebContentsDestroyed() is broadcasted since
794 // AudioFocusManager will be destroyed after that.
795 pepper_playback_observer_.reset();
796#endif // defined(ENABLED_PLUGINS)
797
Chris Hamiltondf0d72cd2018-05-29 16:23:53798 // If audio is playing then notify external observers of the audio stream
799 // disappearing.
800 if (is_currently_audible_) {
801 is_currently_audible_ = false;
802 for (auto& observer : observers_)
803 observer.OnAudioStateChanged(false);
804
805 if (GetOuterWebContents())
806 GetOuterWebContents()->OnAudioStateChanged();
807 }
808
ericwilligersde386342016-10-19 02:35:09809 for (auto& observer : observers_)
810 observer.FrameDeleted(root->current_frame_host());
naskoa83483fb2015-02-27 16:57:10811
ericwilligersde386342016-10-19 02:35:09812 for (auto& observer : observers_)
813 observer.RenderViewDeleted(root->current_host());
[email protected]f273ee52013-10-18 16:05:27814
ericwilligersde386342016-10-19 02:35:09815 for (auto& observer : observers_)
816 observer.WebContentsDestroyed();
[email protected]12a46832014-05-09 13:35:58817
ericwilligersde386342016-10-19 02:35:09818 for (auto& observer : observers_)
819 observer.ResetWebContents();
[email protected]232a5812011-03-04 22:42:08820
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28821 SetDelegate(nullptr);
[email protected]b5a1d11c2011-02-17 03:09:42822}
823
erikchen50735fd2018-05-05 15:08:33824std::unique_ptr<WebContentsImpl> WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59825 const WebContents::CreateParams& params,
Ian Clelland5cbaaf82017-11-27 22:00:03826 RenderFrameHostImpl* opener_rfh) {
[email protected]e11f0e92013-06-12 15:12:03827 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
Ian Clelland5cbaaf82017-11-27 22:00:03828 FrameTreeNode* opener = nullptr;
829 if (opener_rfh)
830 opener = opener_rfh->frame_tree_node();
erikchen50735fd2018-05-05 15:08:33831 std::unique_ptr<WebContentsImpl> new_contents(
832 new WebContentsImpl(params.browser_context));
lukasza6f8ac622017-06-06 03:10:20833 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
alexmose201c7cd2015-06-10 17:14:21834
alexmosaedfc6f2016-01-21 23:57:38835 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
836 // flags, and these flags take effect immediately. An exception is if the
837 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
838 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
839 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
lukasza6f8ac622017-06-06 03:10:20840 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
alexmosaedfc6f2016-01-21 23:57:38841 if (opener) {
Ian Clelland5cbaaf82017-11-27 22:00:03842 blink::WebSandboxFlags opener_flags = opener_rfh->active_sandbox_flags();
alexmosaedfc6f2016-01-21 23:57:38843 const blink::WebSandboxFlags inherit_flag =
Blink Reformat1c4d759e2017-04-09 16:34:54844 blink::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts;
alexmosaedfc6f2016-01-21 23:57:38845 if ((opener_flags & inherit_flag) == inherit_flag) {
Ian Clellandcdc4f312017-10-13 22:24:12846 // TODO(iclelland): Transfer correct container policy from opener as well.
847 // https://crbug.com/774620
848 new_root->SetPendingFramePolicy({opener_flags, {}});
alexmosaedfc6f2016-01-21 23:57:38849 }
850 }
851
mark a. foltzef394fce2017-10-21 09:11:02852 // Apply starting sandbox flags.
Luna Luc3fdacdf2017-11-08 04:48:53853 blink::FramePolicy frame_policy(new_root->pending_frame_policy());
mark a. foltzef394fce2017-10-21 09:11:02854 frame_policy.sandbox_flags |= params.starting_sandbox_flags;
855 new_root->SetPendingFramePolicy(frame_policy);
856 new_root->CommitPendingFramePolicy();
857
alexmose201c7cd2015-06-10 17:14:21858 // This may be true even when opener is null, such as when opening blocked
859 // popups.
alexmos090fae8e2015-05-28 17:09:28860 if (params.created_with_opener)
861 new_contents->created_with_opener_ = true;
862
[email protected]4858e432014-06-23 18:14:17863 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06864 // This makes |new_contents| act as a guest.
865 // For more info, see comment above class BrowserPluginGuest.
erikchen50735fd2018-05-05 15:08:33866 BrowserPluginGuest::Create(new_contents.get(), params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06867 }
mark a. foltzef394fce2017-10-21 09:11:02868
[email protected]54944cde2012-12-09 09:24:59869 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19870 return new_contents;
871}
872
[email protected]95640212014-07-26 18:14:30873// static
874std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
875 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08876 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30877 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30878 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30879 RenderViewHost* rvh = RenderViewHost::From(rwh);
880 if (!rvh)
881 continue;
882 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
883 if (!web_contents)
884 continue;
avidf38c952015-10-27 13:45:13885 if (web_contents->GetRenderViewHost() != rvh)
886 continue;
887 // Because a WebContents can only have one current RVH at a time, there will
888 // be no duplicate WebContents here.
889 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30890 }
891 return result;
892}
893
clamya16aa8172015-05-26 13:07:25894// static
895WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
paulmeyerfeafc2d2017-04-25 21:46:40896 const FrameTreeNode* frame_tree_node) {
clamya16aa8172015-05-26 13:07:25897 return static_cast<WebContentsImpl*>(
898 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
899}
900
clamy0d32d6d2015-11-24 11:16:26901// static
902WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
903 int render_frame_host_id) {
904 DCHECK_CURRENTLY_ON(BrowserThread::UI);
905 RenderFrameHost* render_frame_host =
906 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
907 if (!render_frame_host)
908 return nullptr;
909
910 return WebContents::FromRenderFrameHost(render_frame_host);
911}
912
paulmeyerfeafc2d2017-04-25 21:46:40913// static
914WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode(
915 const FrameTreeNode* frame_tree_node) {
916 return WebContentsImpl::FromFrameTreeNode(frame_tree_node)
917 ->node_.GetInnerWebContentsInFrame(frame_tree_node);
918}
919
[email protected]b0936d22013-11-28 06:47:36920RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21921 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28922}
923
nicka0ac8382016-12-15 23:59:23924bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host,
[email protected]7bb761892012-07-20 09:32:47925 const IPC::Message& message) {
nicka0ac8382016-12-15 23:59:23926 for (auto& observer : observers_) {
Lukasz Anforowicz89f2c1b2017-08-30 21:36:46927 // TODO(nick, creis): https://crbug.com/758026: Replace all uses of this
928 // variant of OnMessageReceived with the version that takes a
929 // RenderFrameHost, and then delete it.
nicka0ac8382016-12-15 23:59:23930 if (observer.OnMessageReceived(message))
931 return true;
[email protected]64ffefa2014-05-10 12:06:33932 }
[email protected]403415a2011-01-10 18:57:53933
[email protected]724159a2010-12-30 01:11:18934 bool handled = true;
nicka0ac8382016-12-15 23:59:23935 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host)
936 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
937 OnFirstVisuallyNonEmptyPaint)
938 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
939 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
940 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
941 OnPageScaleFactorChanged)
942 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
943 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
nicka0ac8382016-12-15 23:59:23944#if BUILDFLAG(ENABLE_PLUGINS)
945 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
946 OnRequestPpapiBrokerPermission)
947#endif
nicka0ac8382016-12-15 23:59:23948#if defined(OS_ANDROID)
949 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, OnOpenDateTimeDialog)
950#endif
951 IPC_MESSAGE_UNHANDLED(handled = false)
952 IPC_END_MESSAGE_MAP()
953
954 return handled;
955}
956
957bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host,
958 const IPC::Message& message) {
Lukasz Anforowicz02923102017-10-09 18:11:37959 {
960 WebUIImpl* web_ui = render_frame_host->web_ui();
961 if (web_ui && web_ui->OnMessageReceived(message, render_frame_host))
962 return true;
963 }
964
nicka0ac8382016-12-15 23:59:23965 for (auto& observer : observers_) {
966 if (observer.OnMessageReceived(message, render_frame_host))
967 return true;
968 }
969
970 bool handled = true;
971 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host)
[email protected]cfa856d62014-02-22 07:58:40972 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
973 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05974 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
975 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48976 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
977 OnDocumentLoadedInFrame)
978 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
avi7830c852015-08-31 23:46:25979 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18980 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54981 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18982 OnDidDisplayInsecureContent)
elawrenceb2ac2a232017-03-27 21:46:25983 IPC_MESSAGE_HANDLER(FrameHostMsg_DidContainInsecureFormAction,
984 OnDidContainInsecureFormAction)
avi3a3332622015-09-01 01:18:54985 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18986 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41987 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
988 OnDidDisplayContentWithCertificateErrors)
989 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
990 OnDidRunContentWithCertificateErrors)
avia23e16b2015-07-09 14:18:48991 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
992 OnRegisterProtocolHandler)
993 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
994 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01995 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
996 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52997 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
lukasza178ff092017-06-07 23:39:50998 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
brettw4b461082016-11-19 18:55:16999#if BUILDFLAG(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:001000 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
1001 OnPepperInstanceCreated)
1002 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
1003 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:421004 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:171005 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
1006 OnPepperStartsPlayback)
1007 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
1008 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:421009 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]c4538072013-03-18 02:17:551010 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:401011 OnBrowserPluginMessage(render_frame_host,
1012 message))
thestigc4cac8f2014-09-04 21:17:501013#endif
[email protected]724159a2010-12-30 01:11:181014 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:331015 IPC_END_MESSAGE_MAP()
[email protected]724159a2010-12-30 01:11:181016
[email protected]724159a2010-12-30 01:11:181017 return handled;
1018}
1019
[email protected]d1198fd2012-08-13 22:50:191020NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:561021 return controller_;
1022}
1023
[email protected]d1198fd2012-08-13 22:50:191024const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:561025 return controller_;
1026}
1027
[email protected]8ff00d72012-10-23 19:12:211028BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:551029 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:301030}
1031
[email protected]b172aee2012-04-10 17:05:261032const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:241033 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:321034 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:511035 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:311036}
1037
[email protected]a093ce02013-07-22 20:53:141038const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:241039 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:321040 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:241041 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
1042}
1043
1044const GURL& WebContentsImpl::GetLastCommittedURL() const {
1045 // We may not have a navigation entry yet.
1046 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1047 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
1048}
1049
[email protected]8ff00d72012-10-23 19:12:211050WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:311051 return delegate_;
1052}
1053
[email protected]8ff00d72012-10-23 19:12:211054void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:311055 // TODO(cbentzel): remove this debugging code?
1056 if (delegate == delegate_)
1057 return;
1058 if (delegate_)
1059 delegate_->Detach(this);
1060 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:081061 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:311062 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:081063 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:001064 if (view_)
[email protected]e85165c642014-06-10 14:34:311065 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
Joel Einbinder848001c2017-09-19 21:39:311066 if (GetRenderViewHost())
1067 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]a6b73c62013-02-11 23:05:081068 }
[email protected]be1f56ab2011-12-22 06:55:311069}
1070
Lukasz Anforowicze9ae3722017-09-29 17:37:381071RenderFrameHostImpl* WebContentsImpl::GetMainFrame() const {
[email protected]94d0cc12013-12-18 00:07:411072 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:161073}
1074
nick53d5cbf2015-04-23 22:50:141075RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
1076 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
1077 if (!focused_node)
1078 return nullptr;
1079 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:071080}
1081
rob3e2a0732016-01-06 21:22:091082RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
creisf71a2632017-05-04 19:03:501083 int frame_tree_node_id,
1084 int process_id) {
1085 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
1086
1087 // Sanity check that this is in the caller's expected process. Otherwise a
1088 // recent cross-process navigation may have led to a privilege change that the
1089 // caller is not expecting.
1090 if (!frame ||
1091 frame->current_frame_host()->GetProcess()->GetID() != process_id)
1092 return nullptr;
1093
1094 return frame->current_frame_host();
1095}
1096
1097RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId(
rob3e2a0732016-01-06 21:22:091098 int frame_tree_node_id) {
creisf71a2632017-05-04 19:03:501099 // Beware using this! The RenderFrameHost may have changed since the caller
1100 // obtained frame_tree_node_id.
rob3e2a0732016-01-06 21:22:091101 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
1102 return frame ? frame->current_frame_host() : nullptr;
1103}
1104
[email protected]a86c0e962013-12-17 17:10:391105void WebContentsImpl::ForEachFrame(
Lei Zhangebcc6302018-01-12 19:46:451106 const base::RepeatingCallback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:381107 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1108 on_frame.Run(node->current_frame_host());
1109 }
[email protected]a86c0e962013-12-17 17:10:391110}
1111
dchengafb53e22016-02-04 08:11:081112std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
1113 std::vector<RenderFrameHost*> frame_hosts;
1114 for (FrameTreeNode* node : frame_tree_.Nodes())
1115 frame_hosts.push_back(node->current_frame_host());
1116 return frame_hosts;
1117}
1118
lukaszacbdf52e2016-01-15 21:19:511119int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
1120 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:081121 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:251122 if (!rfh->IsRenderFrameLive())
1123 continue;
1124
dchengafb53e22016-02-04 08:11:081125 ++number_of_messages;
1126 IPC::Message* message_copy = new IPC::Message(*message);
1127 message_copy->set_routing_id(rfh->GetRoutingID());
1128 rfh->Send(message_copy);
1129 }
[email protected]a86c0e962013-12-17 17:10:391130 delete message;
lukaszacbdf52e2016-01-15 21:19:511131 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:391132}
1133
lfgdb5c4ed2016-03-04 23:09:071134void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:411135 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:071136}
1137
creisc014b402015-04-23 16:41:451138RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:211139 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:311140}
1141
creis89a0f782015-05-27 16:13:171142void WebContentsImpl::CancelActiveAndPendingDialogs() {
avi5d3b8692016-10-12 22:00:461143 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:531144 dialog_manager_->CancelDialogs(this, /*reset_state=*/false);
avi5d3b8692016-10-12 22:00:461145 }
creis89a0f782015-05-27 16:13:171146 if (browser_plugin_embedder_)
1147 browser_plugin_embedder_->CancelGuestDialogs();
1148}
1149
naskoc0fceff2015-04-30 15:53:521150void WebContentsImpl::ClosePage() {
1151 GetRenderViewHost()->ClosePage();
1152}
1153
[email protected]b172aee2012-04-10 17:05:261154RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:211155 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:311156}
1157
lfg265a2672016-04-23 03:11:021158RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
1159 if (GetOuterWebContents())
1160 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
1161 return GetRenderManager()->GetRenderWidgetHostView();
1162}
1163
[email protected]4aebbca2013-09-17 22:26:491164RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
1165 const {
vmpstr6d9996c82017-02-23 00:43:251166 if (auto* widget_host = GetFullscreenRenderWidgetHost())
ekaramadaeb3c5c2016-11-09 03:22:351167 return widget_host->GetView();
1168 return nullptr;
[email protected]4aebbca2013-09-17 22:26:491169}
1170
[email protected]8ff00d72012-10-23 19:12:211171WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:311172 return view_.get();
1173}
1174
leon.han552e9de2017-02-09 14:37:301175void WebContentsImpl::OnScreenOrientationChange() {
1176 DCHECK(screen_orientation_provider_);
Becca Hughese9e27952018-06-25 17:08:271177 screen_orientation_provider_->OnOrientationChange();
leon.hane4db177a2017-02-07 14:19:161178}
1179
yusufod41c5f92015-03-06 00:14:281180SkColor WebContentsImpl::GetThemeColor() const {
1181 return theme_color_;
1182}
1183
Doug Turner63f3c7b2017-07-29 05:10:011184void WebContentsImpl::SetAccessibilityMode(ui::AXMode mode) {
[email protected]95640212014-07-26 18:14:301185 if (mode == accessibility_mode_)
1186 return;
1187
dmazzonif8a31042016-12-03 00:52:131188 // Don't allow accessibility to be enabled for WebContents that are never
1189 // visible, like background pages.
1190 if (IsNeverVisible())
1191 return;
1192
[email protected]95640212014-07-26 18:14:301193 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:381194
1195 for (FrameTreeNode* node : frame_tree_.Nodes()) {
dmazzonif8a31042016-12-03 00:52:131196 UpdateAccessibilityModeOnFrame(node->current_frame_host());
clamy610c63b32017-12-22 15:05:181197 // Also update accessibility mode on the speculative RenderFrameHost for
1198 // this FrameTreeNode, if one exists.
Alex Moshchuk3d8a1f392017-10-24 19:01:261199 RenderFrameHost* speculative_frame_host =
1200 node->render_manager()->speculative_frame_host();
1201 if (speculative_frame_host)
1202 UpdateAccessibilityModeOnFrame(speculative_frame_host);
dcheng57e39e22016-01-21 00:25:381203 }
[email protected]95640212014-07-26 18:14:301204}
1205
Doug Turner63f3c7b2017-07-29 05:10:011206void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) {
1207 ui::AXMode new_mode(accessibility_mode_);
dougtcd3dad732017-03-14 03:26:231208 new_mode |= mode;
1209 SetAccessibilityMode(new_mode);
[email protected]95640212014-07-26 18:14:301210}
1211
Avi Drissman1e620f32018-03-16 13:57:291212// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
1213// Handles the callbacks from parallel snapshot requests to each frame,
1214// and feeds the results to an AXTreeCombiner, which converts them into a
1215// single combined accessibility tree.
1216class WebContentsImpl::AXTreeSnapshotCombiner
1217 : public base::RefCounted<AXTreeSnapshotCombiner> {
1218 public:
1219 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
1220 : callback_(std::move(callback)) {}
1221
1222 AXTreeSnapshotCallback AddFrame(bool is_root) {
1223 // Adds a reference to |this|.
1224 return base::BindOnce(&AXTreeSnapshotCombiner::ReceiveSnapshot, this,
1225 is_root);
1226 }
1227
1228 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
1229 combiner_.AddTree(snapshot, is_root);
1230 }
1231
1232 private:
1233 friend class base::RefCounted<AXTreeSnapshotCombiner>;
1234
1235 // This is called automatically after the last call to ReceiveSnapshot
1236 // when there are no more references to this object.
1237 ~AXTreeSnapshotCombiner() {
1238 combiner_.Combine();
1239 std::move(callback_).Run(combiner_.combined());
1240 }
1241
1242 ui::AXTreeCombiner combiner_;
1243 AXTreeSnapshotCallback callback_;
1244};
1245
1246void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback,
1247 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391248 // Send a request to each of the frames in parallel. Each one will return
1249 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
1250 // them into a single tree and call |callback| with that result, then
1251 // delete |combiner|.
Avi Drissman1e620f32018-03-16 13:57:291252 FrameTreeNode* root_node = frame_tree_.root();
Avi Drissmanb30851c2018-03-08 20:34:331253 AXTreeSnapshotCombiner* combiner =
1254 new AXTreeSnapshotCombiner(std::move(callback));
Avi Drissman1e620f32018-03-16 13:57:291255
1256 RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner, ax_mode);
1257}
1258
1259void WebContentsImpl::RecursiveRequestAXTreeSnapshotOnFrame(
1260 FrameTreeNode* root_node,
1261 AXTreeSnapshotCombiner* combiner,
1262 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391263 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
Avi Drissman1e620f32018-03-16 13:57:291264 WebContentsImpl* inner_contents =
1265 node_.GetInnerWebContentsInFrame(frame_tree_node);
1266 if (inner_contents) {
1267 inner_contents->RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner,
1268 ax_mode);
1269 } else {
1270 bool is_root = frame_tree_node == root_node;
1271 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
1272 combiner->AddFrame(is_root), ax_mode);
1273 }
dmazzonid95ae842016-04-12 21:17:391274 }
dmazzoni83ba5c82015-04-14 07:11:511275}
1276
mcnee336ea2c2017-05-23 22:50:591277#if !defined(OS_ANDROID)
akabac6bd1212018-06-25 20:10:481278void WebContentsImpl::UpdateZoom() {
1279 RenderWidgetHostImpl* rwh = GetRenderViewHost()->GetWidget();
1280 if (rwh->GetView())
1281 rwh->SynchronizeVisualProperties();
wjmaclean64951902016-04-29 20:59:121282}
1283
wjmaclean64951902016-04-29 20:59:121284
1285void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
akabac6bd1212018-06-25 20:10:481286 const std::string& host) {
wjmaclean64951902016-04-29 20:59:121287 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1288 if (!entry)
1289 return;
1290
1291 GURL url = HostZoomMap::GetURLFromEntry(entry);
1292 if (host != net::GetHostOrSpecFromURL(url) ||
1293 (!scheme.empty() && !url.SchemeIs(scheme))) {
1294 return;
1295 }
1296
akabac6bd1212018-06-25 20:10:481297 UpdateZoom();
wjmaclean64951902016-04-29 20:59:121298}
mcnee336ea2c2017-05-23 22:50:591299#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:121300
rockotf62002a2016-09-15 00:08:591301base::Closure WebContentsImpl::AddBindingSet(
1302 const std::string& interface_name,
1303 WebContentsBindingSet* binding_set) {
1304 auto result =
1305 binding_sets_.insert(std::make_pair(interface_name, binding_set));
1306 DCHECK(result.second);
1307 return base::Bind(&WebContentsImpl::RemoveBindingSet,
1308 weak_factory_.GetWeakPtr(), interface_name);
1309}
1310
rockot8bbad222017-03-22 04:34:051311WebContentsBindingSet* WebContentsImpl::GetBindingSet(
1312 const std::string& interface_name) {
1313 auto it = binding_sets_.find(interface_name);
1314 if (it == binding_sets_.end())
1315 return nullptr;
1316 return it->second;
1317}
1318
paulmeyerfeafc2d2017-04-25 21:46:401319std::vector<WebContentsImpl*> WebContentsImpl::GetInnerWebContents() {
1320 if (browser_plugin_embedder_) {
1321 std::vector<WebContentsImpl*> inner_contents;
1322 GetBrowserContext()->GetGuestManager()->ForEachGuest(
Mark Pilgrimd84121732018-03-22 14:12:121323 this, base::BindRepeating(&GetInnerWebContentsHelper, &inner_contents));
paulmeyerfeafc2d2017-04-25 21:46:401324 return inner_contents;
1325 }
1326
1327 return node_.inner_web_contents();
1328}
1329
1330std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() {
1331 std::vector<WebContentsImpl*> all_contents(1, this);
1332
1333 for (size_t i = 0; i != all_contents.size(); ++i) {
1334 for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) {
1335 all_contents.push_back(inner_contents);
1336 }
1337 }
1338
1339 return all_contents;
1340}
1341
Sam McNally145fb172017-05-10 00:13:231342void WebContentsImpl::NotifyManifestUrlChanged(
1343 const base::Optional<GURL>& manifest_url) {
1344 for (auto& observer : observers_)
1345 observer.DidUpdateWebManifestURL(manifest_url);
1346}
1347
[email protected]8ff00d72012-10-23 19:12:211348WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:401349 WebUI* commited_web_ui = GetCommittedWebUI();
1350 return commited_web_ui ? commited_web_ui
1351 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:311352}
1353
[email protected]8ff00d72012-10-23 19:12:211354WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:401355 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341356}
1357
Changwan Ryuc1134a82018-03-07 02:10:141358void WebContentsImpl::SetUserAgentOverride(const std::string& override,
1359 bool override_in_new_tabs) {
[email protected]bf70edce2012-06-20 22:32:221360 if (GetUserAgentOverride() == override)
1361 return;
1362
Changwan Ryuc1134a82018-03-07 02:10:141363 should_override_user_agent_in_new_tabs_ = override_in_new_tabs;
1364
[email protected]bf70edce2012-06-20 22:32:221365 renderer_preferences_.user_agent_override = override;
1366
1367 // Send the new override string to the renderer.
1368 RenderViewHost* host = GetRenderViewHost();
1369 if (host)
1370 host->SyncRendererPrefs();
1371
1372 // Reload the page if a load is currently in progress to avoid having
1373 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271374 NavigationEntry* entry = controller_.GetVisibleEntry();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281375 if (IsLoading() && entry != nullptr && entry->GetIsOverridingUserAgent())
toyoshim6142d96f2016-12-19 09:07:251376 controller_.Reload(ReloadType::BYPASSING_CACHE, true);
[email protected]8d0f3312012-08-18 01:47:531377
ericwilligersde386342016-10-19 02:35:091378 for (auto& observer : observers_)
1379 observer.UserAgentOverrideSet(override);
[email protected]86ef6a392012-05-11 22:03:111380}
1381
1382const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:221383 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111384}
1385
Changwan Ryuc1134a82018-03-07 02:10:141386bool WebContentsImpl::ShouldOverrideUserAgentInNewTabs() {
1387 return should_override_user_agent_in_new_tabs_;
1388}
1389
dmazzonidd3d51a72016-12-14 18:41:011390void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() {
dougtcd3dad732017-03-14 03:26:231391 if (!GetAccessibilityMode().is_mode_off()) {
dchengafb53e22016-02-04 08:11:081392 for (RenderFrameHost* rfh : GetAllFrames())
1393 ResetAccessibility(rfh);
1394 } else {
Doug Turner63f3c7b2017-07-29 05:10:011395 AddAccessibilityMode(ui::kAXModeWebContentsOnly);
dchengafb53e22016-02-04 08:11:081396 }
[email protected]95640212014-07-26 18:14:301397}
1398
dmazzonidd3d51a72016-12-14 18:41:011399bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011400 return accessibility_mode_ == ui::kAXModeWebContentsOnly;
[email protected]95640212014-07-26 18:14:301401}
1402
1403bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011404 return accessibility_mode_ == ui::kAXModeComplete;
[email protected]95640212014-07-26 18:14:301405}
1406
kouhei40f03cb2015-09-24 07:47:011407const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
1408 return page_importance_signals_;
1409}
1410
Guido Urdanetaf4008002018-05-03 10:43:041411const std::string& WebContentsImpl::GetMediaDeviceGroupIDSaltBase() const {
1412 return media_device_group_id_salt_base_;
1413}
1414
Becca Hughes6daf5662018-06-27 16:50:541415#if defined(OS_ANDROID)
1416
1417void WebContentsImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) {
Becca Hughes86334622018-07-09 21:29:381418 if (display_cutout_host_impl_)
1419 display_cutout_host_impl_->SetDisplayCutoutSafeArea(insets);
Becca Hughes6daf5662018-06-27 16:50:541420}
1421
1422#endif
1423
[email protected]fcf75d42013-12-03 20:11:261424const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:551425 // Transient entries take precedence. They are used for interstitial pages
1426 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231427 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231428 if (entry) {
jshin1fb76462016-04-05 22:13:031429 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231430 }
carlosk35f35af2015-12-01 10:55:401431
1432 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
1433 WebUI* our_web_ui = navigating_web_ui
1434 ? navigating_web_ui
1435 : GetRenderManager()->current_frame_host()->web_ui();
1436
[email protected]7ade2732011-02-10 00:13:581437 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541438 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321439 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541440 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351441 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261442 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541443 if (!title.empty())
1444 return title;
1445 }
1446 }
1447
1448 // We use the title for the last committed entry rather than a pending
1449 // navigation entry. For example, when the user types in a URL, we want to
1450 // keep the old page's title until the new load has committed and we get a new
1451 // title.
[email protected]96d185d2009-04-24 03:28:541452 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321453
creis072b61f2015-09-28 20:52:241454 // We make an exception for initial navigations. We only want to use the title
1455 // from the visible entry if:
1456 // 1. The pending entry has been explicitly assigned a title to display.
1457 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1458 // which case there is a pending entry index other than -1.
1459 //
1460 // Otherwise, we want to stick with the last committed entry's title during
1461 // new navigations, which have pending entries at index -1 with no title.
1462 if (controller_.IsInitialNavigation() &&
1463 ((controller_.GetVisibleEntry() &&
1464 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1465 controller_.GetPendingEntryIndex() != -1)) {
1466 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471467 }
[email protected]59167c22013-06-03 18:07:321468
[email protected]45d0ef7f2011-01-05 13:46:231469 if (entry) {
jshin1fb76462016-04-05 22:13:031470 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231471 }
[email protected]987fc3a2011-05-26 14:18:091472
1473 // |page_title_when_no_navigation_entry_| is finally used
1474 // if no title cannot be retrieved.
1475 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541476}
1477
creiscce56cd2014-09-29 22:45:221478SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211479 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541480}
1481
[email protected]b172aee2012-04-10 17:05:261482bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251483 return frame_tree_.IsLoading() &&
creisadca9862017-06-16 19:12:111484 !(ShowingInterstitialPage() && interstitial_page_->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491485}
1486
[email protected]6dfed692014-05-22 04:18:031487bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251488 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031489}
1490
[email protected]b172aee2012-04-10 17:05:261491bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031492 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311493}
1494
[email protected]b172aee2012-04-10 17:05:261495const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311496 return load_state_;
1497}
1498
[email protected]fcf75d42013-12-03 20:11:261499const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311500 return load_state_host_;
1501}
1502
avib7348942015-12-25 20:57:101503uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311504 return upload_size_;
1505}
1506
avib7348942015-12-25 20:57:101507uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311508 return upload_position_;
1509}
1510
[email protected]b172aee2012-04-10 17:05:261511const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541512 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311513}
1514
Shubhie Panickerddf2a4e2018-03-06 00:09:061515void WebContentsImpl::SetWasDiscarded(bool was_discarded) {
1516 GetFrameTree()->root()->set_was_discarded();
1517}
1518
[email protected]222f5822014-02-05 23:40:491519void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251520 DCHECK(!is_being_destroyed_);
Francois Doraye6161152018-03-27 22:05:371521 const bool was_captured = IsBeingCaptured();
[email protected]54597982013-02-06 01:59:551522 ++capturer_count_;
1523 DVLOG(1) << "There are now " << capturer_count_
1524 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491525
1526 // Note: This provides a hint to upstream code to size the views optimally
1527 // for quality (e.g., to avoid scaling).
1528 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1529 preferred_size_for_capture_ = capture_size;
1530 OnPreferredSizeChanged(preferred_size_);
1531 }
ccameron8807c38f2015-01-17 00:29:191532
Francois Doraye6161152018-03-27 22:05:371533 if (GetVisibility() != Visibility::VISIBLE && !was_captured) {
1534 // Ensure that all views act as if they were visible before capture begins.
1535 // TODO(fdoray): Replace RenderWidgetHostView::WasUnOccluded() with a method
1536 // to explicitly notify the RenderWidgetHostView that capture began.
1537 // https://crbug.com/668690
1538 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1539 view->WasUnOccluded();
1540 }
[email protected]54597982013-02-06 01:59:551541}
1542
1543void WebContentsImpl::DecrementCapturerCount() {
1544 --capturer_count_;
1545 DVLOG(1) << "There are now " << capturer_count_
1546 << " capturing(s) of WebContentsImpl@" << this;
1547 DCHECK_LE(0, capturer_count_);
1548
[email protected]5a652232013-02-12 06:15:251549 if (is_being_destroyed_)
1550 return;
1551
Francois Doray24fc62c2017-12-11 17:27:331552 if (!IsBeingCaptured()) {
[email protected]222f5822014-02-05 23:40:491553 const gfx::Size old_size = preferred_size_for_capture_;
1554 preferred_size_for_capture_ = gfx::Size();
1555 OnPreferredSizeChanged(old_size);
[email protected]222f5822014-02-05 23:40:491556
Francois Doraye6161152018-03-27 22:05:371557 if (visibility_ == Visibility::HIDDEN) {
Francois Doray18800972017-08-25 22:38:581558 DVLOG(1) << "Executing delayed WasHidden().";
1559 WasHidden();
Francois Doraye6161152018-03-27 22:05:371560 } else if (visibility_ == Visibility::OCCLUDED) {
Mitsuru Oshima04a80242018-03-03 03:06:151561 WasOccluded();
Francois Doraye6161152018-03-27 22:05:371562 }
[email protected]54597982013-02-06 01:59:551563 }
[email protected]be1f56ab2011-12-22 06:55:311564}
1565
Francois Doray24fc62c2017-12-11 17:27:331566bool WebContentsImpl::IsBeingCaptured() const {
1567 return capturer_count_ > 0;
[email protected]f2bd40812013-07-20 04:30:441568}
1569
miu50f97892014-09-22 22:49:521570bool WebContentsImpl::IsAudioMuted() const {
Max Morinb5506f72018-05-16 07:33:101571 if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) {
1572 return audio_stream_factory_ && audio_stream_factory_->IsMuted();
1573 }
miu50f97892014-09-22 22:49:521574 return audio_muter_.get() && audio_muter_->is_muting();
1575}
1576
1577void WebContentsImpl::SetAudioMuted(bool mute) {
1578 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1579 << " for WebContentsImpl@" << this;
1580
1581 if (mute == IsAudioMuted())
1582 return;
1583
Max Morinb5506f72018-05-16 07:33:101584 if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) {
1585 GetAudioStreamFactory()->SetMuted(mute);
miu50f97892014-09-22 22:49:521586 } else {
Max Morinb5506f72018-05-16 07:33:101587 if (mute) {
1588 if (!audio_muter_)
1589 audio_muter_.reset(new WebContentsAudioMuter(this));
1590 audio_muter_->StartMuting();
1591 } else {
1592 DCHECK(audio_muter_);
1593 audio_muter_->StopMuting();
1594 }
miu50f97892014-09-22 22:49:521595 }
1596
ericwilligersde386342016-10-19 02:35:091597 for (auto& observer : observers_)
1598 observer.DidUpdateAudioMutingState(mute);
wjmaclean2f797c782016-01-07 14:52:031599
Jan Rucka442c83f2017-08-08 13:27:541600 // Notification for UI updates in response to the changed muting state.
1601 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1602}
1603
1604bool WebContentsImpl::IsCurrentlyAudible() {
Chris Hamiltondf0d72cd2018-05-29 16:23:531605 return is_currently_audible_;
miu50f97892014-09-22 22:49:521606}
1607
ortunodf4d7982016-04-08 02:33:351608bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1609 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201610}
1611
sawtellea7333a82018-05-31 02:36:361612bool WebContentsImpl::HasPictureInPictureVideo() const {
1613 return has_picture_in_picture_video_;
1614}
1615
1616void WebContentsImpl::SetHasPictureInPictureVideo(
1617 bool has_picture_in_picture_video) {
1618 // If status of |this| is already accurate, there is no need to update.
1619 if (has_picture_in_picture_video == has_picture_in_picture_video_)
1620 return;
1621 has_picture_in_picture_video_ = has_picture_in_picture_video;
1622 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1623}
1624
[email protected]b172aee2012-04-10 17:05:261625bool WebContentsImpl::IsCrashed() const {
Dominic Mazzoni73a48322018-05-25 18:14:071626 switch (crashed_status_) {
1627 case base::TERMINATION_STATUS_PROCESS_CRASHED:
1628 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
1629 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
1630 case base::TERMINATION_STATUS_OOM:
1631 case base::TERMINATION_STATUS_LAUNCH_FAILED:
oshima620225722015-06-04 19:45:271632#if defined(OS_CHROMEOS)
Dominic Mazzoni73a48322018-05-25 18:14:071633 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM:
oshima620225722015-06-04 19:45:271634#endif
Dominic Mazzoni73a48322018-05-25 18:14:071635#if defined(OS_ANDROID)
1636 case base::TERMINATION_STATUS_OOM_PROTECTED:
1637#endif
1638 return true;
1639 case base::TERMINATION_STATUS_NORMAL_TERMINATION:
1640 case base::TERMINATION_STATUS_STILL_RUNNING:
1641 return false;
1642 case base::TERMINATION_STATUS_MAX_ENUM:
1643 NOTREACHED();
1644 return false;
1645 }
1646
1647 NOTREACHED();
1648 return false;
[email protected]3c9e1872010-11-18 16:17:491649}
1650
[email protected]b172aee2012-04-10 17:05:261651void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1652 int error_code) {
[email protected]443b80e2010-12-14 00:42:231653 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341654 return;
1655
[email protected]443b80e2010-12-14 00:42:231656 crashed_status_ = status;
1657 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211658 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341659}
1660
[email protected]b172aee2012-04-10 17:05:261661base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311662 return crashed_status_;
1663}
1664
afakhry98241832016-03-11 19:27:471665int WebContentsImpl::GetCrashedErrorCode() const {
1666 return crashed_error_code_;
1667}
1668
[email protected]b172aee2012-04-10 17:05:261669bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311670 return is_being_destroyed_;
1671}
1672
[email protected]7f924832014-08-09 05:57:221673void WebContentsImpl::NotifyNavigationStateChanged(
1674 InvalidateTypes changed_flags) {
dalecurtis88c240072015-12-09 02:11:181675 // Notify the media observer of potential audibility changes.
1676 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271677 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301678 }
1679
[email protected]d5f942ba2008-09-26 19:30:341680 if (delegate_)
1681 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441682
1683 if (GetOuterWebContents())
1684 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341685}
1686
Chris Hamiltondf0d72cd2018-05-29 16:23:531687void WebContentsImpl::OnAudioStateChanged() {
1688 // This notification can come from any embedded contents or from this
1689 // WebContents' stream monitor. Aggregate these signals to get the actual
1690 // state.
1691 bool is_currently_audible =
1692 audio_stream_monitor_.IsCurrentlyAudible() ||
1693 (browser_plugin_embedder_ &&
1694 browser_plugin_embedder_->AreAnyGuestsCurrentlyAudible());
1695 if (is_currently_audible == is_currently_audible_)
1696 return;
1697
1698 // Update internal state.
1699 is_currently_audible_ = is_currently_audible;
1700 was_ever_audible_ = was_ever_audible_ || is_currently_audible_;
1701
1702 SendPageMessage(
1703 new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_currently_audible_));
altimind8bd26c2016-11-04 11:44:541704
altiminec87fd1f2016-11-17 20:22:491705 // Notification for UI updates in response to the changed audio state.
altimind8bd26c2016-11-04 11:44:541706 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
Jan Rucka442c83f2017-08-08 13:27:541707
Chris Hamiltondf0d72cd2018-05-29 16:23:531708 // Ensure that audio state changes propagate from innermost to outermost
1709 // WebContents.
1710 if (GetOuterWebContents())
1711 GetOuterWebContents()->OnAudioStateChanged();
Tommy Steimel18360512017-11-01 00:38:191712
Chris Hamiltoneb41198f2018-05-24 18:41:261713 for (auto& observer : observers_)
Chris Hamiltondf0d72cd2018-05-29 16:23:531714 observer.OnAudioStateChanged(is_currently_audible_);
altimind8bd26c2016-11-04 11:44:541715}
1716
gab0dccfef2015-05-20 18:43:391717base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021718 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331719}
1720
[email protected]9e2e4632012-07-27 16:38:411721void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541722 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591723
EhsanK2075c7e2017-08-21 02:42:391724 if (auto* view = GetRenderWidgetHostView()) {
lfgf949e0e2017-05-10 22:18:111725 view->Show();
[email protected]789e9152009-08-04 21:59:431726#if defined(OS_MACOSX)
lfgf949e0e2017-05-10 22:18:111727 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431728#endif
1729 }
[email protected]96d185d2009-04-24 03:28:541730
EhsanK2075c7e2017-08-21 02:42:391731 if (!ShowingInterstitialPage())
1732 SetVisibilityForChildViews(true);
1733
lfg717154072016-06-30 15:04:161734 SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE));
1735
gab0dccfef2015-05-20 18:43:391736 last_active_time_ = base::TimeTicks::Now();
Francois Doraye6161152018-03-27 22:05:371737 SetVisibility(Visibility::VISIBLE);
Lukasz Anforowicz873e6082018-05-17 00:12:331738
1739 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1740 RenderFrameProxyHost* parent = node->render_manager()->GetProxyToParent();
1741 if (!parent)
1742 continue;
1743
1744 if (parent->cross_process_frame_connector()->IsVisible()) {
1745 // MaybeLogCrash will check 1) if there was a crash or not and 2) if the
1746 // crash might have been already logged earlier as kCrashedWhileVisible.
1747 parent->cross_process_frame_connector()->MaybeLogCrash(
1748 CrossProcessFrameConnector::CrashVisibility::kShownAfterCrashing);
1749 }
1750 }
[email protected]be1f56ab2011-12-22 06:55:311751}
1752
[email protected]b172aee2012-04-10 17:05:261753void WebContentsImpl::WasHidden() {
Jennifer Apacible72c31412018-06-19 16:52:241754 // If there are entities capturing screenshots or video (e.g. mirroring),
1755 // or in Picture-in-Picture mode, don't activate the "disable rendering"
1756 // optimization.
1757 if (!IsBeingCaptured() && !HasPictureInPictureVideo()) {
[email protected]151a63d2011-12-20 22:32:521758 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551759 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261760 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521761 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331762 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521763 // calls us).
EhsanK2075c7e2017-08-21 02:42:391764 if (auto* view = GetRenderWidgetHostView())
lfgf949e0e2017-05-10 22:18:111765 view->Hide();
lfg717154072016-06-30 15:04:161766
EhsanK2075c7e2017-08-21 02:42:391767 if (!ShowingInterstitialPage())
Igor Eremeevef59187a2017-09-29 00:25:421768 SetVisibilityForChildViews(false);
EhsanK2075c7e2017-08-21 02:42:391769
lfg717154072016-06-30 15:04:161770 SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
[email protected]96d185d2009-04-24 03:28:541771 }
1772
Francois Doraye6161152018-03-27 22:05:371773 SetVisibility(Visibility::HIDDEN);
[email protected]375fa1b2012-05-22 22:05:371774}
1775
Daniel Cheng90196c82018-04-25 21:49:141776bool WebContentsImpl::HasRecentInteractiveInputEvent() const {
1777 static constexpr base::TimeDelta kMaxInterval =
1778 base::TimeDelta::FromSeconds(5);
1779 base::TimeDelta delta =
1780 ui::EventTimeForNow() - last_interactive_input_event_time_;
1781 // Note: the expectation is that the caller is typically expecting an input
1782 // event, e.g. validating that a WebUI message that requires a gesture is
1783 // actually attached to a gesture. Logging to UMA here should hopefully give
1784 // sufficient data if 5 seconds is actually sufficient (or even too high a
1785 // threshhold).
1786 UMA_HISTOGRAM_TIMES("Tabs.TimeSinceLastInteraction", delta);
1787 return delta <= kMaxInterval;
1788}
1789
Bo Liu168c8642017-08-28 18:26:021790#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:501791void WebContentsImpl::SetMainFrameImportance(
1792 ChildProcessImportance importance) {
1793 GetMainFrame()->GetRenderWidgetHost()->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281794 if (ShowingInterstitialPage()) {
Bo Liu16dd7b8322018-05-02 21:19:501795 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
1796 ->GetRenderWidgetHost()
1797 ->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281798 }
Bo Liu7c6779e92017-08-16 02:02:281799}
Bo Liu168c8642017-08-28 18:26:021800#endif
Bo Liu7c6779e92017-08-16 02:02:281801
ccameron8807c38f2015-01-17 00:29:191802void WebContentsImpl::WasOccluded() {
Francois Doray24fc62c2017-12-11 17:27:331803 if (!IsBeingCaptured()) {
Francois Doray18800972017-08-25 22:38:581804 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1805 view->WasOccluded();
1806 }
Francois Doraye6161152018-03-27 22:05:371807 SetVisibility(Visibility::OCCLUDED);
ccameron8807c38f2015-01-17 00:29:191808}
1809
Francois Dorayfe4a1772018-02-17 04:17:091810Visibility WebContentsImpl::GetVisibility() const {
Francois Doraye6161152018-03-27 22:05:371811 return visibility_;
Francois Dorayfe4a1772018-02-17 04:17:091812}
1813
[email protected]b172aee2012-04-10 17:05:261814bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311815 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451816 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
jam40444982017-04-11 03:01:411817 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311818}
1819
nasko148bb0b92016-05-10 21:03:191820void WebContentsImpl::DispatchBeforeUnload() {
1821 bool for_cross_site_transition = false;
clamybfd6a812016-05-30 16:25:171822 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false);
[email protected]1c3f80bd2014-04-08 23:02:061823}
1824
lazyboy6ec48b2a2015-06-29 15:18:141825void WebContentsImpl::AttachToOuterWebContentsFrame(
1826 WebContents* outer_web_contents,
1827 RenderFrameHost* outer_contents_frame) {
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391828 DCHECK(!node_.outer_web_contents());
1829
lfg91a79e12016-04-01 23:52:191830 RenderFrameHostManager* render_manager = GetRenderManager();
1831
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391832 // When attaching a WebContents as an inner WebContents, we need to replace
1833 // the Webcontents' view with a WebContentsViewChildFrame.
1834 view_.reset(new WebContentsViewChildFrame(
1835 this, GetContentClient()->browser()->GetWebContentsViewDelegate(this),
1836 &render_view_host_delegate_view_));
1837
lfg91a79e12016-04-01 23:52:191838 // When the WebContents being initialized has an opener, the browser side
1839 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1840 // created. This is needed because the usual initialization happens during
1841 // the first navigation, but when attaching a new window we don't navigate
1842 // before attaching. If the browser side is already initialized, the calls
1843 // below will just early return.
1844 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1845 GetMainFrame()->Init();
1846 if (!render_manager->GetRenderWidgetHostView())
1847 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1848
avallee7529b2a2017-04-26 11:37:511849 auto* outer_web_contents_impl =
1850 static_cast<WebContentsImpl*>(outer_web_contents);
1851 auto* outer_contents_frame_impl =
1852 static_cast<RenderFrameHostImpl*>(outer_contents_frame);
lazyboy6ec48b2a2015-06-29 15:18:141853 // Create a link to our outer WebContents.
avallee7529b2a2017-04-26 11:37:511854 node_.ConnectToOuterWebContents(outer_web_contents_impl,
1855 outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141856
1857 DCHECK(outer_contents_frame);
1858
1859 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1860 // SiteInstance of the outer WebContents. The proxy will be used to send
1861 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191862 render_manager->CreateOuterDelegateProxy(
avallee7529b2a2017-04-26 11:37:511863 outer_contents_frame->GetSiteInstance(), outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141864
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141865 ReattachToOuterWebContentsFrame();
ekaramadadd882292016-06-08 15:22:561866
avallee7529b2a2017-04-26 11:37:511867 if (outer_web_contents_impl->frame_tree_.GetFocusedFrame() ==
1868 outer_contents_frame_impl->frame_tree_node()) {
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:571869 SetFocusedFrame(frame_tree_.root(),
1870 outer_contents_frame->GetSiteInstance());
avallee7529b2a2017-04-26 11:37:511871 }
1872
ekaramadadd882292016-06-08 15:22:561873 // At this point, we should destroy the TextInputManager which will notify all
1874 // the RWHV in this WebContents. The RWHV in this WebContents should use the
1875 // TextInputManager owned by the outer WebContents.
1876 // TODO(ekaramad): Is it possible to have TextInputState before attaching to
1877 // outer WebContents? In such a case, is this still the right way to hand off
1878 // state tracking from inner WebContents's TextInputManager to that of the
1879 // outer WebContent (crbug.com/609846)?
1880 text_input_manager_.reset(nullptr);
lazyboy6ec48b2a2015-06-29 15:18:141881}
1882
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141883void WebContentsImpl::ReattachToOuterWebContentsFrame() {
1884 DCHECK(node_.outer_web_contents());
1885 auto* render_manager = GetRenderManager();
1886 auto* parent_frame =
1887 node_.OuterContentsFrameTreeNode()->current_frame_host()->GetParent();
1888 render_manager->SetRWHViewForInnerContents(
1889 render_manager->GetRenderWidgetHostView());
1890
1891 static_cast<RenderWidgetHostViewChildFrame*>(
1892 render_manager->GetRenderWidgetHostView())
1893 ->RegisterFrameSinkId();
1894
1895 // Set up the the guest's AX tree to point back at the embedder's AX tree.
1896 GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(
1897 parent_frame->GetAXTreeID());
1898 GetMainFrame()->UpdateAXTreeData();
1899}
1900
dalecurtis6c58ed02016-10-28 23:02:371901void WebContentsImpl::DidChangeVisibleSecurityState() {
1902 if (delegate_) {
1903 delegate_->VisibleSecurityStateChanged(this);
cjgrant6d1d727a2016-12-09 21:16:571904 for (auto& observer : observers_)
1905 observer.DidChangeVisibleSecurityState();
dalecurtis6c58ed02016-10-28 23:02:371906 }
1907}
1908
Ahmed Fakhryd70bf37b2018-04-04 17:07:241909void WebContentsImpl::NotifyPreferencesChanged() {
1910 std::set<RenderViewHost*> render_view_host_set;
1911 for (FrameTreeNode* node : frame_tree_.Nodes()) {
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531912 render_view_host_set.insert(
1913 node->current_frame_host()->GetRenderViewHost());
Ahmed Fakhryd70bf37b2018-04-04 17:07:241914 }
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531915
Ahmed Fakhryd70bf37b2018-04-04 17:07:241916 for (RenderViewHost* render_view_host : render_view_host_set)
1917 render_view_host->OnWebkitPreferencesChanged();
1918}
1919
[email protected]b172aee2012-04-10 17:05:261920void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381921 for (FrameTreeNode* node : frame_tree_.Nodes())
1922 node->StopLoading();
ericwilligersde386342016-10-19 02:35:091923 for (auto& observer : observers_)
1924 observer.NavigationStopped();
[email protected]0bfbf882011-12-22 18:19:271925}
1926
Francois Doray47f759d2018-06-11 18:13:511927void WebContentsImpl::SetPageFrozen(bool frozen) {
1928 // A visible page is never frozen.
1929 DCHECK_NE(Visibility::VISIBLE, GetVisibility());
1930
1931 SendPageMessage(new PageMsg_SetPageFrozen(MSG_ROUTING_NONE, frozen));
Fadi Meawada6573e02018-03-10 00:52:111932}
1933
erikchen6c7df7f7a2018-05-03 18:13:591934std::unique_ptr<WebContents> WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441935 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211936 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451937 // before.
[email protected]54944cde2012-12-09 09:24:591938 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451939 create_params.initial_size = GetContainerBounds().size();
Ian Clelland5cbaaf82017-11-27 22:00:031940 FrameTreeNode* opener = frame_tree_.root()->opener();
1941 RenderFrameHostImpl* opener_rfh = nullptr;
1942 if (opener)
1943 opener_rfh = opener->current_frame_host();
erikchen6c7df7f7a2018-05-03 18:13:591944 std::unique_ptr<WebContentsImpl> tc =
erikchen50735fd2018-05-05 15:08:331945 CreateWithOpener(create_params, opener_rfh);
Francois Dorayeaace782017-06-21 16:37:241946 tc->GetController().CopyStateFrom(controller_, true);
ericwilligersde386342016-10-19 02:35:091947 for (auto& observer : observers_)
erikchen6c7df7f7a2018-05-03 18:13:591948 observer.DidCloneToNewWebContents(this, tc.get());
[email protected]0bfbf882011-12-22 18:19:271949 return tc;
1950}
1951
[email protected]14392a52012-05-02 20:28:441952void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211953 const NotificationSource& source,
1954 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441955 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211956 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1957 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031958 RenderWidgetHostView* view = host->GetView();
1959 if (view == GetFullscreenRenderWidgetHostView()) {
1960 // We cannot just call view_->RestoreFocus() here. On some platforms,
1961 // attempting to focus the currently-invisible WebContentsView will be
1962 // flat-out ignored. Therefore, this boolean is used to track whether
1963 // we will request focus after the fullscreen widget has been
1964 // destroyed.
1965 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1966 } else {
alexmosc2a8cec2016-05-23 22:19:531967 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:031968 i != pending_widget_views_.end(); ++i) {
1969 if (host->GetView() == i->second) {
1970 pending_widget_views_.erase(i);
1971 break;
1972 }
[email protected]bafe6cd2012-05-23 23:09:501973 }
1974 }
1975 break;
1976 }
[email protected]14392a52012-05-02 20:28:441977 default:
1978 NOTREACHED();
1979 }
1980}
1981
[email protected]ec6c05f2013-10-23 18:41:571982WebContents* WebContentsImpl::GetWebContents() {
1983 return this;
1984}
1985
[email protected]54944cde2012-12-09 09:24:591986void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211987 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361988 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211989 // it should be hidden.
Francois Doraye6161152018-03-27 22:05:371990 visibility_ =
1991 params.initially_hidden ? Visibility::HIDDEN : Visibility::VISIBLE;
[email protected]d6fa88f2013-10-18 16:00:431992
Sebastien Marchand28cf23182018-06-20 02:39:351993 if (!params.last_active_time.is_null())
1994 last_active_time_ = params.last_active_time;
1995
dcheng3ce04b62015-10-26 23:30:551996 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541997 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551998 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1999 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:542000 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:552001 params.main_frame_routing_id != MSG_ROUTING_NONE &&
2002 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
2003
2004 scoped_refptr<SiteInstance> site_instance = params.site_instance;
2005 if (!site_instance)
2006 site_instance = SiteInstance::Create(params.browser_context);
Lukasz Anforowicz3caa8372018-06-05 17:22:072007 if (params.desired_renderer_state == CreateParams::kNoRendererProcess) {
2008 static_cast<SiteInstanceImpl*>(site_instance.get())
2009 ->PreventAssociationWithSpareProcess();
2010 }
dcheng3ce04b62015-10-26 23:30:552011
2012 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
2013 // local root by definition.
2014 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
2015 // longer be necessary to eagerly grab a routing ID for the view.
2016 // https://crbug.com/545684
2017 int32_t view_routing_id = params.routing_id;
2018 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
2019 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
Albert J. Wongcb004632018-07-10 22:58:252020 view_routing_id = site_instance->GetProcess()->GetNextRoutingID();
2021 main_frame_widget_routing_id =
dcheng3ce04b62015-10-26 23:30:552022 site_instance->GetProcess()->GetNextRoutingID();
2023 }
2024
Albert J. Wongcb004632018-07-10 22:58:252025 DCHECK_NE(view_routing_id, main_frame_widget_routing_id);
2026
Dave Tapuska485aca92017-08-08 00:47:582027 GetRenderManager()->Init(
2028 site_instance.get(), view_routing_id, params.main_frame_routing_id,
2029 main_frame_widget_routing_id, params.renderer_initiated_creation);
lukasza464d8692016-02-22 19:26:322030
lukasza5140a412016-09-15 21:12:302031 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
2032 // main frame - let's do the same thing here.
2033 std::string unique_name;
lukasza464d8692016-02-22 19:26:322034 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:192035
[email protected]fc2b46b2014-05-03 16:33:452036 WebContentsViewDelegate* delegate =
2037 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
2038
sky52a39e342016-12-17 17:23:222039 if (GuestMode::IsCrossProcessFrameGuest(this)) {
2040 view_.reset(new WebContentsViewChildFrame(
2041 this, delegate, &render_view_host_delegate_view_));
2042 } else {
2043 view_.reset(CreateWebContentsView(this, delegate,
2044 &render_view_host_delegate_view_));
Scott Violetc884c7fd2017-11-03 23:51:012045 if (browser_plugin_guest_) {
2046 view_ = std::make_unique<WebContentsViewGuest>(
2047 this, browser_plugin_guest_.get(), std::move(view_),
2048 &render_view_host_delegate_view_);
2049 }
[email protected]d1198fd2012-08-13 22:50:192050 }
[email protected]fc2b46b2014-05-03 16:33:452051 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:192052 CHECK(view_.get());
2053
[email protected]ed245db2012-12-18 08:00:452054 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:592055 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:192056
brettw4b461082016-11-19 18:55:162057#if BUILDFLAG(ENABLE_PLUGINS)
tommyclieb25b2a2014-11-03 19:45:092058 plugin_content_origin_whitelist_.reset(
2059 new PluginContentOriginWhitelist(this));
2060#endif
2061
[email protected]d1198fd2012-08-13 22:50:192062 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:212063 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
2064 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:102065
leon.hane4db177a2017-02-07 14:19:162066 screen_orientation_provider_.reset(new ScreenOrientationProvider(this));
[email protected]01f83f92014-06-17 14:41:542067
mlamouriefdca9d2014-09-16 16:55:402068 manifest_manager_host_.reset(new ManifestManagerHost(this));
2069
mfomitchev2b8b066a2016-01-28 19:23:152070#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:102071 date_time_chooser_.reset(new DateTimeChooserAndroid());
2072#endif
fsamuel7310a4262014-12-05 05:06:442073
2074 // BrowserPluginGuest::Init needs to be called after this WebContents has
2075 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
2076 if (browser_plugin_guest_)
2077 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:372078
2079 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
2080 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:562081
2082 // If the WebContents creation was renderer-initiated, it means that the
2083 // corresponding RenderView and main RenderFrame have already been created.
2084 // Ensure observers are notified about this.
2085 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:432086 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
Alex Moshchuk27caae82017-09-11 23:11:182087 GetRenderViewHost()->DispatchRenderViewCreated();
naskob21fe4872015-02-24 14:15:562088 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
2089 }
naskof5940b9f2015-03-02 23:04:052090
lof84501da082016-05-23 21:22:542091 // Create the renderer process in advance if requested.
Lukasz Anforowicz3caa8372018-06-05 17:22:072092 if (params.desired_renderer_state ==
2093 CreateParams::kInitializeAndWarmupRendererProcess) {
lof84501da082016-05-23 21:22:542094 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
2095 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
2096 }
2097 }
2098
naskof5940b9f2015-03-02 23:04:052099 // Ensure that observers are notified of the creation of this WebContents's
2100 // main RenderFrameHost. It must be done here for main frames, since the
2101 // NotifySwappedFromRenderManager expects view_ to already be created and that
2102 // happens after RenderFrameHostManager::Init.
2103 NotifySwappedFromRenderManager(
2104 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:192105}
2106
[email protected]7fff43e2013-05-21 20:21:102107void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
2108 RemoveDestructionObserver(web_contents);
2109
[email protected]ceee8cd2013-03-08 04:59:512110 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:532111 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:512112 ++iter) {
erikchenbee5c9622018-04-27 19:30:252113 if (iter->second.get() != web_contents)
[email protected]ceee8cd2013-03-08 04:59:512114 continue;
erikchenbee5c9622018-04-27 19:30:252115
2116 // Someone else has deleted the WebContents. That should never happen!
2117 // TODO(erikchen): Fix semantics here. https://crbug.com/832879.
2118 iter->second.release();
[email protected]ceee8cd2013-03-08 04:59:512119 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:512120 return;
2121 }
2122 NOTREACHED();
[email protected]14392a52012-05-02 20:28:442123}
2124
[email protected]7fff43e2013-05-21 20:21:102125void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
2126 if (!ContainsKey(destruction_observers_, web_contents)) {
2127 destruction_observers_[web_contents] =
Jeremy Roman04f27c372017-10-27 15:20:552128 std::make_unique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:102129 }
2130}
2131
2132void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:462133 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:102134}
2135
[email protected]b172aee2012-04-10 17:05:262136void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312137 observers_.AddObserver(observer);
2138}
2139
[email protected]b172aee2012-04-10 17:05:262140void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312141 observers_.RemoveObserver(observer);
2142}
2143
[email protected]948481d2014-06-11 18:32:222144std::set<RenderWidgetHostView*>
2145WebContentsImpl::GetRenderWidgetHostViewsInTree() {
2146 std::set<RenderWidgetHostView*> set;
2147 if (ShowingInterstitialPage()) {
lfgf949e0e2017-05-10 22:18:112148 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView())
2149 set.insert(rwhv);
[email protected]948481d2014-06-11 18:32:222150 } else {
dchengafb53e22016-02-04 08:11:082151 for (RenderFrameHost* rfh : GetAllFrames()) {
lfgf949e0e2017-05-10 22:18:112152 if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
2153 ->frame_tree_node()
2154 ->render_manager()
2155 ->GetRenderWidgetHostView()) {
2156 set.insert(rwhv);
2157 }
dchengafb53e22016-02-04 08:11:082158 }
[email protected]948481d2014-06-11 18:32:222159 }
[email protected]de3c5d82014-05-28 22:12:592160 return set;
2161}
2162
[email protected]b172aee2012-04-10 17:05:262163void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:342164 if (delegate_)
2165 delegate_->ActivateContents(this);
2166}
2167
avi3e4b8512015-11-11 01:55:492168void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
2169 if (!RenderViewHostImpl::From(render_widget_host))
2170 return;
2171
[email protected]63954792011-07-11 04:17:482172 if (delegate_)
2173 delegate_->LostCapture();
2174}
2175
Steven Holte38041342018-06-22 22:00:572176ukm::SourceId WebContentsImpl::GetUkmSourceIdForLastCommittedSource() const {
2177 return last_committed_source_id_;
2178}
2179
lazyboy63f5b312015-11-23 20:19:522180void WebContentsImpl::RenderWidgetCreated(
2181 RenderWidgetHostImpl* render_widget_host) {
2182 created_widgets_.insert(render_widget_host);
2183}
2184
[email protected]b24b68a2012-09-24 21:57:262185void WebContentsImpl::RenderWidgetDeleted(
2186 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:522187 // Note that |is_being_destroyed_| can be true at this point as
2188 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
2189 // us here.
2190 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262191
lazyboy63f5b312015-11-23 20:19:522192 if (is_being_destroyed_)
2193 return;
[email protected]44470a22013-01-24 01:21:542194
2195 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:372196 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
2197 render_widget_host->GetProcess()->GetID() ==
2198 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:492199 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:532200 delegate_->ExitFullscreenModeForTab(this);
ericwilligersde386342016-10-19 02:35:092201 for (auto& observer : observers_)
2202 observer.DidDestroyFullscreenWidget();
alexmosc9e76ec2016-05-16 22:59:372203 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:542204 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:032205 if (fullscreen_widget_had_focus_at_shutdown_)
2206 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:542207 }
lfgbee1e0a2016-06-08 21:24:212208
lfg7d4caad2017-03-22 09:01:452209 if (render_widget_host == mouse_lock_widget_)
lfgff8dfc8d2016-10-21 17:42:322210 LostMouseLock(mouse_lock_widget_);
Joe Downing192998b22018-03-22 15:51:362211
Joe Downingc1a57efe2018-05-09 18:23:542212 CancelKeyboardLock(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262213}
2214
miu9e14e492014-10-25 02:39:042215void WebContentsImpl::RenderWidgetGotFocus(
2216 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:372217 // Notify the observers if an embedded fullscreen widget was focused.
2218 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2219 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
Michael Thiessen896405db2017-07-20 17:52:322220 NotifyWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:372221 }
miu9e14e492014-10-25 02:39:042222}
2223
zijiehe3bee08e22017-05-17 04:14:462224void WebContentsImpl::RenderWidgetLostFocus(
2225 RenderWidgetHostImpl* render_widget_host) {
Michael Thiessen896405db2017-07-20 17:52:322226 // Notify the observers if an embedded fullscreen widget lost focus.
2227 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2228 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
2229 NotifyWebContentsLostFocus(render_widget_host);
2230 }
zijiehe3bee08e22017-05-17 04:14:462231}
2232
estaded0a0c992015-01-21 14:12:062233void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:312234 RenderWidgetHostImpl* render_widget_host,
Christopher Cameron07f666b2018-02-13 23:41:192235 const ScreenInfo& screen_info,
rouslan2f5993f2015-01-29 00:18:312236 bool width_changed) {
creisc014b402015-04-23 16:41:452237 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:292238 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:062239 return;
estaded0a0c992015-01-21 14:12:062240
lfg8d649cc2017-04-28 18:04:302241 SendPageMessage(new PageMsg_UpdateScreenInfo(MSG_ROUTING_NONE, screen_info));
2242
ericwilligersde386342016-10-19 02:35:092243 for (auto& observer : observers_)
2244 observer.MainFrameWasResized(width_changed);
estaded0a0c992015-01-21 14:12:062245}
2246
skyf65d9bb2017-03-24 02:26:392247KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(
2248 const NativeWebKeyboardEvent& event) {
2249 return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event)
2250 : KeyboardEventProcessingResult::NOT_HANDLED;
[email protected]63954792011-07-11 04:17:482251}
2252
[email protected]b172aee2012-04-10 17:05:262253void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:102254 if (browser_plugin_embedder_ &&
2255 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
2256 return;
2257 }
[email protected]63954792011-07-11 04:17:482258 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132259 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:482260}
2261
[email protected]d92026ef2014-03-03 21:04:132262bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:462263 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:192264#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:332265 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
2266 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:192267 // -the OS already has a gesture to do this through pinch-zoom
2268 // -if a user starts an inertial scroll, let's go, and presses control
2269 // (i.e. control+tab) then the OS's buffered scroll events will come in
2270 // with control key set which isn't what the user wants
Blink Reformat1c4d759e2017-04-09 16:34:542271 if (delegate_ && event.wheel_ticks_y &&
chongz4a9751942016-08-17 17:49:392272 !ui::WebInputEventTraits::CanCauseScroll(event)) {
w.shackleton49bcd392016-01-06 17:38:222273 // Count only integer cumulative scrolls as zoom events; this handles
2274 // smooth scroll and regular scroll device behavior.
Blink Reformat1c4d759e2017-04-09 16:34:542275 zoom_scroll_remainder_ += event.wheel_ticks_y;
w.shackleton49bcd392016-01-06 17:38:222276 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
2277 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
2278 if (whole_zoom_scroll_remainder_ != 0) {
2279 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
2280 }
[email protected]fb3f066e2013-02-12 19:12:522281 return true;
2282 }
[email protected]bccc4472013-04-18 16:37:192283#endif
[email protected]fb3f066e2013-02-12 19:12:522284 return false;
2285}
2286
[email protected]04bce562014-01-30 05:34:542287bool WebContentsImpl::PreHandleGestureEvent(
2288 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:032289 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:542290}
2291
kenrb2a565f82015-09-02 20:24:592292RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:452293 if (!is_being_destroyed_ && GetOuterWebContents())
2294 return GetOuterWebContents()->GetInputEventRouter();
2295
2296 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:592297 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
2298 return rwh_input_event_router_.get();
2299}
2300
alexmos3fcd0ca2015-10-23 18:18:332301void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
2302 // Focus loss may occur while this WebContents is being destroyed. Don't
2303 // send the message in this case, as the main frame's RenderFrameHost and
2304 // other state has already been cleared.
2305 if (is_being_destroyed_)
2306 return;
2307
2308 frame_tree_.ReplicatePageFocus(is_focused);
2309}
2310
alexmosc4cbacb2015-11-21 01:29:222311RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
2312 RenderWidgetHostImpl* receiving_widget) {
alexmosc4cbacb2015-11-21 01:29:222313 // Events for widgets other than the main frame (e.g., popup menus) should be
2314 // forwarded directly to the widget they arrived on.
2315 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
2316 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522317
lfg1453e412017-04-11 00:48:502318 WebContentsImpl* focused_contents = GetFocusedWebContents();
2319
2320 // If the focused WebContents is showing an interstitial, return the
2321 // interstitial's widget.
2322 if (focused_contents->ShowingInterstitialPage()) {
2323 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112324 focused_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502325 ->GetRenderWidgetHost();
2326 }
2327
paulmeyerfeafc2d2017-04-25 21:46:402328 // If the focused WebContents is a guest WebContents, then get the focused
2329 // frame in the embedder WebContents instead.
2330 FrameTreeNode* focused_frame = nullptr;
2331 if (focused_contents->browser_plugin_guest_ &&
2332 !GuestMode::IsCrossProcessFrameGuest(focused_contents)) {
2333 focused_frame = frame_tree_.GetFocusedFrame();
2334 } else {
2335 focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
2336 }
lfg1453e412017-04-11 00:48:502337
alexmosc4d183e2015-11-06 00:46:522338 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:222339 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522340
alexmos732ca3a2015-12-08 02:01:022341 // The view may be null if a subframe's renderer process has crashed while
2342 // the subframe has focus. Drop the event in that case. Do not give
2343 // it to the main frame, so that the user doesn't unexpectedly type into the
2344 // wrong frame if a focused subframe renderer crashes while they type.
2345 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
2346 if (!view)
2347 return nullptr;
2348
2349 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:522350}
2351
avallee9993fca2016-11-17 06:16:502352RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
lfg1453e412017-04-11 00:48:502353 WebContentsImpl* focused_web_contents = GetFocusedWebContents();
2354
2355 if (focused_web_contents->ShowingInterstitialPage()) {
2356 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112357 focused_web_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502358 ->GetRenderWidgetHost();
2359 }
Alex Valléedc80ae2ed2017-09-06 21:55:442360 if (!GuestMode::IsCrossProcessFrameGuest(focused_web_contents) &&
2361 focused_web_contents->browser_plugin_guest_) {
2362 // If this is a guest, we need to be controlled by our embedder.
2363 return focused_web_contents->GetOuterWebContents()
2364 ->GetMainFrame()
2365 ->GetRenderWidgetHost();
2366 }
lfg1453e412017-04-11 00:48:502367
2368 return focused_web_contents->GetMainFrame()->GetRenderWidgetHost();
avallee9993fca2016-11-17 06:16:502369}
2370
Dave Tapuska3ed44192018-05-01 18:53:302371void WebContentsImpl::EnterFullscreenMode(
2372 const GURL& origin,
2373 const blink::WebFullscreenOptions& options) {
mlamouri7a78d6fd2015-01-17 13:23:532374 // This method is being called to enter renderer-initiated fullscreen mode.
2375 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:492376 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372377 if (widget_view) {
2378 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2379 ->ShutdownAndDestroyWidget(true);
2380 }
[email protected]4aebbca2013-09-17 22:26:492381
Joe Downing13dd76b2018-04-09 18:32:152382 if (delegate_) {
Dave Tapuska3ed44192018-05-01 18:53:302383 delegate_->EnterFullscreenModeForTab(this, origin, options);
mlamouri7a78d6fd2015-01-17 13:23:532384
Joe Downing13dd76b2018-04-09 18:32:152385 if (keyboard_lock_widget_)
2386 delegate_->RequestKeyboardLock(this, esc_key_locked_);
2387 }
2388
ericwilligersde386342016-10-19 02:35:092389 for (auto& observer : observers_)
2390 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false);
mlamouri7a78d6fd2015-01-17 13:23:532391}
2392
bokanece34a82016-01-28 19:49:462393void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532394 // This method is being called to leave renderer-initiated fullscreen mode.
2395 // Make sure any existing fullscreen widget is shut down first.
2396 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372397 if (widget_view) {
2398 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2399 ->ShutdownAndDestroyWidget(true);
2400 }
mlamouri7a78d6fd2015-01-17 13:23:532401
hugo.holgersson61288e6c2015-01-28 17:04:402402#if defined(OS_ANDROID)
2403 ContentVideoView* video_view = ContentVideoView::GetInstance();
2404 if (video_view != NULL)
watk98292292016-01-19 22:24:082405 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:402406#endif
2407
Joe Downing13dd76b2018-04-09 18:32:152408 if (delegate_) {
mlamouri7a78d6fd2015-01-17 13:23:532409 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:372410
Joe Downing13dd76b2018-04-09 18:32:152411 if (keyboard_lock_widget_)
2412 delegate_->CancelKeyboardLockRequest(this);
2413 }
2414
bokanece34a82016-01-28 19:49:462415 // The fullscreen state is communicated to the renderer through a resize
2416 // message. If the change in fullscreen state doesn't cause a view resize
2417 // then we must ensure web contents exit the fullscreen state by explicitly
2418 // sending a resize message. This is required for the situation of the browser
2419 // moving the view into a "browser fullscreen" state and then the contents
2420 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
2421 // have the side effect of the view resizing, hence the explicit call here is
2422 // required.
2423 if (!will_cause_resize) {
2424 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
2425 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:162426 render_widget_host->SynchronizeVisualProperties();
bokanece34a82016-01-28 19:49:462427 }
scheib3dcb6c932015-02-23 10:55:582428 }
2429
Becca Hughese9e27952018-06-25 17:08:272430 // Clear the current fullscreen frame ID.
2431 current_fullscreen_frame_tree_node_id_ = RenderFrameHost::kNoFrameTreeNodeId;
2432
ericwilligersde386342016-10-19 02:35:092433 for (auto& observer : observers_) {
2434 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
2435 will_cause_resize);
2436 }
[email protected]8a5e0ca2011-08-25 06:30:472437}
2438
Becca Hughesfd5d8f892018-06-14 18:23:362439void WebContentsImpl::FullscreenStateChanged(RenderFrameHost* rfh,
2440 bool is_fullscreen) {
2441 int frame_tree_node_id = rfh->GetFrameTreeNodeId();
2442 auto it = fullscreen_frame_tree_nodes_.find(frame_tree_node_id);
2443 bool changed = false;
2444
2445 if (is_fullscreen) {
2446 // If we are fullscreen then add the FrameTreeNode ID to the set.
2447 if (it == fullscreen_frame_tree_nodes_.end()) {
2448 fullscreen_frame_tree_nodes_.insert(frame_tree_node_id);
2449 changed = true;
2450 }
2451 } else {
2452 FrameTreeNode* ancestor =
2453 static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node();
2454 DCHECK(ancestor);
2455
2456 // If we are not fullscreen then remove this frame and any descendants
2457 // from the set.
2458 for (it = fullscreen_frame_tree_nodes_.begin();
2459 it != fullscreen_frame_tree_nodes_.end();) {
2460 FrameTreeNode* node = FrameTreeNode::GloballyFindByID(*it);
2461
2462 if (!node || frame_tree_node_id == *it ||
2463 node->IsDescendantOf(ancestor)) {
2464 it = fullscreen_frame_tree_nodes_.erase(it);
2465 changed = true;
2466 } else {
2467 ++it;
2468 }
2469 }
2470 }
2471
2472 // If we have changed then find the current fullscreen FrameTreeNode
2473 // and call the observers. If we have exited fullscreen then this
2474 // will be the last frame that was fullscreen.
2475 if (changed && fullscreen_frame_tree_nodes_.size() > 0) {
2476 unsigned int max_depth = 0;
2477 RenderFrameHost* max_depth_rfh = nullptr;
2478
2479 for (auto node_id : fullscreen_frame_tree_nodes_) {
2480 FrameTreeNode* fullscreen_node = FrameTreeNode::GloballyFindByID(node_id);
2481 DCHECK(fullscreen_node);
2482
2483 if (max_depth_rfh == nullptr || fullscreen_node->depth() > max_depth) {
2484 max_depth = fullscreen_node->depth();
2485 max_depth_rfh = fullscreen_node->current_frame_host();
2486 }
2487 }
2488
2489 // If we have already notified observers about this frame then we should not
2490 // fire the observers again.
2491 DCHECK(max_depth_rfh);
2492 if (max_depth_rfh->GetFrameTreeNodeId() ==
2493 current_fullscreen_frame_tree_node_id_)
2494 return;
2495
2496 current_fullscreen_frame_tree_node_id_ =
2497 max_depth_rfh->GetFrameTreeNodeId();
2498
2499 for (auto& observer : observers_)
2500 observer.DidAcquireFullscreen(max_depth_rfh);
2501 } else if (fullscreen_frame_tree_nodes_.size() == 0) {
2502 current_fullscreen_frame_tree_node_id_ =
2503 RenderFrameHost::kNoFrameTreeNodeId;
2504 }
2505}
2506
alexmos5dd617d2016-06-07 04:21:152507bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:382508 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:122509}
2510
billorr21c005d2016-11-17 03:57:042511bool WebContentsImpl::IsFullscreen() {
2512 return IsFullscreenForCurrentTab();
2513}
2514
avibf58fa0c2015-11-11 01:45:522515blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
2516 RenderWidgetHostImpl* render_widget_host) const {
2517 if (!RenderViewHostImpl::From(render_widget_host))
Blink Reformat1c4d759e2017-04-09 16:34:542518 return blink::kWebDisplayModeBrowser;
avibf58fa0c2015-11-11 01:45:522519
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122520 return delegate_ ? delegate_->GetDisplayMode(this)
Blink Reformat1c4d759e2017-04-09 16:34:542521 : blink::kWebDisplayModeBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122522}
2523
avic3aa8422015-11-09 20:57:222524void WebContentsImpl::RequestToLockMouse(
2525 RenderWidgetHostImpl* render_widget_host,
2526 bool user_gesture,
lfgad8244352016-07-13 16:55:512527 bool last_unlocked_by_target,
2528 bool privileged) {
lfgf0cd46e2017-01-04 00:05:232529 for (WebContentsImpl* current = this; current;
2530 current = current->GetOuterWebContents()) {
2531 if (current->mouse_lock_widget_) {
2532 render_widget_host->GotResponseToLockMouseRequest(false);
2533 return;
2534 }
[email protected]e9621112011-10-17 05:38:372535 }
avic3aa8422015-11-09 20:57:222536
lfgad8244352016-07-13 16:55:512537 if (privileged) {
lfgf0cd46e2017-01-04 00:05:232538 DCHECK(!GetOuterWebContents());
lfgad8244352016-07-13 16:55:512539 mouse_lock_widget_ = render_widget_host;
2540 render_widget_host->GotResponseToLockMouseRequest(true);
2541 return;
2542 }
2543
lfgbee1e0a2016-06-08 21:24:212544 bool widget_in_frame_tree = false;
2545 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2546 if (node->current_frame_host()->GetRenderWidgetHost() ==
2547 render_widget_host) {
2548 widget_in_frame_tree = true;
2549 break;
2550 }
2551 }
2552
2553 if (widget_in_frame_tree && delegate_) {
lfgf0cd46e2017-01-04 00:05:232554 for (WebContentsImpl* current = this; current;
2555 current = current->GetOuterWebContents()) {
2556 current->mouse_lock_widget_ = render_widget_host;
2557 }
2558
avic3aa8422015-11-09 20:57:222559 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:212560 } else {
2561 render_widget_host->GotResponseToLockMouseRequest(false);
2562 }
[email protected]e9621112011-10-17 05:38:372563}
2564
avi3e4b8512015-11-11 01:55:492565void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:212566 CHECK(mouse_lock_widget_);
lfgf0cd46e2017-01-04 00:05:232567
2568 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this)
2569 return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host);
2570
lfgbee1e0a2016-06-08 21:24:212571 mouse_lock_widget_->SendMouseLockLost();
lfgf0cd46e2017-01-04 00:05:232572 for (WebContentsImpl* current = this; current;
2573 current = current->GetOuterWebContents()) {
2574 current->mouse_lock_widget_ = nullptr;
2575 }
avi3e4b8512015-11-11 01:55:492576
[email protected]e9621112011-10-17 05:38:372577 if (delegate_)
2578 delegate_->LostMouseLock();
2579}
2580
lfgad8244352016-07-13 16:55:512581bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
2582 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
2583 // assigned to the widget that requested the mouse lock, and the top-level
2584 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
2585 return mouse_lock_widget_ == render_widget_host &&
2586 GetTopLevelRenderWidgetHostView()->IsMouseLocked();
2587}
2588
lfg84763c92017-02-16 18:55:152589RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() {
lfge2176fb2017-03-26 00:45:472590 if (GetTopLevelRenderWidgetHostView()->IsMouseLocked() ||
2591 (GetFullscreenRenderWidgetHostView() &&
2592 GetFullscreenRenderWidgetHostView()->IsMouseLocked()))
lfg84763c92017-02-16 18:55:152593 return mouse_lock_widget_;
2594
2595 return nullptr;
2596}
2597
Joe Downing192998b22018-03-22 15:51:362598bool WebContentsImpl::RequestKeyboardLock(
Joe Downing13dd76b2018-04-09 18:32:152599 RenderWidgetHostImpl* render_widget_host,
2600 bool esc_key_locked) {
Joe Downing192998b22018-03-22 15:51:362601 DCHECK(render_widget_host);
Joe Downing192998b22018-03-22 15:51:362602 if (render_widget_host->delegate()->GetAsWebContents() != this) {
2603 NOTREACHED();
2604 return false;
2605 }
2606
2607 // KeyboardLock is only supported when called by the top-level browsing
2608 // context and is not supported in embedded content scenarios.
2609 if (GetOuterWebContents())
2610 return false;
2611
Joe Downing13dd76b2018-04-09 18:32:152612 esc_key_locked_ = esc_key_locked;
Joe Downing192998b22018-03-22 15:51:362613 keyboard_lock_widget_ = render_widget_host;
2614
Joe Downing13dd76b2018-04-09 18:32:152615 if (delegate_)
2616 delegate_->RequestKeyboardLock(this, esc_key_locked_);
Joe Downing192998b22018-03-22 15:51:362617 return true;
2618}
2619
2620void WebContentsImpl::CancelKeyboardLock(
2621 RenderWidgetHostImpl* render_widget_host) {
2622 if (!keyboard_lock_widget_ || render_widget_host != keyboard_lock_widget_)
2623 return;
2624
2625 RenderWidgetHostImpl* old_keyboard_lock_widget = keyboard_lock_widget_;
2626 keyboard_lock_widget_ = nullptr;
2627
Joe Downing13dd76b2018-04-09 18:32:152628 if (delegate_)
2629 delegate_->CancelKeyboardLockRequest(this);
2630
Joe Downing192998b22018-03-22 15:51:362631 old_keyboard_lock_widget->CancelKeyboardLock();
2632}
2633
2634RenderWidgetHostImpl* WebContentsImpl::GetKeyboardLockWidget() {
2635 return keyboard_lock_widget_;
2636}
2637
ekaramada4f42692016-02-11 19:48:372638void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
lfg9462cef2016-07-18 23:51:062639 if (visible && !GetOuterWebContents()->IsHidden())
ekaramada4f42692016-02-11 19:48:372640 WasShown();
lfg9462cef2016-07-18 23:51:062641 else if (!visible)
ekaramada4f42692016-02-11 19:48:372642 WasHidden();
2643}
2644
[email protected]bafe6cd2012-05-23 23:09:502645void WebContentsImpl::CreateNewWindow(
csharrison95f01e922017-04-24 18:52:352646 RenderFrameHost* opener,
nick5ae4d2d2017-01-06 01:18:352647 int32_t render_view_route_id,
dcheng3ce04b62015-10-26 23:30:552648 int32_t main_frame_route_id,
2649 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:182650 const mojom::CreateNewWindowParams& params,
[email protected]97714c82012-06-06 10:15:132651 SessionStorageNamespace* session_storage_namespace) {
nick5ae4d2d2017-01-06 01:18:352652 // We should have zero valid routing ids, or three valid routing IDs.
2653 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2654 (main_frame_route_id == MSG_ROUTING_NONE));
2655 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2656 (main_frame_widget_route_id == MSG_ROUTING_NONE));
csharrison95f01e922017-04-24 18:52:352657 DCHECK(opener);
nick5ae4d2d2017-01-06 01:18:352658
csharrison95f01e922017-04-24 18:52:352659 int render_process_id = opener->GetProcess()->GetID();
2660 SiteInstance* source_site_instance = opener->GetSiteInstance();
2661
2662 // The route IDs passed into this function can be trusted not to already
2663 // be in use; they were allocated by the RenderWidgetHelper by the caller.
nick5ae4d2d2017-01-06 01:18:352664 DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id));
2665
[email protected]bafe6cd2012-05-23 23:09:502666 // We usually create the new window in the same BrowsingInstance (group of
2667 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:552668 // if the opener is being suppressed (in a non-guest), we create a new
2669 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:252670 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:552671
[email protected]04cbd3d2013-12-04 04:58:202672 // If the opener is to be suppressed, the new window can be in any process.
2673 // Since routing ids are process specific, we must not have one passed in
2674 // as argument here.
nick5ae4d2d2017-01-06 01:18:352675 DCHECK(!params.opener_suppressed || render_view_route_id == MSG_ROUTING_NONE);
[email protected]04cbd3d2013-12-04 04:58:202676
[email protected]bafe6cd2012-05-23 23:09:502677 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:432678 params.opener_suppressed && !is_guest
2679 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
2680 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:502681
[email protected]d1198fd2012-08-13 22:50:192682 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:342683 //
2684 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:302685 const std::string& partition_id =
2686 GetContentClient()->browser()->
2687 GetStoragePartitionIdForSite(GetBrowserContext(),
2688 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:462689 StoragePartition* partition = BrowserContext::GetStoragePartition(
2690 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:412691 DOMStorageContextWrapper* dom_storage_context =
2692 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:192693 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2694 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2695 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:372696
2697 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:552698 !delegate_->ShouldCreateWebContents(
lukasza6f8ac622017-06-06 03:10:202699 this, opener, source_site_instance, render_view_route_id,
2700 main_frame_route_id, main_frame_widget_route_id,
2701 params.window_container_type, opener->GetLastCommittedURL(),
2702 params.frame_name, params.target_url, partition_id,
2703 session_storage_namespace)) {
jambaaab3a2016-11-05 00:46:182704 // Note: even though we're not creating a WebContents here, it could have
2705 // been created by the embedder so ensure that the RenderFrameHost is
2706 // properly initialized.
csharrisona2280cd2016-02-03 23:21:152707 // It's safe to only target the frame because the render process will not
2708 // have a chance to create more frames at this point.
jambaaab3a2016-11-05 00:46:182709 RenderFrameHostImpl* rfh =
2710 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id);
nick5ae4d2d2017-01-06 01:18:352711 if (rfh) {
2712 DCHECK(rfh->IsRenderFrameLive());
jambaaab3a2016-11-05 00:46:182713 rfh->Init();
nick5ae4d2d2017-01-06 01:18:352714 }
[email protected]dd6730412013-08-14 15:03:372715 return;
2716 }
2717
2718 // Create the new web contents. This will automatically create the new
2719 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462720 CreateParams create_params(GetBrowserContext(), site_instance.get());
nick5ae4d2d2017-01-06 01:18:352721 create_params.routing_id = render_view_route_id;
[email protected]227692c52013-05-31 22:43:042722 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:552723 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:122724 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432725 create_params.opener_render_process_id = render_process_id;
csharrison95f01e922017-04-24 18:52:352726 create_params.opener_render_frame_id = opener->GetRoutingID();
[email protected]50d326e2014-05-20 17:59:062727 create_params.opener_suppressed = params.opener_suppressed;
nick3b04f322016-08-31 19:29:192728 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
[email protected]50d326e2014-05-20 17:59:062729 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:192730 create_params.renderer_initiated_creation =
2731 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:062732
erikchenbee5c9622018-04-27 19:30:252733 std::unique_ptr<WebContents> new_contents;
[email protected]c4538072013-03-18 02:17:552734 if (!is_guest) {
2735 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:452736 create_params.initial_size = GetContainerBounds().size();
Erik Chenbb8e738e2018-04-28 14:10:432737 new_contents = WebContents::Create(create_params);
[email protected]4858e432014-06-23 18:14:172738 } else {
erikchenbee5c9622018-04-27 19:30:252739 new_contents = base::WrapUnique(
2740 GetBrowserPluginGuest()->CreateNewGuestWindow(create_params));
[email protected]c4538072013-03-18 02:17:552741 }
erikchenbee5c9622018-04-27 19:30:252742 WebContentsImpl* raw_new_contents =
2743 static_cast<WebContentsImpl*>(new_contents.get());
2744 raw_new_contents->GetController().SetSessionStorageNamespace(
2745 partition_id, session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192746
alexmos646fec02015-07-25 00:11:492747 // If the new frame has a name, make sure any SiteInstances that can find
2748 // this named frame have proxies for it. Must be called after
2749 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2750 // GetSessionStorageNamespace.
2751 if (!params.frame_name.empty())
erikchenbee5c9622018-04-27 19:30:252752 raw_new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
alexmos646fec02015-07-25 00:11:492753
[email protected]c4538072013-03-18 02:17:552754 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342755 // will be shown immediately).
2756 if (!params.opener_suppressed) {
2757 if (!is_guest) {
erikchenbee5c9622018-04-27 19:30:252758 WebContentsView* new_view = raw_new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502759
[email protected]d70bea92013-04-05 04:23:342760 // TODO(brettw): It seems bogus that we have to call this function on the
2761 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:432762 new_view->CreateViewForWidget(
2763 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:342764 }
[email protected]bafe6cd2012-05-23 23:09:502765 // Save the created window associated with the route so we can show it
2766 // later.
Albert J. Wongcb004632018-07-10 22:58:252767 //
2768 // TODO(ajwong): This should be keyed off the RenderFrame routing id or the
2769 // FrameTreeNode id instead of the routing id of the Widget for the main
2770 // frame. https://crbug.com/545684
nick5ae4d2d2017-01-06 01:18:352771 DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id);
erikchenbee5c9622018-04-27 19:30:252772 pending_contents_[std::make_pair(render_process_id,
2773 main_frame_widget_route_id)] =
2774 std::move(new_contents);
2775 AddDestructionObserver(raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502776 }
2777
2778 if (delegate_) {
Bryan McQuaded2b93c02017-07-14 22:26:312779 delegate_->WebContentsCreated(this, render_process_id,
2780 opener->GetRoutingID(), params.frame_name,
erikchenbee5c9622018-04-27 19:30:252781 params.target_url, raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502782 }
2783
csharrison95f01e922017-04-24 18:52:352784 if (opener) {
pnolandaae574e2017-03-06 21:04:212785 for (auto& observer : observers_) {
erikchenbee5c9622018-04-27 19:30:252786 observer.DidOpenRequestedURL(raw_new_contents, opener, params.target_url,
csharrison95f01e922017-04-24 18:52:352787 params.referrer, params.disposition,
2788 ui::PAGE_TRANSITION_LINK,
pnolandaae574e2017-03-06 21:04:212789 false, // started_from_context_menu
2790 true); // renderer_initiated
2791 }
2792 }
2793
Avi Drissmanba3b1b342017-08-29 18:16:132794 // Any new WebContents opened while this WebContents is in fullscreen can be
2795 // used to confuse the user, so drop fullscreen.
2796 if (IsFullscreenForCurrentTab())
2797 ExitFullscreen(true);
2798
[email protected]bafe6cd2012-05-23 23:09:502799 if (params.opener_suppressed) {
2800 // When the opener is suppressed, the original renderer cannot access the
2801 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002802 bool was_blocked = false;
erikchenbee5c9622018-04-27 19:30:252803
2804 base::WeakPtr<WebContentsImpl> weak_new_contents =
2805 raw_new_contents->weak_factory_.GetWeakPtr();
[email protected]eda238a12012-09-07 23:44:002806 if (delegate_) {
bokan107a47f2015-02-03 23:23:392807 gfx::Rect initial_rect;
nick0d558482017-02-13 22:27:222808
erikchenbee5c9622018-04-27 19:30:252809 delegate_->AddNewContents(this, std::move(new_contents),
2810 params.disposition, initial_rect,
Mustaq Ahmedc4cb7162018-06-05 16:28:362811 params.mimic_user_gesture, &was_blocked);
nick0d558482017-02-13 22:27:222812 if (!weak_new_contents)
2813 return; // The delegate deleted |new_contents| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002814 }
erikchenbee5c9622018-04-27 19:30:252815
[email protected]eda238a12012-09-07 23:44:002816 if (!was_blocked) {
nick3b04f322016-08-31 19:29:192817 OpenURLParams open_params(params.target_url, params.referrer,
2818 WindowOpenDisposition::CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352819 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212820 true /* is_renderer_initiated */);
Mustaq Ahmedc4cb7162018-06-05 16:28:362821 open_params.user_gesture = params.mimic_user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372822
2823 if (delegate_ && !is_guest &&
2824 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
erikchenbee5c9622018-04-27 19:30:252825 DCHECK(weak_new_contents);
mariakhomenkoa4971c12015-07-21 19:04:372826 // We are in asynchronous add new contents path, delay opening url
erikchenbee5c9622018-04-27 19:30:252827 weak_new_contents->delayed_open_url_params_.reset(
mariakhomenkoa4971c12015-07-21 19:04:372828 new OpenURLParams(open_params));
2829 } else {
erikchenbee5c9622018-04-27 19:30:252830 weak_new_contents->OpenURL(open_params);
mariakhomenkoa4971c12015-07-21 19:04:372831 }
[email protected]eda238a12012-09-07 23:44:002832 }
[email protected]bafe6cd2012-05-23 23:09:502833 }
2834}
2835
avib7348942015-12-25 20:57:102836void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2837 int32_t route_id,
Dave Tapuska1bdf1832017-07-07 18:07:192838 mojom::WidgetPtr widget,
[email protected]180ef242013-11-07 06:50:462839 blink::WebPopupType popup_type) {
Dave Tapuska1bdf1832017-07-07 18:07:192840 CreateNewWidget(render_process_id, route_id, false, std::move(widget),
2841 popup_type);
[email protected]bafe6cd2012-05-23 23:09:502842}
2843
avib7348942015-12-25 20:57:102844void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
Dave Tapuska1bdf1832017-07-07 18:07:192845 int32_t route_id,
2846 mojom::WidgetPtr widget) {
2847 CreateNewWidget(render_process_id, route_id, true, std::move(widget),
2848 blink::kWebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502849}
2850
avib7348942015-12-25 20:57:102851void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2852 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502853 bool is_fullscreen,
Dave Tapuska1bdf1832017-07-07 18:07:192854 mojom::WidgetPtr widget,
[email protected]180ef242013-11-07 06:50:462855 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252856 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232857 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512858 // this WebContentsImpl instance. If any other process sends the request,
2859 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382860 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
Lukasz Anforowicz6f746282018-01-04 23:24:512861 ReceivedBadMessage(process, bad_message::WCI_NEW_WIDGET_PROCESS_MISMATCH);
[email protected]a8504022013-12-04 20:23:512862 return;
2863 }
2864
Dave Tapuska485aca92017-08-08 00:47:582865 RenderWidgetHostImpl* widget_host = new RenderWidgetHostImpl(
2866 this, process, route_id, std::move(widget), IsHidden());
[email protected]b24b68a2012-09-24 21:57:262867
[email protected]cfd80b02014-05-01 17:46:482868 RenderWidgetHostViewBase* widget_view =
2869 static_cast<RenderWidgetHostViewBase*>(
2870 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192871 if (!widget_view)
2872 return;
[email protected]bafe6cd2012-05-23 23:09:502873 if (!is_fullscreen) {
2874 // Popups should not get activated.
2875 widget_view->SetPopupType(popup_type);
2876 }
2877 // Save the created widget associated with the route so we can show it later.
alexmosc2a8cec2016-05-23 22:19:532878 pending_widget_views_[std::make_pair(render_process_id, route_id)] =
2879 widget_view;
[email protected]bafe6cd2012-05-23 23:09:502880}
2881
alexmosc2a8cec2016-05-23 22:19:532882void WebContentsImpl::ShowCreatedWindow(int process_id,
nick5ae4d2d2017-01-06 01:18:352883 int main_frame_widget_route_id,
[email protected]bafe6cd2012-05-23 23:09:502884 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392885 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502886 bool user_gesture) {
erikchenbee5c9622018-04-27 19:30:252887 std::unique_ptr<WebContents> popup =
nick5ae4d2d2017-01-06 01:18:352888 GetCreatedWindow(process_id, main_frame_widget_route_id);
nick0d558482017-02-13 22:27:222889 if (popup) {
erikchenbee5c9622018-04-27 19:30:252890 WebContentsImpl* raw_popup = static_cast<WebContentsImpl*>(popup.get());
[email protected]eda238a12012-09-07 23:44:002891 WebContentsDelegate* delegate = GetDelegate();
erikchenbee5c9622018-04-27 19:30:252892 raw_popup->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382893 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
erikchenbee5c9622018-04-27 19:30:252894 raw_popup->ResumeLoadingCreatedWebContents();
mariakhomenko44bdc4732015-04-29 01:55:382895
erikchenbee5c9622018-04-27 19:30:252896 base::WeakPtr<WebContentsImpl> weak_popup =
2897 raw_popup->weak_factory_.GetWeakPtr();
[email protected]eda238a12012-09-07 23:44:002898 if (delegate) {
erikchenbee5c9622018-04-27 19:30:252899 delegate->AddNewContents(this, std::move(popup), disposition,
2900 initial_rect, user_gesture, nullptr);
nick0d558482017-02-13 22:27:222901 if (!weak_popup)
2902 return; // The delegate deleted |popup| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002903 }
nick5ae4d2d2017-01-06 01:18:352904
erikchenbee5c9622018-04-27 19:30:252905 RenderWidgetHostImpl* rwh =
2906 weak_popup->GetMainFrame()->GetRenderWidgetHost();
nick0d558482017-02-13 22:27:222907 DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID());
Avi Drissman014dec72018-06-07 02:34:012908 rwh->Send(new ViewMsg_SetBounds_ACK(rwh->GetRoutingID()));
[email protected]eda238a12012-09-07 23:44:002909 }
[email protected]bafe6cd2012-05-23 23:09:502910}
2911
alexmosc2a8cec2016-05-23 22:19:532912void WebContentsImpl::ShowCreatedWidget(int process_id,
2913 int route_id,
bokan107a47f2015-02-03 23:23:392914 const gfx::Rect& initial_rect) {
alexmosc2a8cec2016-05-23 22:19:532915 ShowCreatedWidget(process_id, route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502916}
2917
alexmosc2a8cec2016-05-23 22:19:532918void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
2919 int route_id) {
2920 ShowCreatedWidget(process_id, route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:502921}
2922
alexmosc2a8cec2016-05-23 22:19:532923void WebContentsImpl::ShowCreatedWidget(int process_id,
2924 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502925 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392926 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482927 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:532928 static_cast<RenderWidgetHostViewBase*>(
2929 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502930 if (!widget_host_view)
2931 return;
[email protected]cfd80b02014-05-01 17:46:482932
Ivan Kotenkov2c0d2bb32017-11-01 15:41:282933 RenderWidgetHostView* view = nullptr;
lfgc740d4b22016-04-15 16:45:332934 if (GetOuterWebContents()) {
2935 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482936 } else {
2937 view = GetRenderWidgetHostView();
2938 }
2939
[email protected]4aebbca2013-09-17 22:26:492940 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312941 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032942 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:372943 fullscreen_widget_process_id_ =
2944 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:312945 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492946 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2947 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
Dave Tapuska3ed44192018-05-01 18:53:302948 delegate_->EnterFullscreenModeForTab(this, GURL(),
2949 blink::WebFullscreenOptions());
[email protected]4aebbca2013-09-17 22:26:492950 } else {
[email protected]cfd80b02014-05-01 17:46:482951 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492952 }
ericwilligersde386342016-10-19 02:35:092953 for (auto& observer : observers_)
2954 observer.DidShowFullscreenWidget();
[email protected]4aebbca2013-09-17 22:26:492955 if (!widget_host_view->HasFocus())
2956 widget_host_view->Focus();
2957 } else {
bokan107a47f2015-02-03 23:23:392958 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492959 }
[email protected]89054502012-06-03 10:29:242960
yiyixcb1fbc4f2018-03-16 19:54:082961 RenderWidgetHostImpl* render_widget_host_impl = widget_host_view->host();
[email protected]89054502012-06-03 10:29:242962 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312963 // Only allow privileged mouse lock for fullscreen render widget, which is
2964 // used to implement Pepper Flash fullscreen.
2965 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502966}
2967
erikchenbee5c9622018-04-27 19:30:252968std::unique_ptr<WebContents> WebContentsImpl::GetCreatedWindow(
nick5ae4d2d2017-01-06 01:18:352969 int process_id,
2970 int main_frame_widget_route_id) {
2971 auto key = std::make_pair(process_id, main_frame_widget_route_id);
2972 auto iter = pending_contents_.find(key);
[email protected]bafe6cd2012-05-23 23:09:502973
2974 // Certain systems can block the creation of new windows. If we didn't succeed
2975 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:532976 if (iter == pending_contents_.end())
2977 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502978
erikchenbee5c9622018-04-27 19:30:252979 std::unique_ptr<WebContents> new_contents = std::move(iter->second);
nick5ae4d2d2017-01-06 01:18:352980 pending_contents_.erase(key);
erikchenbee5c9622018-04-27 19:30:252981 WebContentsImpl* raw_new_contents =
2982 static_cast<WebContentsImpl*>(new_contents.get());
2983 RemoveDestructionObserver(raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502984
[email protected]d70bea92013-04-05 04:23:342985 // Don't initialize the guest WebContents immediately.
erikchenbee5c9622018-04-27 19:30:252986 if (BrowserPluginGuest::IsGuest(raw_new_contents))
[email protected]d70bea92013-04-05 04:23:342987 return new_contents;
2988
Lukasz Anforowicz5510ed652018-06-06 16:16:192989 if (!new_contents->GetMainFrame()->GetProcess()->IsInitializedAndNotDead() ||
nick5ae4d2d2017-01-06 01:18:352990 !new_contents->GetMainFrame()->GetView()) {
alexmosc2a8cec2016-05-23 22:19:532991 return nullptr;
nick5ae4d2d2017-01-06 01:18:352992 }
[email protected]bafe6cd2012-05-23 23:09:502993
[email protected]bafe6cd2012-05-23 23:09:502994 return new_contents;
2995}
2996
alexmosc2a8cec2016-05-23 22:19:532997RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
2998 int route_id) {
2999 auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:503000 if (iter == pending_widget_views_.end()) {
3001 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:533002 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:503003 }
3004
3005 RenderWidgetHostView* widget_host_view = iter->second;
alexmosc2a8cec2016-05-23 22:19:533006 pending_widget_views_.erase(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:503007
3008 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
Lukasz Anforowicz5510ed652018-06-06 16:16:193009 if (!widget_host->GetProcess()->IsInitializedAndNotDead()) {
[email protected]bafe6cd2012-05-23 23:09:503010 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:533011 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:503012 }
3013
3014 return widget_host_view;
3015}
3016
[email protected]f13b4202012-06-12 23:53:233017void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:093018 const MediaStreamRequest& request,
Mark Pilgrim57499082018-06-12 12:38:303019 MediaResponseCallback callback) {
[email protected]d19b84b2014-03-14 11:52:373020 if (delegate_) {
Mark Pilgrim57499082018-06-12 12:38:303021 delegate_->RequestMediaAccessPermission(this, request, std::move(callback));
[email protected]d19b84b2014-03-14 11:52:373022 } else {
Mark Pilgrim57499082018-06-12 12:38:303023 std::move(callback).Run(MediaStreamDevices(),
3024 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
3025 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:373026 }
[email protected]f13b4202012-06-12 23:53:233027}
3028
Chandan Padhia4b8bcb72017-09-12 16:41:043029bool WebContentsImpl::CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:583030 RenderFrameHost* render_frame_host,
Chandan Padhia4b8bcb72017-09-12 16:41:043031 const url::Origin& security_origin,
3032 MediaStreamType type) {
grunell657d4d82014-09-18 00:09:433033 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
3034 type == MEDIA_DEVICE_VIDEO_CAPTURE);
Chandan Padhia4b8bcb72017-09-12 16:41:043035 return delegate_ && delegate_->CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:583036 render_frame_host, security_origin.GetURL(), type);
grunell657d4d82014-09-18 00:09:433037}
3038
guidou8a440b842017-01-30 13:58:433039std::string WebContentsImpl::GetDefaultMediaDeviceID(MediaStreamType type) {
3040 if (!delegate_)
3041 return std::string();
3042 return delegate_->GetDefaultMediaDeviceID(this, type);
3043}
3044
[email protected]cc9200432013-07-23 23:02:403045SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
3046 SiteInstance* instance) {
3047 return controller_.GetSessionStorageNamespace(instance);
3048}
3049
[email protected]6de7fc482014-06-06 10:46:443050SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
3051 return controller_.GetSessionStorageNamespaceMap();
3052}
3053
[email protected]9b159a52013-10-03 17:24:553054FrameTree* WebContentsImpl::GetFrameTree() {
3055 return &frame_tree_;
3056}
3057
aelias5252baa2016-04-10 01:18:023058bool WebContentsImpl::IsOverridingUserAgent() {
3059 return GetController().GetVisibleEntry() &&
3060 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
3061}
3062
avi85ee8362016-10-08 02:09:083063bool WebContentsImpl::IsJavaScriptDialogShowing() const {
3064 return is_showing_javascript_dialog_;
3065}
3066
avic031d392017-03-03 03:09:423067bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() {
3068 // Ignore unresponsive renderers if the debugger is attached to them since the
3069 // unresponsiveness might be a result of the renderer sitting on a breakpoint.
3070 //
3071 // TODO(pfeldman): Fix this to only return true if the renderer is *actually*
3072 // sitting on a breakpoint. https://crbug.com/684202
3073 return DevToolsAgentHost::IsDebuggerAttached(this);
3074}
3075
Doug Turner63f3c7b2017-07-29 05:10:013076ui::AXMode WebContentsImpl::GetAccessibilityMode() const {
[email protected]95640212014-07-26 18:14:303077 return accessibility_mode_;
3078}
3079
Dominic Mazzonia7b0edb22017-08-09 16:32:513080void WebContentsImpl::AccessibilityEventReceived(
Dominic Mazzoniccbaa9b2018-06-06 07:44:233081 const AXEventNotificationDetails& details) {
ericwilligersde386342016-10-19 02:35:093082 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513083 observer.AccessibilityEventReceived(details);
[email protected]31a71eaf2014-03-13 01:47:363084}
3085
dmazzoni2400c462016-08-23 15:07:133086void WebContentsImpl::AccessibilityLocationChangesReceived(
3087 const std::vector<AXLocationChangeNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:093088 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513089 observer.AccessibilityLocationChangesReceived(details);
dmazzoni2400c462016-08-23 15:07:133090}
3091
dmazzonia656928e2014-09-15 20:28:543092RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:403093 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:543094 int browser_plugin_instance_id) {
3095 BrowserPluginGuestManager* guest_manager =
3096 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:203097 if (!guest_manager)
3098 return nullptr;
3099
dmazzonia656928e2014-09-15 20:28:543100 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:443101 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:543102 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:203103 return nullptr;
3104
dmazzonia656928e2014-09-15 20:28:543105 return guest->GetMainFrame();
3106}
3107
Ke He7319dbe2017-11-09 05:54:443108device::mojom::GeolocationContext* WebContentsImpl::GetGeolocationContext() {
3109 if (geolocation_context_)
3110 return geolocation_context_.get();
3111
3112 auto request = mojo::MakeRequest(&geolocation_context_);
3113 if (!ServiceManagerConnection::GetForProcess())
3114 return geolocation_context_.get();
3115
3116 service_manager::Connector* connector =
3117 ServiceManagerConnection::GetForProcess()->GetConnector();
3118 connector->BindInterface(device::mojom::kServiceName, std::move(request));
Conley Owens6894c4f2017-07-10 19:29:133119 return geolocation_context_.get();
blundellc57b93f2014-10-29 13:19:573120}
3121
ke.he98b761e2017-05-09 05:59:173122device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() {
blundelld8cd72b2017-03-28 07:18:383123 if (!wake_lock_context_host_)
3124 wake_lock_context_host_.reset(new WakeLockContextHost(this));
blundelle75a8f92017-03-27 08:11:173125 return wake_lock_context_host_->GetWakeLockContext();
alogvinovf50445a2015-10-30 13:00:123126}
3127
juncai8e8d6ec2017-06-06 20:48:183128device::mojom::WakeLock* WebContentsImpl::GetRendererWakeLock() {
3129 // WebContents creates a long-lived connection to one WakeLock.
ke.he98b761e2017-05-09 05:59:173130 // All the frames' requests will be added into the BindingSet of
juncai8e8d6ec2017-06-06 20:48:183131 // WakeLock via this connection.
ke.he98b761e2017-05-09 05:59:173132 if (!renderer_wake_lock_) {
3133 device::mojom::WakeLockContext* wake_lock_context = GetWakeLockContext();
3134 if (!wake_lock_context) {
3135 return nullptr;
3136 }
ke.hef435c1e82017-05-11 04:09:103137 wake_lock_context->GetWakeLock(
Daniel Erat28922ba2017-11-08 16:18:263138 device::mojom::WakeLockType::kPreventDisplaySleep,
3139 device::mojom::WakeLockReason::kOther, "Wake Lock API",
ke.hef435c1e82017-05-11 04:09:103140 mojo::MakeRequest(&renderer_wake_lock_));
ke.he98b761e2017-05-09 05:59:173141 }
3142 return renderer_wake_lock_.get();
3143}
3144
blundellf5316fc2017-05-15 11:49:033145#if defined(OS_ANDROID)
Han Leonf6a2e5f2017-05-23 13:40:473146void WebContentsImpl::GetNFC(device::mojom::NFCRequest request) {
blundellf5316fc2017-05-15 11:49:033147 if (!nfc_host_)
3148 nfc_host_.reset(new NFCHost(this));
3149 nfc_host_->GetNFC(std::move(request));
3150}
3151#endif
3152
Evan Stade5e750ad02017-08-07 21:59:273153void WebContentsImpl::SetNotWaitingForResponse() {
3154 if (waiting_for_response_ == false)
3155 return;
3156
3157 waiting_for_response_ = false;
3158 if (delegate_)
3159 delegate_->LoadingStateChanged(this, is_load_to_different_document_);
Chris Hamiltonf82f2a702018-02-15 19:37:293160 for (auto& observer : observers_)
3161 observer.DidReceiveResponse();
Evan Stade5e750ad02017-08-07 21:59:273162}
3163
lfgbb9c28a2016-03-01 03:19:493164void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:373165 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:403166 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:373167 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
3168 }
lfgbb9c28a2016-03-01 03:19:493169
lfgdb5c4ed2016-03-04 23:09:073170 RenderWidgetHostViewBase* rwhv =
3171 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3172 if (rwhv) {
3173 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
3174 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
3175 }
3176
avallee9f43b012016-11-26 07:02:103177 if (browser_plugin_embedder_ && !is_being_destroyed_)
[email protected]a7568e62013-06-14 07:50:443178 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:043179}
3180
ekaramadadd882292016-06-08 15:22:563181TextInputManager* WebContentsImpl::GetTextInputManager() {
3182 if (GetOuterWebContents())
3183 return GetOuterWebContents()->GetTextInputManager();
3184
Darren Shenca53d5f2018-05-15 04:56:013185 if (!text_input_manager_) {
3186 text_input_manager_.reset(new TextInputManager(
3187 GetBrowserContext() &&
3188 !GetBrowserContext()->IsOffTheRecord()) /* should_do_learning */);
3189 }
ekaramadadd882292016-06-08 15:22:563190
3191 return text_input_manager_.get();
3192}
3193
paulmeyer7f6f1d4f2016-11-15 00:00:273194bool WebContentsImpl::OnUpdateDragCursor() {
3195 if (browser_plugin_embedder_)
3196 return browser_plugin_embedder_->OnUpdateDragCursor();
3197 return false;
3198}
3199
kenrb11f213a2017-03-24 18:12:063200bool WebContentsImpl::IsWidgetForMainFrame(
3201 RenderWidgetHostImpl* render_widget_host) {
3202 return render_widget_host == GetMainFrame()->GetRenderWidgetHost();
3203}
3204
[email protected]95640212014-07-26 18:14:303205BrowserAccessibilityManager*
3206 WebContentsImpl::GetRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223207 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3208 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3209 : GetMainFrame());
creisc014b402015-04-23 16:41:453210 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:303211}
3212
3213BrowserAccessibilityManager*
3214 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223215 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3216 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3217 : GetMainFrame());
creisc014b402015-04-23 16:41:453218 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:303219}
3220
Dave Tapuskab336b922017-07-06 19:24:053221void WebContentsImpl::ExecuteEditCommand(
3222 const std::string& command,
3223 const base::Optional<base::string16>& value) {
3224 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
3225 if (!focused_frame)
3226 return;
3227
3228 focused_frame->GetFrameInputHandler()->ExecuteEditCommand(command, value);
3229}
3230
mohsen7ab1ec16ec2015-07-02 18:26:233231void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:053232 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:233233 if (!focused_frame)
3234 return;
3235
dtapuska9d46ef7d2017-05-26 19:06:063236 focused_frame->GetFrameInputHandler()->MoveRangeSelectionExtent(extent);
mohsen7ab1ec16ec2015-07-02 18:26:233237}
3238
3239void WebContentsImpl::SelectRange(const gfx::Point& base,
3240 const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:053241 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:233242 if (!focused_frame)
3243 return;
3244
dtapuska9d46ef7d2017-05-26 19:06:063245 focused_frame->GetFrameInputHandler()->SelectRange(base, extent);
mohsen7ab1ec16ec2015-07-02 18:26:233246}
3247
Tessa Nijssenc4b101232018-06-25 20:28:083248#if defined(OS_MACOSX)
Tessa Nijssendbef4742018-06-29 21:02:083249void WebContentsImpl::DidChangeTextSelection(const base::string16& text,
3250 const gfx::Range& range) {
3251 for (auto& observer : observers_)
3252 observer.DidChangeTextSelection(text, range);
Tessa Nijssenc4b101232018-06-25 20:28:083253}
3254#endif
3255
Dave Tapuskab336b922017-07-06 19:24:053256void WebContentsImpl::MoveCaret(const gfx::Point& extent) {
3257 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
3258 if (!focused_frame)
3259 return;
3260
3261 focused_frame->GetFrameInputHandler()->MoveCaret(extent);
3262}
3263
Shimi Zhang37deeb22017-09-28 00:59:013264void WebContentsImpl::AdjustSelectionByCharacterOffset(
3265 int start_adjust,
3266 int end_adjust,
3267 bool show_selection_menu) {
Dave Tapuskab336b922017-07-06 19:24:053268 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
aurimasab0319022015-07-10 21:57:383269 if (!focused_frame)
3270 return;
3271
Shimi Zhang37deeb22017-09-28 00:59:013272 using blink::mojom::SelectionMenuBehavior;
dtapuska9d46ef7d2017-05-26 19:06:063273 focused_frame->GetFrameInputHandler()->AdjustSelectionByCharacterOffset(
Shimi Zhang37deeb22017-09-28 00:59:013274 start_adjust, end_adjust,
3275 show_selection_menu ? SelectionMenuBehavior::kShow
3276 : SelectionMenuBehavior::kHide);
aurimasab0319022015-07-10 21:57:383277}
3278
[email protected]b172aee2012-04-10 17:05:263279void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:493280 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:233281 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:493282 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:333283}
3284
avic3aa8422015-11-09 20:57:223285void WebContentsImpl::ResizeDueToAutoResize(
3286 RenderWidgetHostImpl* render_widget_host,
Fady Samuel97947112018-05-05 16:24:543287 const gfx::Size& new_size) {
avic3aa8422015-11-09 20:57:223288 if (render_widget_host != GetRenderViewHost()->GetWidget())
3289 return;
3290
kenrbe4f91082017-06-02 20:32:083291 auto_resize_size_ = new_size;
3292
3293 // Out-of-process iframe visible viewport sizes usually come from the
3294 // top-level RenderWidgetHostView, but when auto-resize is enabled on the
3295 // top frame then that size is used instead.
3296 for (FrameTreeNode* node : frame_tree_.Nodes()) {
3297 if (node->current_frame_host()->is_local_root()) {
3298 RenderWidgetHostImpl* host =
3299 node->current_frame_host()->GetRenderWidgetHost();
3300 if (host != render_widget_host)
Fady Samuel0b911822018-04-25 13:22:163301 host->SynchronizeVisualProperties();
kenrbe4f91082017-06-02 20:32:083302 }
3303 }
3304
[email protected]61e2b3cc2012-03-02 16:13:343305 if (delegate_)
3306 delegate_->ResizeDueToAutoResize(this, new_size);
3307}
3308
kenrbe4f91082017-06-02 20:32:083309gfx::Size WebContentsImpl::GetAutoResizeSize() {
3310 return auto_resize_size_;
3311}
3312
3313void WebContentsImpl::ResetAutoResizeSize() {
3314 auto_resize_size_ = gfx::Size();
3315}
3316
[email protected]b172aee2012-04-10 17:05:263317WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
Bo Liu300c6052018-06-12 04:46:073318 if (!delegate_) {
3319 // Embedder can delay setting a delegate on new WebContents with
3320 // WebContentsDelegate::ShouldResumeRequestsForCreatedWindow. In the mean
3321 // time, navigations, including the initial one, that goes through OpenURL
3322 // should be delayed until embedder is ready to resume loading.
3323 delayed_open_url_params_ = std::make_unique<OpenURLParams>(params);
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283324 return nullptr;
Bo Liu300c6052018-06-12 04:46:073325 }
[email protected]00c37fc2011-08-02 00:22:503326
[email protected]e5d549d2011-12-28 01:29:203327 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
pnoland488944652017-02-22 18:58:543328
3329 RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID(
3330 params.source_render_process_id, params.source_render_frame_id);
3331
3332 if (source_render_frame_host && params.source_site_instance) {
3333 CHECK_EQ(source_render_frame_host->GetSiteInstance(),
3334 params.source_site_instance.get());
3335 }
3336
3337 if (new_contents && source_render_frame_host && new_contents != this) {
3338 for (auto& observer : observers_) {
3339 observer.DidOpenRequestedURL(new_contents, source_render_frame_host,
3340 params.url, params.referrer,
3341 params.disposition, params.transition,
pnolandaae574e2017-03-06 21:04:213342 params.started_from_context_menu, false);
pnoland488944652017-02-22 18:58:543343 }
3344 }
3345
[email protected]e5d549d2011-12-28 01:29:203346 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:343347}
3348
[email protected]a86c0e962013-12-17 17:10:393349void WebContentsImpl::RenderFrameForInterstitialPageCreated(
3350 RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:093351 for (auto& observer : observers_)
3352 observer.RenderFrameForInterstitialPageCreated(render_frame_host);
[email protected]ba45bfd2012-05-22 21:51:443353}
3354
[email protected]20ca0382013-02-28 19:50:073355void WebContentsImpl::AttachInterstitialPage(
3356 InterstitialPageImpl* interstitial_page) {
creisadca9862017-06-16 19:12:113357 DCHECK(!interstitial_page_ && interstitial_page);
3358 interstitial_page_ = interstitial_page;
[email protected]90fb08ed2013-09-24 17:43:293359
3360 // Cancel any visible dialogs so that they don't interfere with the
3361 // interstitial.
creis89a0f782015-05-27 16:13:173362 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:293363
ericwilligersde386342016-10-19 02:35:093364 for (auto& observer : observers_)
3365 observer.DidAttachInterstitialPage();
clamy44e84ce2016-02-22 15:38:253366
3367 // Stop the throbber if needed while the interstitial page is shown.
3368 if (frame_tree_.IsLoading())
3369 LoadingStateChanged(true, true, nullptr);
lfg1453e412017-04-11 00:48:503370
3371 // Connect to outer WebContents if necessary.
3372 if (node_.OuterContentsFrameTreeNode()) {
3373 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3374 DCHECK(
3375 static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView())
3376 ->IsRenderWidgetHostViewChildFrame());
3377 RenderWidgetHostViewChildFrame* view =
3378 static_cast<RenderWidgetHostViewChildFrame*>(
3379 interstitial_page->GetView());
3380 GetRenderManager()->SetRWHViewForInnerContents(view);
3381 }
3382 }
Bo Liu7c6779e92017-08-16 02:02:283383
Bo Liu168c8642017-08-28 18:26:023384#if defined(OS_ANDROID)
Bo Liu7c6779e92017-08-16 02:02:283385 // Update importance of the interstitial.
3386 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
3387 ->GetRenderWidgetHost()
3388 ->SetImportance(GetMainFrame()->GetRenderWidgetHost()->importance());
Bo Liu168c8642017-08-28 18:26:023389#endif
Dominic Mazzoniefb5f9e32017-12-21 01:08:223390
3391 if (accessibility_mode_.has_mode(ui::AXMode::kNativeAPIs)) {
3392 // Make sure that the main page's accessibility tree is hidden and the
3393 // interstitial gets focus.
3394 RenderFrameHostImpl* rfh =
3395 static_cast<RenderFrameHostImpl*>(GetMainFrame());
3396 if (rfh) {
3397 BrowserAccessibilityManager* accessibility_manager =
3398 rfh->browser_accessibility_manager();
3399 if (accessibility_manager)
3400 accessibility_manager->set_hidden_by_interstitial_page(true);
3401 }
3402 rfh = static_cast<RenderFrameHostImpl*>(
3403 GetInterstitialPage()->GetMainFrame());
3404 if (rfh) {
3405 BrowserAccessibilityManager* accessibility_manager =
3406 rfh->GetOrCreateBrowserAccessibilityManager();
3407 if (accessibility_manager)
3408 accessibility_manager->OnWindowFocused();
3409 }
3410 }
clamy44e84ce2016-02-22 15:38:253411}
3412
3413void WebContentsImpl::DidProceedOnInterstitial() {
3414 // The interstitial page should no longer be pausing the throbber.
creisadca9862017-06-16 19:12:113415 DCHECK(!(ShowingInterstitialPage() && interstitial_page_->pause_throbber()));
clamy44e84ce2016-02-22 15:38:253416
3417 // Restart the throbber now that the interstitial page no longer pauses it.
3418 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
3419 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073420}
3421
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043422void WebContentsImpl::DetachInterstitialPage(bool has_focus) {
Lucas Furukawa Gadani69b609192017-07-10 17:08:343423 bool interstitial_pausing_throbber =
3424 ShowingInterstitialPage() && interstitial_page_->pause_throbber();
3425 if (ShowingInterstitialPage())
3426 interstitial_page_ = nullptr;
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043427
Dominic Mazzoniefb5f9e32017-12-21 01:08:223428 // Make sure that the main page's accessibility tree is no longer
3429 // suppressed.
3430 RenderFrameHostImpl* rfh = GetMainFrame();
3431 if (rfh) {
3432 BrowserAccessibilityManager* accessibility_manager =
3433 rfh->browser_accessibility_manager();
3434 if (accessibility_manager)
3435 accessibility_manager->set_hidden_by_interstitial_page(false);
3436 }
3437
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043438 // If the focus was on the interstitial, let's keep it to the page.
3439 // (Note that in unit-tests the RVH may not have a view).
3440 if (has_focus && GetRenderViewHost()->GetWidget()->GetView())
3441 GetRenderViewHost()->GetWidget()->GetView()->Focus();
3442
Lucas Furukawa Gadani69b609192017-07-10 17:08:343443 for (auto& observer : observers_)
3444 observer.DidDetachInterstitialPage();
3445
3446 // Disconnect from outer WebContents if necessary. This must happen after the
3447 // interstitial page is cleared above, since the call to
3448 // SetRWHViewForInnerContents below may loop over all the
3449 // RenderWidgetHostViews in the tree (otherwise, including the now-deleted
3450 // view for the interstitial).
lfg1453e412017-04-11 00:48:503451 if (node_.OuterContentsFrameTreeNode()) {
3452 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3453 DCHECK(static_cast<RenderWidgetHostViewBase*>(
3454 GetRenderManager()->current_frame_host()->GetView())
3455 ->IsRenderWidgetHostViewChildFrame());
3456 RenderWidgetHostViewChildFrame* view =
3457 static_cast<RenderWidgetHostViewChildFrame*>(
3458 GetRenderManager()->current_frame_host()->GetView());
3459 GetRenderManager()->SetRWHViewForInnerContents(view);
3460 }
3461 }
3462
clamy44e84ce2016-02-22 15:38:253463 // Restart the throbber if needed now that the interstitial page is going
3464 // away.
3465 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
3466 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073467}
3468
avi2b177592014-12-10 02:08:023469void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
3470 int history_length) {
alexmos136fd6e62016-08-15 20:58:413471 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
3472 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:023473}
3474
3475void WebContentsImpl::SetHistoryOffsetAndLengthForView(
3476 RenderViewHost* render_view_host,
3477 int history_offset,
3478 int history_length) {
alexmos136fd6e62016-08-15 20:58:413479 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:023480 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:143481}
3482
toyoshim24a4c7ab2016-04-05 09:24:143483void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:173484 RenderFrameHost* focused_frame = GetFocusedFrame();
3485 if (!focused_frame)
3486 return;
3487
[email protected]959be4c2014-04-08 15:01:333488 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:143489 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:333490}
3491
megjablon3f5941072016-02-04 23:27:523492void WebContentsImpl::ReloadLoFiImages() {
3493 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
3494}
3495
Ryan Sturmc65dbe42018-05-31 20:37:043496std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr>
3497WebContentsImpl::PauseSubresourceLoading() {
3498 std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr> handles;
3499 for (RenderFrameHost* rfh : GetAllFrames()) {
3500 if (!rfh->IsRenderFrameLive())
3501 continue;
3502 handles.push_back(rfh->PauseSubresourceLoading());
3503 }
3504 return handles;
3505}
3506
[email protected]959be4c2014-04-08 15:01:333507void WebContentsImpl::Undo() {
Dave Tapuskab336b922017-07-06 19:24:053508 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333509 if (!focused_frame)
3510 return;
3511
dtapuska9d46ef7d2017-05-26 19:06:063512 focused_frame->GetFrameInputHandler()->Undo();
[email protected]959be4c2014-04-08 15:01:333513 RecordAction(base::UserMetricsAction("Undo"));
3514}
3515
3516void WebContentsImpl::Redo() {
Dave Tapuskab336b922017-07-06 19:24:053517 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333518 if (!focused_frame)
3519 return;
dtapuska9d46ef7d2017-05-26 19:06:063520 focused_frame->GetFrameInputHandler()->Redo();
[email protected]959be4c2014-04-08 15:01:333521 RecordAction(base::UserMetricsAction("Redo"));
3522}
3523
3524void WebContentsImpl::Cut() {
Dave Tapuskab336b922017-07-06 19:24:053525 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333526 if (!focused_frame)
3527 return;
3528
dtapuska9d46ef7d2017-05-26 19:06:063529 focused_frame->GetFrameInputHandler()->Cut();
[email protected]959be4c2014-04-08 15:01:333530 RecordAction(base::UserMetricsAction("Cut"));
3531}
3532
3533void WebContentsImpl::Copy() {
Dave Tapuskab336b922017-07-06 19:24:053534 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333535 if (!focused_frame)
3536 return;
3537
dtapuska9d46ef7d2017-05-26 19:06:063538 focused_frame->GetFrameInputHandler()->Copy();
[email protected]959be4c2014-04-08 15:01:333539 RecordAction(base::UserMetricsAction("Copy"));
3540}
3541
3542void WebContentsImpl::CopyToFindPboard() {
3543#if defined(OS_MACOSX)
Dave Tapuskab336b922017-07-06 19:24:053544 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333545 if (!focused_frame)
3546 return;
3547
3548 // Windows/Linux don't have the concept of a find pasteboard.
dtapuska9d46ef7d2017-05-26 19:06:063549 focused_frame->GetFrameInputHandler()->CopyToFindPboard();
[email protected]959be4c2014-04-08 15:01:333550 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
3551#endif
3552}
3553
3554void WebContentsImpl::Paste() {
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()->Paste();
[email protected]959be4c2014-04-08 15:01:333560 RecordAction(base::UserMetricsAction("Paste"));
3561}
3562
3563void WebContentsImpl::PasteAndMatchStyle() {
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()->PasteAndMatchStyle();
[email protected]959be4c2014-04-08 15:01:333569 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
3570}
3571
3572void WebContentsImpl::Delete() {
Dave Tapuskab336b922017-07-06 19:24:053573 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333574 if (!focused_frame)
3575 return;
3576
dtapuska9d46ef7d2017-05-26 19:06:063577 focused_frame->GetFrameInputHandler()->Delete();
[email protected]959be4c2014-04-08 15:01:333578 RecordAction(base::UserMetricsAction("DeleteSelection"));
3579}
3580
3581void WebContentsImpl::SelectAll() {
Dave Tapuskab336b922017-07-06 19:24:053582 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333583 if (!focused_frame)
3584 return;
3585
dtapuska9d46ef7d2017-05-26 19:06:063586 focused_frame->GetFrameInputHandler()->SelectAll();
[email protected]959be4c2014-04-08 15:01:333587 RecordAction(base::UserMetricsAction("SelectAll"));
3588}
3589
yabinh351e7ec2017-03-10 02:43:243590void WebContentsImpl::CollapseSelection() {
Dave Tapuskab336b922017-07-06 19:24:053591 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333592 if (!focused_frame)
3593 return;
3594
dtapuska9d46ef7d2017-05-26 19:06:063595 focused_frame->GetFrameInputHandler()->CollapseSelection();
[email protected]1f3fc1d2014-04-03 14:50:173596}
3597
3598void WebContentsImpl::Replace(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053599 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173600 if (!focused_frame)
3601 return;
3602
dtapuska9d46ef7d2017-05-26 19:06:063603 focused_frame->GetFrameInputHandler()->Replace(word);
[email protected]1f3fc1d2014-04-03 14:50:173604}
3605
3606void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053607 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173608 if (!focused_frame)
3609 return;
3610
dtapuska9d46ef7d2017-05-26 19:06:063611 focused_frame->GetFrameInputHandler()->ReplaceMisspelling(word);
[email protected]959be4c2014-04-08 15:01:333612}
3613
3614void WebContentsImpl::NotifyContextMenuClosed(
3615 const CustomContextMenuContext& context) {
3616 RenderFrameHost* focused_frame = GetFocusedFrame();
3617 if (!focused_frame)
3618 return;
3619
3620 focused_frame->Send(new FrameMsg_ContextMenuClosed(
3621 focused_frame->GetRoutingID(), context));
3622}
3623
3624void WebContentsImpl::ExecuteCustomContextMenuCommand(
3625 int action, const CustomContextMenuContext& context) {
3626 RenderFrameHost* focused_frame = GetFocusedFrame();
3627 if (!focused_frame)
3628 return;
3629
3630 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
3631 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:003632}
3633
[email protected]fc2b46b2014-05-03 16:33:453634gfx::NativeView WebContentsImpl::GetNativeView() {
3635 return view_->GetNativeView();
3636}
3637
3638gfx::NativeView WebContentsImpl::GetContentNativeView() {
3639 return view_->GetContentNativeView();
3640}
3641
3642gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
3643 return view_->GetTopLevelNativeWindow();
3644}
3645
3646gfx::Rect WebContentsImpl::GetViewBounds() {
3647 return view_->GetViewBounds();
3648}
3649
3650gfx::Rect WebContentsImpl::GetContainerBounds() {
3651 gfx::Rect rv;
3652 view_->GetContainerBounds(&rv);
3653 return rv;
3654}
3655
3656DropData* WebContentsImpl::GetDropData() {
3657 return view_->GetDropData();
3658}
3659
3660void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:043661 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:453662}
3663
3664void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:043665 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:453666}
3667
3668void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:043669 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453670}
3671
3672void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:043673 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453674}
3675
[email protected]b172aee2012-04-10 17:05:263676void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
Maxim Podgorodskiya926c4ff2017-11-20 02:06:393677 view_->FocusThroughTabTraversal(reverse);
[email protected]96d185d2009-04-24 03:28:543678}
3679
[email protected]b172aee2012-04-10 17:05:263680bool WebContentsImpl::ShowingInterstitialPage() const {
creisadca9862017-06-16 19:12:113681 return interstitial_page_ != nullptr;
[email protected]96d185d2009-04-24 03:28:543682}
3683
Pete Williamson89aa1402017-07-07 19:58:413684void WebContentsImpl::AdjustPreviewsStateForNavigation(
3685 PreviewsState* previews_state) {
3686 if (delegate_)
Doug Arnettc681bbe2018-04-06 04:04:463687 delegate_->AdjustPreviewsStateForNavigation(this, previews_state);
Pete Williamson89aa1402017-07-07 19:58:413688}
3689
Maxim Podgorodskiya926c4ff2017-11-20 02:06:393690InterstitialPageImpl* WebContentsImpl::GetInterstitialPage() const {
creisadca9862017-06-16 19:12:113691 return interstitial_page_;
[email protected]686493142011-07-15 21:47:223692}
3693
Gyuyoung Kim80143f5e2018-04-02 02:40:253694void WebContentsImpl::PausePageScheduledTasks(bool paused) {
3695 SendPageMessage(
3696 new PageMsg_PausePageScheduledTasks(MSG_ROUTING_NONE, paused));
3697}
3698
[email protected]b172aee2012-04-10 17:05:263699bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:163700 // WebKit creates Document object when MIME type is application/xhtml+xml,
3701 // so we also support this MIME type.
3702 return contents_mime_type_ == "text/html" ||
3703 contents_mime_type_ == "text/xml" ||
3704 contents_mime_type_ == "application/xhtml+xml" ||
3705 contents_mime_type_ == "text/plain" ||
3706 contents_mime_type_ == "text/css" ||
Kinuko Yasuda74702f92017-07-31 03:27:533707 blink::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:163708}
3709
[email protected]b172aee2012-04-10 17:05:263710void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:593711 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:163712 if (!IsSavable()) {
Min Qinda0ed2062018-02-23 22:00:533713 download::RecordSavePackageEvent(
3714 download::SAVE_PACKAGE_DOWNLOAD_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:193715 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:143716 return;
[email protected]c7dd2f62011-07-18 15:57:593717 }
3718
3719 Stop();
3720
3721 // Create the save package and possibly prompt the user for the name to save
3722 // the page as. The user prompt is an asynchronous operation that runs on
3723 // another thread.
3724 save_package_ = new SavePackage(this);
3725 save_package_->GetSaveInfo();
3726}
3727
3728// Used in automated testing to bypass prompting the user for file names.
3729// Instead, the names and paths are hard coded rather than running them through
3730// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:343731bool WebContentsImpl::SavePage(const base::FilePath& main_file,
3732 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:213733 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:593734 // Stop the page from navigating.
3735 Stop();
3736
3737 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:213738 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:593739}
3740
[email protected]3c71576ce2013-07-23 02:00:013741void WebContentsImpl::SaveFrame(const GURL& url,
3742 const Referrer& referrer) {
Xing Liu10329bf2018-03-20 19:22:143743 SaveFrameWithHeaders(url, referrer, std::string(), base::string16());
kundaji6c7f9692015-03-09 18:00:373744}
3745
Xing Liu10329bf2018-03-20 19:22:143746void WebContentsImpl::SaveFrameWithHeaders(
3747 const GURL& url,
3748 const Referrer& referrer,
3749 const std::string& headers,
3750 const base::string16& suggested_filename) {
nasko89ad7742015-03-05 22:14:193751 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:013752 return;
sammc92af61552014-11-19 23:27:403753 if (delegate_ && delegate_->SaveFrame(url, referrer))
3754 return;
3755
nasko89ad7742015-03-05 22:14:193756 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:223757 // by explicitly passing in which frame this method should target. This would
3758 // indicate whether it's the main frame, and also tell us the frame pointer
3759 // to use for routing.
nasko89ad7742015-03-05 22:14:193760 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:223761 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:013762
brettw760f7442016-05-23 21:19:223763 StoragePartition* storage_partition = BrowserContext::GetStoragePartition(
3764 GetBrowserContext(), frame_host->GetSiteInstance());
avib7348942015-12-25 20:57:103765 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:013766 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:273767 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:013768 if (entry)
3769 post_id = entry->GetPostID();
3770 }
Ramin Halavati24e21012017-07-10 12:56:063771 net::NetworkTrafficAnnotationTag traffic_annotation =
3772 net::DefineNetworkTrafficAnnotation("download_web_contents_frame", R"(
3773 semantics {
3774 sender: "Save Page Action"
3775 description:
3776 "Saves the given frame's URL to the local file system."
3777 trigger:
3778 "The user has triggered a save operation on the frame through a "
3779 "context menu or other mechanism."
3780 data: "None."
3781 destination: WEBSITE
3782 }
3783 policy {
Ramin Halavati3b979782017-07-21 11:40:263784 cookies_allowed: YES
Ramin Halavati24e21012017-07-10 12:56:063785 cookies_store: "user"
3786 setting:
3787 "This feature cannot be disabled by settings, but it's is only "
3788 "triggered by user request."
3789 policy_exception_justification: "Not implemented."
3790 })");
Min Qina904f3302018-02-13 23:33:343791 auto params = std::make_unique<download::DownloadUrlParameters>(
brettw760f7442016-05-23 21:19:223792 url, frame_host->GetProcess()->GetID(),
3793 frame_host->GetRenderViewHost()->GetRoutingID(),
Ramin Halavati03efa732017-06-12 09:28:203794 frame_host->GetRoutingID(), storage_partition->GetURLRequestContext(),
Ramin Halavati24e21012017-07-10 12:56:063795 traffic_annotation);
Min Qina904f3302018-02-13 23:33:343796 params->set_referrer(referrer.url);
3797 params->set_referrer_policy(
3798 Referrer::ReferrerPolicyForUrlRequest(referrer.policy));
[email protected]3c71576ce2013-07-23 02:00:013799 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:013800 if (post_id >= 0)
3801 params->set_method("POST");
3802 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:373803
3804 if (headers.empty()) {
3805 params->set_prefer_cache(true);
3806 } else {
Min Qina904f3302018-02-13 23:33:343807 for (download::DownloadUrlParameters::RequestHeadersNameValuePair
3808 key_value : ParseDownloadHeaders(headers)) {
Megan Jablonski2f6a4c52017-07-10 23:01:253809 params->add_request_header(key_value.first, key_value.second);
kundaji6c7f9692015-03-09 18:00:373810 }
3811 }
Xing Liu10329bf2018-03-20 19:22:143812 params->set_suggested_name(suggested_filename);
Min Qin0ca8e1ee2018-01-31 00:49:353813 params->set_download_source(download::DownloadSource::WEB_CONTENTS_API);
thestig859c78892017-05-15 21:17:063814 BrowserContext::GetDownloadManager(GetBrowserContext())
Ramin Halavati03efa732017-06-12 09:28:203815 ->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:013816}
3817
[email protected]b172aee2012-04-10 17:05:263818void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:473819 const MHTMLGenerationParams& params,
Avi Drissman149b7832018-03-23 14:31:493820 base::OnceCallback<void(int64_t)> callback) {
3821 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params,
3822 std::move(callback));
[email protected]aa4f3972012-03-01 18:12:123823}
3824
[email protected]b172aee2012-04-10 17:05:263825const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:273826 return contents_mime_type_;
3827}
3828
[email protected]b172aee2012-04-10 17:05:263829bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:273830 return notify_disconnection_;
3831}
3832
[email protected]8ff00d72012-10-23 19:12:213833RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:273834 return &renderer_preferences_;
3835}
3836
[email protected]e35ccd52012-05-23 16:22:473837void WebContentsImpl::Close() {
3838 Close(GetRenderViewHost());
3839}
3840
Ella Ge80a52dce2017-11-15 18:01:523841void WebContentsImpl::DragSourceEndedAt(float client_x,
3842 float client_y,
3843 float screen_x,
3844 float screen_y,
Paul Meyer0c58c3712016-11-17 22:59:513845 blink::WebDragOperation operation,
3846 RenderWidgetHost* source_rwh) {
[email protected]cf200a562013-05-03 16:24:293847 if (browser_plugin_embedder_.get())
paulmeyer8fc8ea92016-11-15 05:12:213848 browser_plugin_embedder_->DragSourceEndedAt(
3849 client_x, client_y, screen_x, screen_y, operation);
Paul Meyer0c58c3712016-11-17 22:59:513850 if (source_rwh) {
Ella Ge80a52dce2017-11-15 18:01:523851 source_rwh->DragSourceEndedAt(gfx::PointF(client_x, client_y),
3852 gfx::PointF(screen_x, screen_y), operation);
Paul Meyer0c58c3712016-11-17 22:59:513853 }
[email protected]cf200a562013-05-03 16:24:293854}
3855
jam73f892642016-09-11 06:04:063856void WebContentsImpl::LoadStateChanged(
Charles Harrison911fa062018-03-06 21:01:463857 const std::string& host,
jam73f892642016-09-11 06:04:063858 const net::LoadStateWithParam& load_state,
3859 uint64_t upload_position,
3860 uint64_t upload_size) {
Charles Harrison911fa062018-03-06 21:01:463861 base::string16 host16 = url_formatter::IDNToUnicode(host);
Elly Fong-Jonescad9c3d12018-01-31 17:26:103862 // Drop no-op updates.
3863 if (load_state_.state == load_state.state &&
3864 load_state_.param == load_state.param &&
3865 upload_position_ == upload_position && upload_size_ == upload_size &&
Charles Harrison911fa062018-03-06 21:01:463866 load_state_host_ == host16) {
Elly Fong-Jonescad9c3d12018-01-31 17:26:103867 return;
3868 }
jam73f892642016-09-11 06:04:063869 load_state_ = load_state;
3870 upload_position_ = upload_position;
3871 upload_size_ = upload_size;
Charles Harrison911fa062018-03-06 21:01:463872 load_state_host_ = host16;
jam73f892642016-09-11 06:04:063873 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
3874 SetNotWaitingForResponse();
3875 if (IsLoading()) {
3876 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
3877 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
3878 }
3879}
3880
Francois Doraye6161152018-03-27 22:05:373881void WebContentsImpl::SetVisibility(Visibility visibility) {
3882 const Visibility previous_visibility = visibility_;
3883 visibility_ = visibility;
3884
Francois Dorayfe4a1772018-02-17 04:17:093885 // Notify observers if the visibility changed or if WasShown() is being called
3886 // for the first time.
Francois Dorayfe4a1772018-02-17 04:17:093887 if (visibility != previous_visibility ||
3888 (visibility == Visibility::VISIBLE && !did_first_set_visible_)) {
3889 for (auto& observer : observers_)
3890 observer.OnVisibilityChanged(visibility);
3891 }
3892}
3893
Michael Thiessen896405db2017-07-20 17:52:323894void WebContentsImpl::NotifyWebContentsFocused(
3895 RenderWidgetHost* render_widget_host) {
ericwilligersde386342016-10-19 02:35:093896 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323897 observer.OnWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:373898}
3899
Michael Thiessen896405db2017-07-20 17:52:323900void WebContentsImpl::NotifyWebContentsLostFocus(
3901 RenderWidgetHost* render_widget_host) {
zijiehe3bee08e22017-05-17 04:14:463902 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323903 observer.OnWebContentsLostFocus(render_widget_host);
zijiehe3bee08e22017-05-17 04:14:463904}
3905
Paul Meyer0c58c3712016-11-17 22:59:513906void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) {
3907 if (source_rwh)
3908 source_rwh->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:293909 if (browser_plugin_embedder_.get())
3910 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:343911}
3912
Daniel Cheng90196c82018-04-25 21:49:143913void WebContentsImpl::NavigatedByUser() {
3914 OnUserInteraction(blink::WebInputEvent::kUndefined);
[email protected]e35ccd52012-05-23 16:22:473915}
3916
[email protected]b172aee2012-04-10 17:05:263917void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:273918 closed_by_user_gesture_ = value;
3919}
3920
[email protected]b172aee2012-04-10 17:05:263921bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:273922 return closed_by_user_gesture_;
3923}
3924
[email protected]b172aee2012-04-10 17:05:263925int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273926 return minimum_zoom_percent_;
3927}
3928
[email protected]b172aee2012-04-10 17:05:263929int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273930 return maximum_zoom_percent_;
3931}
3932
mcnee432e47d2015-11-09 19:37:463933void WebContentsImpl::SetPageScale(float page_scale_factor) {
Lukasz Anforowiczf4357ca2017-09-07 01:43:323934 GetRenderViewHost()->Send(new ViewMsg_SetPageScale(
3935 GetRenderViewHost()->GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:243936}
3937
[email protected]b172aee2012-04-10 17:05:263938gfx::Size WebContentsImpl::GetPreferredSize() const {
Francois Doray24fc62c2017-12-11 17:27:333939 return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_;
[email protected]bcd2815602012-01-14 18:17:233940}
3941
[email protected]b172aee2012-04-10 17:05:263942bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
lfgf0cd46e2017-01-04 00:05:233943 if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) &&
3944 GetBrowserPluginGuest())
[email protected]660f18e2014-05-15 20:53:053945 return GetBrowserPluginGuest()->LockMouse(allowed);
3946
lfgf0cd46e2017-01-04 00:05:233947 if (mouse_lock_widget_) {
3948 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
3949 return mouse_lock_widget_->delegate()
3950 ->GetAsWebContents()
3951 ->GotResponseToLockMouseRequest(allowed);
3952 }
lfgad8244352016-07-13 16:55:513953
lfgf0cd46e2017-01-04 00:05:233954 if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3955 return true;
3956 }
3957
3958 for (WebContentsImpl* current = this; current;
3959 current = current->GetOuterWebContents()) {
3960 current->mouse_lock_widget_ = nullptr;
3961 }
3962
lfgbee1e0a2016-06-08 21:24:213963 return false;
[email protected]0bfbf882011-12-22 18:19:273964}
3965
Joe Downing13dd76b2018-04-09 18:32:153966bool WebContentsImpl::GotResponseToKeyboardLockRequest(bool allowed) {
3967 if (!keyboard_lock_widget_)
3968 return false;
3969
3970 if (keyboard_lock_widget_->delegate()->GetAsWebContents() != this) {
3971 NOTREACHED();
3972 return false;
3973 }
3974
3975 // KeyboardLock is only supported when called by the top-level browsing
3976 // context and is not supported in embedded content scenarios.
3977 if (GetOuterWebContents())
3978 return false;
3979
3980 keyboard_lock_widget_->GotResponseToKeyboardLockRequest(allowed);
3981 return true;
3982}
3983
[email protected]b172aee2012-04-10 17:05:263984bool WebContentsImpl::HasOpener() const {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283985 return GetOpener() != nullptr;
[email protected]a0358d72012-03-09 14:06:503986}
3987
lukasza6f8ac622017-06-06 03:10:203988RenderFrameHostImpl* WebContentsImpl::GetOpener() const {
alexmose201c7cd2015-06-10 17:14:213989 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
lukasza6f8ac622017-06-06 03:10:203990 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen55ff3502014-12-18 20:52:573991}
3992
jochen6004a362017-02-04 00:11:403993bool WebContentsImpl::HasOriginalOpener() const {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283994 return GetOriginalOpener() != nullptr;
jochen6004a362017-02-04 00:11:403995}
3996
lukasza6f8ac622017-06-06 03:10:203997RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() const {
jochen6004a362017-02-04 00:11:403998 FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener();
lukasza6f8ac622017-06-06 03:10:203999 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen6004a362017-02-04 00:11:404000}
4001
[email protected]cb805452013-05-22 15:16:214002void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
Joel Hockey85b379d2017-12-11 10:42:134003 color_chooser_->DidChooseColorInColorChooser(color);
[email protected]da8543762012-03-20 08:52:204004}
4005
[email protected]cb805452013-05-22 15:16:214006void WebContentsImpl::DidEndColorChooser() {
Joel Hockey85b379d2017-12-11 10:42:134007 color_chooser_.reset();
[email protected]da8543762012-03-20 08:52:204008}
4009
halton.huoca2eabd2015-07-06 08:17:404010int WebContentsImpl::DownloadImage(
4011 const GURL& url,
4012 bool is_favicon,
4013 uint32_t max_bitmap_size,
4014 bool bypass_cache,
Avi Drissmana5a52dd2018-03-27 03:39:024015 WebContents::ImageDownloadCallback callback) {
amistry9f01b772015-07-29 01:54:554016 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:404017 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:064018 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:404019 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:554020 const int download_id = ++next_image_download_id;
4021 if (!mojo_image_downloader) {
4022 // If the renderer process is dead (i.e. crash, or memory pressure on
4023 // Android), the downloader service will be invalid. Pre-Mojo, this would
Avi Drissmana5a52dd2018-03-27 03:39:024024 // hang the callback indefinitely since the IPC would be dropped. Now,
amistry9f01b772015-07-29 01:54:554025 // respond with a 400 HTTP error code to indicate that something went wrong.
4026 BrowserThread::PostTask(
4027 BrowserThread::UI, FROM_HERE,
tzike2aca992017-09-05 08:50:544028 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:024029 weak_factory_.GetWeakPtr(), std::move(callback),
4030 download_id, url, 400, std::vector<SkBitmap>(),
4031 std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:554032 return download_id;
4033 }
4034
halton.huoca2eabd2015-07-06 08:17:404035 mojo_image_downloader->DownloadImage(
sammcf6f4fcf2016-06-21 05:39:394036 url, is_favicon, max_bitmap_size, bypass_cache,
tzike2aca992017-09-05 08:50:544037 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:024038 weak_factory_.GetWeakPtr(), std::move(callback),
4039 download_id, url));
amistry9f01b772015-07-29 01:54:554040 return download_id;
[email protected]795c28972012-12-06 06:13:394041}
4042
[email protected]36ec24f2014-01-09 00:32:084043void WebContentsImpl::Find(int request_id,
4044 const base::string16& search_text,
4045 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:334046 // Cowardly refuse to search for no text.
4047 if (search_text.empty()) {
4048 NOTREACHED();
4049 return;
4050 }
4051
paulmeyerc0b762b2016-04-13 11:55:174052 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:084053}
4054
4055void WebContentsImpl::StopFinding(StopFindAction action) {
paulmeyerfeafc2d2017-04-25 21:46:404056 if (FindRequestManager* manager = GetFindRequestManager())
4057 manager->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:084058}
4059
Tommy Steimel18360512017-11-01 00:38:194060bool WebContentsImpl::WasEverAudible() {
4061 return was_ever_audible_;
4062}
4063
Avi Drissmana5a52dd2018-03-27 03:39:024064void WebContentsImpl::GetManifest(GetManifestCallback callback) {
4065 manifest_manager_host_->GetManifest(std::move(callback));
mlamouriefdca9d2014-09-16 16:55:404066}
4067
bokanece34a82016-01-28 19:49:464068void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:534069 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:434070 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:464071 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:534072}
4073
mariakhomenko44bdc4732015-04-29 01:55:384074void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:374075 if (delayed_open_url_params_.get()) {
4076 OpenURL(*delayed_open_url_params_.get());
4077 delayed_open_url_params_.reset(nullptr);
4078 return;
4079 }
4080
mariakhomenko44bdc4732015-04-29 01:55:384081 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
4082 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:164083 if (is_resume_pending_) {
4084 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:134085 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:164086 GetMainFrame()->Init();
4087 }
mariakhomenko44bdc4732015-04-29 01:55:384088}
4089
[email protected]b172aee2012-04-10 17:05:264090bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:264091 // When the browser is started with about:blank as the startup URL, focus
4092 // the location bar (which will also select its contents) so people can
4093 // simply begin typing to navigate elsewhere.
4094 //
4095 // We need to be careful not to trigger this for anything other than the
4096 // startup navigation. In particular, if we allow an attacker to open a
4097 // popup to about:blank, then navigate, focusing the Omnibox will cause the
4098 // end of the new URL to be scrolled into view instead of the start,
4099 // allowing the attacker to spoof other URLs. The conditions checked here
4100 // are all aimed at ensuring no such attacker-controlled navigation can
4101 // trigger this.
4102 //
4103 // Note that we check the pending entry instead of the visible one; for the
4104 // startup URL case these are the same, but for the attacker-controlled
4105 // navigation case the visible entry is the committed "about:blank" URL and
4106 // the pending entry is the problematic navigation elsewhere.
4107 NavigationEntryImpl* entry = controller_.GetPendingEntry();
4108 if (controller_.IsInitialNavigation() && entry &&
4109 !entry->is_renderer_initiated() &&
csharrisona3bd0b32016-10-19 18:40:484110 entry->GetURL() == url::kAboutBlankURL) {
[email protected]0c9406632013-02-08 01:13:334111 return true;
palmerc70cb1f2016-03-04 23:41:264112 }
[email protected]0c9406632013-02-08 01:13:334113 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:274114}
4115
[email protected]b172aee2012-04-10 17:05:264116void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:274117 if (delegate_)
4118 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:214119}
4120
clamy0e119882015-07-31 16:12:334121void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484122 TRACE_EVENT1("navigation", "WebContentsImpl::DidStartNavigation",
4123 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094124 for (auto& observer : observers_)
4125 observer.DidStartNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:334126}
4127
4128void WebContentsImpl::DidRedirectNavigation(
4129 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484130 TRACE_EVENT1("navigation", "WebContentsImpl::DidRedirectNavigation",
4131 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094132 for (auto& observer : observers_)
4133 observer.DidRedirectNavigation(navigation_handle);
jam5f358e52017-02-13 16:37:034134
4135 // Notify accessibility if this is a reload. This has to called on the
4136 // BrowserAccessibilityManager associated with the old RFHI.
4137 if (navigation_handle->GetReloadType() != ReloadType::NONE) {
4138 NavigationHandleImpl* nhi =
4139 static_cast<NavigationHandleImpl*>(navigation_handle);
4140 BrowserAccessibilityManager* manager =
4141 nhi->frame_tree_node()
4142 ->current_frame_host()
4143 ->browser_accessibility_manager();
4144 if (manager)
4145 manager->UserIsReloading();
4146 }
clamy0e119882015-07-31 16:12:334147}
4148
clamyefca29e2015-09-17 00:22:114149void WebContentsImpl::ReadyToCommitNavigation(
4150 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484151 TRACE_EVENT1("navigation", "WebContentsImpl::ReadyToCommitNavigation",
4152 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094153 for (auto& observer : observers_)
4154 observer.ReadyToCommitNavigation(navigation_handle);
John Abd-El-Malekd4882642017-12-04 21:45:194155
Kenneth Russell954ed9ce2018-04-12 23:07:014156 // If any domains are blocked from accessing 3D APIs because they may
4157 // have caused the GPU to reset recently, unblock them here if the user
4158 // initiated this navigation. This implies that the user was involved in
4159 // the decision to navigate, so there's no concern about
4160 // denial-of-service issues. Want to do this as early as
4161 // possible to avoid race conditions with pages attempting to access
4162 // WebGL early on.
4163 //
4164 // TODO(crbug.com/617904): currently navigations initiated by the browser
4165 // (reload button, reload menu option, pressing return in the Omnibox)
4166 // return false from HasUserGesture(). If or when that is addressed,
4167 // remove the check for IsRendererInitiated() below.
4168 //
4169 // TODO(crbug.com/832180): HasUserGesture comes from the renderer
4170 // process and isn't validated. Until it is, don't trust it.
4171 if (!navigation_handle->IsRendererInitiated()) {
4172 GpuDataManagerImpl::GetInstance()->UnblockDomainFrom3DAPIs(
4173 navigation_handle->GetURL());
4174 }
4175
John Abd-El-Malekfde08e6da2017-12-05 04:06:244176 if (navigation_handle->IsSameDocument())
4177 return;
4178
John Abd-El-Malekd4882642017-12-04 21:45:194179 controller_.ssl_manager()->DidStartResourceResponse(
4180 navigation_handle->GetURL(),
4181 net::IsCertStatusError(navigation_handle->GetSSLInfo().cert_status));
John Abd-El-Malekfde08e6da2017-12-05 04:06:244182
4183 SetNotWaitingForResponse();
clamyefca29e2015-09-17 00:22:114184}
4185
clamy0e119882015-07-31 16:12:334186void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484187 TRACE_EVENT1("navigation", "WebContentsImpl::DidFinishNavigation",
4188 "navigation_handle", navigation_handle);
Steven Holte38041342018-06-22 22:00:574189
ericwilligersde386342016-10-19 02:35:094190 for (auto& observer : observers_)
4191 observer.DidFinishNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:334192
jam5f358e52017-02-13 16:37:034193 if (navigation_handle->HasCommitted()) {
dmazzonibf8cec42015-02-08 08:28:084194 BrowserAccessibilityManager* manager =
jam5f358e52017-02-13 16:37:034195 static_cast<RenderFrameHostImpl*>(
4196 navigation_handle->GetRenderFrameHost())
4197 ->browser_accessibility_manager();
4198 if (manager) {
4199 if (navigation_handle->IsErrorPage()) {
4200 manager->NavigationFailed();
4201 } else {
4202 manager->NavigationSucceeded();
4203 }
4204 }
Tommy Steimel18360512017-11-01 00:38:194205
4206 if (navigation_handle->IsInMainFrame() &&
4207 !navigation_handle->IsSameDocument()) {
4208 was_ever_audible_ = false;
Steven Holte38041342018-06-22 22:00:574209 last_committed_source_id_ =
4210 ukm::ConvertToSourceId(navigation_handle->GetNavigationId(),
4211 ukm::SourceIdType::NAVIGATION_ID);
Tommy Steimel18360512017-11-01 00:38:194212 }
dmazzonibf8cec42015-02-08 08:28:084213 }
[email protected]400992b2012-06-14 00:03:544214}
4215
[email protected]b80624c2014-02-09 02:46:554216void WebContentsImpl::DidFailLoadWithError(
4217 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:554218 const GURL& url,
[email protected]b80624c2014-02-09 02:46:554219 int error_code,
Yutaka Hirano16d3c5d2017-07-31 06:17:304220 const base::string16& error_description) {
ericwilligersde386342016-10-19 02:35:094221 for (auto& observer : observers_) {
Yutaka Hirano16d3c5d2017-07-31 06:17:304222 observer.DidFailLoad(render_frame_host, url, error_code, error_description);
ericwilligersde386342016-10-19 02:35:094223 }
[email protected]b80624c2014-02-09 02:46:554224}
4225
[email protected]52913802013-12-10 05:52:184226void WebContentsImpl::NotifyChangedNavigationState(
4227 InvalidateTypes changed_flags) {
4228 NotifyNavigationStateChanged(changed_flags);
4229}
4230
toyoshim0df1d3a2016-09-09 09:52:484231void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
4232 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:204233 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094234 for (auto& observer : observers_)
4235 observer.DidStartNavigationToPendingEntry(url, reload_type);
[email protected]3691e5cf2014-01-22 10:16:204236}
4237
lukasza1d025732016-09-28 21:36:084238bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:224239 if (!delegate_)
4240 return true;
lukasza1d025732016-09-28 21:36:084241 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:224242}
4243
[email protected]aa62afd2014-04-22 19:22:464244bool WebContentsImpl::ShouldPreserveAbortedURLs() {
4245 if (!delegate_)
4246 return false;
4247 return delegate_->ShouldPreserveAbortedURLs(this);
4248}
4249
[email protected]0d0f4c492014-04-02 06:42:574250void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:234251 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:574252 // Ensure fullscreen mode is exited before committing the navigation to a
4253 // different page. The next page will not start out assuming it is in
4254 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:234255 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:194256 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:574257 return;
4258 }
alexmos5dd617d2016-06-07 04:21:154259 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464260 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:154261 DCHECK(!IsFullscreenForCurrentTab());
Joe Downingc1a57efe2018-05-09 18:23:544262
4263 // Clean up keyboard lock state when navigating.
4264 CancelKeyboardLock(keyboard_lock_widget_);
[email protected]0d0f4c492014-04-02 06:42:574265}
4266
[email protected]37567b432014-02-12 01:12:224267void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:284268 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:224269 const LoadCommittedDetails& details,
4270 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
4271 if (details.is_navigation_to_different_page()) {
4272 // Clear the status bubble. This is a workaround for a bug where WebKit
4273 // doesn't let us know that the cursor left an element during a
4274 // transition (this is also why the mouse cursor remains as a hand after
4275 // clicking on a link); see bugs 1184641 and 980803. We don't want to
4276 // clear the bubble when a user navigates to a named anchor in the same
4277 // page.
Lukasz Anforowiczfd707142018-02-07 19:46:134278 ClearTargetURL();
lanwei9d343ad22015-02-11 01:46:004279
4280 RenderWidgetHostViewBase* rwhvb =
4281 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
4282 if (rwhvb)
4283 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:284284
peter90afaba2015-06-01 12:05:294285 did_first_visually_non_empty_paint_ = false;
4286
yusufod41c5f92015-03-06 00:14:284287 // Reset theme color on navigation to new page.
4288 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:224289 }
4290
[email protected]e85165c642014-06-10 14:34:314291 if (delegate_)
[email protected]37567b432014-02-12 01:12:224292 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:314293 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:224294}
4295
4296void WebContentsImpl::DidNavigateAnyFramePostCommit(
4297 RenderFrameHostImpl* render_frame_host,
4298 const LoadCommittedDetails& details,
4299 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:104300 // Now that something has committed, we don't need to track whether the
4301 // initial page has been accessed.
4302 has_accessed_initial_document_ = false;
4303
[email protected]37567b432014-02-12 01:12:224304 // If we navigate off the page, close all JavaScript dialogs.
eugenebutee08663a2017-04-27 17:43:124305 if (!details.is_same_document)
creis89a0f782015-05-27 16:13:174306 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:224307
avid53461d2016-02-25 17:15:044308 // If this is a user-initiated navigation, start allowing JavaScript dialogs
4309 // again.
avi5d3b8692016-10-12 22:00:464310 if (params.gesture == NavigationGestureUser && dialog_manager_) {
avi6879fcf2017-01-21 05:27:534311 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:464312 }
[email protected]37567b432014-02-12 01:12:224313}
4314
4315void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
4316 contents_mime_type_ = mime_type;
4317}
4318
[email protected]277857a2014-06-03 10:38:014319bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:314320 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:054321 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:314322 return false;
4323
[email protected]37567b432014-02-12 01:12:224324 if (delegate_)
4325 return delegate_->CanOverscrollContent();
4326
4327 return false;
4328}
4329
nicka0ac8382016-12-15 23:59:234330void WebContentsImpl::OnThemeColorChanged(RenderFrameHostImpl* source,
4331 SkColor theme_color) {
4332 if (source != GetMainFrame()) {
4333 // Only the main frame may control the theme.
4334 return;
4335 }
4336
peter90afaba2015-06-01 12:05:294337 // Update the theme color. This is to be published to observers after the
4338 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:284339 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:294340
4341 if (did_first_visually_non_empty_paint_ &&
4342 last_sent_theme_color_ != theme_color_) {
ericwilligersde386342016-10-19 02:35:094343 for (auto& observer : observers_)
4344 observer.DidChangeThemeColor(theme_color_);
peter90afaba2015-06-01 12:05:294345 last_sent_theme_color_ = theme_color_;
4346 }
[email protected]e7104762014-06-20 19:17:254347}
4348
[email protected]b172aee2012-04-10 17:05:264349void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
nicka0ac8382016-12-15 23:59:234350 RenderFrameHostImpl* source,
[email protected]724159a2010-12-30 01:11:184351 const GURL& url,
[email protected]70435962011-08-02 20:13:284352 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:184353 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:404354 ResourceType resource_type) {
ericwilligersde386342016-10-19 02:35:094355 for (auto& observer : observers_)
4356 observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type);
[email protected]b0f724c2013-09-05 04:21:134357
[email protected]8bfc8272013-09-09 20:10:534358 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
nicka0ac8382016-12-15 23:59:234359 StoragePartition* partition = source->GetProcess()->GetStoragePartition();
[email protected]8bfc8272013-09-09 20:10:534360 scoped_refptr<net::URLRequestContextGetter> request_context(
nicka0ac8382016-12-15 23:59:234361 resource_type == RESOURCE_TYPE_MEDIA
4362 ? partition->GetMediaURLRequestContext()
4363 : partition->GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:534364 BrowserThread::PostTask(
nicka0ac8382016-12-15 23:59:234365 BrowserThread::IO, FROM_HERE,
tzike2aca992017-09-05 08:50:544366 base::BindOnce(&NotifyCacheOnIO, request_context, url, http_method));
[email protected]8bfc8272013-09-09 20:10:534367 }
[email protected]724159a2010-12-30 01:11:184368}
4369
nicka0ac8382016-12-15 23:59:234370void WebContentsImpl::OnDidDisplayInsecureContent(RenderFrameHostImpl* source) {
4371 // Any frame can trigger display of insecure content, so we don't check
4372 // |source| here.
carloskd9d97942017-02-16 08:58:094373 DidDisplayInsecureContent();
4374}
4375
4376void WebContentsImpl::DidDisplayInsecureContent() {
estarkc2273502016-10-12 22:03:024377 controller_.ssl_manager()->DidDisplayMixedContent();
[email protected]724159a2010-12-30 01:11:184378}
4379
elawrenceb2ac2a232017-03-27 21:46:254380void WebContentsImpl::OnDidContainInsecureFormAction(
4381 RenderFrameHostImpl* source) {
4382 controller_.ssl_manager()->DidContainInsecureFormAction();
4383}
4384
nicka0ac8382016-12-15 23:59:234385void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source,
4386 const GURL& security_origin,
estark910b4572015-12-09 20:55:414387 const GURL& target_url) {
nicka0ac8382016-12-15 23:59:234388 // TODO(nick, estark): Should we call FilterURL using |source|'s process on
4389 // these parameters? |target_url| seems unused, except for a log message. And
4390 // |security_origin| might be replaceable with the origin of the main frame.
carloskd9d97942017-02-16 08:58:094391 DidRunInsecureContent(security_origin, target_url);
4392}
4393
4394void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin,
4395 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:584396 LOG(WARNING) << security_origin << " ran insecure content from "
4397 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:394398 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:414399 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:294400 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:394401 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
estarkc2273502016-10-12 22:03:024402 controller_.ssl_manager()->DidRunMixedContent(security_origin);
[email protected]724159a2010-12-30 01:11:184403}
4404
carloskd9d97942017-02-16 08:58:094405void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364406 if (delegate_) {
4407 delegate_->PassiveInsecureContentFound(resource_url);
4408 }
carloskd9d97942017-02-16 08:58:094409}
4410
4411bool WebContentsImpl::ShouldAllowRunningInsecureContent(
4412 WebContents* web_contents,
4413 bool allowed_per_prefs,
4414 const url::Origin& origin,
4415 const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364416 if (delegate_) {
4417 return delegate_->ShouldAllowRunningInsecureContent(
4418 web_contents, allowed_per_prefs, origin, resource_url);
4419 }
4420
4421 return allowed_per_prefs;
carloskd9d97942017-02-16 08:58:094422}
4423
Lukasz Anforowicze1b954d92017-10-30 21:28:064424void WebContentsImpl::ViewSource(RenderFrameHostImpl* frame) {
4425 DCHECK_EQ(this, WebContents::FromRenderFrameHost(frame));
4426
4427 // Don't do anything if there is no |delegate_| that could accept and show the
4428 // new WebContents containing the view-source.
4429 if (!delegate_)
4430 return;
4431
4432 // Use the last committed entry, since the pending entry hasn't loaded yet and
4433 // won't be copied into the cloned tab.
4434 NavigationEntryImpl* last_committed_entry =
4435 static_cast<NavigationEntryImpl*>(frame->frame_tree_node()
4436 ->navigator()
4437 ->GetController()
4438 ->GetLastCommittedEntry());
4439 if (!last_committed_entry)
4440 return;
4441
4442 FrameNavigationEntry* frame_entry =
4443 last_committed_entry->GetFrameEntry(frame->frame_tree_node());
4444 if (!frame_entry)
4445 return;
4446
4447 // Any new WebContents opened while this WebContents is in fullscreen can be
4448 // used to confuse the user, so drop fullscreen.
4449 if (IsFullscreenForCurrentTab())
4450 ExitFullscreen(true);
4451
4452 // We intentionally don't share the SiteInstance with the original frame so
4453 // that view source has a consistent process model and always ends up in a new
4454 // process (https://crbug.com/699493).
4455 scoped_refptr<SiteInstanceImpl> site_instance_for_view_source = nullptr;
4456 // Referrer is not important, because view-source should not hit the network,
4457 // but should be served from the cache instead.
4458 Referrer referrer_for_view_source;
4459 // Do not restore title, derive it from the url.
4460 base::string16 title_for_view_source;
4461 auto navigation_entry = std::make_unique<NavigationEntryImpl>(
4462 site_instance_for_view_source, frame_entry->url(),
4463 referrer_for_view_source, title_for_view_source, ui::PAGE_TRANSITION_LINK,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:094464 /* is_renderer_initiated = */ false,
4465 /* blob_url_loader_factory = */ nullptr);
Lukasz Anforowicze1b954d92017-10-30 21:28:064466 navigation_entry->SetVirtualURL(GURL(content::kViewSourceScheme +
4467 std::string(":") +
4468 frame_entry->url().spec()));
4469
4470 // Do not restore scroller position.
4471 // TODO(creis, lukasza, arthursonzogni): Do not reuse the original PageState,
4472 // but start from a new one and only copy the needed data.
4473 const PageState& new_page_state =
4474 frame_entry->page_state().RemoveScrollOffset();
4475
4476 scoped_refptr<FrameNavigationEntry> new_frame_entry =
4477 navigation_entry->root_node()->frame_entry;
4478 new_frame_entry->set_method(frame_entry->method());
4479 new_frame_entry->SetPageState(new_page_state);
4480
4481 // Create a new WebContents, which is used to display the source code.
erikchenbee5c9622018-04-27 19:30:254482 std::unique_ptr<WebContents> view_source_contents =
Erik Chenbb8e738e2018-04-28 14:10:434483 Create(CreateParams(GetBrowserContext()));
Lukasz Anforowicze1b954d92017-10-30 21:28:064484
4485 // Restore the previously created NavigationEntry.
4486 std::vector<std::unique_ptr<NavigationEntry>> navigation_entries;
4487 navigation_entries.push_back(std::move(navigation_entry));
4488 view_source_contents->GetController().Restore(0, RestoreType::CURRENT_SESSION,
4489 &navigation_entries);
4490
4491 // Add |view_source_contents| as a new tab.
4492 gfx::Rect initial_rect;
4493 constexpr bool kUserGesture = true;
4494 bool ignored_was_blocked;
erikchenbee5c9622018-04-27 19:30:254495 delegate_->AddNewContents(this, std::move(view_source_contents),
Lukasz Anforowicze1b954d92017-10-30 21:28:064496 WindowOpenDisposition::NEW_FOREGROUND_TAB,
4497 initial_rect, kUserGesture, &ignored_was_blocked);
4498 // Note that the |delegate_| could have deleted |view_source_contents| during
4499 // AddNewContents method call.
4500}
4501
Jay Civellid5904f02018-03-23 19:43:574502void WebContentsImpl::SubresourceResponseStarted(const GURL& url,
4503 net::CertStatus cert_status) {
4504 controller_.ssl_manager()->DidStartResourceResponse(url, cert_status);
4505 SetNotWaitingForResponse();
4506}
4507
Jay Civelli116683f2018-03-27 19:56:234508void WebContentsImpl::ResourceLoadComplete(
Jay Civelli52a63302018-04-30 22:39:554509 RenderFrameHost* render_frame_host,
Jay Civelli116683f2018-03-27 19:56:234510 mojom::ResourceLoadInfoPtr resource_load_info) {
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254511 for (auto& observer : observers_) {
Jay Civelli718fd6c02018-05-11 21:04:274512 observer.ResourceLoadComplete(render_frame_host, *resource_load_info);
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254513 }
John Abd-El-Malekd4882642017-12-04 21:45:194514}
4515
Wei Li5bb659742018-02-14 03:07:584516void WebContentsImpl::PrintCrossProcessSubframe(
4517 const gfx::Rect& rect,
4518 int document_cookie,
4519 RenderFrameHost* subframe_host) {
Wei Li5c0b4d12018-03-22 15:05:224520 auto* outer_contents = GetOuterWebContents();
4521 if (outer_contents) {
4522 // When an extension or app page is printed, the content should be
4523 // composited with outer content, so the outer contents should handle the
4524 // print request.
4525 outer_contents->PrintCrossProcessSubframe(rect, document_cookie,
4526 subframe_host);
4527 return;
4528 }
4529
Wei Li5bb659742018-02-14 03:07:584530 // If there is no delegate such as in tests or during deletion, do nothing.
4531 if (!delegate_)
4532 return;
4533
4534 delegate_->PrintCrossProcessSubframe(this, rect, document_cookie,
4535 subframe_host);
4536}
4537
rob.buis300b0872017-03-10 20:43:584538#if defined(OS_ANDROID)
4539base::android::ScopedJavaLocalRef<jobject>
4540WebContentsImpl::GetJavaRenderFrameHostDelegate() {
4541 return GetJavaWebContents();
4542}
4543#endif
4544
estark910b4572015-12-09 20:55:414545void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004546 RenderFrameHostImpl* source) {
estarkc2273502016-10-12 22:03:024547 controller_.ssl_manager()->DidDisplayContentWithCertErrors();
estark910b4572015-12-09 20:55:414548}
4549
4550void WebContentsImpl::OnDidRunContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004551 RenderFrameHostImpl* source) {
nicka0ac8382016-12-15 23:59:234552 // TODO(nick, estark): Do we need to consider |source| here somehow?
estarkcd2e30c2016-08-12 06:51:154553 NavigationEntry* entry = controller_.GetVisibleEntry();
4554 if (!entry)
estarkaeda1422016-05-10 02:31:124555 return;
4556
estarkaeda1422016-05-10 02:31:124557 // TODO(estark): check that this does something reasonable for
4558 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:154559 controller_.ssl_manager()->DidRunContentWithCertErrors(
4560 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:414561}
4562
nicka0ac8382016-12-15 23:59:234563void WebContentsImpl::OnDocumentLoadedInFrame(RenderFrameHostImpl* source) {
ericwilligersde386342016-10-19 02:35:094564 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:234565 observer.DocumentLoadedInFrame(source);
[email protected]724159a2010-12-30 01:11:184566}
4567
nicka0ac8382016-12-15 23:59:234568void WebContentsImpl::OnDidFinishLoad(RenderFrameHostImpl* source,
4569 const GURL& url) {
[email protected]8b3af1e2014-01-24 13:29:124570 GURL validated_url(url);
nicka0ac8382016-12-15 23:59:234571 source->GetProcess()->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:374572
ericwilligersde386342016-10-19 02:35:094573 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:234574 observer.DidFinishLoad(source, validated_url);
[email protected]1a55c5be2011-11-29 11:36:314575}
4576
nicka0ac8382016-12-15 23:59:234577void WebContentsImpl::OnGoToEntryAtOffset(RenderViewHostImpl* source,
4578 int offset) {
4579 // All frames are allowed to navigate the global history.
avi6ddfcae2015-06-30 15:50:574580 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
4581 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:264582}
4583
nicka0ac8382016-12-15 23:59:234584void WebContentsImpl::OnUpdateZoomLimits(RenderViewHostImpl* source,
4585 int minimum_percent,
[email protected]fce823222014-05-30 16:24:304586 int maximum_percent) {
[email protected]216813952011-05-19 22:21:264587 minimum_zoom_percent_ = minimum_percent;
4588 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:264589}
4590
nicka0ac8382016-12-15 23:59:234591void WebContentsImpl::OnPageScaleFactorChanged(RenderViewHostImpl* source,
4592 float page_scale_factor) {
mcnee336ea2c2017-05-23 22:50:594593#if !defined(OS_ANDROID)
4594 // While page scale factor is used on mobile, this PageScaleFactorIsOne logic
4595 // is only needed on desktop.
mcnee432e47d2015-11-09 19:37:464596 bool is_one = page_scale_factor == 1.f;
4597 if (is_one != page_scale_factor_is_one_) {
4598 page_scale_factor_is_one_ = is_one;
4599
4600 HostZoomMapImpl* host_zoom_map =
4601 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
4602
nicka0ac8382016-12-15 23:59:234603 if (host_zoom_map) {
mcnee432e47d2015-11-09 19:37:464604 host_zoom_map->SetPageScaleFactorIsOneForView(
nicka0ac8382016-12-15 23:59:234605 source->GetProcess()->GetID(), source->GetRoutingID(),
mcnee432e47d2015-11-09 19:37:464606 page_scale_factor_is_one_);
4607 }
4608 }
mcnee336ea2c2017-05-23 22:50:594609#endif // !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:464610
ericwilligersde386342016-10-19 02:35:094611 for (auto& observer : observers_)
4612 observer.OnPageScaleFactorChanged(page_scale_factor);
mcnee432e47d2015-11-09 19:37:464613}
4614
nicka0ac8382016-12-15 23:59:234615void WebContentsImpl::OnEnumerateDirectory(RenderViewHostImpl* source,
4616 int request_id,
[email protected]2dec8ec2013-02-07 19:20:344617 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:434618 if (!delegate_)
4619 return;
4620
[email protected]b9535422012-02-09 01:47:594621 ChildProcessSecurityPolicyImpl* policy =
4622 ChildProcessSecurityPolicyImpl::GetInstance();
nicka0ac8382016-12-15 23:59:234623 if (policy->CanReadFile(source->GetProcess()->GetID(), path)) {
4624 // TODO(nick): |this| param in the call below ought to be a RenderFrameHost.
[email protected]b9535422012-02-09 01:47:594625 delegate_->EnumerateDirectory(this, request_id, path);
nicka0ac8382016-12-15 23:59:234626 }
[email protected]3a29a6e2011-08-24 18:26:214627}
4628
nicka0ac8382016-12-15 23:59:234629void WebContentsImpl::OnRegisterProtocolHandler(RenderFrameHostImpl* source,
4630 const std::string& protocol,
[email protected]b172aee2012-04-10 17:05:264631 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:264632 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:364633 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234634 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4635 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]e5f2de02012-07-20 22:15:434636 if (!delegate_)
4637 return;
4638
[email protected]b9535422012-02-09 01:47:594639 ChildProcessSecurityPolicyImpl* policy =
4640 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:324641 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:594642 return;
[email protected]8f810632013-06-06 22:33:324643
[email protected]c125e532014-05-10 20:39:064644 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:204645}
4646
nicka0ac8382016-12-15 23:59:234647void WebContentsImpl::OnUnregisterProtocolHandler(RenderFrameHostImpl* source,
4648 const std::string& protocol,
[email protected]f5273e52014-07-14 16:30:204649 const GURL& url,
4650 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234651 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4652 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]f5273e52014-07-14 16:30:204653 if (!delegate_)
4654 return;
4655
4656 ChildProcessSecurityPolicyImpl* policy =
4657 ChildProcessSecurityPolicyImpl::GetInstance();
4658 if (policy->IsPseudoScheme(protocol))
4659 return;
4660
4661 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
4662}
4663
kouhei40f03cb2015-09-24 07:47:014664void WebContentsImpl::OnUpdatePageImportanceSignals(
nicka0ac8382016-12-15 23:59:234665 RenderFrameHostImpl* source,
kouhei40f03cb2015-09-24 07:47:014666 const PageImportanceSignals& signals) {
nicka0ac8382016-12-15 23:59:234667 // TODO(nick, kouhei): Fix this for oopifs; currently all frames' state gets
4668 // written to this one field.
kouhei40f03cb2015-09-24 07:47:014669 page_importance_signals_ = signals;
4670}
4671
nicka0ac8382016-12-15 23:59:234672void WebContentsImpl::OnFindReply(RenderFrameHostImpl* source,
4673 int request_id,
[email protected]b172aee2012-04-10 17:05:264674 int number_of_matches,
4675 const gfx::Rect& selection_rect,
4676 int active_match_ordinal,
4677 bool final_update) {
paulmeyerfeafc2d2017-04-25 21:46:404678 if (active_match_ordinal > 0)
4679 SetFocusedFrame(source->frame_tree_node(), source->GetSiteInstance());
4680
paulmeyerc0b762b2016-04-13 11:55:174681 // Forward the find reply to the FindRequestManager, along with the
4682 // RenderFrameHost associated with the frame that the reply came from.
nicka0ac8382016-12-15 23:59:234683 GetOrCreateFindRequestManager()->OnFindReply(
4684 source, request_id, number_of_matches, selection_rect,
4685 active_match_ordinal, final_update);
[email protected]b888919c2011-09-02 00:32:164686}
4687
mfomitchev2b8b066a2016-01-28 19:23:154688#if defined(OS_ANDROID)
[email protected]1ff427972013-02-07 21:14:074689void WebContentsImpl::OnOpenDateTimeDialog(
nicka0ac8382016-12-15 23:59:234690 RenderViewHostImpl* source,
[email protected]1ff427972013-02-07 21:14:074691 const ViewHostMsg_DateTimeDialogValue_Params& value) {
nicka0ac8382016-12-15 23:59:234692 date_time_chooser_->ShowDialog(
4693 GetTopLevelNativeWindow(), source, value.dialog_type, value.dialog_value,
4694 value.minimum, value.maximum, value.step, value.suggestions);
[email protected]583418cc2013-01-17 14:01:104695}
[email protected]59363fc92012-09-05 03:46:314696#endif
4697
nicka0ac8382016-12-15 23:59:234698void WebContentsImpl::OnDomOperationResponse(RenderFrameHostImpl* source,
4699 const std::string& json_string) {
4700 // TODO(nick, lukasza): The notification below should probably be updated to
4701 // include |source|.
avi60bd4902015-09-23 20:39:244702 std::string json = json_string;
4703 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
4704 Source<WebContents>(this),
4705 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:404706}
4707
nicka0ac8382016-12-15 23:59:234708void WebContentsImpl::OnAppCacheAccessed(RenderViewHostImpl* source,
4709 const GURL& manifest_url,
[email protected]b172aee2012-04-10 17:05:264710 bool blocked_by_policy) {
nicka0ac8382016-12-15 23:59:234711 // TODO(nick): Should we consider |source| here? Should we call FilterURL on
4712 // |manifest_url|?
4713
[email protected]7fc4bbb2011-09-08 21:23:104714 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094715 for (auto& observer : observers_)
4716 observer.AppCacheAccessed(manifest_url, blocked_by_policy);
[email protected]7fc4bbb2011-09-08 21:23:104717}
4718
Joel Hockey85b379d2017-12-11 10:42:134719void WebContentsImpl::OnColorChooserFactoryRequest(
Joel Hockey163835a2017-12-20 11:51:574720 blink::mojom::ColorChooserFactoryRequest request) {
Joel Hockey85b379d2017-12-11 10:42:134721 color_chooser_factory_bindings_.AddBinding(this, std::move(request));
4722}
4723
4724void WebContentsImpl::OpenColorChooser(
Joel Hockey163835a2017-12-20 11:51:574725 blink::mojom::ColorChooserRequest chooser_request,
4726 blink::mojom::ColorChooserClientPtr client,
[email protected]8ed16472014-04-11 19:02:484727 SkColor color,
Joel Hockey163835a2017-12-20 11:51:574728 std::vector<blink::mojom::ColorSuggestionPtr> suggestions) {
Joel Hockey85b379d2017-12-11 10:42:134729 content::ColorChooser* new_color_chooser =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:284730 delegate_ ? delegate_->OpenColorChooser(this, color, suggestions)
4731 : nullptr;
[email protected]820957a2014-01-14 14:56:304732 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:214733 return;
[email protected]8ed16472014-04-11 19:02:484734
Joel Hockey85b379d2017-12-11 10:42:134735 color_chooser_.reset();
4736 color_chooser_ = std::make_unique<ColorChooser>(
4737 new_color_chooser, std::move(chooser_request), std::move(client));
[email protected]da8543762012-03-20 08:52:204738}
4739
brettw4b461082016-11-19 18:55:164740#if BUILDFLAG(ENABLE_PLUGINS)
nicka0ac8382016-12-15 23:59:234741void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source,
4742 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094743 for (auto& observer : observers_)
4744 observer.PepperInstanceCreated();
nicka0ac8382016-12-15 23:59:234745 pepper_playback_observer_->PepperInstanceCreated(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004746}
4747
nicka0ac8382016-12-15 23:59:234748void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source,
4749 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094750 for (auto& observer : observers_)
4751 observer.PepperInstanceDeleted();
nicka0ac8382016-12-15 23:59:234752 pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004753}
4754
nicka0ac8382016-12-15 23:59:234755void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source,
4756 int plugin_child_id,
tommyclie6633ca72014-10-31 00:40:424757 const base::FilePath& path,
4758 bool is_hung) {
4759 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
4760
ericwilligersde386342016-10-19 02:35:094761 for (auto& observer : observers_)
4762 observer.PluginHungStatusChanged(plugin_child_id, path, is_hung);
tommyclie6633ca72014-10-31 00:40:424763}
4764
nicka0ac8382016-12-15 23:59:234765void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source,
4766 int32_t pp_instance) {
4767 pepper_playback_observer_->PepperStartsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174768}
4769
nicka0ac8382016-12-15 23:59:234770void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source,
4771 int32_t pp_instance) {
4772 pepper_playback_observer_->PepperStopsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174773}
4774
nicka0ac8382016-12-15 23:59:234775void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source,
4776 const base::FilePath& plugin_path,
tommyclie6633ca72014-10-31 00:40:424777 base::ProcessId plugin_pid) {
nicka0ac8382016-12-15 23:59:234778 // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted,
4779 // and is only used by BlinkTestController.
ericwilligersde386342016-10-19 02:35:094780 for (auto& observer : observers_)
4781 observer.PluginCrashed(plugin_path, plugin_pid);
tommyclie6633ca72014-10-31 00:40:424782}
4783
[email protected]d8415ad92012-08-23 14:40:504784void WebContentsImpl::OnRequestPpapiBrokerPermission(
nicka0ac8382016-12-15 23:59:234785 RenderViewHostImpl* source,
4786 int ppb_broker_route_id,
[email protected]d8415ad92012-08-23 14:40:504787 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:344788 const base::FilePath& plugin_path) {
nicka0ac8382016-12-15 23:59:234789 base::Callback<void(bool)> permission_result_callback = base::Bind(
4790 &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this),
4791 source->GetProcess()->GetID(), ppb_broker_route_id);
[email protected]8c8fc292012-11-23 18:57:164792 if (!delegate_) {
Tommy Nyquist4b749d02018-03-20 21:46:294793 std::move(permission_result_callback).Run(false);
[email protected]8c8fc292012-11-23 18:57:164794 return;
[email protected]d8415ad92012-08-23 14:40:504795 }
4796
nicka0ac8382016-12-15 23:59:234797 if (!delegate_->RequestPpapiBrokerPermission(this, url, plugin_path,
4798 permission_result_callback)) {
[email protected]8c8fc292012-11-23 18:57:164799 NOTIMPLEMENTED();
Tommy Nyquist4b749d02018-03-20 21:46:294800 std::move(permission_result_callback).Run(false);
[email protected]8c8fc292012-11-23 18:57:164801 }
[email protected]d8415ad92012-08-23 14:40:504802}
4803
nicka0ac8382016-12-15 23:59:234804void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id,
4805 int ppb_broker_route_id,
4806 bool result) {
4807 RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
4808 if (rph) {
4809 // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it
4810 // is not routed to a RenderView.
4811 rph->Send(
4812 new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result));
4813 }
[email protected]d8415ad92012-08-23 14:40:504814}
4815
fsamuel833ee7c2015-02-13 23:40:404816void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
4817 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:394818 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:144819 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:404820 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:374821}
brettw4b461082016-11-19 18:55:164822#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:374823
[email protected]795c28972012-12-06 06:13:394824void WebContentsImpl::OnUpdateFaviconURL(
lukasza178ff092017-06-07 23:39:504825 RenderFrameHostImpl* source,
[email protected]795c28972012-12-06 06:13:394826 const std::vector<FaviconURL>& candidates) {
lukasza178ff092017-06-07 23:39:504827 // Ignore favicons for non-main frame.
4828 if (source->GetParent()) {
4829 NOTREACHED();
4830 return;
4831 }
4832
pkotwiczf9bc20592015-04-21 18:57:064833 // We get updated favicon URLs after the page stops loading. If a cross-site
4834 // navigation occurs while a page is still loading, the initial page
4835 // may stop loading and send us updated favicon URLs after the navigation
4836 // for the new page has committed.
lukasza178ff092017-06-07 23:39:504837 if (!source->IsCurrent())
pkotwiczf9bc20592015-04-21 18:57:064838 return;
4839
ericwilligersde386342016-10-19 02:35:094840 for (auto& observer : observers_)
4841 observer.DidUpdateFaviconURL(candidates);
[email protected]795c28972012-12-06 06:13:394842}
4843
qinmin72e8bd02016-10-21 19:35:374844void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) {
4845 is_overlay_content_ = is_overlay_content;
4846}
4847
nicka0ac8382016-12-15 23:59:234848void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(RenderViewHostImpl* source) {
4849 // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if
4850 // |source| is the main frame.
ericwilligersde386342016-10-19 02:35:094851 for (auto& observer : observers_)
4852 observer.DidFirstVisuallyNonEmptyPaint();
yusufod41c5f92015-03-06 00:14:284853
peter90afaba2015-06-01 12:05:294854 did_first_visually_non_empty_paint_ = true;
4855
yusufod41c5f92015-03-06 00:14:284856 if (theme_color_ != last_sent_theme_color_) {
4857 // Theme color should have updated by now if there was one.
ericwilligersde386342016-10-19 02:35:094858 for (auto& observer : observers_)
4859 observer.DidChangeThemeColor(theme_color_);
yusufod41c5f92015-03-06 00:14:284860 last_sent_theme_color_ = theme_color_;
4861 }
[email protected]9f268072013-11-07 00:02:154862}
[email protected]d9030b82013-07-19 08:26:064863
[email protected]17e286e2013-03-01 23:29:394864void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
ericwilligersde386342016-10-19 02:35:094865 for (auto& observer : observers_)
4866 observer.BeforeFormRepostWarningShow();
[email protected]17e286e2013-03-01 23:29:394867}
4868
[email protected]ec6c05f2013-10-23 18:41:574869void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
4870 Activate();
4871 if (delegate_)
4872 delegate_->ShowRepostFormWarningDialog(this);
4873}
4874
[email protected]b4c84012014-04-28 19:51:104875bool WebContentsImpl::HasAccessedInitialDocument() {
4876 return has_accessed_initial_document_;
4877}
4878
afakhry6f0c1ec22016-07-14 13:55:134879void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:264880 const base::string16& title) {
[email protected]fcf75d42013-12-03 20:11:264881 base::string16 final_title;
Avi Drissman93002212017-09-27 03:20:524882 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:324883
[email protected]987fc3a2011-05-26 14:18:094884 // If a page is created via window.open and never navigated,
4885 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:554886 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:094887 if (entry) {
[email protected]36fc0392011-12-25 03:59:514888 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:134889 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:324890
[email protected]36fc0392011-12-25 03:59:514891 entry->SetTitle(final_title);
Avi Drissman93002212017-09-27 03:20:524892
4893 // The title for display may differ from the title just set; grab it.
4894 final_title = entry->GetTitleForDisplay();
[email protected]987fc3a2011-05-26 14:18:094895 } else {
4896 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:134897 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:094898
4899 page_title_when_no_navigation_entry_ = final_title;
4900 }
[email protected]420ae012009-04-24 05:16:324901
[email protected]420ae012009-04-24 05:16:324902 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:234903 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:324904
ericwilligersde386342016-10-19 02:35:094905 for (auto& observer : observers_)
Avi Drissman93002212017-09-27 03:20:524906 observer.TitleWasSet(entry);
[email protected]66798902013-10-01 18:40:164907
afakhry6f0c1ec22016-07-14 13:55:134908 // Broadcast notifications when the UI should be updated.
4909 if (entry == controller_.GetEntryAtOffset(0))
4910 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:324911}
4912
fdegansa696e5112015-04-17 01:57:594913void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:004914 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:004915 if (delegate_)
fdegansa696e5112015-04-17 01:57:594916 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:004917}
4918
4919void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:344920 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:004921 loading_weak_factory_.InvalidateWeakPtrs();
4922 loading_last_progress_update_ = base::TimeTicks();
4923}
4924
clamy44e84ce2016-02-22 15:38:254925// Notifies the RenderWidgetHost instance about the fact that the page is
4926// loading, or done loading.
4927void WebContentsImpl::LoadingStateChanged(bool to_different_document,
4928 bool due_to_interstitial,
4929 LoadNotificationDetails* details) {
4930 // Do not send notifications about loading changes in the FrameTree while the
4931 // interstitial page is pausing the throbber.
creisadca9862017-06-16 19:12:114932 if (ShowingInterstitialPage() && interstitial_page_->pause_throbber() &&
clamy44e84ce2016-02-22 15:38:254933 !due_to_interstitial) {
4934 return;
4935 }
4936
4937 bool is_loading = IsLoading();
4938
4939 if (!is_loading) {
4940 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
4941 base::string16());
4942 load_state_host_.clear();
4943 upload_size_ = 0;
4944 upload_position_ = 0;
4945 }
4946
4947 GetRenderManager()->SetIsLoading(is_loading);
4948
4949 waiting_for_response_ = is_loading;
4950 is_load_to_different_document_ = to_different_document;
4951
4952 if (delegate_)
4953 delegate_->LoadingStateChanged(this, to_different_document);
4954 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
4955
4956 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
4957 if (is_loading) {
4958 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
4959 this, "URL", url, "Main FrameTreeNode id",
4960 GetFrameTree()->root()->frame_tree_node_id());
ericwilligersde386342016-10-19 02:35:094961 for (auto& observer : observers_)
4962 observer.DidStartLoading();
clamy44e84ce2016-02-22 15:38:254963 } else {
4964 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
4965 this, "URL", url);
ericwilligersde386342016-10-19 02:35:094966 for (auto& observer : observers_)
4967 observer.DidStopLoading();
clamy44e84ce2016-02-22 15:38:254968 }
4969
4970 // TODO(avi): Remove. http://crbug.com/170921
4971 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
4972 NotificationDetails det = NotificationService::NoDetails();
4973 if (details)
4974 det = Details<LoadNotificationDetails>(details);
4975 NotificationService::current()->Notify(
4976 type, Source<NavigationController>(&controller_), det);
4977}
4978
[email protected]02d7b6e2014-06-24 21:01:504979void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
4980 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:324981 // After sending out a swap notification, we need to send a disconnect
4982 // notification so that clients that pick up a pointer to |this| can NULL the
4983 // pointer. See Bug 1230284.
4984 notify_disconnection_ = true;
ericwilligersde386342016-10-19 02:35:094985 for (auto& observer : observers_)
4986 observer.RenderViewHostChanged(old_host, new_host);
[email protected]da7a7182013-09-06 08:11:114987
[email protected]7a846df2012-09-20 19:17:394988 // Ensure that the associated embedder gets cleared after a RenderViewHost
4989 // gets swapped, so we don't reuse the same embedder next time a
4990 // RenderViewHost is attached to this WebContents.
4991 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:324992}
4993
[email protected]02d7b6e2014-06-24 21:01:504994void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
Jinsuk Kim895b2c52018-07-03 06:49:164995 RenderFrameHost* new_host,
4996 bool is_main_frame) {
Bo Liu168c8642017-08-28 18:26:024997#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:504998 // Copy importance from |old_host| if |new_host| is a main frame.
4999 if (old_host && !new_host->GetParent()) {
Bo Liu7c6779e92017-08-16 02:02:285000 static_cast<RenderFrameHostImpl*>(new_host)
5001 ->GetRenderWidgetHost()
Bo Liu16dd7b8322018-05-02 21:19:505002 ->SetImportance(static_cast<RenderFrameHostImpl*>(old_host)
5003 ->GetRenderWidgetHost()
5004 ->importance());
Bo Liu7c6779e92017-08-16 02:02:285005 }
Bo Liu168c8642017-08-28 18:26:025006#endif
ericwilligersde386342016-10-19 02:35:095007 for (auto& observer : observers_)
5008 observer.RenderFrameHostChanged(old_host, new_host);
Jinsuk Kim895b2c52018-07-03 06:49:165009
5010 view_->RenderFrameSwappedIn(old_host, new_host, is_main_frame);
[email protected]02d7b6e2014-06-24 21:01:505011}
5012
[email protected]da7a7182013-09-06 08:11:115013// TODO(avi): Remove this entire function because this notification is already
5014// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:265015void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:325016 if (!notify_disconnection_)
5017 return;
5018
5019 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:215020 NotificationService::current()->Notify(
5021 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
5022 Source<WebContents>(this),
5023 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:325024}
5025
[email protected]cbb1ef592013-06-05 19:49:465026void WebContentsImpl::NotifyNavigationEntryCommitted(
5027 const LoadCommittedDetails& load_details) {
ericwilligersde386342016-10-19 02:35:095028 for (auto& observer : observers_)
5029 observer.NavigationEntryCommitted(load_details);
[email protected]cbb1ef592013-06-05 19:49:465030}
5031
Sam McNally5c087a32017-08-25 01:46:145032void WebContentsImpl::NotifyNavigationEntryChanged(
5033 const EntryChangedDetails& change_details) {
5034 for (auto& observer : observers_)
5035 observer.NavigationEntryChanged(change_details);
5036}
5037
5038void WebContentsImpl::NotifyNavigationListPruned(
5039 const PrunedDetails& pruned_details) {
5040 for (auto& observer : observers_)
5041 observer.NavigationListPruned(pruned_details);
5042}
5043
Christian Dullweber1af31e62018-02-22 11:49:485044void WebContentsImpl::NotifyNavigationEntriesDeleted() {
5045 for (auto& observer : observers_)
5046 observer.NavigationEntriesDeleted();
5047}
5048
rockotf62002a2016-09-15 00:08:595049void WebContentsImpl::OnAssociatedInterfaceRequest(
5050 RenderFrameHost* render_frame_host,
5051 const std::string& interface_name,
5052 mojo::ScopedInterfaceEndpointHandle handle) {
5053 auto it = binding_sets_.find(interface_name);
5054 if (it != binding_sets_.end())
5055 it->second->OnRequestForFrame(render_frame_host, std::move(handle));
5056}
5057
Ben Goodger9e24929e2017-07-21 03:13:405058void WebContentsImpl::OnInterfaceRequest(
5059 RenderFrameHost* render_frame_host,
5060 const std::string& interface_name,
5061 mojo::ScopedMessagePipeHandle* interface_pipe) {
Joel Hockey85b379d2017-12-11 10:42:135062 registry_.TryBindInterface(interface_name, interface_pipe);
Ben Goodger9e24929e2017-07-21 03:13:405063 for (auto& observer : observers_) {
5064 observer.OnInterfaceRequestFromFrame(render_frame_host, interface_name,
5065 interface_pipe);
5066 if (!interface_pipe->is_valid())
5067 break;
5068 }
5069}
5070
Nicolas Dossou-gbetebcab2472017-09-09 12:28:405071void WebContentsImpl::OnDidBlockFramebust(const GURL& url) {
5072 if (delegate_)
5073 delegate_->OnDidBlockFramebust(this, url);
5074}
5075
[email protected]c31a84802014-04-03 15:55:495076const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
5077 return GetLastCommittedURL();
5078}
5079
[email protected]b849847b2013-12-10 21:57:585080void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:095081 for (auto& observer : observers_)
5082 observer.RenderFrameCreated(render_frame_host);
dmazzonif8a31042016-12-03 00:52:135083 UpdateAccessibilityModeOnFrame(render_frame_host);
clamy91b7abf2016-03-24 15:17:455084
5085 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
5086 return;
5087
5088 NavigationEntry* entry = controller_.GetPendingEntry();
5089 if (entry && entry->IsViewSourceMode()) {
5090 // Put the renderer in view source mode.
5091 render_frame_host->Send(
5092 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
5093 }
[email protected]b849847b2013-12-10 21:57:585094}
5095
5096void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
creis3638897452017-05-09 22:07:505097 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095098 for (auto& observer : observers_)
5099 observer.RenderFrameDeleted(render_frame_host);
creis3638897452017-05-09 22:07:505100 is_notifying_observers_ = false;
zqzhang7b6f4f02016-12-07 22:10:225101#if BUILDFLAG(ENABLE_PLUGINS)
5102 pepper_playback_observer_->RenderFrameDeleted(render_frame_host);
5103#endif
Becca Hughesfd5d8f892018-06-14 18:23:365104
5105 // Remove any fullscreen state that the frame has stored.
5106 FullscreenStateChanged(render_frame_host, false /* is_fullscreen */);
[email protected]b849847b2013-12-10 21:57:585107}
5108
[email protected]a09d53ce2014-01-31 00:46:425109void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
5110 const ContextMenuParams& params) {
avie9fd8722017-04-10 16:17:585111 // If a renderer fires off a second command to show a context menu before the
5112 // first context menu is closed, just ignore it. https://crbug.com/707534
ekaramadf6750aa2017-06-06 18:29:425113 if (showing_context_menu_)
avie9fd8722017-04-10 16:17:585114 return;
5115
[email protected]077e704b2014-05-23 19:24:105116 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:425117 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:105118 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:425119 return;
5120
[email protected]077e704b2014-05-23 19:24:105121 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
5122 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:425123}
5124
avi777ff452017-02-09 19:04:485125void WebContentsImpl::RunJavaScriptDialog(RenderFrameHost* render_frame_host,
5126 const base::string16& message,
5127 const base::string16& default_prompt,
avi777ff452017-02-09 19:04:485128 JavaScriptDialogType dialog_type,
5129 IPC::Message* reply_msg) {
Avi Drissman2ccbb402018-03-20 21:11:365130 // Ensure that if showing a dialog is the first thing that a page does, that
5131 // the contents of the previous page aren't shown behind it. This is required
5132 // because showing a dialog freezes the renderer, so no frames will be coming
5133 // from it. https://crbug.com/823353
5134 auto* render_widget_host_impl =
5135 static_cast<RenderFrameHostImpl*>(render_frame_host)
5136 ->GetRenderWidgetHost();
5137 if (render_widget_host_impl)
5138 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5139
avi0720b02e2017-06-13 03:22:135140 // Running a dialog causes an exit to webpage-initiated fullscreen.
5141 // http://crbug.com/728276
5142 if (IsFullscreenForCurrentTab())
5143 ExitFullscreen(true);
5144
Avi Drissmane04d3992017-10-05 15:11:365145 auto callback =
5146 base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
5147 render_frame_host->GetProcess()->GetID(),
5148 render_frame_host->GetRoutingID(), reply_msg);
Pavel Feldman3c1842b2017-08-02 05:00:165149
Pavel Feldman3c1842b2017-08-02 05:00:165150 std::vector<protocol::PageHandler*> page_handlers =
5151 protocol::PageHandler::EnabledForWebContents(this);
5152
Pavel Feldmanfab3cb62017-10-05 01:02:015153 if (delegate_)
5154 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5155
5156 // Suppress JavaScript dialogs when requested. Also suppress messages when
5157 // showing an interstitial as it's shown over the previous page and we don't
5158 // want the hidden page's dialogs to interfere with the interstitial.
5159 bool should_suppress = ShowingInterstitialPage() ||
5160 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055161 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5162 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015163 bool suppress_this_message = should_suppress || !has_handlers;
5164
5165 if (suppress_this_message) {
Avi Drissmane04d3992017-10-05 15:11:365166 std::move(callback).Run(true, false, base::string16());
Pavel Feldman3c1842b2017-08-02 05:00:165167 return;
5168 }
5169
5170 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365171 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165172
5173 is_showing_javascript_dialog_ = true;
5174
5175 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365176 handler->DidRunJavaScriptDialog(
Avi Drissman2fefc4b2018-02-22 20:41:015177 render_frame_host->GetLastCommittedURL(), message, default_prompt,
Pavel Feldman1c587bc52018-04-04 21:16:055178 dialog_type, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365179 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165180 }
5181
5182 if (dialog_manager_) {
[email protected]87de04b02014-04-08 22:14:495183 dialog_manager_->RunJavaScriptDialog(
Avi Drissman2fefc4b2018-02-22 20:41:015184 this, render_frame_host, dialog_type, message, default_prompt,
Avi Drissmane04d3992017-10-05 15:11:365185 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false),
5186 &suppress_this_message);
[email protected]87de04b02014-04-08 22:14:495187 }
5188
5189 if (suppress_this_message) {
5190 // If we are suppressing messages, just reply as if the user immediately
5191 // pressed "Cancel", passing true to |dialog_was_suppressed|.
Avi Drissmane04d3992017-10-05 15:11:365192 wrapper->Run(true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:495193 }
[email protected]87de04b02014-04-08 22:14:495194}
5195
5196void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:015197 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:495198 bool is_reload,
5199 IPC::Message* reply_msg) {
Avi Drissman2ccbb402018-03-20 21:11:365200 // Ensure that if showing a dialog is the first thing that a page does, that
5201 // the contents of the previous page aren't shown behind it. This is required
5202 // because showing a dialog freezes the renderer, so no frames will be coming
5203 // from it. https://crbug.com/823353
5204 auto* render_widget_host_impl =
5205 static_cast<RenderFrameHostImpl*>(render_frame_host)
5206 ->GetRenderWidgetHost();
5207 if (render_widget_host_impl)
5208 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5209
avi0720b02e2017-06-13 03:22:135210 // Running a dialog causes an exit to webpage-initiated fullscreen.
5211 // http://crbug.com/728276
5212 if (IsFullscreenForCurrentTab())
5213 ExitFullscreen(true);
5214
[email protected]39f2f9252014-05-03 00:54:015215 RenderFrameHostImpl* rfhi =
5216 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:495217 if (delegate_)
5218 delegate_->WillRunBeforeUnloadConfirm();
5219
Avi Drissmane04d3992017-10-05 15:11:365220 auto callback =
5221 base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
5222 render_frame_host->GetProcess()->GetID(),
5223 render_frame_host->GetRoutingID(), reply_msg);
Pavel Feldman3c1842b2017-08-02 05:00:165224
Pavel Feldman3c1842b2017-08-02 05:00:165225 std::vector<protocol::PageHandler*> page_handlers =
5226 protocol::PageHandler::EnabledForWebContents(this);
5227
Pavel Feldmanfab3cb62017-10-05 01:02:015228 if (delegate_)
5229 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5230
5231 bool should_suppress = ShowingInterstitialPage() || !rfhi->is_active() ||
5232 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055233 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5234 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015235 if (should_suppress || !has_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365236 std::move(callback).Run(false, true, base::string16());
[email protected]87de04b02014-04-08 22:14:495237 return;
5238 }
5239
5240 is_showing_before_unload_dialog_ = true;
Pavel Feldman3c1842b2017-08-02 05:00:165241
5242 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365243 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165244
5245 GURL frame_url = rfhi->GetLastCommittedURL();
5246 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365247 handler->DidRunBeforeUnloadConfirm(
Pavel Feldman1c587bc52018-04-04 21:16:055248 frame_url, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365249 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165250 }
5251
5252 if (dialog_manager_) {
Avi Drissmane04d3992017-10-05 15:11:365253 dialog_manager_->RunBeforeUnloadDialog(
Avi Drissmanff9ed752017-11-28 21:18:125254 this, render_frame_host, is_reload,
Avi Drissmane04d3992017-10-05 15:11:365255 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165256 }
[email protected]87de04b02014-04-08 22:14:495257}
5258
naskoada75b22016-06-11 16:09:465259void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host,
5260 const FileChooserParams& params) {
5261 if (delegate_)
5262 delegate_->RunFileChooser(render_frame_host, params);
5263}
5264
[email protected]a86c0e962013-12-17 17:10:395265WebContents* WebContentsImpl::GetAsWebContents() {
5266 return this;
5267}
5268
mcnee336ea2c2017-05-23 22:50:595269#if !defined(OS_ANDROID)
akabac6bd1212018-06-25 20:10:485270double WebContentsImpl::GetPendingPageZoomLevel() const {
wjmaclean64951902016-04-29 20:59:125271 NavigationEntry* pending_entry = GetController().GetPendingEntry();
5272 if (!pending_entry)
5273 return HostZoomMap::GetZoomLevel(this);
5274
5275 GURL url = pending_entry->GetURL();
5276 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
5277 url.scheme(), net::GetHostOrSpecFromURL(url));
5278}
mcnee336ea2c2017-05-23 22:50:595279#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:125280
qinmin72e8bd02016-10-21 19:35:375281bool WebContentsImpl::HideDownloadUI() const {
5282 return is_overlay_content_;
5283}
5284
mlamouri5cd9ae82017-02-18 11:05:095285bool WebContentsImpl::HasPersistentVideo() const {
5286 return has_persistent_video_;
5287}
5288
Alex Moshchuk27caae82017-09-11 23:11:185289RenderFrameHost* WebContentsImpl::GetPendingMainFrame() {
clamy610c63b32017-12-22 15:05:185290 return GetRenderManager()->speculative_frame_host();
Alex Moshchuk27caae82017-09-11 23:11:185291}
5292
mlamourie52c1b542017-02-23 14:57:505293bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const {
5294 return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo();
5295}
5296
François Beaufortad6c5232018-02-26 11:00:445297bool WebContentsImpl::IsPictureInPictureAllowedForFullscreenVideo() const {
5298 return media_web_contents_observer_
5299 ->IsPictureInPictureAllowedForFullscreenVideo();
5300}
5301
ekaramada110f642016-12-21 19:47:285302bool WebContentsImpl::IsFocusedElementEditable() {
5303 RenderFrameHostImpl* frame = GetFocusedFrame();
5304 return frame && frame->has_focused_editable_element();
5305}
5306
ekaramadf6750aa2017-06-06 18:29:425307bool WebContentsImpl::IsShowingContextMenu() const {
5308 return showing_context_menu_;
5309}
5310
5311void WebContentsImpl::SetShowingContextMenu(bool showing) {
5312 DCHECK_NE(showing_context_menu_, showing);
5313 showing_context_menu_ = showing;
5314
5315 if (auto* view = GetRenderWidgetHostView()) {
5316 // Notify the main frame's RWHV to run the platform-specific code, if any.
5317 static_cast<RenderWidgetHostViewBase*>(view)->SetShowingContextMenu(
5318 showing);
5319 }
5320}
5321
ekaramada110f642016-12-21 19:47:285322void WebContentsImpl::ClearFocusedElement() {
5323 if (auto* frame = GetFocusedFrame())
5324 frame->ClearFocusedElement();
5325}
5326
[email protected]7912e822014-04-16 02:37:035327bool WebContentsImpl::IsNeverVisible() {
5328 if (!delegate_)
5329 return false;
5330 return delegate_->IsNeverVisible(this);
5331}
5332
[email protected]5a3bdf52012-05-24 15:12:575333RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
5334 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:325335}
5336
[email protected]8ff00d72012-10-23 19:12:215337RendererPreferences WebContentsImpl::GetRendererPrefs(
5338 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:465339 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:515340}
5341
[email protected]7a846df2012-09-20 19:17:395342void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:275343 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:395344 browser_plugin_embedder_.reset();
5345}
5346
avallee0206f782016-07-28 18:55:335347WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
lfg601233692017-03-06 22:45:445348 if (GuestMode::IsCrossProcessFrameGuest(this))
5349 return node_.outer_web_contents();
ekaramad1beabecc2016-09-23 20:18:175350
5351 if (browser_plugin_guest_)
5352 return browser_plugin_guest_->embedder_web_contents();
5353
Lucas Furukawa Gadani105de1e812018-05-31 19:38:395354 return node_.outer_web_contents();
avallee0206f782016-07-28 18:55:335355}
5356
5357WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
lfg601233692017-03-06 22:45:445358 return GetOutermostWebContents()->node_.focused_web_contents();
avallee0206f782016-07-28 18:55:335359}
5360
avallee9993fca2016-11-17 06:16:505361bool WebContentsImpl::ContainsOrIsFocusedWebContents() {
5362 for (WebContentsImpl* focused_contents = GetFocusedWebContents();
5363 focused_contents;
5364 focused_contents = focused_contents->GetOuterWebContents()) {
5365 if (focused_contents == this)
5366 return true;
5367 }
5368
5369 return false;
5370}
5371
avallee0206f782016-07-28 18:55:335372WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
5373 WebContentsImpl* root = this;
5374 while (root->GetOuterWebContents())
5375 root = root->GetOuterWebContents();
5376 return root;
5377}
5378
avalleed68cdd12017-06-21 22:07:275379void WebContentsImpl::FocusOuterAttachmentFrameChain() {
5380 WebContentsImpl* outer_contents = GetOuterWebContents();
5381 if (!outer_contents)
5382 return;
5383
5384 FrameTreeNode* outer_node =
5385 FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId());
5386 outer_contents->frame_tree_.SetFocusedFrame(outer_node, nullptr);
5387
5388 // For a browser initiated focus change, let embedding renderer know of the
5389 // change. Otherwise, if the currently focused element is just across a
5390 // process boundary in focus order, it will not be possible to move across
5391 // that boundary. This is because the target element will already be focused
5392 // (that renderer was not notified) and drop the event.
5393 if (GetRenderManager()->GetProxyToOuterDelegate())
5394 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame();
5395
5396 outer_contents->FocusOuterAttachmentFrameChain();
5397}
5398
[email protected]b172aee2012-04-10 17:05:265399void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]86f98a22013-03-20 14:35:005400 if (delegate_)
[email protected]e85165c642014-06-10 14:34:315401 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:085402
[email protected]8ff00d72012-10-23 19:12:215403 NotificationService::current()->Notify(
5404 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
5405 Source<WebContents>(this),
5406 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:325407
[email protected]60780f412013-02-25 16:34:105408 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:265409
ericwilligersde386342016-10-19 02:35:095410 for (auto& observer : observers_)
5411 observer.RenderViewCreated(render_view_host);
Joel Einbinder848001c2017-09-19 21:39:315412 if (delegate_)
5413 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]420ae012009-04-24 05:16:325414}
5415
[email protected]b172aee2012-04-10 17:05:265416void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:525417 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325418 // Don't notify the world, since this came from a renderer in the
5419 // background.
5420 return;
5421 }
5422
dmazzoni62111452017-04-28 23:46:555423 RenderWidgetHostViewBase* rwhv =
5424 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5425 if (rwhv)
5426 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
5427
[email protected]da7a7182013-09-06 08:11:115428 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:115429
[email protected]be1f56ab2011-12-22 06:55:315430 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:235431 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:305432
5433 // Restore the focus to the tab (otherwise the focus will be on the top
5434 // window).
[email protected]484ae5912010-09-29 19:16:145435 if (was_crashed && !FocusLocationBarByDefault() &&
5436 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:065437 view_->Focus();
[email protected]484ae5912010-09-29 19:16:145438 }
[email protected]32ded2212011-11-10 18:51:435439
ericwilligersde386342016-10-19 02:35:095440 for (auto& observer : observers_)
5441 observer.RenderViewReady();
Jinsuk Kim895b2c52018-07-03 06:49:165442
5443 view_->RenderViewReady();
[email protected]420ae012009-04-24 05:16:325444}
5445
[email protected]ec6a7eb2013-04-22 17:34:225446void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
5447 base::TerminationStatus status,
5448 int error_code) {
[email protected]151a63d2011-12-20 22:32:525449 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325450 // The pending page's RenderViewHost is gone.
5451 return;
5452 }
5453
[email protected]2fcdcc32014-03-05 02:14:075454 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
5455 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:155456 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:465457 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:075458
Jennifer Apacibleb4b972a2018-06-07 04:41:025459 // Ensure any video in Picture-in-Picture is exited in the |delegate_| since
5460 // a crashed renderer may not have made a clean exit.
5461 if (HasPictureInPictureVideo())
5462 ExitPictureInPicture();
5463
[email protected]698191dc2014-02-25 01:06:135464 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:175465 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:135466
dalecurtis3d1e1302017-02-20 22:33:255467 audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID());
5468
[email protected]960b0372014-05-19 18:01:005469 // Reset the loading progress. TODO(avi): What does it mean to have a
5470 // "renderer crash" when there is more than one renderer process serving a
5471 // webpage? Once this function is called at a more granular frame level, we
5472 // probably will need to more granularly reset the state here.
5473 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:255474 NotifyDisconnected();
5475 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:005476
ericwilligersde386342016-10-19 02:35:095477 for (auto& observer : observers_)
5478 observer.RenderProcessGone(GetCrashedStatus());
[email protected]420ae012009-04-24 05:16:325479}
5480
[email protected]b172aee2012-04-10 17:05:265481void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
ericwilligersde386342016-10-19 02:35:095482 for (auto& observer : observers_)
5483 observer.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:065484}
5485
sky8b00392d2015-01-10 00:30:285486void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
5487 const GURL& url) {
5488 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
Lukasz Anforowiczfd707142018-02-07 19:46:135489 // If we're in flash fullscreen (i.e. Pepper plugin fullscreen) only update
5490 // the url if it's from the fullscreen renderer.
sky8b00392d2015-01-10 00:30:285491 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:445492 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:285493 return;
5494 }
Lukasz Anforowiczfd707142018-02-07 19:46:135495
5496 // In case of racey updates from multiple RenderViewHosts, the last URL should
5497 // be shown - see also some discussion in https://crbug.com/807776.
5498 if (!url.is_valid() && render_view_host != view_that_set_last_target_url_)
5499 return;
5500 view_that_set_last_target_url_ = url.is_valid() ? render_view_host : nullptr;
5501
[email protected]6934a702011-12-20 00:04:515502 if (delegate_)
avi450ce00e2014-09-24 01:58:525503 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:325504}
5505
Lukasz Anforowiczfd707142018-02-07 19:46:135506void WebContentsImpl::ClearTargetURL() {
5507 view_that_set_last_target_url_ = nullptr;
5508 if (delegate_)
5509 delegate_->UpdateTargetURL(this, GURL());
5510}
5511
[email protected]b172aee2012-04-10 17:05:265512void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:105513#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:295514 // The UI may be in an event-tracking loop, such as between the
5515 // mouse-down and mouse-up in text selection or a button click.
5516 // Defer the close until after tracking is complete, so that we
5517 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:295518 // TODO(shess): This could get more fine-grained. For instance,
5519 // closing a tab in another window while selecting text in the
5520 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:105521 if (view_->IsEventTracking()) {
5522 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:295523 return;
5524 }
[email protected]60780f412013-02-25 16:34:105525#endif
[email protected]07707302009-11-06 00:50:295526
[email protected]420ae012009-04-24 05:16:325527 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:525528 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:515529 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:325530}
5531
Avi Drissman014dec72018-06-07 02:34:015532void WebContentsImpl::RequestSetBounds(const gfx::Rect& new_bounds) {
5533 if (delegate_)
5534 delegate_->SetContentsBounds(this, new_bounds);
[email protected]420ae012009-04-24 05:16:325535}
5536
fdegansa696e5112015-04-17 01:57:595537void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:095538 bool to_different_document) {
Evan Stadec3b26022017-07-14 19:50:245539 LoadingStateChanged(frame_tree_node->IsMainFrame() && to_different_document,
5540 false, nullptr);
dmazzonibf8cec42015-02-08 08:28:085541
5542 // Notify accessibility that the user is navigating away from the
5543 // current document.
5544 //
5545 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:085546 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:595547 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:085548 if (manager)
5549 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:325550}
5551
fdegansc73eec22015-03-19 14:47:545552void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:085553 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:325554
[email protected]9595fd82013-04-19 21:28:495555 // Use the last committed entry rather than the active one, in case a
5556 // pending entry has been created.
5557 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:205558 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:495559
[email protected]420ae012009-04-24 05:16:325560 // An entry may not exist for a stop when loading an initial blank page or
5561 // if an iframe injected by script into a blank page finishes loading.
5562 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:205563 base::TimeDelta elapsed =
5564 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:325565
5566 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:515567 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:325568 elapsed,
5569 &controller_,
5570 controller_.GetCurrentEntryIndex()));
5571 }
5572
clamy44e84ce2016-02-22 15:38:255573 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:325574}
5575
fdegansa696e5112015-04-17 01:57:595576void WebContentsImpl::DidChangeLoadProgress() {
5577 double load_progress = frame_tree_.load_progress();
5578
5579 // The delegate is notified immediately for the first and last updates. Also,
5580 // since the message loop may be pretty busy when a page is loaded, it might
5581 // not execute a posted task in a timely manner so the progress report is sent
5582 // immediately if enough time has passed.
5583 base::TimeDelta min_delay =
5584 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
5585 bool delay_elapsed = loading_last_progress_update_.is_null() ||
5586 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
5587
5588 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
5589 // If there is a pending task to send progress, it is now obsolete.
5590 loading_weak_factory_.InvalidateWeakPtrs();
5591
5592 // Notify the load progress change.
5593 SendChangeLoadProgress();
5594
5595 // Clean-up the states if needed.
5596 if (load_progress == 1.0)
5597 ResetLoadProgressState();
5598 return;
5599 }
5600
5601 if (loading_weak_factory_.HasWeakPtrs())
5602 return;
5603
skyostil95082a62015-06-05 19:53:075604 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
tzike2aca992017-09-05 08:50:545605 FROM_HERE,
5606 base::BindOnce(&WebContentsImpl::SendChangeLoadProgress,
5607 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:595608 min_delay);
5609}
5610
avid6d88b912017-01-13 00:16:005611std::vector<std::unique_ptr<NavigationThrottle>>
5612WebContentsImpl::CreateThrottlesForNavigation(
clamycbf524d42016-09-27 12:48:355613 NavigationHandle* navigation_handle) {
5614 return GetContentClient()->browser()->CreateThrottlesForNavigation(
5615 navigation_handle);
5616}
5617
clamy1e5574e2016-09-29 16:48:445618std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
5619 NavigationHandle* navigation_handle) {
5620 DCHECK(IsBrowserSideNavigationEnabled());
5621 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
5622}
5623
pdr15f5b5b2017-06-20 00:58:005624void WebContentsImpl::DidCancelLoading() {
5625 controller_.DiscardNonCommittedEntries();
5626
5627 // Update the URL display.
5628 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
5629}
5630
[email protected]59167c22013-06-03 18:07:325631void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:105632 has_accessed_initial_document_ = true;
5633
[email protected]d1371bf8e2014-04-19 03:26:245634 // We may have left a failed browser-initiated navigation in the address bar
5635 // to let the user edit it and try again. Clear it now that content might
5636 // show up underneath it.
5637 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:455638 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:245639
[email protected]59167c22013-06-03 18:07:325640 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:505641 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:325642}
5643
alexmosbe2f4c32015-03-10 02:30:235644void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
5645 const std::string& name) {
ericwilligersde386342016-10-19 02:35:095646 for (auto& observer : observers_)
5647 observer.FrameNameChanged(render_frame_host, name);
alexmosbe2f4c32015-03-10 02:30:235648}
5649
[email protected]39f2f9252014-05-03 00:54:015650void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:295651 RenderFrameHost* render_frame_host) {
falken52a56e32016-12-08 05:02:405652 ShowInsecureLocalhostWarningIfNeeded();
5653
creis97867aa2017-02-17 18:39:455654 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095655 for (auto& observer : observers_)
5656 observer.DocumentOnLoadCompletedInMainFrame();
creis97867aa2017-02-17 18:39:455657 is_notifying_observers_ = false;
[email protected]6578fef2013-10-14 02:35:095658
5659 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:215660 NotificationService::current()->Notify(
5661 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
5662 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:295663 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:085664}
5665
creis8eb8ef22015-11-04 22:51:385666void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
5667 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:385668 // The state update affects the last NavigationEntry associated with the given
5669 // |render_frame_host|. This may not be the last committed NavigationEntry (as
5670 // in the case of an UpdateState from a frame being swapped out). We track
5671 // which entry this is in the RenderFrameHost's nav_entry_id.
5672 RenderFrameHostImpl* rfhi =
5673 static_cast<RenderFrameHostImpl*>(render_frame_host);
5674 NavigationEntryImpl* entry =
5675 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
5676 if (!entry)
5677 return;
5678
5679 FrameNavigationEntry* frame_entry =
5680 entry->GetFrameEntry(rfhi->frame_tree_node());
5681 if (!frame_entry)
5682 return;
5683
creisd06a9422015-11-11 03:08:455684 // The SiteInstance might not match if we do a cross-process navigation with
5685 // replacement (e.g., auto-subframe), in which case the swap out of the old
5686 // RenderFrameHost runs in the background after the old FrameNavigationEntry
5687 // has already been replaced and destroyed.
5688 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
5689 return;
5690
creis8eb8ef22015-11-04 22:51:385691 if (page_state == frame_entry->page_state())
5692 return; // Nothing to update.
5693
creis0cade2e2017-02-28 06:37:475694 DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState.";
nasko34634672016-07-29 18:46:065695
5696 // The document_sequence_number and item_sequence_number recorded in the
5697 // FrameNavigationEntry should not differ from the one coming with the update,
5698 // since it must come from the same document. Do not update it if a difference
5699 // is detected, as this indicates that |frame_entry| is not the correct one.
5700 ExplodedPageState exploded_state;
5701 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
5702 return;
5703
5704 if (exploded_state.top.document_sequence_number !=
5705 frame_entry->document_sequence_number() ||
5706 exploded_state.top.item_sequence_number !=
5707 frame_entry->item_sequence_number()) {
5708 return;
5709 }
5710
nasko04a322f25a2016-09-01 00:00:345711 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:385712 controller_.NotifyEntryChanged(entry);
5713}
5714
[email protected]ef3adfc2014-05-11 00:04:545715void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
[email protected]ef3adfc2014-05-11 00:04:545716 const base::string16& title,
5717 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:545718 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:585719 // For example, it might be from a recently swapped out RFH.
avi1edc8552016-10-13 21:37:165720 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
creisad8c31a2016-05-24 17:07:045721 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
[email protected]ef3adfc2014-05-11 00:04:545722
5723 // We can handle title updates when we don't have an entry in
5724 // UpdateTitleForEntry, but only if the update is from the current RVH.
5725 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:585726 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:545727 return;
5728
5729 // TODO(evan): make use of title_direction.
5730 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:135731 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:545732}
5733
5734void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
5735 const std::string& encoding) {
5736 SetEncoding(encoding);
5737}
5738
[email protected]39f2f9252014-05-03 00:54:015739void WebContentsImpl::DocumentAvailableInMainFrame(
5740 RenderViewHost* render_view_host) {
ericwilligersde386342016-10-19 02:35:095741 for (auto& observer : observers_)
5742 observer.DocumentAvailableInMainFrame();
[email protected]39f2f9252014-05-03 00:54:015743}
naskoc0fceff2015-04-30 15:53:525744
[email protected]e1c3a552012-05-04 20:51:325745void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
5746 // Tell the active RenderViewHost to run unload handlers and close, as long
5747 // as the request came from a RenderViewHost in the same BrowsingInstance.
5748 // In most cases, we receive this from a swapped out RenderViewHost.
5749 // It is possible to receive it from one that has just been swapped in,
5750 // in which case we might as well deliver the message anyway.
5751 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:525752 ClosePage();
[email protected]e1c3a552012-05-04 20:51:325753}
5754
alexmose7da5a12015-04-09 02:22:165755bool WebContentsImpl::ShouldRouteMessageEvent(
5756 RenderFrameHost* target_rfh,
5757 SiteInstance* source_site_instance) const {
5758 // Allow the message if this WebContents is dedicated to a browser plugin
5759 // guest.
[email protected]0eba810b2012-10-18 03:19:365760 // Note: This check means that an embedder could theoretically receive a
5761 // postMessage from anyone (not just its own guests). However, this is
5762 // probably not a risk for apps since other pages won't have references
5763 // to App windows.
alexmose7da5a12015-04-09 02:22:165764 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
5765}
[email protected]f546640b2012-05-15 00:03:495766
alexmos58729042015-06-18 23:20:005767void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:165768 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
5769 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:495770
alexmose7da5a12015-04-09 02:22:165771 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:145772 // If this message is going to outer WebContents from inner WebContents,
5773 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
5774 // already created a RenderFrameProxyHost for that purpose.
5775 if (GetBrowserPluginEmbedder() &&
ekaramad1beabecc2016-09-23 20:18:175776 GuestMode::IsCrossProcessFrameGuest(source_web_contents)) {
lazyboy6ec48b2a2015-06-29 15:18:145777 return;
5778 }
5779
lfg812874d2016-02-09 22:26:135780 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:065781 // We create a RenderFrameProxyHost for the embedder in the guest's render
5782 // process but we intentionally do not expose the embedder's opener chain
5783 // to it.
5784 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
5785 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:495786 } else {
alexmos58729042015-06-18 23:20:005787 RenderFrameHostImpl* source_rfhi =
5788 static_cast<RenderFrameHostImpl*>(source_rfh);
5789 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:395790 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:495791 }
5792 }
[email protected]f546640b2012-05-15 00:03:495793}
5794
avallee9993fca2016-11-17 06:16:505795void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
5796 // Only change focus if we are not currently focused.
5797 WebContentsImpl* old_contents = GetFocusedWebContents();
5798 if (old_contents == this)
5799 return;
5800
paulmeyerfeafc2d2017-04-25 21:46:405801 GetOutermostWebContents()->node_.SetFocusedWebContents(this);
5802
Greg Thompsonfb957602017-09-04 10:25:525803 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
paulmeyerfeafc2d2017-04-25 21:46:405804 return;
5805
avallee9993fca2016-11-17 06:16:505806 // Send a page level blur to the old contents so that it displays inactive UI
5807 // and focus this contents to activate it.
5808 if (old_contents)
5809 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
avalleec2ff1ef2017-01-21 00:12:305810
5811 // Make sure the outer web contents knows our frame is focused. Otherwise, the
5812 // outer renderer could have the element before or after the frame element
5813 // focused which would return early without actually advancing focus.
avalleed68cdd12017-06-21 22:07:275814 FocusOuterAttachmentFrameChain();
avalleec2ff1ef2017-01-21 00:12:305815
lfg1453e412017-04-11 00:48:505816 if (ShowingInterstitialPage()) {
creisadca9862017-06-16 19:12:115817 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:505818 ->GetRenderWidgetHost()
5819 ->SetPageFocus(true);
5820 } else {
5821 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
5822 }
avallee9993fca2016-11-17 06:16:505823}
5824
avallee0206f782016-07-28 18:55:335825void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
5826 SiteInstance* source) {
avallee0206f782016-07-28 18:55:335827 frame_tree_.SetFocusedFrame(node, source);
avalleed68cdd12017-06-21 22:07:275828
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:575829 if (auto* inner_contents = node_.GetInnerWebContentsInFrame(node)) {
5830 // |this| is an outer WebContents and |node| represents an inner
5831 // WebContents. Transfer the focus to the inner contents if |this| is
5832 // focused.
5833 if (GetFocusedWebContents() == this)
5834 inner_contents->SetAsFocusedWebContentsIfNecessary();
5835 } else if (node_.OuterContentsFrameTreeNode() &&
5836 node_.OuterContentsFrameTreeNode()
5837 ->current_frame_host()
5838 ->GetSiteInstance() == source) {
5839 // |this| is an inner WebContents, |node| is its main FrameTreeNode and
5840 // the outer WebContents FrameTreeNode is at |source|'s SiteInstance.
5841 // Transfer the focus to the inner WebContents if the outer WebContents is
5842 // focused. This branch is used when an inner WebContents is focused through
5843 // its RenderFrameProxyHost (via FrameHostMsg_FrameFocused IPC, used to
5844 // implement the window.focus() API).
5845 if (GetFocusedWebContents() == GetOuterWebContents())
5846 SetAsFocusedWebContentsIfNecessary();
5847 } else if (!GetOuterWebContents()) {
5848 // This is an outermost WebContents.
5849 SetAsFocusedWebContentsIfNecessary();
5850 } else if (!GuestMode::IsCrossProcessFrameGuest(this) &&
5851 GetOuterWebContents()) {
5852 // TODO(lfg, paulmeyer): Allows BrowserPlugins to set themselves as the
5853 // focused WebContents. This works around a bug in FindRequestManager that
5854 // doesn't support properly traversing BrowserPlugins.
5855 SetAsFocusedWebContentsIfNecessary();
5856 }
avalleed68cdd12017-06-21 22:07:275857}
5858
Avi Drissman36f801f2018-02-01 20:06:045859void WebContentsImpl::DidCallFocus() {
5860 // Any explicit focusing of another window while this WebContents is in
5861 // fullscreen can be used to confuse the user, so drop fullscreen.
5862 if (IsFullscreenForCurrentTab())
5863 ExitFullscreen(true);
5864}
5865
avalleed68cdd12017-06-21 22:07:275866RenderFrameHost* WebContentsImpl::GetFocusedFrameIncludingInnerWebContents() {
5867 WebContentsImpl* contents = this;
5868 FrameTreeNode* focused_node = contents->frame_tree_.GetFocusedFrame();
5869
5870 // If there is no focused frame in the outer WebContents, we need to return
5871 // null.
5872 if (!focused_node)
5873 return nullptr;
5874
5875 // If the focused frame is embedding an inner WebContents, we must descend
5876 // into that contents. If the current WebContents does not have a focused
5877 // frame, return the main frame of this contents instead of the focused empty
5878 // frame embedding this contents.
5879 while (true) {
5880 contents = contents->node_.GetInnerWebContentsInFrame(focused_node);
5881 if (!contents)
5882 return focused_node->current_frame_host();
5883
5884 focused_node = contents->frame_tree_.GetFocusedFrame();
5885 if (!focused_node)
5886 return contents->GetMainFrame();
5887 }
avallee0206f782016-07-28 18:55:335888}
5889
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:575890void WebContentsImpl::OnAdvanceFocus(RenderFrameHostImpl* source_rfh) {
5891 // When a RenderFrame needs to advance focus to a RenderFrameProxy (by hitting
5892 // TAB), the RenderFrameProxy sends an IPC to RenderFrameProxyHost. When this
5893 // RenderFrameProxyHost represents an inner WebContents, the outer WebContents
5894 // needs to focus the inner WebContents.
5895 if (GetOuterWebContents() &&
5896 GetOuterWebContents() == source_rfh->delegate()->GetAsWebContents() &&
5897 GetFocusedWebContents() == GetOuterWebContents()) {
5898 SetAsFocusedWebContentsIfNecessary();
5899 }
5900}
5901
ekaramada110f642016-12-21 19:47:285902void WebContentsImpl::OnFocusedElementChangedInFrame(
5903 RenderFrameHostImpl* frame,
5904 const gfx::Rect& bounds_in_root_view) {
5905 RenderWidgetHostViewBase* root_view =
5906 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5907 if (!root_view || !frame->GetView())
5908 return;
5909
5910 // Converting to screen coordinates.
5911 gfx::Point origin = bounds_in_root_view.origin();
5912 origin += root_view->GetViewBounds().OffsetFromOrigin();
5913 gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size());
5914
5915 root_view->FocusedNodeChanged(frame->has_focused_editable_element(),
5916 bounds_in_screen);
5917
5918 FocusedNodeDetails details = {frame->has_focused_editable_element(),
5919 bounds_in_screen};
5920
5921 // TODO(ekaramad): We should replace this with an observer notification
5922 // (https://crbug.com/675975).
5923 NotificationService::current()->Notify(
5924 NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
5925 Source<RenderViewHost>(GetRenderViewHost()),
5926 Details<FocusedNodeDetails>(&details));
5927}
5928
avia90ae4e2016-11-11 20:49:335929bool WebContentsImpl::DidAddMessageToConsole(int32_t level,
5930 const base::string16& message,
5931 int32_t line_no,
5932 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:255933 if (!delegate_)
5934 return false;
avia90ae4e2016-11-11 20:49:335935 return delegate_->DidAddMessageToConsole(this, level, message, line_no,
5936 source_id);
[email protected]a796f202012-05-30 14:14:255937}
5938
Daniel Cheng90196c82018-04-25 21:49:145939void WebContentsImpl::DidReceiveInputEvent(
dominickn9c7ceaa32016-02-27 01:52:535940 RenderWidgetHostImpl* render_widget_host,
5941 const blink::WebInputEvent::Type type) {
Daniel Cheng90196c82018-04-25 21:49:145942 // Ideally, this list would be based more off of
5943 // https://whatwg.org/C/interaction.html#triggered-by-user-activation.
5944 if (type != blink::WebInputEvent::kMouseDown &&
5945 type != blink::WebInputEvent::kGestureScrollBegin &&
5946 type != blink::WebInputEvent::kTouchStart &&
5947 type != blink::WebInputEvent::kRawKeyDown)
5948 return;
5949
kenrb19221852016-04-29 17:21:405950 // Ignore unless the widget is currently in the frame tree.
5951 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:225952 return;
5953
Daniel Cheng90196c82018-04-25 21:49:145954 if (type != blink::WebInputEvent::kGestureScrollBegin)
5955 last_interactive_input_event_time_ = ui::EventTimeForNow();
dominickn9c7ceaa32016-02-27 01:52:535956
Daniel Cheng90196c82018-04-25 21:49:145957 OnUserInteraction(type);
dominickn2dd142dd2015-10-29 05:30:505958}
5959
avallee9993fca2016-11-17 06:16:505960void WebContentsImpl::FocusOwningWebContents(
5961 RenderWidgetHostImpl* render_widget_host) {
5962 // The PDF plugin still runs as a BrowserPlugin and must go through the
5963 // input redirection mechanism. It must not become focused direcly.
5964 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
5965 return;
5966
5967 RenderWidgetHostImpl* focused_widget =
5968 GetFocusedRenderWidgetHost(render_widget_host);
5969
5970 if (focused_widget != render_widget_host &&
avallee8e881592016-11-19 00:39:305971 (!focused_widget ||
5972 focused_widget->delegate() != render_widget_host->delegate())) {
avallee9993fca2016-11-17 06:16:505973 SetAsFocusedWebContentsIfNecessary();
5974 }
5975}
5976
[email protected]b172aee2012-04-10 17:05:265977void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:445978 // Notify observers.
ericwilligersde386342016-10-19 02:35:095979 for (auto& observer : observers_)
5980 observer.DidGetIgnoredUIEvent();
[email protected]fa1cf0b82010-01-15 21:49:445981}
5982
avic3aa8422015-11-09 20:57:225983void WebContentsImpl::RendererUnresponsive(
Lukasz Anforowicz52b93722018-06-20 16:11:395984 RenderWidgetHostImpl* render_widget_host,
5985 base::RepeatingClosure hang_monitor_restarter) {
ericwilligersde386342016-10-19 02:35:095986 for (auto& observer : observers_)
Avi Drissman1572e8c3c2018-02-02 19:06:365987 observer.OnRendererUnresponsive(render_widget_host->GetProcess());
afakhry98241832016-03-11 19:27:475988
avic031d392017-03-03 03:09:425989 if (ShouldIgnoreUnresponsiveRenderer())
[email protected]e5fc1632011-08-08 07:51:535990 return;
5991
Avi Drissman8920def2018-01-31 19:53:365992 if (!render_widget_host->renderer_initialized())
[email protected]55452902011-06-01 21:57:475993 return;
5994
Dave Tapuskac6146c52017-12-20 22:48:155995 if (delegate_)
Lukasz Anforowicz52b93722018-06-20 16:11:395996 delegate_->RendererUnresponsive(this, render_widget_host,
5997 std::move(hang_monitor_restarter));
[email protected]420ae012009-04-24 05:16:325998}
5999
avic3aa8422015-11-09 20:57:226000void WebContentsImpl::RendererResponsive(
6001 RenderWidgetHostImpl* render_widget_host) {
[email protected]6934a702011-12-20 00:04:516002 if (delegate_)
Avi Drissman1572e8c3c2018-02-02 19:06:366003 delegate_->RendererResponsive(this, render_widget_host);
[email protected]420ae012009-04-24 05:16:326004}
6005
[email protected]b172aee2012-04-10 17:05:266006void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:556007 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:326008 bool* proceed_to_fire_unload) {
ericwilligersde386342016-10-19 02:35:096009 for (auto& observer : observers_)
6010 observer.BeforeUnloadFired(proceed_time);
[email protected]6934a702011-12-20 00:04:516011 if (delegate_)
6012 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:096013 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:326014}
6015
[email protected]58d5cfe2013-07-10 02:40:526016void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:546017 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:236018 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:226019 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:546020}
6021
Jianzhou Fengd8720c72018-01-18 03:06:306022void WebContentsImpl::UpdateRenderViewSizeForRenderManager(bool is_main_frame) {
[email protected]8643e6d2012-01-18 20:26:106023 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
Jianzhou Fengd8720c72018-01-18 03:06:306024 gfx::Size size = GetSizeForNewRenderView(is_main_frame);
[email protected]0323ee42010-02-17 22:03:266025 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
6026 // here during container initialization and normal window size will be set
6027 // later. In case of tab duplication this resizing to 0x0 prevents setting
6028 // normal size later so just ignore it.
6029 if (!size.IsEmpty())
6030 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:326031}
6032
[email protected]af905902013-10-01 21:38:516033void WebContentsImpl::CancelModalDialogsForRenderManager() {
6034 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:546035 // deferrer would prevent us from swapping out. We also clear the state
6036 // because this is a cross-process navigation, which means that it's a new
6037 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:176038 //
6039 // Note that we don't bother telling browser_plugin_embedder_ because the
6040 // cross-process navigation will either destroy the browser plugins or not
6041 // require their dialogs to close.
avi5d3b8692016-10-12 22:00:466042 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:536043 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:466044 }
[email protected]af905902013-10-01 21:38:516045}
6046
[email protected]02d7b6e2014-06-24 21:01:506047void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
6048 RenderFrameHost* new_host,
6049 bool is_main_frame) {
6050 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:056051 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:506052 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:086053
[email protected]02d7b6e2014-06-24 21:01:506054 // Make sure the visible RVH reflects the new delegate's preferences.
6055 if (delegate_)
6056 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:396057
dmazzoni62111452017-04-28 23:46:556058 RenderWidgetHostViewBase* rwhv =
6059 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
6060 if (rwhv)
6061 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
[email protected]02d7b6e2014-06-24 21:01:506062 }
6063
Jinsuk Kim895b2c52018-07-03 06:49:166064 NotifyFrameSwapped(old_host, new_host, is_main_frame);
[email protected]3a3d47472010-07-15 21:03:546065}
6066
naskof5940b9f2015-03-02 23:04:056067void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
Jinsuk Kim895b2c52018-07-03 06:49:166068 RenderFrameHost* old_host,
6069 RenderFrameHost* new_host) {
6070 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
6071 new_host->GetRenderViewHost());
naskof5940b9f2015-03-02 23:04:056072}
6073
[email protected]b172aee2012-04-10 17:05:266074NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:196075 return GetController();
[email protected]3a3d47472010-07-15 21:03:546076}
6077
dcheng59716272016-04-09 05:19:086078std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:296079 const GURL& url) {
Dan Beam055fe8f2017-10-04 23:23:366080 return CreateWebUI(url);
[email protected]420ae012009-04-24 05:16:326081}
6082
[email protected]10f417c52011-12-28 21:04:236083NavigationEntry*
[email protected]b172aee2012-04-10 17:05:266084 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:326085 return controller_.GetLastCommittedEntry();
6086}
6087
creisadca9862017-06-16 19:12:116088InterstitialPageImpl* WebContentsImpl::GetInterstitialForRenderManager() {
6089 return interstitial_page_;
6090}
6091
lfgbede6392015-09-11 21:54:066092void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
6093 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:336094 RenderWidgetHostViewBase* rwh_view =
6095 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:526096
[email protected]420ae012009-04-24 05:16:326097 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:446098 if (rwh_view)
Jianzhou Fengd8720c72018-01-18 03:06:306099 rwh_view->SetSize(GetSizeForNewRenderView(true));
lfgbede6392015-09-11 21:54:066100}
6101
6102bool WebContentsImpl::CreateRenderViewForRenderManager(
6103 RenderViewHost* render_view_host,
6104 int opener_frame_routing_id,
6105 int proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066106 const base::UnguessableToken& devtools_frame_token,
lfgbede6392015-09-11 21:54:066107 const FrameReplicationState& replicated_frame_state) {
6108 TRACE_EVENT0("browser,navigation",
6109 "WebContentsImpl::CreateRenderViewForRenderManager");
6110
piman00cf9402017-04-03 17:09:206111 if (proxy_routing_id == MSG_ROUTING_NONE)
lfg9431efd2016-12-14 14:45:266112 CreateRenderWidgetHostViewForRenderManager(render_view_host);
lfg9431efd2016-12-14 14:45:266113
piman00cf9402017-04-03 17:09:206114 if (!static_cast<RenderViewHostImpl*>(render_view_host)
6115 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066116 devtools_frame_token, replicated_frame_state,
6117 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:526118 return false;
[email protected]14392a52012-05-02 20:28:446119 }
[email protected]a4127722011-04-27 23:13:526120
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:146121 if (proxy_routing_id == MSG_ROUTING_NONE && node_.outer_web_contents())
6122 ReattachToOuterWebContentsFrame();
6123
avi2b177592014-12-10 02:08:026124 SetHistoryOffsetAndLengthForView(render_view_host,
6125 controller_.GetLastCommittedEntryIndex(),
6126 controller_.GetEntryCount());
6127
[email protected]a220b5932013-09-21 03:47:446128#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:506129 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
6130 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:446131 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:446132 if (rwh_view) {
6133 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:166134 render_widget_host->SynchronizeVisualProperties();
[email protected]245f7d52011-11-28 15:36:446135 }
[email protected]f8233cc2011-05-31 20:24:506136#endif
6137
[email protected]420ae012009-04-24 05:16:326138 return true;
6139}
6140
[email protected]82307f6b2014-08-07 03:30:126141bool WebContentsImpl::CreateRenderFrameForRenderManager(
6142 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:046143 int proxy_routing_id,
6144 int opener_routing_id,
japhete6adf142014-10-31 00:01:496145 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:046146 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:436147 TRACE_EVENT0("browser,navigation",
6148 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:126149
6150 RenderFrameHostImpl* rfh =
6151 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:046152 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
6153 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:126154 return false;
6155
6156 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
6157 // RenderFrameHost will have to be associated with the appropriate
6158 // RenderWidgetHostView or a new one should be created here.
6159
6160 return true;
6161}
6162
mfomitchev2b8b066a2016-01-28 19:23:156163#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:456164
[email protected]155c7f22013-12-09 17:07:186165base::android::ScopedJavaLocalRef<jobject>
6166WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:406167 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:566168 return GetWebContentsAndroid()->GetJavaObject();
6169}
[email protected]155c7f22013-12-09 17:07:186170
[email protected]0e813a52014-08-13 10:34:566171WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:186172 WebContentsAndroid* web_contents_android =
6173 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
6174 if (!web_contents_android) {
6175 web_contents_android = new WebContentsAndroid(this);
avicb129c02017-05-03 06:49:296176 SetUserData(kWebContentsAndroidKey, base::WrapUnique(web_contents_android));
[email protected]155c7f22013-12-09 17:07:186177 }
[email protected]0e813a52014-08-13 10:34:566178 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:186179}
6180
paulmeyerc0b762b2016-04-13 11:55:176181void WebContentsImpl::ActivateNearestFindResult(float x,
6182 float y) {
6183 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
6184}
6185
6186void WebContentsImpl::RequestFindMatchRects(int current_version) {
6187 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
6188}
6189
[email protected]7d244f12013-08-22 21:41:516190bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:066191 return CreateRenderViewForRenderManager(
6192 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
Pavel Feldman25234722017-10-11 02:49:066193 frame_tree_.root()->devtools_frame_token(),
lfgbede6392015-09-11 21:54:066194 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:516195}
[email protected]fc2b46b2014-05-03 16:33:456196
rockot400ea35b2016-10-15 19:15:326197service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
sammcf5f1b0f2016-09-20 23:05:116198 if (!java_interfaces_) {
rockot400ea35b2016-10-15 19:15:326199 service_manager::mojom::InterfaceProviderPtr provider;
blundelle0a9f1582016-12-20 11:23:326200 BindInterfaceRegistryForWebContents(mojo::MakeRequest(&provider), this);
rockot400ea35b2016-10-15 19:15:326201 java_interfaces_.reset(new service_manager::InterfaceProvider);
sammcf5f1b0f2016-09-20 23:05:116202 java_interfaces_->Bind(std::move(provider));
6203 }
6204 return java_interfaces_.get();
6205}
6206
[email protected]fc2b46b2014-05-03 16:33:456207#elif defined(OS_MACOSX)
6208
[email protected]75f4df72014-07-16 22:39:426209void WebContentsImpl::SetAllowOtherViews(bool allow) {
6210 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:456211}
6212
[email protected]75f4df72014-07-16 22:39:426213bool WebContentsImpl::GetAllowOtherViews() {
6214 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:456215}
6216
spqchane72c3cb2017-06-30 23:02:106217bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() const {
6218 return did_first_visually_non_empty_paint_;
6219}
6220
[email protected]7d244f12013-08-22 21:41:516221#endif
6222
pkotwicz75ca8ffd2016-02-16 23:10:196223void WebContentsImpl::OnDidDownloadImage(
Avi Drissmana5a52dd2018-03-27 03:39:026224 ImageDownloadCallback callback,
pkotwicz75ca8ffd2016-02-16 23:10:196225 int id,
6226 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:526227 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:186228 const std::vector<SkBitmap>& images,
6229 const std::vector<gfx::Size>& original_image_sizes) {
Avi Drissmana5a52dd2018-03-27 03:39:026230 std::move(callback).Run(id, http_status_code, image_url, images,
6231 original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:196232}
6233
[email protected]6fba26d2014-04-29 09:38:286234void WebContentsImpl::OnDialogClosed(int render_process_id,
6235 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:266236 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:496237 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:266238 bool success,
[email protected]fcf75d42013-12-03 20:11:266239 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:286240 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
6241 render_frame_id);
[email protected]87de04b02014-04-08 22:14:496242 last_dialog_suppressed_ = dialog_was_suppressed;
6243
[email protected]beb440c2009-11-06 04:08:546244 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:236245 // It is possible for the current RenderFrameHost to have changed in the
6246 // meantime. Do not reset the navigation state in that case.
6247 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:256248 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:236249 controller_.DiscardNonCommittedEntries();
6250 }
[email protected]ec8e8b02013-06-19 04:57:106251
Charles Reis15d60b132017-11-03 17:43:476252 // Update the URL display either way, to avoid showing a stale URL.
6253 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
6254
ericwilligersde386342016-10-19 02:35:096255 for (auto& observer : observers_)
6256 observer.BeforeUnloadDialogCancelled();
[email protected]beb440c2009-11-06 04:08:546257 }
[email protected]87de04b02014-04-08 22:14:496258
[email protected]6fba26d2014-04-29 09:38:286259 if (rfh) {
avi44acfaa82017-05-03 22:55:356260 rfh->JavaScriptDialogClosed(reply_msg, success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:166261
6262 std::vector<protocol::PageHandler*> page_handlers =
6263 protocol::PageHandler::EnabledForWebContents(this);
6264 for (auto* handler : page_handlers)
6265 handler->DidCloseJavaScriptDialog(success, user_input);
6266
[email protected]6fba26d2014-04-29 09:38:286267 } else {
6268 // Don't leak the sync IPC reply if the RFH or process is gone.
6269 delete reply_msg;
6270 }
avi1c51fb62017-02-27 20:43:036271
6272 is_showing_javascript_dialog_ = false;
6273 is_showing_before_unload_dialog_ = false;
[email protected]beb440c2009-11-06 04:08:546274}
6275
[email protected]b172aee2012-04-10 17:05:266276void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:546277 if (encoding == last_reported_encoding_)
6278 return;
6279 last_reported_encoding_ = encoding;
6280
jinsukkim79df88a2017-01-04 06:26:156281 canonical_encoding_ = base::GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:106282}
[email protected]f45d2a72010-03-08 23:28:356283
[email protected]1ac10dca2013-08-20 20:47:046284bool WebContentsImpl::IsHidden() {
Francois Doraye6161152018-03-27 22:05:376285 return !IsBeingCaptured() && visibility_ != Visibility::VISIBLE;
[email protected]1ac10dca2013-08-20 20:47:046286}
6287
rob97250742015-12-10 17:45:156288int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lfg601233692017-03-06 22:45:446289 return node_.outer_contents_frame_tree_node_id();
lazyboy6ec48b2a2015-06-29 15:18:146290}
6291
ekaramadaeb3c5c2016-11-09 03:22:356292RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const {
6293 return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
6294 fullscreen_widget_routing_id_);
6295}
6296
[email protected]b0936d22013-11-28 06:47:366297RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:216298 return frame_tree_.root()->render_manager();
6299}
6300
[email protected]f8497342013-02-05 22:15:026301BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:396302 return browser_plugin_guest_.get();
6303}
6304
[email protected]738f57a2013-06-29 21:06:546305void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
6306 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:146307 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:546308 browser_plugin_guest_.reset(guest);
6309}
6310
[email protected]f8497342013-02-05 22:15:026311BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:396312 return browser_plugin_embedder_.get();
6313}
[email protected]8ff00d72012-10-23 19:12:216314
fsamuel60b42282015-03-10 03:29:146315void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
6316 if (browser_plugin_embedder_)
6317 return;
6318 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
6319}
6320
Jianzhou Fengd8720c72018-01-18 03:06:306321gfx::Size WebContentsImpl::GetSizeForNewRenderView(bool is_main_frame) {
[email protected]dc0fd432013-08-27 15:29:216322 gfx::Size size;
Jianzhou Fengd8720c72018-01-18 03:06:306323 if (is_main_frame)
6324 size = device_emulation_size_;
6325 if (size.IsEmpty() && delegate_)
[email protected]dc0fd432013-08-27 15:29:216326 size = delegate_->GetSizeForNewRenderView(this);
6327 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:456328 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:216329 return size;
6330}
6331
[email protected]ae7eeda2014-07-04 01:53:266332void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:096333 for (auto& observer : observers_)
6334 observer.FrameDeleted(render_frame_host);
[email protected]9b159a52013-10-03 17:24:556335}
6336
[email protected]222f5822014-02-05 23:40:496337void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
6338 if (!delegate_)
6339 return;
6340 const gfx::Size new_size = GetPreferredSize();
6341 if (new_size != old_size)
6342 delegate_->UpdatePreferredSize(this, new_size);
6343}
6344
Daniel Cheng90196c82018-04-25 21:49:146345void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) {
6346 for (auto& observer : observers_)
6347 observer.DidGetUserInteraction(type);
6348
6349 // TODO(https://crbug.com/827659): This used to check if type != kMouseWheel.
6350 // However, due to the caller already filtering event types, this would never
6351 // be called with type == kMouseWheel so checking for that here is pointless.
6352 // However, mouse wheel events *also* generate a kGestureScrollBegin event...
6353 // which is *not* filtered out. Maybe they should be?
6354 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
6355 if (rdh) // null in unittests. =(
6356 rdh->OnUserGesture();
6357}
6358
Dan Beam055fe8f2017-10-04 23:23:366359std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI(const GURL& url) {
Jeremy Roman04f27c372017-10-27 15:20:556360 std::unique_ptr<WebUIImpl> web_ui = std::make_unique<WebUIImpl>(this);
Lei Zhangee3b63ad2018-06-06 23:25:316361 std::unique_ptr<WebUIController> controller(
avie865b1d2016-10-24 19:42:596362 WebUIControllerFactoryRegistry::GetInstance()
Lei Zhangee3b63ad2018-06-06 23:25:316363 ->CreateWebUIControllerForURL(web_ui.get(), url));
dbeama1b926a2015-08-31 23:17:516364 if (controller) {
Jeremy Roman04f27c372017-10-27 15:20:556365 web_ui->AddMessageHandler(std::make_unique<GenericHandler>());
Lei Zhangee3b63ad2018-06-06 23:25:316366 web_ui->SetController(std::move(controller));
dbeama1b926a2015-08-31 23:17:516367 return web_ui;
6368 }
6369
avie865b1d2016-10-24 19:42:596370 return nullptr;
dbeama1b926a2015-08-31 23:17:516371}
6372
paulmeyerfeafc2d2017-04-25 21:46:406373FindRequestManager* WebContentsImpl::GetFindRequestManager() {
6374 for (WebContentsImpl* contents = this; contents;
6375 contents = contents->GetOuterWebContents()) {
6376 if (contents->find_request_manager_)
6377 return contents->find_request_manager_.get();
6378 }
6379
6380 return nullptr;
6381}
6382
paulmeyerc0b762b2016-04-13 11:55:176383FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
paulmeyerfeafc2d2017-04-25 21:46:406384 if (FindRequestManager* manager = GetFindRequestManager())
6385 return manager;
6386
6387 // No existing FindRequestManager found, so one must be created.
6388 find_request_manager_.reset(new FindRequestManager(this));
6389
6390 // Concurrent find sessions must not overlap, so destroy any existing
6391 // FindRequestManagers in any inner WebContentses.
6392 for (WebContentsImpl* contents : GetWebContentsAndAllInner()) {
6393 if (contents == this)
6394 continue;
6395 if (contents->find_request_manager_) {
6396 contents->find_request_manager_->StopFinding(
6397 content::STOP_FIND_ACTION_CLEAR_SELECTION);
6398 contents->find_request_manager_.release();
6399 }
6400 }
paulmeyerc0b762b2016-04-13 11:55:176401
6402 return find_request_manager_.get();
6403}
6404
6405void WebContentsImpl::NotifyFindReply(int request_id,
6406 int number_of_matches,
6407 const gfx::Rect& selection_rect,
6408 int active_match_ordinal,
6409 bool final_update) {
Sebastien Marchandcf97ed52017-07-24 23:50:346410 if (delegate_ && !is_being_destroyed_ &&
Lukasz Anforowicze9ae3722017-09-29 17:37:386411 !GetMainFrame()->GetProcess()->FastShutdownStarted()) {
paulmeyerc0b762b2016-04-13 11:55:176412 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
6413 active_match_ordinal, final_update);
6414 }
6415}
6416
ortuno467e5792016-06-10 04:32:396417void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
6418 // Trying to invalidate the tab state while being destroyed could result in a
6419 // use after free.
6420 if (IsBeingDestroyed()) {
6421 return;
6422 }
6423 // Notify for UI updates if the state changes.
6424 bluetooth_connected_device_count_++;
6425 if (bluetooth_connected_device_count_ == 1) {
6426 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6427 }
6428}
6429
6430void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
6431 // Trying to invalidate the tab state while being destroyed could result in a
6432 // use after free.
6433 if (IsBeingDestroyed()) {
6434 return;
6435 }
6436 // Notify for UI updates if the state changes.
Lukasz Anforowicze9ae3722017-09-29 17:37:386437 DCHECK_NE(bluetooth_connected_device_count_, 0u);
ortuno467e5792016-06-10 04:32:396438 bluetooth_connected_device_count_--;
6439 if (bluetooth_connected_device_count_ == 0) {
6440 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6441 }
6442}
6443
zqzhang8ac49002017-03-16 21:51:356444void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) {
6445 if (has_persistent_video_ == has_persistent_video)
mlamouri5cd9ae82017-02-18 11:05:096446 return;
6447
zqzhang8ac49002017-03-16 21:51:356448 has_persistent_video_ = has_persistent_video;
mlamouri5cd9ae82017-02-18 11:05:096449 NotifyPreferencesChanged();
zqzhang8ac49002017-03-16 21:51:356450 media_web_contents_observer()->RequestPersistentVideo(has_persistent_video);
mlamouri5cd9ae82017-02-18 11:05:096451}
6452
paulmeyerfeafc2d2017-04-25 21:46:406453void WebContentsImpl::BrowserPluginGuestWillDetach() {
6454 WebContentsImpl* outermost = GetOutermostWebContents();
6455 if (this != outermost && ContainsOrIsFocusedWebContents())
6456 outermost->SetAsFocusedWebContentsIfNecessary();
6457}
6458
Mounir Lamouri11e9ef42018-05-22 03:10:166459gfx::Size WebContentsImpl::EnterPictureInPicture(
6460 const viz::SurfaceId& surface_id,
6461 const gfx::Size& natural_size) {
6462 return delegate_ ? delegate_->EnterPictureInPicture(surface_id, natural_size)
6463 : gfx::Size();
6464}
6465
Mounir Lamouri6d759e12018-05-16 20:01:306466void WebContentsImpl::ExitPictureInPicture() {
6467 if (delegate_)
6468 delegate_->ExitPictureInPicture();
6469}
6470
paulmeyerc0b762b2016-04-13 11:55:176471#if defined(OS_ANDROID)
6472void WebContentsImpl::NotifyFindMatchRectsReply(
6473 int version,
6474 const std::vector<gfx::RectF>& rects,
6475 const gfx::RectF& active_rect) {
6476 if (delegate_)
6477 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
6478}
6479#endif
6480
[email protected]34ff1cfc2014-08-20 06:16:056481void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
6482 force_disable_overscroll_content_ = force_disable;
6483 if (view_)
6484 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
6485}
6486
Jianzhou Fengd8720c72018-01-18 03:06:306487bool WebContentsImpl::SetDeviceEmulationSize(const gfx::Size& new_size) {
6488 device_emulation_size_ = new_size;
6489 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
6490
6491 const gfx::Size current_size = rwhv->GetViewBounds().size();
6492 if (view_size_before_emulation_.IsEmpty())
6493 view_size_before_emulation_ = current_size;
6494
6495 if (current_size != new_size)
6496 rwhv->SetSize(new_size);
6497
6498 return current_size != new_size;
6499}
6500
6501void WebContentsImpl::ClearDeviceEmulationSize() {
6502 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
6503 // WebContentsView could get resized during emulation, which also resizes
6504 // RWHV. If it happens, assume user would like to keep using the size after
6505 // emulation.
6506 // TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when
6507 // WebContentsView size changes).
Dmitry Gozmanc63707182018-03-06 00:09:396508 if (!view_size_before_emulation_.IsEmpty() && rwhv &&
6509 rwhv->GetViewBounds().size() == device_emulation_size_) {
Jianzhou Fengd8720c72018-01-18 03:06:306510 rwhv->SetSize(view_size_before_emulation_);
Dmitry Gozmanc63707182018-03-06 00:09:396511 }
Jianzhou Fengd8720c72018-01-18 03:06:306512 device_emulation_size_ = gfx::Size();
6513 view_size_before_emulation_ = gfx::Size();
6514}
6515
Max Morin5bc74f52018-05-09 07:00:216516ForwardingAudioStreamFactory* WebContentsImpl::GetAudioStreamFactory() {
6517 if (!audio_stream_factory_) {
6518 audio_stream_factory_.emplace(
6519 this,
6520 content::ServiceManagerConnection::GetForProcess()
6521 ->GetConnector()
6522 ->Clone(),
6523 AudioStreamBrokerFactory::CreateImpl());
6524 }
6525
6526 return &*audio_stream_factory_;
6527}
6528
dalecurtis88c240072015-12-09 02:11:186529void WebContentsImpl::MediaStartedPlaying(
billorr21c005d2016-11-17 03:57:046530 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:186531 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:046532 if (media_info.has_video)
6533 currently_playing_video_count_++;
6534
ericwilligersde386342016-10-19 02:35:096535 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:046536 observer.MediaStartedPlaying(media_info, id);
dalecurtis88c240072015-12-09 02:11:186537}
6538
6539void WebContentsImpl::MediaStoppedPlaying(
billorr21c005d2016-11-17 03:57:046540 const WebContentsObserver::MediaPlayerInfo& media_info,
Becca Hughes220bfc102017-11-14 18:24:076541 const WebContentsObserver::MediaPlayerId& id,
6542 WebContentsObserver::MediaStoppedReason reason) {
billorr21c005d2016-11-17 03:57:046543 if (media_info.has_video)
6544 currently_playing_video_count_--;
6545
ericwilligersde386342016-10-19 02:35:096546 for (auto& observer : observers_)
Becca Hughes220bfc102017-11-14 18:24:076547 observer.MediaStoppedPlaying(media_info, id, reason);
billorr21c005d2016-11-17 03:57:046548}
6549
peconn257951522017-06-09 18:24:596550void WebContentsImpl::MediaResized(
6551 const gfx::Size& size,
6552 const WebContentsObserver::MediaPlayerId& id) {
6553 cached_video_sizes_[id] = size;
6554
6555 for (auto& observer : observers_)
6556 observer.MediaResized(size, id);
6557}
6558
Peter E Conneccb34c22017-09-08 09:37:586559void WebContentsImpl::MediaEffectivelyFullscreenChanged(bool is_fullscreen) {
6560 for (auto& observer : observers_)
6561 observer.MediaEffectivelyFullscreenChanged(is_fullscreen);
6562}
6563
Peter Conn31c726a2017-08-17 11:07:346564base::Optional<gfx::Size> WebContentsImpl::GetFullscreenVideoSize() {
6565 base::Optional<WebContentsObserver::MediaPlayerId> id =
6566 media_web_contents_observer_->GetFullscreenVideoMediaPlayerId();
6567 if (id && cached_video_sizes_.count(id.value()))
6568 return base::Optional<gfx::Size>(cached_video_sizes_[id.value()]);
6569 return base::Optional<gfx::Size>();
peconn257951522017-06-09 18:24:596570}
6571
billorr21c005d2016-11-17 03:57:046572int WebContentsImpl::GetCurrentlyPlayingVideoCount() {
6573 return currently_playing_video_count_;
dalecurtis88c240072015-12-09 02:11:186574}
6575
Francois Doraye6161152018-03-27 22:05:376576void WebContentsImpl::UpdateWebContentsVisibility(Visibility visibility) {
Francois Doray3f2afbd2018-04-06 19:18:186577 // Occlusion is disabled when |features::kWebContentsOcclusion| is disabled
6578 // (for power and speed impact assessment) or when
6579 // |switches::kDisableBackgroundingOccludedWindowsForTesting| is specified on
6580 // the command line (to avoid flakiness in browser tests).
6581 const bool occlusion_is_disabled =
6582 !base::FeatureList::IsEnabled(features::kWebContentsOcclusion) ||
Francois Doraye6161152018-03-27 22:05:376583 base::CommandLine::ForCurrentProcess()->HasSwitch(
6584 switches::kDisableBackgroundingOccludedWindowsForTesting);
6585 if (occlusion_is_disabled && visibility == Visibility::OCCLUDED)
6586 visibility = Visibility::VISIBLE;
6587
tapted65ff2ea72016-03-01 23:39:006588 if (!did_first_set_visible_) {
Francois Doraye6161152018-03-27 22:05:376589 if (visibility == Visibility::VISIBLE) {
6590 // A WebContents created with CreateParams::initially_hidden = false
6591 // starts with GetVisibility() == Visibility::VISIBLE even though it is
6592 // not really visible. Call WasShown() when it becomes visible for real as
6593 // the page load mechanism and some WebContentsObserver rely on that.
tapted65ff2ea72016-03-01 23:39:006594 WasShown();
Francois Dorayfe4a1772018-02-17 04:17:096595 did_first_set_visible_ = true;
tapted65ff2ea72016-03-01 23:39:006596 }
Francois Doraye6161152018-03-27 22:05:376597
6598 // Trust the initial visibility of the WebContents and do not switch it to
6599 // HIDDEN or OCCLUDED before it becomes VISIBLE for real. Doing so would
6600 // result in destroying resources that would immediately be recreated (e.g.
6601 // UpdateWebContents(HIDDEN) can be called when a WebContents is added to a
6602 // hidden window that is about to be shown).
6603
tapted65ff2ea72016-03-01 23:39:006604 return;
6605 }
Francois Doraye6161152018-03-27 22:05:376606
6607 if (visibility == visibility_)
tapted65ff2ea72016-03-01 23:39:006608 return;
6609
Francois Doraye6161152018-03-27 22:05:376610 if (visibility == Visibility::VISIBLE)
tapted65ff2ea72016-03-01 23:39:006611 WasShown();
Francois Doraye6161152018-03-27 22:05:376612 else if (visibility == Visibility::OCCLUDED)
6613 WasOccluded();
tapted65ff2ea72016-03-01 23:39:006614 else
6615 WasHidden();
6616}
6617
aelias5252baa2016-04-10 01:18:026618void WebContentsImpl::UpdateOverridingUserAgent() {
mlamouri5cd9ae82017-02-18 11:05:096619 NotifyPreferencesChanged();
aelias5252baa2016-04-10 01:18:026620}
6621
avid53461d2016-02-25 17:15:046622void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
6623 JavaScriptDialogManager* dialog_manager) {
6624 dialog_manager_ = dialog_manager;
6625}
6626
rockotf62002a2016-09-15 00:08:596627void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) {
6628 auto it = binding_sets_.find(interface_name);
6629 if (it != binding_sets_.end())
6630 binding_sets_.erase(it);
6631}
6632
nzolghadrd87a308d2016-12-07 15:45:566633bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) {
nzolghadrbbffc6c2017-05-25 17:56:396634 // Here we associate this metric to the main frame URL regardless of what
6635 // caused it.
nzolghadrd87a308d2016-12-07 15:45:566636 sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL(
6637 GetLastCommittedURL()));
nzolghadrd87a308d2016-12-07 15:45:566638 return true;
6639}
6640
ekaramada110f642016-12-21 19:47:286641void WebContentsImpl::FocusedNodeTouched(bool editable) {
6642#if defined(OS_WIN)
ekaramada110f642016-12-21 19:47:286643 RenderWidgetHostView* view = GetRenderWidgetHostView();
6644 if (!view)
6645 return;
Dave Tapuska2315d8f2018-03-06 17:52:556646 view->FocusedNodeTouched(editable);
ekaramada110f642016-12-21 19:47:286647#endif
6648}
6649
samans90fb8162017-04-04 22:30:456650void WebContentsImpl::DidReceiveCompositorFrame() {
6651 for (auto& observer : observers_)
6652 observer.DidReceiveCompositorFrame();
6653}
6654
falken52a56e32016-12-08 05:02:406655void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() {
6656 bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch(
6657 switches::kAllowInsecureLocalhost);
6658 if (!allow_localhost)
6659 return;
6660
6661 content::NavigationEntry* entry = GetController().GetLastCommittedEntry();
Rob Wuf79b3ba2018-01-14 01:54:316662 if (!entry || !net::IsLocalhost(entry->GetURL()))
falken52a56e32016-12-08 05:02:406663 return;
6664
6665 content::SSLStatus ssl_status = entry->GetSSL();
6666 bool is_cert_error = net::IsCertStatusError(ssl_status.cert_status) &&
6667 !net::IsCertStatusMinorError(ssl_status.cert_status);
6668 if (!is_cert_error)
6669 return;
6670
6671 GetMainFrame()->AddMessageToConsole(
6672 content::CONSOLE_MESSAGE_LEVEL_WARNING,
6673 base::StringPrintf("This site does not have a valid SSL "
6674 "certificate! Without SSL, your site's and "
6675 "visitors' data is vulnerable to theft and "
6676 "tampering. Get a valid SSL certificate before"
6677 " releasing your website to the public."));
6678}
6679
ekaramadf6750aa2017-06-06 18:29:426680bool WebContentsImpl::IsShowingContextMenuOnPage() const {
6681 return showing_context_menu_;
6682}
6683
Min Qina904f3302018-02-13 23:33:346684download::DownloadUrlParameters::RequestHeadersType
6685WebContentsImpl::ParseDownloadHeaders(const std::string& headers) {
6686 download::DownloadUrlParameters::RequestHeadersType request_headers;
Megan Jablonski2f6a4c52017-07-10 23:01:256687 for (const base::StringPiece& key_value : base::SplitStringPiece(
6688 headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
6689 std::vector<std::string> pair = base::SplitString(
6690 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
6691 if (2ul == pair.size())
6692 request_headers.push_back(make_pair(pair[0], pair[1]));
6693 }
6694 return request_headers;
6695}
6696
lukasza6f8ac622017-06-06 03:10:206697void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener,
6698 bool opener_suppressed) {
6699 if (opener) {
6700 FrameTreeNode* new_root = GetFrameTree()->root();
6701
6702 // For the "original opener", track the opener's main frame instead, because
6703 // if the opener is a subframe, the opener tracking could be easily bypassed
6704 // by spawning from a subframe and deleting the subframe.
6705 // https://crbug.com/705316
6706 new_root->SetOriginalOpener(opener->frame_tree()->root());
6707
6708 if (!opener_suppressed) {
6709 new_root->SetOpener(opener);
6710 created_with_opener_ = true;
6711 }
6712 }
6713}
6714
Becca Hughes9f6fd4b82017-06-15 10:01:406715void WebContentsImpl::MediaMutedStatusChanged(
6716 const WebContentsObserver::MediaPlayerId& id,
6717 bool muted) {
6718 for (auto& observer : observers_)
6719 observer.MediaMutedStatusChanged(id, muted);
6720}
6721
EhsanK2075c7e2017-08-21 02:42:396722void WebContentsImpl::SetVisibilityForChildViews(bool visible) {
6723 GetMainFrame()->SetVisibilityForChildViews(visible);
6724}
6725
[email protected]8ff00d72012-10-23 19:12:216726} // namespace content