blob: 48fbc30476cadd0204929559519b0abcc041e71c [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
avib7348942015-12-25 20:57:107#include <stddef.h>
8
w.shackleton49bcd392016-01-06 17:38:229#include <cmath>
[email protected]2bb171882012-03-07 02:09:4610#include <utility>
rkaplowe56a52032017-02-07 00:14:5411#include <vector>
[email protected]b75b8292010-10-01 07:28:2512
[email protected]36fb2c7c2011-04-04 15:49:0813#include "base/command_line.h"
creisfafed882016-07-29 00:03:0914#include "base/debug/dump_without_crashing.h"
zqzhang181047e62016-07-01 13:37:1715#include "base/feature_list.h"
jinsukkim79df88a2017-01-04 06:26:1516#include "base/i18n/character_encoding.h"
[email protected]cbb1ef592013-06-05 19:49:4617#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0718#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5619#include "base/logging.h"
avib7348942015-12-25 20:57:1020#include "base/macros.h"
fdorayba121422016-12-23 19:51:4821#include "base/memory/ptr_util.h"
dmazzonid95ae842016-04-12 21:17:3922#include "base/memory/ref_counted.h"
asvitkine8d51e9d2016-09-02 23:55:4323#include "base/metrics/histogram_macros.h"
bratell0a7406f2017-03-28 07:46:3724#include "base/metrics/user_metrics.h"
[email protected]04cbd3d2013-12-04 04:58:2025#include "base/process/process.h"
skyostil95082a62015-06-05 19:53:0726#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5127#include "base/strings/string16.h"
28#include "base/strings/string_number_conversions.h"
29#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0030#include "base/strings/utf_string_conversions.h"
gab30f26df2016-05-11 19:37:5531#include "base/threading/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3732#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4233#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1034#include "build/build_config.h"
Min Qinda0ed2062018-02-23 22:00:5335#include "components/download/public/common/download_stats.h"
nzolghadrd87a308d2016-12-07 15:45:5636#include "components/rappor/public/rappor_utils.h"
rsleevi24f64dc22015-08-07 21:39:2137#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3038#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1839#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3940#include "content/browser/browser_plugin/browser_plugin_embedder.h"
41#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5942#include "content/browser/child_process_security_policy_impl.h"
Pavel Feldman3c1842b2017-08-02 05:00:1643#include "content/browser/devtools/protocol/page_handler.h"
dgozmanf00c4f72016-10-19 17:45:1544#include "content/browser/devtools/render_frame_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4145#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0446#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]aa4f3972012-03-01 18:12:1247#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1648#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1749#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1650#include "content/browser/frame_host/cross_process_frame_connector.h"
ananta4b7467a52016-09-23 01:42:3851#include "content/browser/frame_host/frame_tree_node.h"
[email protected]d4a8ca482013-10-30 21:06:4052#include "content/browser/frame_host/interstitial_page_impl.h"
53#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3354#include "content/browser/frame_host/navigation_handle_impl.h"
Arthur Hemeryc3380172018-01-22 14:00:1755#include "content/browser/frame_host/navigation_request.h"
[email protected]6ea6bdf2013-12-06 13:35:0156#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1857#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0758#include "content/browser/frame_host/render_frame_proxy_host.h"
Kenneth Russell954ed9ce2018-04-12 23:07:0159#include "content/browser/gpu/gpu_data_manager_impl.h"
csharrison2e8c98e2016-08-01 23:56:2560#include "content/browser/loader/loader_io_thread_notifier.h"
[email protected]678c0362012-12-05 08:02:4461#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4062#include "content/browser/manifest/manifest_manager_host.h"
Max Morin5bc74f52018-05-09 07:00:2163#include "content/browser/media/audio_stream_broker.h"
dalecurtisbc6572e12014-09-12 19:22:3064#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5265#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1866#include "content/browser/media/media_web_contents_observer.h"
zqzhang1adf3cb2016-11-01 11:26:4567#include "content/browser/media/session/media_session_impl.h"
tommyclieb25b2a2014-11-03 19:45:0968#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3069#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5070#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3271#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5072#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5973#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4874#include "content/browser/renderer_host/render_widget_host_view_base.h"
Ken Buchanandaef006b2017-08-17 18:32:1575#include "content/browser/renderer_host/render_widget_host_view_child_frame.h"
ekaramadadd882292016-06-08 15:22:5676#include "content/browser/renderer_host/text_input_manager.h"
leon.han552e9de2017-02-09 14:37:3077#include "content/browser/screen_orientation/screen_orientation_provider.h"
[email protected]b6583592012-01-25 19:52:3378#include "content/browser/site_instance_impl.h"
lfgc740d4b22016-04-15 16:45:3379#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1180#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5881#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0382#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5683#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1484#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4285#include "content/common/browser_plugin/browser_plugin_messages.h"
Paul Meyer0c58c3712016-11-17 22:59:5186#include "content/common/drag_messages.h"
[email protected]f114fa42013-12-06 17:06:4487#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1788#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0789#include "content/common/page_messages.h"
nasko34634672016-07-29 18:46:0690#include "content/common/page_state_serialization.h"
rockot5c478a72016-09-28 23:14:1891#include "content/common/render_message_filter.mojom.h"
[email protected]2c5569662011-03-22 20:45:0292#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3693#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1194#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2895#include "content/public/browser/browser_plugin_guest_manager.h"
Gabriel Charette790754c2018-03-16 21:32:5996#include "content/public/browser/browser_thread.h"
[email protected]87f3c082011-10-19 18:07:4497#include "content/public/browser/content_browser_client.h"
[email protected]e582fdd2011-12-20 16:48:1798#include "content/public/browser/download_manager.h"
ekaramada110f642016-12-21 19:47:2899#include "content/public/browser/focused_node_details.h"
ekaramad1beabecc2016-09-23 20:18:17100#include "content/public/browser/guest_mode.h"
[email protected]d9083482012-01-06 00:38:46101#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:15102#include "content/public/browser/javascript_dialog_manager.h"
skyf65d9bb2017-03-24 02:26:39103#include "content/public/browser/keyboard_event_processing_result.h"
[email protected]09d31d52012-03-11 22:30:27104#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:00105#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:37106#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:14107#include "content/public/browser/notification_service.h"
scottmg011d96e32016-06-29 19:15:08108#include "content/public/browser/notification_types.h"
[email protected]95640212014-07-26 18:14:30109#include "content/public/browser/render_widget_host_iterator.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:06110#include "content/public/browser/restore_type.h"
estark5ea80e52015-06-19 18:43:12111#include "content/public/browser/security_style_explanations.h"
falken52a56e32016-12-08 05:02:40112#include "content/public/browser/ssl_status.h"
[email protected]4c3a23582012-08-18 08:54:34113#include "content/public/browser/storage_partition.h"
rockotf62002a2016-09-15 00:08:59114#include "content/public/browser/web_contents_binding_set.h"
[email protected]674bc592011-12-20 23:00:42115#include "content/public/browser/web_contents_delegate.h"
Lei Zhangee3b63ad2018-06-06 23:25:31116#include "content/public/browser/web_ui_controller.h"
[email protected]e091df82011-10-11 18:13:21117#include "content/public/common/bindings_policy.h"
carloskd80262f52015-12-16 14:40:35118#include "content/public/common/browser_side_navigation_policy.h"
alexmosc9e76ec2016-05-16 22:59:37119#include "content/public/common/child_process_host.h"
[email protected]54087fe2011-10-28 22:02:48120#include "content/public/common/content_constants.h"
Francois Doray3f2afbd2018-04-06 19:18:18121#include "content/public/common/content_features.h"
[email protected]64d69de42012-02-06 00:19:54122#include "content/public/common/content_switches.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:06123#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:49124#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20125#include "content/public/common/result_codes.h"
Ke He7319dbe2017-11-09 05:54:44126#include "content/public/common/service_manager_connection.h"
[email protected]f16cc6782013-12-16 23:42:57127#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05128#include "content/public/common/web_preferences.h"
wjmaclean64951902016-04-29 20:59:12129#include "net/base/url_util.h"
[email protected]8bfc8272013-09-09 20:10:53130#include "net/http/http_cache.h"
131#include "net/http/http_transaction_factory.h"
rhalavati0fbaeef32017-06-01 15:56:30132#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]8bfc8272013-09-09 20:10:53133#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34134#include "net/url_request/url_request_context_getter.h"
Scott Violet02e38b92018-03-27 23:42:14135#include "ppapi/buildflags/buildflags.h"
Ke He31d0bb02018-02-24 07:16:24136#include "services/device/public/mojom/constants.mojom.h"
Mounir Lamourifd9dcefa2017-07-06 10:26:55137#include "services/metrics/public/cpp/ukm_recorder.h"
Ke He7319dbe2017-11-09 05:54:44138#include "services/service_manager/public/cpp/connector.h"
rockot734fb662016-10-15 16:41:30139#include "services/service_manager/public/cpp/interface_provider.h"
Becca Hughes6daf5662018-06-27 16:50:54140#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Blink Reformata30d4232018-04-07 15:31:06141#include "third_party/blink/public/common/frame/sandbox_flags.h"
142#include "third_party/blink/public/common/mime_util/mime_util.h"
143#include "third_party/blink/public/platform/web_security_style.h"
halton.huoca2eabd2015-07-06 08:17:40144#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39145#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56146#include "ui/base/layout.h"
Daniel Cheng90196c82018-04-25 21:49:14147#include "ui/events/base_event_utils.h"
chongz4a9751942016-08-17 17:49:39148#include "ui/events/blink/web_input_event_traits.h"
[email protected]66bd5512012-08-01 02:02:52149#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31150
ekaramada110f642016-12-21 19:47:28151#if defined(OS_WIN)
152#include "content/browser/renderer_host/dip_util.h"
153#include "ui/gfx/geometry/dip_util.h"
154#endif
155
[email protected]583418cc2013-01-17 14:01:10156#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40157#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15158#include "content/browser/android/date_time_chooser_android.h"
sammcf5f1b0f2016-09-20 23:05:11159#include "content/browser/android/java_interfaces_impl.h"
dalecurtisc85ed632016-01-13 00:22:46160#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18161#include "content/browser/web_contents/web_contents_android.h"
Ke He31d0bb02018-02-24 07:16:24162#include "services/device/public/mojom/nfc.mojom.h"
mcnee336ea2c2017-05-23 22:50:59163#else // !OS_ANDROID
164#include "content/browser/host_zoom_map_impl.h"
165#include "content/browser/host_zoom_map_observer.h"
mfomitchev2b8b066a2016-01-28 19:23:15166#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10167
brettw4b461082016-11-19 18:55:16168#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17169#include "content/browser/media/session/pepper_playback_observer.h"
Lei Zhangebcc6302018-01-12 19:46:45170#endif
zqzhang181047e62016-07-01 13:37:17171
[email protected]8ff00d72012-10-23 19:12:21172namespace content {
[email protected]420ae012009-04-24 05:16:32173namespace {
174
[email protected]960b0372014-05-19 18:01:00175const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41176const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05177
[email protected]155c7f22013-12-09 17:07:18178#if defined(OS_ANDROID)
rob.buisf06a8bf2017-03-10 18:11:32179const void* const kWebContentsAndroidKey = &kWebContentsAndroidKey;
Lei Zhangebcc6302018-01-12 19:46:45180#endif
[email protected]155c7f22013-12-09 17:07:18181
Avi Drissmana9114822018-03-23 18:25:55182base::LazyInstance<std::vector<
183 WebContentsImpl::FriendWrapper::CreatedCallback>>::DestructorAtExit
184 g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
[email protected]cbb1ef592013-06-05 19:49:46185
[email protected]8bfc8272013-09-09 20:10:53186void NotifyCacheOnIO(
187 scoped_refptr<net::URLRequestContextGetter> request_context,
188 const GURL& url,
189 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58190 net::HttpCache* cache = request_context->GetURLRequestContext()->
191 http_transaction_factory()->GetCache();
192 if (cache)
193 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53194}
195
dcheng57e39e22016-01-21 00:25:38196bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
197 for (FrameTreeNode* node : tree->Nodes()) {
198 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
199 return true;
alexmos4cf2aa32015-07-15 23:40:43200 }
dcheng57e39e22016-01-21 00:25:38201 return false;
[email protected]95640212014-07-26 18:14:30202}
203
kenrb19221852016-04-29 17:21:40204bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) {
205 // This method scans the frame tree rather than checking whether
206 // host->delegate() == this, which allows it to return false when the host
207 // for a frame that is pending or pending deletion.
208 if (!host)
209 return false;
210
211 for (FrameTreeNode* node : tree->Nodes()) {
212 if (node->current_frame_host()->GetRenderWidgetHost() == host)
213 return true;
214 }
215 return false;
216}
217
dmazzonif8a31042016-12-03 00:52:13218void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) {
219 static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode();
[email protected]95640212014-07-26 18:14:30220}
221
dtseng0dd3fa12015-07-22 19:00:52222void ResetAccessibility(RenderFrameHost* rfh) {
223 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
224}
225
paulmeyerfeafc2d2017-04-25 21:46:40226// Helper for GetInnerWebContents().
227bool GetInnerWebContentsHelper(
228 std::vector<WebContentsImpl*>* all_guest_contents,
229 WebContents* guest_contents) {
230 all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents));
231 return false;
232}
233
Ian Clelland5cbaaf82017-11-27 22:00:03234RenderFrameHostImpl* FindOpenerRFH(const WebContents::CreateParams& params) {
235 RenderFrameHostImpl* opener_rfh = nullptr;
alexmose201c7cd2015-06-10 17:14:21236 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
Ian Clelland5cbaaf82017-11-27 22:00:03237 opener_rfh = RenderFrameHostImpl::FromID(params.opener_render_process_id,
238 params.opener_render_frame_id);
alexmose201c7cd2015-06-10 17:14:21239 }
Ian Clelland5cbaaf82017-11-27 22:00:03240 return opener_rfh;
lukasza6f8ac622017-06-06 03:10:20241}
242
Pavel Feldman3c1842b2017-08-02 05:00:16243// Ensures that OnDialogClosed is only called once.
244class CloseDialogCallbackWrapper
245 : public base::RefCountedThreadSafe<CloseDialogCallbackWrapper> {
246 public:
Avi Drissmane04d3992017-10-05 15:11:36247 using CloseCallback =
248 base::OnceCallback<void(bool, bool, const base::string16&)>;
249
250 explicit CloseDialogCallbackWrapper(CloseCallback callback)
251 : callback_(std::move(callback)) {}
Pavel Feldman3c1842b2017-08-02 05:00:16252
253 void Run(bool dialog_was_suppressed,
254 bool success,
255 const base::string16& user_input) {
Avi Drissmane04d3992017-10-05 15:11:36256 if (callback_.is_null())
Pavel Feldman3c1842b2017-08-02 05:00:16257 return;
Avi Drissmane04d3992017-10-05 15:11:36258 std::move(callback_).Run(dialog_was_suppressed, success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:16259 }
260
261 private:
262 friend class base::RefCountedThreadSafe<CloseDialogCallbackWrapper>;
263 ~CloseDialogCallbackWrapper() {}
Avi Drissmane04d3992017-10-05 15:11:36264
265 CloseCallback callback_;
Pavel Feldman3c1842b2017-08-02 05:00:16266};
267
lukasza6f8ac622017-06-06 03:10:20268} // namespace
269
Erik Chenbb8e738e2018-04-28 14:10:43270std::unique_ptr<WebContents> WebContents::Create(
271 const WebContents::CreateParams& params) {
erikchen50735fd2018-05-05 15:08:33272 return WebContentsImpl::CreateWithOpener(params, FindOpenerRFH(params));
[email protected]d1198fd2012-08-13 22:50:19273}
274
erikchenade1fef2018-05-02 22:07:57275std::unique_ptr<WebContents> WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59276 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30277 const SessionStorageNamespaceMap& session_storage_namespace_map) {
erikchenade1fef2018-05-02 22:07:57278 std::unique_ptr<WebContentsImpl> new_contents(
279 new WebContentsImpl(params.browser_context));
Ian Clelland5cbaaf82017-11-27 22:00:03280 RenderFrameHostImpl* opener_rfh = FindOpenerRFH(params);
281 FrameTreeNode* opener = nullptr;
282 if (opener_rfh)
283 opener = opener_rfh->frame_tree_node();
284 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
[email protected]fdac6ade2013-07-20 01:06:30285
286 for (SessionStorageNamespaceMap::const_iterator it =
287 session_storage_namespace_map.begin();
288 it != session_storage_namespace_map.end();
289 ++it) {
290 new_contents->GetController()
291 .SetSessionStorageNamespace(it->first, it->second.get());
292 }
293
Sam McNally69a33772018-06-27 16:54:12294 if (params.guest_delegate) {
295 // This makes |new_contents| act as a guest.
296 // For more info, see comment above class BrowserPluginGuest.
297 BrowserPluginGuest::Create(new_contents.get(), params.guest_delegate);
298 }
299
[email protected]54944cde2012-12-09 09:24:59300 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19301 return new_contents;
[email protected]a81343d232011-12-27 07:39:20302}
[email protected]746d3052012-05-22 15:15:47303
benwells5e7260d2017-03-20 23:36:33304void WebContentsImpl::FriendWrapper::AddCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37305 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46306 g_created_callbacks.Get().push_back(callback);
307}
308
benwells5e7260d2017-03-20 23:36:33309void WebContentsImpl::FriendWrapper::RemoveCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37310 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46311 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
312 if (g_created_callbacks.Get().at(i).Equals(callback)) {
313 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
314 return;
315 }
316 }
317}
318
avidf38c952015-10-27 13:45:13319WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
320 if (!rvh)
321 return nullptr;
[email protected]746d3052012-05-22 15:15:47322 return rvh->GetDelegate()->GetAsWebContents();
323}
324
[email protected]a86c0e962013-12-17 17:10:39325WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13326 if (!rfh)
327 return nullptr;
328 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39329}
330
ananta4b7467a52016-09-23 01:42:38331WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) {
332 FrameTreeNode* frame_tree_node =
333 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
anantab8cfa3b2016-10-14 22:43:19334 if (!frame_tree_node)
335 return nullptr;
jam8c4edd02017-05-06 18:50:33336 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
ananta4b7467a52016-09-23 01:42:38337}
338
leon.han552e9de2017-02-09 14:37:30339void WebContents::SetScreenOrientationDelegate(
340 ScreenOrientationDelegate* delegate) {
341 ScreenOrientationProvider::SetDelegate(delegate);
342}
343
[email protected]7fff43e2013-05-21 20:21:10344// WebContentsImpl::DestructionObserver ----------------------------------------
345
346class WebContentsImpl::DestructionObserver : public WebContentsObserver {
347 public:
348 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
349 : WebContentsObserver(watched_contents),
350 owner_(owner) {
351 }
352
353 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58354 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58355 owner_->OnWebContentsDestroyed(
356 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10357 }
358
359 private:
360 WebContentsImpl* owner_;
361
362 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
363};
364
Joel Hockey85b379d2017-12-11 10:42:13365// WebContentsImpl::ColorChooser ----------------------------------------------
Joel Hockey163835a2017-12-20 11:51:57366class WebContentsImpl::ColorChooser : public blink::mojom::ColorChooser {
Joel Hockey85b379d2017-12-11 10:42:13367 public:
368 ColorChooser(content::ColorChooser* chooser,
Joel Hockey163835a2017-12-20 11:51:57369 blink::mojom::ColorChooserRequest request,
370 blink::mojom::ColorChooserClientPtr client)
Joel Hockey85b379d2017-12-11 10:42:13371 : chooser_(chooser),
372 binding_(this, std::move(request)),
373 client_(std::move(client)) {
374 binding_.set_connection_error_handler(
375 base::BindOnce([](content::ColorChooser* chooser) { chooser->End(); },
376 base::Unretained(chooser)));
377 }
[email protected]8ed16472014-04-11 19:02:48378
Joel Hockey85b379d2017-12-11 10:42:13379 ~ColorChooser() override { chooser_->End(); }
[email protected]8ed16472014-04-11 19:02:48380
Joel Hockey85b379d2017-12-11 10:42:13381 void SetSelectedColor(SkColor color) override {
382 chooser_->SetSelectedColor(color);
383 }
384
385 void DidChooseColorInColorChooser(SkColor color) {
386 client_->DidChooseColor(color);
387 }
388
389 private:
390 // Color chooser that was opened by this tab.
391 std::unique_ptr<content::ColorChooser> chooser_;
392
393 // mojo bindings.
Joel Hockey163835a2017-12-20 11:51:57394 mojo::Binding<blink::mojom::ColorChooser> binding_;
Joel Hockey85b379d2017-12-11 10:42:13395
396 // mojo renderer client.
Joel Hockey163835a2017-12-20 11:51:57397 blink::mojom::ColorChooserClientPtr client_;
Joel Hockey85b379d2017-12-11 10:42:13398};
nicka0ac8382016-12-15 23:59:23399
Becca Hughes6fe54e432018-06-09 04:18:56400// WebContentsImpl::DisplayCutoutHostImpl --------------------------------------
401
402class WebContentsImpl::DisplayCutoutHostImpl
Becca Hughese9e27952018-06-25 17:08:27403 : public blink::mojom::DisplayCutoutHost,
404 public WebContentsObserver {
Becca Hughes6fe54e432018-06-09 04:18:56405 public:
406 explicit DisplayCutoutHostImpl(WebContentsImpl* web_contents)
Becca Hughese9e27952018-06-25 17:08:27407 : WebContentsObserver(web_contents), bindings_(web_contents, this) {}
Becca Hughes6fe54e432018-06-09 04:18:56408
409 // blink::mojom::DisplayCutoutHost
Becca Hughese9e27952018-06-25 17:08:27410 void NotifyViewportFitChanged(blink::mojom::ViewportFit value) override {
Becca Hughes6fe54e432018-06-09 04:18:56411 ViewportFitChangedForFrame(bindings_.GetCurrentTargetFrame(), value);
412 }
413
Becca Hughese9e27952018-06-25 17:08:27414 // Stores the updated viewport fit value for a |frame| and notifies observers
415 // if it has changed.
Becca Hughes6fe54e432018-06-09 04:18:56416 void ViewportFitChangedForFrame(RenderFrameHost* rfh,
417 blink::mojom::ViewportFit value) {
418 if (GetValueOrDefault(rfh) == value)
419 return;
420
421 values_[rfh] = value;
422
Becca Hughes9ef7f452018-06-27 16:57:31423 // If we are the current |RenderFrameHost| frame then notify
424 // WebContentsObservers about the new value.
425 if (current_rfh_ == rfh)
Becca Hughese9e27952018-06-25 17:08:27426 NotifyObservers(value);
427 }
428
429 // WebContentsObserver override.
430 void DidAcquireFullscreen(RenderFrameHost* rfh) override {
Becca Hughes9ef7f452018-06-27 16:57:31431 SetCurrentRenderFrameHost(rfh);
Becca Hughese9e27952018-06-25 17:08:27432 }
433
434 // WebContentsObserver override.
435 void DidToggleFullscreenModeForTab(bool entered_fullscreen,
436 bool will_cause_resize) override {
437 if (!entered_fullscreen)
Becca Hughes9ef7f452018-06-27 16:57:31438 SetCurrentRenderFrameHost(nullptr);
Becca Hughes6fe54e432018-06-09 04:18:56439 }
440
441 // Removes any state built up by a render frame.
Becca Hughes9ef7f452018-06-27 16:57:31442 void RenderFrameDeleted(RenderFrameHost* rfh) override {
443 values_.erase(rfh);
444
445 // If we were the current |RenderFrameHost| then we should clear that.
446 if (current_rfh_ == rfh)
447 SetCurrentRenderFrameHost(nullptr);
448 }
Becca Hughes6fe54e432018-06-09 04:18:56449
Becca Hughes6daf5662018-06-27 16:50:54450 // Updates the safe area insets on the current frame.
451 void SetDisplayCutoutSafeArea(gfx::Insets insets) {
Becca Hughes9ef7f452018-06-27 16:57:31452 insets_ = insets;
453
454 if (current_rfh_)
455 SendSafeAreaToFrame(current_rfh_, insets);
456 }
457
458 private:
459 // Set the current |RenderFrameHost| that should have control over the
460 // viewport fit value and we should set safe area insets on.
461 void SetCurrentRenderFrameHost(RenderFrameHost* rfh) {
462 if (current_rfh_ == rfh)
463 return;
464
465 // If we had a previous frame then we should clear the insets on that frame.
466 if (current_rfh_)
467 SendSafeAreaToFrame(current_rfh_, gfx::Insets());
468
469 // If the new RenderFrameHost is nullptr we should stop here and notify
470 // observers that the new viewport fit is kAuto (the default).
471 current_rfh_ = rfh;
472 if (!rfh) {
473 NotifyObservers(blink::mojom::ViewportFit::kAuto);
474 return;
475 }
476
477 // Send the current safe area to the new frame.
478 SendSafeAreaToFrame(rfh, insets_);
479
480 // Notify the WebContentsObservers that the viewport fit value has changed.
481 NotifyObservers(GetValueOrDefault(rfh));
482 }
483
484 // Send the safe area insets to a |RenderFrameHost|.
485 void SendSafeAreaToFrame(RenderFrameHost* rfh, gfx::Insets insets) {
Becca Hughes6daf5662018-06-27 16:50:54486 blink::AssociatedInterfaceProvider* provider =
Becca Hughes9ef7f452018-06-27 16:57:31487 rfh->GetRemoteAssociatedInterfaces();
Becca Hughes6daf5662018-06-27 16:50:54488 if (!provider)
489 return;
490
491 blink::mojom::DisplayCutoutClientAssociatedPtr client;
492 provider->GetInterface(&client);
493 client->SetSafeArea(blink::mojom::DisplayCutoutSafeArea::New(
494 insets.top(), insets.left(), insets.bottom(), insets.right()));
495 }
496
Becca Hughes9ef7f452018-06-27 16:57:31497 // Notify WebContentsObservers that the viewport fit value has changed.
Becca Hughese9e27952018-06-25 17:08:27498 void NotifyObservers(blink::mojom::ViewportFit value) {
499 for (auto& observer : web_contents_impl()->observers_)
500 observer.ViewportFitChanged(value);
501 }
502
Becca Hughes6fe54e432018-06-09 04:18:56503 // Get the stored viewport fit value for a frame or kAuto if there is no
504 // stored value.
505 blink::mojom::ViewportFit GetValueOrDefault(RenderFrameHost* rfh) const {
506 auto value = values_.find(rfh);
507 if (value != values_.end())
508 return value->second;
509 return blink::mojom::ViewportFit::kAuto;
510 }
511
Becca Hughese9e27952018-06-25 17:08:27512 WebContentsImpl* web_contents_impl() {
513 return static_cast<WebContentsImpl*>(web_contents());
514 }
515
Becca Hughes9ef7f452018-06-27 16:57:31516 // Stores the current safe area insets.
517 gfx::Insets insets_ = gfx::Insets();
518
519 // Stores the current |RenderFrameHost| that has the applied safe area insets
520 // and is controlling the viewport fit value.
521 RenderFrameHost* current_rfh_ = nullptr;
522
Becca Hughes6fe54e432018-06-09 04:18:56523 // Stores a map of RenderFrameHosts and their current viewport fit values.
524 std::map<RenderFrameHost*, blink::mojom::ViewportFit> values_;
525
Becca Hughes6fe54e432018-06-09 04:18:56526 WebContentsFrameBindingSet<blink::mojom::DisplayCutoutHost> bindings_;
527};
528
lazyboy6ec48b2a2015-06-29 15:18:14529// WebContentsImpl::WebContentsTreeNode ----------------------------------------
lfg601233692017-03-06 22:45:44530WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode(
531 WebContentsImpl* current_web_contents)
532 : current_web_contents_(current_web_contents),
533 outer_web_contents_(nullptr),
lazyboy6ec48b2a2015-06-29 15:18:14534 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33535 FrameTreeNode::kFrameTreeNodeInvalidId),
lfg601233692017-03-06 22:45:44536 focused_web_contents_(current_web_contents) {}
lazyboy6ec48b2a2015-06-29 15:18:14537
538WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
lfga3e2bdc2017-03-07 20:44:01539 if (OuterContentsFrameTreeNode())
540 OuterContentsFrameTreeNode()->RemoveObserver(this);
paulmeyerfeafc2d2017-04-25 21:46:40541
542 if (outer_web_contents_)
543 outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_);
lazyboy6ec48b2a2015-06-29 15:18:14544}
545
546void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
547 WebContentsImpl* outer_web_contents,
548 RenderFrameHostImpl* outer_contents_frame) {
lfg601233692017-03-06 22:45:44549 focused_web_contents_ = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:14550 outer_web_contents_ = outer_web_contents;
551 outer_contents_frame_tree_node_id_ =
552 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
553
paulmeyerfeafc2d2017-04-25 21:46:40554 outer_web_contents_->node_.AttachInnerWebContents(current_web_contents_);
lfga3e2bdc2017-03-07 20:44:01555 outer_contents_frame->frame_tree_node()->AddObserver(this);
lfg601233692017-03-06 22:45:44556}
lazyboy6ec48b2a2015-06-29 15:18:14557
paulmeyerfeafc2d2017-04-25 21:46:40558void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents(
559 WebContentsImpl* inner_web_contents) {
560 inner_web_contents_.push_back(inner_web_contents);
561}
562
563void WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents(
564 WebContentsImpl* inner_web_contents) {
565 DCHECK(std::find(inner_web_contents_.begin(), inner_web_contents_.end(),
566 inner_web_contents) != inner_web_contents_.end());
567 inner_web_contents_.erase(
568 std::remove(inner_web_contents_.begin(), inner_web_contents_.end(),
569 inner_web_contents),
570 inner_web_contents_.end());
571}
572
lfga3e2bdc2017-03-07 20:44:01573FrameTreeNode*
574WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const {
575 return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_);
lfg601233692017-03-06 22:45:44576}
577
lfga3e2bdc2017-03-07 20:44:01578void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed(
579 FrameTreeNode* node) {
580 DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id())
581 << "WebContentsTreeNode should only receive notifications for the "
582 "FrameTreeNode in its outer WebContents that hosts it.";
583 delete current_web_contents_; // deletes |this| too.
lazyboy6ec48b2a2015-06-29 15:18:14584}
585
avallee0206f782016-07-28 18:55:33586void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
587 WebContentsImpl* web_contents) {
588 DCHECK(!outer_web_contents())
589 << "Only the outermost WebContents tracks focus.";
590 focused_web_contents_ = web_contents;
591}
592
paulmeyerfeafc2d2017-04-25 21:46:40593WebContentsImpl*
594WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame(
595 const FrameTreeNode* frame) {
596 auto ftn_id = frame->frame_tree_node_id();
597 for (WebContentsImpl* contents : inner_web_contents_) {
598 if (contents->node_.outer_contents_frame_tree_node_id() == ftn_id) {
599 return contents;
600 }
601 }
602 return nullptr;
603}
604
605const std::vector<WebContentsImpl*>&
606WebContentsImpl::WebContentsTreeNode::inner_web_contents() const {
607 return inner_web_contents_;
608}
609
[email protected]b172aee2012-04-10 17:05:26610// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32611
alexmose201c7cd2015-06-10 17:14:21612WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28613 : delegate_(nullptr),
[email protected]69e797f2013-04-30 01:10:22614 controller_(this, browser_context),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28615 render_view_host_delegate_view_(nullptr),
alexmose201c7cd2015-06-10 17:14:21616 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01617 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57618 this,
619 this,
620 this,
621 this),
lfg601233692017-03-06 22:45:44622 node_(this),
[email protected]6dfed692014-05-22 04:18:03623 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23624 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
625 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34626 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26627 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56628 upload_size_(0),
629 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16630 is_resume_pending_(false),
creisadca9862017-06-16 19:12:11631 interstitial_page_(nullptr),
[email protected]b4c84012014-04-28 19:51:10632 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28633 theme_color_(SK_ColorTRANSPARENT),
634 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29635 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55636 capturer_count_(0),
[email protected]fdd61c62009-04-22 19:22:57637 is_being_destroyed_(false),
creis97867aa2017-02-17 18:39:45638 is_notifying_observers_(false),
[email protected]fdd61c62009-04-22 19:22:57639 notify_disconnection_(false),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28640 dialog_manager_(nullptr),
[email protected]7ab1e7d62009-10-14 23:32:01641 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39642 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38643 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21644 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
645 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22646 zoom_scroll_remainder_(0),
alexmosc9e76ec2016-05-16 22:59:37647 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42648 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03649 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]34ff1cfc2014-08-20 06:16:05650 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30651 last_dialog_suppressed_(false),
waffles1c12bf402016-02-10 17:45:48652 accessibility_mode_(
653 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15654 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35655 bluetooth_connected_device_count_(0),
Guido Urdanetaf4008002018-05-03 10:43:04656 media_device_group_id_salt_base_(
657 BrowserContext::CreateRandomMediaDeviceIDSalt()),
mcnee336ea2c2017-05-23 22:50:59658#if !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:46659 page_scale_factor_is_one_(true),
mcnee336ea2c2017-05-23 22:50:59660#endif // !defined(OS_ANDROID)
qinmin72e8bd02016-10-21 19:35:37661 is_overlay_content_(false),
ekaramadf6750aa2017-06-06 18:29:42662 showing_context_menu_(false),
pkotwicz75ca8ffd2016-02-16 23:10:19663 loading_weak_factory_(this),
664 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55665 frame_tree_.SetFrameRemoveListener(
666 base::Bind(&WebContentsImpl::OnFrameRemoved,
667 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46668#if defined(OS_ANDROID)
669 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
670#else
qinmin58567c82015-01-07 21:00:20671 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46672#endif
brettw4b461082016-11-19 18:55:16673#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17674 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
675#endif
blundelle75a8f92017-03-27 08:11:17676
csharrisona2280cd2016-02-03 23:21:15677 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
mcnee336ea2c2017-05-23 22:50:59678#if !defined(OS_ANDROID)
scottmg276753cf2016-10-27 18:25:22679 host_zoom_map_observer_.reset(new HostZoomMapObserver(this));
mcnee336ea2c2017-05-23 22:50:59680#endif // !defined(OS_ANDROID)
Joel Hockey85b379d2017-12-11 10:42:13681
Becca Hughes6fe54e432018-06-09 04:18:56682 display_cutout_host_impl_ = std::make_unique<DisplayCutoutHostImpl>(this);
683
Joel Hockey85b379d2017-12-11 10:42:13684 registry_.AddInterface(base::BindRepeating(
685 &WebContentsImpl::OnColorChooserFactoryRequest, base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35686}
initial.commit09911bf2008-07-26 23:55:29687
[email protected]b172aee2012-04-10 17:05:26688WebContentsImpl::~WebContentsImpl() {
creisba91ba82017-05-12 22:56:19689 // Imperfect sanity check against double free, given some crashes unexpectedly
690 // observed in the wild.
691 CHECK(!is_being_destroyed_);
692
693 // We generally keep track of is_being_destroyed_ to let other features know
694 // to avoid certain actions during destruction.
[email protected]420ae012009-04-24 05:16:32695 is_being_destroyed_ = true;
696
creis97867aa2017-02-17 18:39:45697 // A WebContents should never be deleted while it is notifying observers,
creisba91ba82017-05-12 22:56:19698 // since this will lead to a use-after-free as it continues to notify later
creis97867aa2017-02-17 18:39:45699 // observers.
700 CHECK(!is_notifying_observers_);
701
kenrb2a565f82015-09-02 20:24:59702 rwh_input_event_router_.reset();
703
rockotf62002a2016-09-15 00:08:59704 for (auto& entry : binding_sets_)
705 entry.second->CloseAllBindings();
706
avallee0206f782016-07-28 18:55:33707 WebContentsImpl* outermost = GetOutermostWebContents();
avallee9993fca2016-11-17 06:16:50708 if (this != outermost && ContainsOrIsFocusedWebContents()) {
avallee0206f782016-07-28 18:55:33709 // If the current WebContents is in focus, unset it.
avallee9993fca2016-11-17 06:16:50710 outermost->SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:33711 }
712
Nick Carterd73635b2018-03-13 18:31:41713 if (mouse_lock_widget_)
714 mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary();
715
dcheng72be33c2016-01-21 04:11:31716 for (FrameTreeNode* node : frame_tree_.Nodes()) {
717 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
718 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38719 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38720 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31721 }
carlosk35f35af2015-12-01 10:55:40722
dcheng57e39e22016-01-21 00:25:38723 for (RenderWidgetHostImpl* widget : created_widgets_)
724 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26725 created_widgets_.clear();
726
[email protected]3ab9cb82011-06-03 18:02:07727 // Clear out any JavaScript state.
avi5d3b8692016-10-12 22:00:46728 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:53729 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:46730 }
[email protected]3ab9cb82011-06-03 18:02:07731
Joel Hockey85b379d2017-12-11 10:42:13732 color_chooser_.reset();
[email protected]da8543762012-03-20 08:52:20733
[email protected]420ae012009-04-24 05:16:32734 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32735
[email protected]ca13a442012-04-17 14:00:12736 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21737 NotificationService::current()->Notify(
738 NOTIFICATION_WEB_CONTENTS_DESTROYED,
739 Source<WebContents>(this),
740 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32741
[email protected]df0c843f2014-05-23 20:37:23742 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14743 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23744 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59745
clamy0e119882015-07-31 16:12:33746 // Manually call the observer methods for the root frame tree node. It is
747 // necessary to manually delete all objects tracking navigations
748 // (NavigationHandle, NavigationRequest) for observers to be properly
749 // notified of these navigations stopping before the WebContents is
750 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23751 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56752
naskob21fe4872015-02-24 14:15:56753 root->current_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28754 root->current_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33755
Arthur Hemeryc3380172018-01-22 14:00:17756 // Do not update state as the WebContents is being destroyed.
757 frame_tree_.root()->ResetNavigationRequest(true, true);
758 if (root->speculative_frame_host()) {
759 root->speculative_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28760 root->speculative_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33761 }
[email protected]f273ee52013-10-18 16:05:27762
brettw4b461082016-11-19 18:55:16763#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17764 // Call this before WebContentsDestroyed() is broadcasted since
765 // AudioFocusManager will be destroyed after that.
766 pepper_playback_observer_.reset();
767#endif // defined(ENABLED_PLUGINS)
768
Chris Hamiltondf0d72cd2018-05-29 16:23:53769 // If audio is playing then notify external observers of the audio stream
770 // disappearing.
771 if (is_currently_audible_) {
772 is_currently_audible_ = false;
773 for (auto& observer : observers_)
774 observer.OnAudioStateChanged(false);
775
776 if (GetOuterWebContents())
777 GetOuterWebContents()->OnAudioStateChanged();
778 }
779
ericwilligersde386342016-10-19 02:35:09780 for (auto& observer : observers_)
781 observer.FrameDeleted(root->current_frame_host());
naskoa83483fb2015-02-27 16:57:10782
ericwilligersde386342016-10-19 02:35:09783 for (auto& observer : observers_)
784 observer.RenderViewDeleted(root->current_host());
[email protected]f273ee52013-10-18 16:05:27785
ericwilligersde386342016-10-19 02:35:09786 for (auto& observer : observers_)
787 observer.WebContentsDestroyed();
[email protected]12a46832014-05-09 13:35:58788
ericwilligersde386342016-10-19 02:35:09789 for (auto& observer : observers_)
790 observer.ResetWebContents();
[email protected]232a5812011-03-04 22:42:08791
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28792 SetDelegate(nullptr);
[email protected]b5a1d11c2011-02-17 03:09:42793}
794
erikchen50735fd2018-05-05 15:08:33795std::unique_ptr<WebContentsImpl> WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59796 const WebContents::CreateParams& params,
Ian Clelland5cbaaf82017-11-27 22:00:03797 RenderFrameHostImpl* opener_rfh) {
[email protected]e11f0e92013-06-12 15:12:03798 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
Ian Clelland5cbaaf82017-11-27 22:00:03799 FrameTreeNode* opener = nullptr;
800 if (opener_rfh)
801 opener = opener_rfh->frame_tree_node();
erikchen50735fd2018-05-05 15:08:33802 std::unique_ptr<WebContentsImpl> new_contents(
803 new WebContentsImpl(params.browser_context));
lukasza6f8ac622017-06-06 03:10:20804 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
alexmose201c7cd2015-06-10 17:14:21805
alexmosaedfc6f2016-01-21 23:57:38806 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
807 // flags, and these flags take effect immediately. An exception is if the
808 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
809 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
810 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
lukasza6f8ac622017-06-06 03:10:20811 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
alexmosaedfc6f2016-01-21 23:57:38812 if (opener) {
Ian Clelland5cbaaf82017-11-27 22:00:03813 blink::WebSandboxFlags opener_flags = opener_rfh->active_sandbox_flags();
alexmosaedfc6f2016-01-21 23:57:38814 const blink::WebSandboxFlags inherit_flag =
Blink Reformat1c4d759e2017-04-09 16:34:54815 blink::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts;
alexmosaedfc6f2016-01-21 23:57:38816 if ((opener_flags & inherit_flag) == inherit_flag) {
Ian Clellandcdc4f312017-10-13 22:24:12817 // TODO(iclelland): Transfer correct container policy from opener as well.
818 // https://crbug.com/774620
819 new_root->SetPendingFramePolicy({opener_flags, {}});
alexmosaedfc6f2016-01-21 23:57:38820 }
821 }
822
mark a. foltzef394fce2017-10-21 09:11:02823 // Apply starting sandbox flags.
Luna Luc3fdacdf2017-11-08 04:48:53824 blink::FramePolicy frame_policy(new_root->pending_frame_policy());
mark a. foltzef394fce2017-10-21 09:11:02825 frame_policy.sandbox_flags |= params.starting_sandbox_flags;
826 new_root->SetPendingFramePolicy(frame_policy);
827 new_root->CommitPendingFramePolicy();
828
alexmose201c7cd2015-06-10 17:14:21829 // This may be true even when opener is null, such as when opening blocked
830 // popups.
alexmos090fae8e2015-05-28 17:09:28831 if (params.created_with_opener)
832 new_contents->created_with_opener_ = true;
833
[email protected]4858e432014-06-23 18:14:17834 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06835 // This makes |new_contents| act as a guest.
836 // For more info, see comment above class BrowserPluginGuest.
erikchen50735fd2018-05-05 15:08:33837 BrowserPluginGuest::Create(new_contents.get(), params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06838 }
mark a. foltzef394fce2017-10-21 09:11:02839
[email protected]54944cde2012-12-09 09:24:59840 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19841 return new_contents;
842}
843
[email protected]95640212014-07-26 18:14:30844// static
845std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
846 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08847 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30848 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30849 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30850 RenderViewHost* rvh = RenderViewHost::From(rwh);
851 if (!rvh)
852 continue;
853 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
854 if (!web_contents)
855 continue;
avidf38c952015-10-27 13:45:13856 if (web_contents->GetRenderViewHost() != rvh)
857 continue;
858 // Because a WebContents can only have one current RVH at a time, there will
859 // be no duplicate WebContents here.
860 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30861 }
862 return result;
863}
864
clamya16aa8172015-05-26 13:07:25865// static
866WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
paulmeyerfeafc2d2017-04-25 21:46:40867 const FrameTreeNode* frame_tree_node) {
clamya16aa8172015-05-26 13:07:25868 return static_cast<WebContentsImpl*>(
869 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
870}
871
clamy0d32d6d2015-11-24 11:16:26872// static
873WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
874 int render_frame_host_id) {
875 DCHECK_CURRENTLY_ON(BrowserThread::UI);
876 RenderFrameHost* render_frame_host =
877 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
878 if (!render_frame_host)
879 return nullptr;
880
881 return WebContents::FromRenderFrameHost(render_frame_host);
882}
883
paulmeyerfeafc2d2017-04-25 21:46:40884// static
885WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode(
886 const FrameTreeNode* frame_tree_node) {
887 return WebContentsImpl::FromFrameTreeNode(frame_tree_node)
888 ->node_.GetInnerWebContentsInFrame(frame_tree_node);
889}
890
[email protected]b0936d22013-11-28 06:47:36891RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21892 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28893}
894
nicka0ac8382016-12-15 23:59:23895bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host,
[email protected]7bb761892012-07-20 09:32:47896 const IPC::Message& message) {
nicka0ac8382016-12-15 23:59:23897 for (auto& observer : observers_) {
Lukasz Anforowicz89f2c1b2017-08-30 21:36:46898 // TODO(nick, creis): https://crbug.com/758026: Replace all uses of this
899 // variant of OnMessageReceived with the version that takes a
900 // RenderFrameHost, and then delete it.
nicka0ac8382016-12-15 23:59:23901 if (observer.OnMessageReceived(message))
902 return true;
[email protected]64ffefa2014-05-10 12:06:33903 }
[email protected]403415a2011-01-10 18:57:53904
[email protected]724159a2010-12-30 01:11:18905 bool handled = true;
nicka0ac8382016-12-15 23:59:23906 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host)
907 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
908 OnFirstVisuallyNonEmptyPaint)
909 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
910 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
911 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
912 OnPageScaleFactorChanged)
913 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
914 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
nicka0ac8382016-12-15 23:59:23915#if BUILDFLAG(ENABLE_PLUGINS)
916 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
917 OnRequestPpapiBrokerPermission)
918#endif
nicka0ac8382016-12-15 23:59:23919#if defined(OS_ANDROID)
920 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, OnOpenDateTimeDialog)
921#endif
922 IPC_MESSAGE_UNHANDLED(handled = false)
923 IPC_END_MESSAGE_MAP()
924
925 return handled;
926}
927
928bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host,
929 const IPC::Message& message) {
Lukasz Anforowicz02923102017-10-09 18:11:37930 {
931 WebUIImpl* web_ui = render_frame_host->web_ui();
932 if (web_ui && web_ui->OnMessageReceived(message, render_frame_host))
933 return true;
934 }
935
nicka0ac8382016-12-15 23:59:23936 for (auto& observer : observers_) {
937 if (observer.OnMessageReceived(message, render_frame_host))
938 return true;
939 }
940
941 bool handled = true;
942 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host)
[email protected]cfa856d62014-02-22 07:58:40943 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
944 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05945 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
946 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48947 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
948 OnDocumentLoadedInFrame)
949 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
avi7830c852015-08-31 23:46:25950 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18951 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54952 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18953 OnDidDisplayInsecureContent)
elawrenceb2ac2a232017-03-27 21:46:25954 IPC_MESSAGE_HANDLER(FrameHostMsg_DidContainInsecureFormAction,
955 OnDidContainInsecureFormAction)
avi3a3332622015-09-01 01:18:54956 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18957 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41958 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
959 OnDidDisplayContentWithCertificateErrors)
960 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
961 OnDidRunContentWithCertificateErrors)
avia23e16b2015-07-09 14:18:48962 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
963 OnRegisterProtocolHandler)
964 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
965 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01966 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
967 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52968 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
lukasza178ff092017-06-07 23:39:50969 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
brettw4b461082016-11-19 18:55:16970#if BUILDFLAG(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00971 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
972 OnPepperInstanceCreated)
973 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
974 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42975 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:17976 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
977 OnPepperStartsPlayback)
978 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
979 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:42980 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]c4538072013-03-18 02:17:55981 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40982 OnBrowserPluginMessage(render_frame_host,
983 message))
thestigc4cac8f2014-09-04 21:17:50984#endif
[email protected]724159a2010-12-30 01:11:18985 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33986 IPC_END_MESSAGE_MAP()
[email protected]724159a2010-12-30 01:11:18987
[email protected]724159a2010-12-30 01:11:18988 return handled;
989}
990
[email protected]d1198fd2012-08-13 22:50:19991NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56992 return controller_;
993}
994
[email protected]d1198fd2012-08-13 22:50:19995const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56996 return controller_;
997}
998
[email protected]8ff00d72012-10-23 19:12:21999BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:551000 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:301001}
1002
[email protected]b172aee2012-04-10 17:05:261003const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:241004 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:321005 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:511006 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:311007}
1008
[email protected]a093ce02013-07-22 20:53:141009const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:241010 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:321011 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:241012 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
1013}
1014
1015const GURL& WebContentsImpl::GetLastCommittedURL() const {
1016 // We may not have a navigation entry yet.
1017 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1018 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
1019}
1020
[email protected]8ff00d72012-10-23 19:12:211021WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:311022 return delegate_;
1023}
1024
[email protected]8ff00d72012-10-23 19:12:211025void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:311026 // TODO(cbentzel): remove this debugging code?
1027 if (delegate == delegate_)
1028 return;
1029 if (delegate_)
1030 delegate_->Detach(this);
1031 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:081032 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:311033 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:081034 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:001035 if (view_)
[email protected]e85165c642014-06-10 14:34:311036 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
Joel Einbinder848001c2017-09-19 21:39:311037 if (GetRenderViewHost())
1038 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]a6b73c62013-02-11 23:05:081039 }
[email protected]be1f56ab2011-12-22 06:55:311040}
1041
Lukasz Anforowicze9ae3722017-09-29 17:37:381042RenderFrameHostImpl* WebContentsImpl::GetMainFrame() const {
[email protected]94d0cc12013-12-18 00:07:411043 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:161044}
1045
nick53d5cbf2015-04-23 22:50:141046RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
1047 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
1048 if (!focused_node)
1049 return nullptr;
1050 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:071051}
1052
rob3e2a0732016-01-06 21:22:091053RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
creisf71a2632017-05-04 19:03:501054 int frame_tree_node_id,
1055 int process_id) {
1056 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
1057
1058 // Sanity check that this is in the caller's expected process. Otherwise a
1059 // recent cross-process navigation may have led to a privilege change that the
1060 // caller is not expecting.
1061 if (!frame ||
1062 frame->current_frame_host()->GetProcess()->GetID() != process_id)
1063 return nullptr;
1064
1065 return frame->current_frame_host();
1066}
1067
1068RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId(
rob3e2a0732016-01-06 21:22:091069 int frame_tree_node_id) {
creisf71a2632017-05-04 19:03:501070 // Beware using this! The RenderFrameHost may have changed since the caller
1071 // obtained frame_tree_node_id.
rob3e2a0732016-01-06 21:22:091072 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
1073 return frame ? frame->current_frame_host() : nullptr;
1074}
1075
[email protected]a86c0e962013-12-17 17:10:391076void WebContentsImpl::ForEachFrame(
Lei Zhangebcc6302018-01-12 19:46:451077 const base::RepeatingCallback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:381078 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1079 on_frame.Run(node->current_frame_host());
1080 }
[email protected]a86c0e962013-12-17 17:10:391081}
1082
dchengafb53e22016-02-04 08:11:081083std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
1084 std::vector<RenderFrameHost*> frame_hosts;
1085 for (FrameTreeNode* node : frame_tree_.Nodes())
1086 frame_hosts.push_back(node->current_frame_host());
1087 return frame_hosts;
1088}
1089
lukaszacbdf52e2016-01-15 21:19:511090int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
1091 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:081092 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:251093 if (!rfh->IsRenderFrameLive())
1094 continue;
1095
dchengafb53e22016-02-04 08:11:081096 ++number_of_messages;
1097 IPC::Message* message_copy = new IPC::Message(*message);
1098 message_copy->set_routing_id(rfh->GetRoutingID());
1099 rfh->Send(message_copy);
1100 }
[email protected]a86c0e962013-12-17 17:10:391101 delete message;
lukaszacbdf52e2016-01-15 21:19:511102 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:391103}
1104
lfgdb5c4ed2016-03-04 23:09:071105void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:411106 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:071107}
1108
creisc014b402015-04-23 16:41:451109RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:211110 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:311111}
1112
creis89a0f782015-05-27 16:13:171113void WebContentsImpl::CancelActiveAndPendingDialogs() {
avi5d3b8692016-10-12 22:00:461114 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:531115 dialog_manager_->CancelDialogs(this, /*reset_state=*/false);
avi5d3b8692016-10-12 22:00:461116 }
creis89a0f782015-05-27 16:13:171117 if (browser_plugin_embedder_)
1118 browser_plugin_embedder_->CancelGuestDialogs();
1119}
1120
naskoc0fceff2015-04-30 15:53:521121void WebContentsImpl::ClosePage() {
1122 GetRenderViewHost()->ClosePage();
1123}
1124
[email protected]b172aee2012-04-10 17:05:261125RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:211126 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:311127}
1128
lfg265a2672016-04-23 03:11:021129RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
1130 if (GetOuterWebContents())
1131 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
1132 return GetRenderManager()->GetRenderWidgetHostView();
1133}
1134
[email protected]4aebbca2013-09-17 22:26:491135RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
1136 const {
vmpstr6d9996c82017-02-23 00:43:251137 if (auto* widget_host = GetFullscreenRenderWidgetHost())
ekaramadaeb3c5c2016-11-09 03:22:351138 return widget_host->GetView();
1139 return nullptr;
[email protected]4aebbca2013-09-17 22:26:491140}
1141
[email protected]8ff00d72012-10-23 19:12:211142WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:311143 return view_.get();
1144}
1145
leon.han552e9de2017-02-09 14:37:301146void WebContentsImpl::OnScreenOrientationChange() {
1147 DCHECK(screen_orientation_provider_);
Becca Hughese9e27952018-06-25 17:08:271148 screen_orientation_provider_->OnOrientationChange();
leon.hane4db177a2017-02-07 14:19:161149}
1150
yusufod41c5f92015-03-06 00:14:281151SkColor WebContentsImpl::GetThemeColor() const {
1152 return theme_color_;
1153}
1154
Doug Turner63f3c7b2017-07-29 05:10:011155void WebContentsImpl::SetAccessibilityMode(ui::AXMode mode) {
[email protected]95640212014-07-26 18:14:301156 if (mode == accessibility_mode_)
1157 return;
1158
dmazzonif8a31042016-12-03 00:52:131159 // Don't allow accessibility to be enabled for WebContents that are never
1160 // visible, like background pages.
1161 if (IsNeverVisible())
1162 return;
1163
[email protected]95640212014-07-26 18:14:301164 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:381165
1166 for (FrameTreeNode* node : frame_tree_.Nodes()) {
dmazzonif8a31042016-12-03 00:52:131167 UpdateAccessibilityModeOnFrame(node->current_frame_host());
clamy610c63b32017-12-22 15:05:181168 // Also update accessibility mode on the speculative RenderFrameHost for
1169 // this FrameTreeNode, if one exists.
Alex Moshchuk3d8a1f392017-10-24 19:01:261170 RenderFrameHost* speculative_frame_host =
1171 node->render_manager()->speculative_frame_host();
1172 if (speculative_frame_host)
1173 UpdateAccessibilityModeOnFrame(speculative_frame_host);
dcheng57e39e22016-01-21 00:25:381174 }
[email protected]95640212014-07-26 18:14:301175}
1176
Doug Turner63f3c7b2017-07-29 05:10:011177void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) {
1178 ui::AXMode new_mode(accessibility_mode_);
dougtcd3dad732017-03-14 03:26:231179 new_mode |= mode;
1180 SetAccessibilityMode(new_mode);
[email protected]95640212014-07-26 18:14:301181}
1182
Avi Drissman1e620f32018-03-16 13:57:291183// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
1184// Handles the callbacks from parallel snapshot requests to each frame,
1185// and feeds the results to an AXTreeCombiner, which converts them into a
1186// single combined accessibility tree.
1187class WebContentsImpl::AXTreeSnapshotCombiner
1188 : public base::RefCounted<AXTreeSnapshotCombiner> {
1189 public:
1190 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
1191 : callback_(std::move(callback)) {}
1192
1193 AXTreeSnapshotCallback AddFrame(bool is_root) {
1194 // Adds a reference to |this|.
1195 return base::BindOnce(&AXTreeSnapshotCombiner::ReceiveSnapshot, this,
1196 is_root);
1197 }
1198
1199 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
1200 combiner_.AddTree(snapshot, is_root);
1201 }
1202
1203 private:
1204 friend class base::RefCounted<AXTreeSnapshotCombiner>;
1205
1206 // This is called automatically after the last call to ReceiveSnapshot
1207 // when there are no more references to this object.
1208 ~AXTreeSnapshotCombiner() {
1209 combiner_.Combine();
1210 std::move(callback_).Run(combiner_.combined());
1211 }
1212
1213 ui::AXTreeCombiner combiner_;
1214 AXTreeSnapshotCallback callback_;
1215};
1216
1217void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback,
1218 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391219 // Send a request to each of the frames in parallel. Each one will return
1220 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
1221 // them into a single tree and call |callback| with that result, then
1222 // delete |combiner|.
Avi Drissman1e620f32018-03-16 13:57:291223 FrameTreeNode* root_node = frame_tree_.root();
Avi Drissmanb30851c2018-03-08 20:34:331224 AXTreeSnapshotCombiner* combiner =
1225 new AXTreeSnapshotCombiner(std::move(callback));
Avi Drissman1e620f32018-03-16 13:57:291226
1227 RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner, ax_mode);
1228}
1229
1230void WebContentsImpl::RecursiveRequestAXTreeSnapshotOnFrame(
1231 FrameTreeNode* root_node,
1232 AXTreeSnapshotCombiner* combiner,
1233 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391234 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
Avi Drissman1e620f32018-03-16 13:57:291235 WebContentsImpl* inner_contents =
1236 node_.GetInnerWebContentsInFrame(frame_tree_node);
1237 if (inner_contents) {
1238 inner_contents->RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner,
1239 ax_mode);
1240 } else {
1241 bool is_root = frame_tree_node == root_node;
1242 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
1243 combiner->AddFrame(is_root), ax_mode);
1244 }
dmazzonid95ae842016-04-12 21:17:391245 }
dmazzoni83ba5c82015-04-14 07:11:511246}
1247
mcnee336ea2c2017-05-23 22:50:591248#if !defined(OS_ANDROID)
akabac6bd1212018-06-25 20:10:481249
1250void WebContentsImpl::UpdateZoom() {
1251 RenderWidgetHostImpl* rwh = GetRenderViewHost()->GetWidget();
1252 if (rwh->GetView())
1253 rwh->SynchronizeVisualProperties();
wjmaclean64951902016-04-29 20:59:121254}
1255
akabac6bd1212018-06-25 20:10:481256bool WebContentsImpl::UsesTemporaryZoomLevel() const {
1257 return HostZoomMap::GetForWebContents(this)->UsesTemporaryZoomLevel(
1258 GetMainFrame()->GetProcess()->GetID(),
1259 GetRenderViewHost()->GetRoutingID());
wjmaclean64951902016-04-29 20:59:121260}
1261
1262void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
akabac6bd1212018-06-25 20:10:481263 const std::string& host) {
wjmaclean64951902016-04-29 20:59:121264 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1265 if (!entry)
1266 return;
1267
1268 GURL url = HostZoomMap::GetURLFromEntry(entry);
1269 if (host != net::GetHostOrSpecFromURL(url) ||
1270 (!scheme.empty() && !url.SchemeIs(scheme))) {
1271 return;
1272 }
1273
akabac6bd1212018-06-25 20:10:481274 UpdateZoom();
wjmaclean64951902016-04-29 20:59:121275}
mcnee336ea2c2017-05-23 22:50:591276#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:121277
rockotf62002a2016-09-15 00:08:591278base::Closure WebContentsImpl::AddBindingSet(
1279 const std::string& interface_name,
1280 WebContentsBindingSet* binding_set) {
1281 auto result =
1282 binding_sets_.insert(std::make_pair(interface_name, binding_set));
1283 DCHECK(result.second);
1284 return base::Bind(&WebContentsImpl::RemoveBindingSet,
1285 weak_factory_.GetWeakPtr(), interface_name);
1286}
1287
rockot8bbad222017-03-22 04:34:051288WebContentsBindingSet* WebContentsImpl::GetBindingSet(
1289 const std::string& interface_name) {
1290 auto it = binding_sets_.find(interface_name);
1291 if (it == binding_sets_.end())
1292 return nullptr;
1293 return it->second;
1294}
1295
paulmeyerfeafc2d2017-04-25 21:46:401296std::vector<WebContentsImpl*> WebContentsImpl::GetInnerWebContents() {
1297 if (browser_plugin_embedder_) {
1298 std::vector<WebContentsImpl*> inner_contents;
1299 GetBrowserContext()->GetGuestManager()->ForEachGuest(
Mark Pilgrimd84121732018-03-22 14:12:121300 this, base::BindRepeating(&GetInnerWebContentsHelper, &inner_contents));
paulmeyerfeafc2d2017-04-25 21:46:401301 return inner_contents;
1302 }
1303
1304 return node_.inner_web_contents();
1305}
1306
1307std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() {
1308 std::vector<WebContentsImpl*> all_contents(1, this);
1309
1310 for (size_t i = 0; i != all_contents.size(); ++i) {
1311 for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) {
1312 all_contents.push_back(inner_contents);
1313 }
1314 }
1315
1316 return all_contents;
1317}
1318
Sam McNally145fb172017-05-10 00:13:231319void WebContentsImpl::NotifyManifestUrlChanged(
1320 const base::Optional<GURL>& manifest_url) {
1321 for (auto& observer : observers_)
1322 observer.DidUpdateWebManifestURL(manifest_url);
1323}
1324
[email protected]8ff00d72012-10-23 19:12:211325WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:401326 WebUI* commited_web_ui = GetCommittedWebUI();
1327 return commited_web_ui ? commited_web_ui
1328 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:311329}
1330
[email protected]8ff00d72012-10-23 19:12:211331WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:401332 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341333}
1334
Changwan Ryuc1134a82018-03-07 02:10:141335void WebContentsImpl::SetUserAgentOverride(const std::string& override,
1336 bool override_in_new_tabs) {
[email protected]bf70edce2012-06-20 22:32:221337 if (GetUserAgentOverride() == override)
1338 return;
1339
Changwan Ryuc1134a82018-03-07 02:10:141340 should_override_user_agent_in_new_tabs_ = override_in_new_tabs;
1341
[email protected]bf70edce2012-06-20 22:32:221342 renderer_preferences_.user_agent_override = override;
1343
1344 // Send the new override string to the renderer.
1345 RenderViewHost* host = GetRenderViewHost();
1346 if (host)
1347 host->SyncRendererPrefs();
1348
1349 // Reload the page if a load is currently in progress to avoid having
1350 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271351 NavigationEntry* entry = controller_.GetVisibleEntry();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281352 if (IsLoading() && entry != nullptr && entry->GetIsOverridingUserAgent())
toyoshim6142d96f2016-12-19 09:07:251353 controller_.Reload(ReloadType::BYPASSING_CACHE, true);
[email protected]8d0f3312012-08-18 01:47:531354
ericwilligersde386342016-10-19 02:35:091355 for (auto& observer : observers_)
1356 observer.UserAgentOverrideSet(override);
[email protected]86ef6a392012-05-11 22:03:111357}
1358
1359const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:221360 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111361}
1362
Changwan Ryuc1134a82018-03-07 02:10:141363bool WebContentsImpl::ShouldOverrideUserAgentInNewTabs() {
1364 return should_override_user_agent_in_new_tabs_;
1365}
1366
dmazzonidd3d51a72016-12-14 18:41:011367void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() {
dougtcd3dad732017-03-14 03:26:231368 if (!GetAccessibilityMode().is_mode_off()) {
dchengafb53e22016-02-04 08:11:081369 for (RenderFrameHost* rfh : GetAllFrames())
1370 ResetAccessibility(rfh);
1371 } else {
Doug Turner63f3c7b2017-07-29 05:10:011372 AddAccessibilityMode(ui::kAXModeWebContentsOnly);
dchengafb53e22016-02-04 08:11:081373 }
[email protected]95640212014-07-26 18:14:301374}
1375
dmazzonidd3d51a72016-12-14 18:41:011376bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011377 return accessibility_mode_ == ui::kAXModeWebContentsOnly;
[email protected]95640212014-07-26 18:14:301378}
1379
1380bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011381 return accessibility_mode_ == ui::kAXModeComplete;
[email protected]95640212014-07-26 18:14:301382}
1383
kouhei40f03cb2015-09-24 07:47:011384const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
1385 return page_importance_signals_;
1386}
1387
Guido Urdanetaf4008002018-05-03 10:43:041388const std::string& WebContentsImpl::GetMediaDeviceGroupIDSaltBase() const {
1389 return media_device_group_id_salt_base_;
1390}
1391
Becca Hughes6daf5662018-06-27 16:50:541392#if defined(OS_ANDROID)
1393
1394void WebContentsImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) {
1395 display_cutout_host_impl_->SetDisplayCutoutSafeArea(insets);
1396}
1397
1398#endif
1399
[email protected]fcf75d42013-12-03 20:11:261400const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:551401 // Transient entries take precedence. They are used for interstitial pages
1402 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231403 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231404 if (entry) {
jshin1fb76462016-04-05 22:13:031405 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231406 }
carlosk35f35af2015-12-01 10:55:401407
1408 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
1409 WebUI* our_web_ui = navigating_web_ui
1410 ? navigating_web_ui
1411 : GetRenderManager()->current_frame_host()->web_ui();
1412
[email protected]7ade2732011-02-10 00:13:581413 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541414 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321415 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541416 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351417 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261418 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541419 if (!title.empty())
1420 return title;
1421 }
1422 }
1423
1424 // We use the title for the last committed entry rather than a pending
1425 // navigation entry. For example, when the user types in a URL, we want to
1426 // keep the old page's title until the new load has committed and we get a new
1427 // title.
[email protected]96d185d2009-04-24 03:28:541428 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321429
creis072b61f2015-09-28 20:52:241430 // We make an exception for initial navigations. We only want to use the title
1431 // from the visible entry if:
1432 // 1. The pending entry has been explicitly assigned a title to display.
1433 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1434 // which case there is a pending entry index other than -1.
1435 //
1436 // Otherwise, we want to stick with the last committed entry's title during
1437 // new navigations, which have pending entries at index -1 with no title.
1438 if (controller_.IsInitialNavigation() &&
1439 ((controller_.GetVisibleEntry() &&
1440 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1441 controller_.GetPendingEntryIndex() != -1)) {
1442 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471443 }
[email protected]59167c22013-06-03 18:07:321444
[email protected]45d0ef7f2011-01-05 13:46:231445 if (entry) {
jshin1fb76462016-04-05 22:13:031446 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231447 }
[email protected]987fc3a2011-05-26 14:18:091448
1449 // |page_title_when_no_navigation_entry_| is finally used
1450 // if no title cannot be retrieved.
1451 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541452}
1453
creiscce56cd2014-09-29 22:45:221454SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211455 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541456}
1457
[email protected]b172aee2012-04-10 17:05:261458bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251459 return frame_tree_.IsLoading() &&
creisadca9862017-06-16 19:12:111460 !(ShowingInterstitialPage() && interstitial_page_->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491461}
1462
[email protected]6dfed692014-05-22 04:18:031463bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251464 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031465}
1466
[email protected]b172aee2012-04-10 17:05:261467bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031468 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311469}
1470
[email protected]b172aee2012-04-10 17:05:261471const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311472 return load_state_;
1473}
1474
[email protected]fcf75d42013-12-03 20:11:261475const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311476 return load_state_host_;
1477}
1478
avib7348942015-12-25 20:57:101479uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311480 return upload_size_;
1481}
1482
avib7348942015-12-25 20:57:101483uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311484 return upload_position_;
1485}
1486
[email protected]b172aee2012-04-10 17:05:261487const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541488 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311489}
1490
Shubhie Panickerddf2a4e2018-03-06 00:09:061491void WebContentsImpl::SetWasDiscarded(bool was_discarded) {
1492 GetFrameTree()->root()->set_was_discarded();
1493}
1494
[email protected]222f5822014-02-05 23:40:491495void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251496 DCHECK(!is_being_destroyed_);
Francois Doraye6161152018-03-27 22:05:371497 const bool was_captured = IsBeingCaptured();
[email protected]54597982013-02-06 01:59:551498 ++capturer_count_;
1499 DVLOG(1) << "There are now " << capturer_count_
1500 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491501
1502 // Note: This provides a hint to upstream code to size the views optimally
1503 // for quality (e.g., to avoid scaling).
1504 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1505 preferred_size_for_capture_ = capture_size;
1506 OnPreferredSizeChanged(preferred_size_);
1507 }
ccameron8807c38f2015-01-17 00:29:191508
Francois Doraye6161152018-03-27 22:05:371509 if (GetVisibility() != Visibility::VISIBLE && !was_captured) {
1510 // Ensure that all views act as if they were visible before capture begins.
1511 // TODO(fdoray): Replace RenderWidgetHostView::WasUnOccluded() with a method
1512 // to explicitly notify the RenderWidgetHostView that capture began.
1513 // https://crbug.com/668690
1514 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1515 view->WasUnOccluded();
1516 }
[email protected]54597982013-02-06 01:59:551517}
1518
1519void WebContentsImpl::DecrementCapturerCount() {
1520 --capturer_count_;
1521 DVLOG(1) << "There are now " << capturer_count_
1522 << " capturing(s) of WebContentsImpl@" << this;
1523 DCHECK_LE(0, capturer_count_);
1524
[email protected]5a652232013-02-12 06:15:251525 if (is_being_destroyed_)
1526 return;
1527
Francois Doray24fc62c2017-12-11 17:27:331528 if (!IsBeingCaptured()) {
[email protected]222f5822014-02-05 23:40:491529 const gfx::Size old_size = preferred_size_for_capture_;
1530 preferred_size_for_capture_ = gfx::Size();
1531 OnPreferredSizeChanged(old_size);
[email protected]222f5822014-02-05 23:40:491532
Francois Doraye6161152018-03-27 22:05:371533 if (visibility_ == Visibility::HIDDEN) {
Francois Doray18800972017-08-25 22:38:581534 DVLOG(1) << "Executing delayed WasHidden().";
1535 WasHidden();
Francois Doraye6161152018-03-27 22:05:371536 } else if (visibility_ == Visibility::OCCLUDED) {
Mitsuru Oshima04a80242018-03-03 03:06:151537 WasOccluded();
Francois Doraye6161152018-03-27 22:05:371538 }
[email protected]54597982013-02-06 01:59:551539 }
[email protected]be1f56ab2011-12-22 06:55:311540}
1541
Francois Doray24fc62c2017-12-11 17:27:331542bool WebContentsImpl::IsBeingCaptured() const {
1543 return capturer_count_ > 0;
[email protected]f2bd40812013-07-20 04:30:441544}
1545
miu50f97892014-09-22 22:49:521546bool WebContentsImpl::IsAudioMuted() const {
Max Morinb5506f72018-05-16 07:33:101547 if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) {
1548 return audio_stream_factory_ && audio_stream_factory_->IsMuted();
1549 }
miu50f97892014-09-22 22:49:521550 return audio_muter_.get() && audio_muter_->is_muting();
1551}
1552
1553void WebContentsImpl::SetAudioMuted(bool mute) {
1554 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1555 << " for WebContentsImpl@" << this;
1556
1557 if (mute == IsAudioMuted())
1558 return;
1559
Max Morinb5506f72018-05-16 07:33:101560 if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) {
1561 GetAudioStreamFactory()->SetMuted(mute);
miu50f97892014-09-22 22:49:521562 } else {
Max Morinb5506f72018-05-16 07:33:101563 if (mute) {
1564 if (!audio_muter_)
1565 audio_muter_.reset(new WebContentsAudioMuter(this));
1566 audio_muter_->StartMuting();
1567 } else {
1568 DCHECK(audio_muter_);
1569 audio_muter_->StopMuting();
1570 }
miu50f97892014-09-22 22:49:521571 }
1572
ericwilligersde386342016-10-19 02:35:091573 for (auto& observer : observers_)
1574 observer.DidUpdateAudioMutingState(mute);
wjmaclean2f797c782016-01-07 14:52:031575
Jan Rucka442c83f2017-08-08 13:27:541576 // Notification for UI updates in response to the changed muting state.
1577 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1578}
1579
1580bool WebContentsImpl::IsCurrentlyAudible() {
Chris Hamiltondf0d72cd2018-05-29 16:23:531581 return is_currently_audible_;
miu50f97892014-09-22 22:49:521582}
1583
ortunodf4d7982016-04-08 02:33:351584bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1585 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201586}
1587
sawtellea7333a82018-05-31 02:36:361588bool WebContentsImpl::HasPictureInPictureVideo() const {
1589 return has_picture_in_picture_video_;
1590}
1591
1592void WebContentsImpl::SetHasPictureInPictureVideo(
1593 bool has_picture_in_picture_video) {
1594 // If status of |this| is already accurate, there is no need to update.
1595 if (has_picture_in_picture_video == has_picture_in_picture_video_)
1596 return;
1597 has_picture_in_picture_video_ = has_picture_in_picture_video;
1598 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1599}
1600
[email protected]b172aee2012-04-10 17:05:261601bool WebContentsImpl::IsCrashed() const {
Dominic Mazzoni73a48322018-05-25 18:14:071602 switch (crashed_status_) {
1603 case base::TERMINATION_STATUS_PROCESS_CRASHED:
1604 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
1605 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
1606 case base::TERMINATION_STATUS_OOM:
1607 case base::TERMINATION_STATUS_LAUNCH_FAILED:
oshima620225722015-06-04 19:45:271608#if defined(OS_CHROMEOS)
Dominic Mazzoni73a48322018-05-25 18:14:071609 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM:
oshima620225722015-06-04 19:45:271610#endif
Dominic Mazzoni73a48322018-05-25 18:14:071611#if defined(OS_ANDROID)
1612 case base::TERMINATION_STATUS_OOM_PROTECTED:
1613#endif
1614 return true;
1615 case base::TERMINATION_STATUS_NORMAL_TERMINATION:
1616 case base::TERMINATION_STATUS_STILL_RUNNING:
1617 return false;
1618 case base::TERMINATION_STATUS_MAX_ENUM:
1619 NOTREACHED();
1620 return false;
1621 }
1622
1623 NOTREACHED();
1624 return false;
[email protected]3c9e1872010-11-18 16:17:491625}
1626
[email protected]b172aee2012-04-10 17:05:261627void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1628 int error_code) {
[email protected]443b80e2010-12-14 00:42:231629 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341630 return;
1631
[email protected]443b80e2010-12-14 00:42:231632 crashed_status_ = status;
1633 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211634 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341635}
1636
[email protected]b172aee2012-04-10 17:05:261637base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311638 return crashed_status_;
1639}
1640
afakhry98241832016-03-11 19:27:471641int WebContentsImpl::GetCrashedErrorCode() const {
1642 return crashed_error_code_;
1643}
1644
[email protected]b172aee2012-04-10 17:05:261645bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311646 return is_being_destroyed_;
1647}
1648
[email protected]7f924832014-08-09 05:57:221649void WebContentsImpl::NotifyNavigationStateChanged(
1650 InvalidateTypes changed_flags) {
dalecurtis88c240072015-12-09 02:11:181651 // Notify the media observer of potential audibility changes.
1652 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271653 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301654 }
1655
[email protected]d5f942ba2008-09-26 19:30:341656 if (delegate_)
1657 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441658
1659 if (GetOuterWebContents())
1660 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341661}
1662
Chris Hamiltondf0d72cd2018-05-29 16:23:531663void WebContentsImpl::OnAudioStateChanged() {
1664 // This notification can come from any embedded contents or from this
1665 // WebContents' stream monitor. Aggregate these signals to get the actual
1666 // state.
1667 bool is_currently_audible =
1668 audio_stream_monitor_.IsCurrentlyAudible() ||
1669 (browser_plugin_embedder_ &&
1670 browser_plugin_embedder_->AreAnyGuestsCurrentlyAudible());
1671 if (is_currently_audible == is_currently_audible_)
1672 return;
1673
1674 // Update internal state.
1675 is_currently_audible_ = is_currently_audible;
1676 was_ever_audible_ = was_ever_audible_ || is_currently_audible_;
1677
1678 SendPageMessage(
1679 new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_currently_audible_));
altimind8bd26c2016-11-04 11:44:541680
altiminec87fd1f2016-11-17 20:22:491681 // Notification for UI updates in response to the changed audio state.
altimind8bd26c2016-11-04 11:44:541682 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
Jan Rucka442c83f2017-08-08 13:27:541683
Chris Hamiltondf0d72cd2018-05-29 16:23:531684 // Ensure that audio state changes propagate from innermost to outermost
1685 // WebContents.
1686 if (GetOuterWebContents())
1687 GetOuterWebContents()->OnAudioStateChanged();
Tommy Steimel18360512017-11-01 00:38:191688
Chris Hamiltoneb41198f2018-05-24 18:41:261689 for (auto& observer : observers_)
Chris Hamiltondf0d72cd2018-05-29 16:23:531690 observer.OnAudioStateChanged(is_currently_audible_);
altimind8bd26c2016-11-04 11:44:541691}
1692
gab0dccfef2015-05-20 18:43:391693base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021694 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331695}
1696
[email protected]9e2e4632012-07-27 16:38:411697void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541698 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591699
EhsanK2075c7e2017-08-21 02:42:391700 if (auto* view = GetRenderWidgetHostView()) {
lfgf949e0e2017-05-10 22:18:111701 view->Show();
[email protected]789e9152009-08-04 21:59:431702#if defined(OS_MACOSX)
lfgf949e0e2017-05-10 22:18:111703 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431704#endif
1705 }
[email protected]96d185d2009-04-24 03:28:541706
EhsanK2075c7e2017-08-21 02:42:391707 if (!ShowingInterstitialPage())
1708 SetVisibilityForChildViews(true);
1709
lfg717154072016-06-30 15:04:161710 SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE));
1711
gab0dccfef2015-05-20 18:43:391712 last_active_time_ = base::TimeTicks::Now();
Francois Doraye6161152018-03-27 22:05:371713 SetVisibility(Visibility::VISIBLE);
Lukasz Anforowicz873e6082018-05-17 00:12:331714
1715 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1716 RenderFrameProxyHost* parent = node->render_manager()->GetProxyToParent();
1717 if (!parent)
1718 continue;
1719
1720 if (parent->cross_process_frame_connector()->IsVisible()) {
1721 // MaybeLogCrash will check 1) if there was a crash or not and 2) if the
1722 // crash might have been already logged earlier as kCrashedWhileVisible.
1723 parent->cross_process_frame_connector()->MaybeLogCrash(
1724 CrossProcessFrameConnector::CrashVisibility::kShownAfterCrashing);
1725 }
1726 }
[email protected]be1f56ab2011-12-22 06:55:311727}
1728
[email protected]b172aee2012-04-10 17:05:261729void WebContentsImpl::WasHidden() {
Jennifer Apacible72c31412018-06-19 16:52:241730 // If there are entities capturing screenshots or video (e.g. mirroring),
1731 // or in Picture-in-Picture mode, don't activate the "disable rendering"
1732 // optimization.
1733 if (!IsBeingCaptured() && !HasPictureInPictureVideo()) {
[email protected]151a63d2011-12-20 22:32:521734 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551735 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261736 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521737 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331738 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521739 // calls us).
EhsanK2075c7e2017-08-21 02:42:391740 if (auto* view = GetRenderWidgetHostView())
lfgf949e0e2017-05-10 22:18:111741 view->Hide();
lfg717154072016-06-30 15:04:161742
EhsanK2075c7e2017-08-21 02:42:391743 if (!ShowingInterstitialPage())
Igor Eremeevef59187a2017-09-29 00:25:421744 SetVisibilityForChildViews(false);
EhsanK2075c7e2017-08-21 02:42:391745
lfg717154072016-06-30 15:04:161746 SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
[email protected]96d185d2009-04-24 03:28:541747 }
1748
Francois Doraye6161152018-03-27 22:05:371749 SetVisibility(Visibility::HIDDEN);
[email protected]375fa1b2012-05-22 22:05:371750}
1751
Daniel Cheng90196c82018-04-25 21:49:141752bool WebContentsImpl::HasRecentInteractiveInputEvent() const {
1753 static constexpr base::TimeDelta kMaxInterval =
1754 base::TimeDelta::FromSeconds(5);
1755 base::TimeDelta delta =
1756 ui::EventTimeForNow() - last_interactive_input_event_time_;
1757 // Note: the expectation is that the caller is typically expecting an input
1758 // event, e.g. validating that a WebUI message that requires a gesture is
1759 // actually attached to a gesture. Logging to UMA here should hopefully give
1760 // sufficient data if 5 seconds is actually sufficient (or even too high a
1761 // threshhold).
1762 UMA_HISTOGRAM_TIMES("Tabs.TimeSinceLastInteraction", delta);
1763 return delta <= kMaxInterval;
1764}
1765
Bo Liu168c8642017-08-28 18:26:021766#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:501767void WebContentsImpl::SetMainFrameImportance(
1768 ChildProcessImportance importance) {
1769 GetMainFrame()->GetRenderWidgetHost()->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281770 if (ShowingInterstitialPage()) {
Bo Liu16dd7b8322018-05-02 21:19:501771 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
1772 ->GetRenderWidgetHost()
1773 ->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281774 }
Bo Liu7c6779e92017-08-16 02:02:281775}
Bo Liu168c8642017-08-28 18:26:021776#endif
Bo Liu7c6779e92017-08-16 02:02:281777
ccameron8807c38f2015-01-17 00:29:191778void WebContentsImpl::WasOccluded() {
Francois Doray24fc62c2017-12-11 17:27:331779 if (!IsBeingCaptured()) {
Francois Doray18800972017-08-25 22:38:581780 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1781 view->WasOccluded();
1782 }
Francois Doraye6161152018-03-27 22:05:371783 SetVisibility(Visibility::OCCLUDED);
ccameron8807c38f2015-01-17 00:29:191784}
1785
Francois Dorayfe4a1772018-02-17 04:17:091786Visibility WebContentsImpl::GetVisibility() const {
Francois Doraye6161152018-03-27 22:05:371787 return visibility_;
Francois Dorayfe4a1772018-02-17 04:17:091788}
1789
[email protected]b172aee2012-04-10 17:05:261790bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311791 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451792 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
jam40444982017-04-11 03:01:411793 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311794}
1795
nasko148bb0b92016-05-10 21:03:191796void WebContentsImpl::DispatchBeforeUnload() {
1797 bool for_cross_site_transition = false;
clamybfd6a812016-05-30 16:25:171798 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false);
[email protected]1c3f80bd2014-04-08 23:02:061799}
1800
lazyboy6ec48b2a2015-06-29 15:18:141801void WebContentsImpl::AttachToOuterWebContentsFrame(
1802 WebContents* outer_web_contents,
1803 RenderFrameHost* outer_contents_frame) {
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391804 DCHECK(!node_.outer_web_contents());
1805
lfg91a79e12016-04-01 23:52:191806 RenderFrameHostManager* render_manager = GetRenderManager();
1807
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391808 // When attaching a WebContents as an inner WebContents, we need to replace
1809 // the Webcontents' view with a WebContentsViewChildFrame.
1810 view_.reset(new WebContentsViewChildFrame(
1811 this, GetContentClient()->browser()->GetWebContentsViewDelegate(this),
1812 &render_view_host_delegate_view_));
1813
lfg91a79e12016-04-01 23:52:191814 // When the WebContents being initialized has an opener, the browser side
1815 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1816 // created. This is needed because the usual initialization happens during
1817 // the first navigation, but when attaching a new window we don't navigate
1818 // before attaching. If the browser side is already initialized, the calls
1819 // below will just early return.
1820 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1821 GetMainFrame()->Init();
1822 if (!render_manager->GetRenderWidgetHostView())
1823 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1824
avallee7529b2a2017-04-26 11:37:511825 auto* outer_web_contents_impl =
1826 static_cast<WebContentsImpl*>(outer_web_contents);
1827 auto* outer_contents_frame_impl =
1828 static_cast<RenderFrameHostImpl*>(outer_contents_frame);
lazyboy6ec48b2a2015-06-29 15:18:141829 // Create a link to our outer WebContents.
avallee7529b2a2017-04-26 11:37:511830 node_.ConnectToOuterWebContents(outer_web_contents_impl,
1831 outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141832
1833 DCHECK(outer_contents_frame);
1834
1835 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1836 // SiteInstance of the outer WebContents. The proxy will be used to send
1837 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191838 render_manager->CreateOuterDelegateProxy(
avallee7529b2a2017-04-26 11:37:511839 outer_contents_frame->GetSiteInstance(), outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141840
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141841 ReattachToOuterWebContentsFrame();
ekaramadadd882292016-06-08 15:22:561842
avallee7529b2a2017-04-26 11:37:511843 if (outer_web_contents_impl->frame_tree_.GetFocusedFrame() ==
1844 outer_contents_frame_impl->frame_tree_node()) {
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:571845 SetFocusedFrame(frame_tree_.root(),
1846 outer_contents_frame->GetSiteInstance());
avallee7529b2a2017-04-26 11:37:511847 }
1848
ekaramadadd882292016-06-08 15:22:561849 // At this point, we should destroy the TextInputManager which will notify all
1850 // the RWHV in this WebContents. The RWHV in this WebContents should use the
1851 // TextInputManager owned by the outer WebContents.
1852 // TODO(ekaramad): Is it possible to have TextInputState before attaching to
1853 // outer WebContents? In such a case, is this still the right way to hand off
1854 // state tracking from inner WebContents's TextInputManager to that of the
1855 // outer WebContent (crbug.com/609846)?
1856 text_input_manager_.reset(nullptr);
lazyboy6ec48b2a2015-06-29 15:18:141857}
1858
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141859void WebContentsImpl::ReattachToOuterWebContentsFrame() {
1860 DCHECK(node_.outer_web_contents());
1861 auto* render_manager = GetRenderManager();
1862 auto* parent_frame =
1863 node_.OuterContentsFrameTreeNode()->current_frame_host()->GetParent();
1864 render_manager->SetRWHViewForInnerContents(
1865 render_manager->GetRenderWidgetHostView());
1866
1867 static_cast<RenderWidgetHostViewChildFrame*>(
1868 render_manager->GetRenderWidgetHostView())
1869 ->RegisterFrameSinkId();
1870
1871 // Set up the the guest's AX tree to point back at the embedder's AX tree.
1872 GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(
1873 parent_frame->GetAXTreeID());
1874 GetMainFrame()->UpdateAXTreeData();
1875}
1876
dalecurtis6c58ed02016-10-28 23:02:371877void WebContentsImpl::DidChangeVisibleSecurityState() {
1878 if (delegate_) {
1879 delegate_->VisibleSecurityStateChanged(this);
cjgrant6d1d727a2016-12-09 21:16:571880 for (auto& observer : observers_)
1881 observer.DidChangeVisibleSecurityState();
dalecurtis6c58ed02016-10-28 23:02:371882 }
1883}
1884
Ahmed Fakhryd70bf37b2018-04-04 17:07:241885void WebContentsImpl::NotifyPreferencesChanged() {
1886 std::set<RenderViewHost*> render_view_host_set;
1887 for (FrameTreeNode* node : frame_tree_.Nodes()) {
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531888 render_view_host_set.insert(
1889 node->current_frame_host()->GetRenderViewHost());
Ahmed Fakhryd70bf37b2018-04-04 17:07:241890 }
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531891
Ahmed Fakhryd70bf37b2018-04-04 17:07:241892 for (RenderViewHost* render_view_host : render_view_host_set)
1893 render_view_host->OnWebkitPreferencesChanged();
1894}
1895
[email protected]b172aee2012-04-10 17:05:261896void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381897 for (FrameTreeNode* node : frame_tree_.Nodes())
1898 node->StopLoading();
ericwilligersde386342016-10-19 02:35:091899 for (auto& observer : observers_)
1900 observer.NavigationStopped();
[email protected]0bfbf882011-12-22 18:19:271901}
1902
Francois Doray47f759d2018-06-11 18:13:511903void WebContentsImpl::SetPageFrozen(bool frozen) {
1904 // A visible page is never frozen.
1905 DCHECK_NE(Visibility::VISIBLE, GetVisibility());
1906
1907 SendPageMessage(new PageMsg_SetPageFrozen(MSG_ROUTING_NONE, frozen));
Fadi Meawada6573e02018-03-10 00:52:111908}
1909
erikchen6c7df7f7a2018-05-03 18:13:591910std::unique_ptr<WebContents> WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441911 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211912 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451913 // before.
[email protected]54944cde2012-12-09 09:24:591914 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451915 create_params.initial_size = GetContainerBounds().size();
Ian Clelland5cbaaf82017-11-27 22:00:031916 FrameTreeNode* opener = frame_tree_.root()->opener();
1917 RenderFrameHostImpl* opener_rfh = nullptr;
1918 if (opener)
1919 opener_rfh = opener->current_frame_host();
erikchen6c7df7f7a2018-05-03 18:13:591920 std::unique_ptr<WebContentsImpl> tc =
erikchen50735fd2018-05-05 15:08:331921 CreateWithOpener(create_params, opener_rfh);
Francois Dorayeaace782017-06-21 16:37:241922 tc->GetController().CopyStateFrom(controller_, true);
ericwilligersde386342016-10-19 02:35:091923 for (auto& observer : observers_)
erikchen6c7df7f7a2018-05-03 18:13:591924 observer.DidCloneToNewWebContents(this, tc.get());
[email protected]0bfbf882011-12-22 18:19:271925 return tc;
1926}
1927
[email protected]14392a52012-05-02 20:28:441928void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211929 const NotificationSource& source,
1930 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441931 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211932 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1933 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031934 RenderWidgetHostView* view = host->GetView();
1935 if (view == GetFullscreenRenderWidgetHostView()) {
1936 // We cannot just call view_->RestoreFocus() here. On some platforms,
1937 // attempting to focus the currently-invisible WebContentsView will be
1938 // flat-out ignored. Therefore, this boolean is used to track whether
1939 // we will request focus after the fullscreen widget has been
1940 // destroyed.
1941 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1942 } else {
alexmosc2a8cec2016-05-23 22:19:531943 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:031944 i != pending_widget_views_.end(); ++i) {
1945 if (host->GetView() == i->second) {
1946 pending_widget_views_.erase(i);
1947 break;
1948 }
[email protected]bafe6cd2012-05-23 23:09:501949 }
1950 }
1951 break;
1952 }
[email protected]14392a52012-05-02 20:28:441953 default:
1954 NOTREACHED();
1955 }
1956}
1957
[email protected]ec6c05f2013-10-23 18:41:571958WebContents* WebContentsImpl::GetWebContents() {
1959 return this;
1960}
1961
[email protected]54944cde2012-12-09 09:24:591962void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211963 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361964 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211965 // it should be hidden.
Francois Doraye6161152018-03-27 22:05:371966 visibility_ =
1967 params.initially_hidden ? Visibility::HIDDEN : Visibility::VISIBLE;
[email protected]d6fa88f2013-10-18 16:00:431968
Sebastien Marchand28cf23182018-06-20 02:39:351969 if (!params.last_active_time.is_null())
1970 last_active_time_ = params.last_active_time;
1971
dcheng3ce04b62015-10-26 23:30:551972 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541973 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551974 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1975 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541976 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551977 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1978 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1979
1980 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1981 if (!site_instance)
1982 site_instance = SiteInstance::Create(params.browser_context);
Lukasz Anforowicz3caa8372018-06-05 17:22:071983 if (params.desired_renderer_state == CreateParams::kNoRendererProcess) {
1984 static_cast<SiteInstanceImpl*>(site_instance.get())
1985 ->PreventAssociationWithSpareProcess();
1986 }
dcheng3ce04b62015-10-26 23:30:551987
1988 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1989 // local root by definition.
1990 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1991 // longer be necessary to eagerly grab a routing ID for the view.
1992 // https://crbug.com/545684
1993 int32_t view_routing_id = params.routing_id;
1994 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1995 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1996 view_routing_id = main_frame_widget_routing_id =
1997 site_instance->GetProcess()->GetNextRoutingID();
1998 }
1999
Dave Tapuska485aca92017-08-08 00:47:582000 GetRenderManager()->Init(
2001 site_instance.get(), view_routing_id, params.main_frame_routing_id,
2002 main_frame_widget_routing_id, params.renderer_initiated_creation);
lukasza464d8692016-02-22 19:26:322003
lukasza5140a412016-09-15 21:12:302004 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
2005 // main frame - let's do the same thing here.
2006 std::string unique_name;
lukasza464d8692016-02-22 19:26:322007 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:192008
[email protected]fc2b46b2014-05-03 16:33:452009 WebContentsViewDelegate* delegate =
2010 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
2011
sky52a39e342016-12-17 17:23:222012 if (GuestMode::IsCrossProcessFrameGuest(this)) {
2013 view_.reset(new WebContentsViewChildFrame(
2014 this, delegate, &render_view_host_delegate_view_));
2015 } else {
2016 view_.reset(CreateWebContentsView(this, delegate,
2017 &render_view_host_delegate_view_));
Scott Violetc884c7fd2017-11-03 23:51:012018 if (browser_plugin_guest_) {
2019 view_ = std::make_unique<WebContentsViewGuest>(
2020 this, browser_plugin_guest_.get(), std::move(view_),
2021 &render_view_host_delegate_view_);
2022 }
[email protected]d1198fd2012-08-13 22:50:192023 }
[email protected]fc2b46b2014-05-03 16:33:452024 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:192025 CHECK(view_.get());
2026
[email protected]ed245db2012-12-18 08:00:452027 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:592028 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:192029
brettw4b461082016-11-19 18:55:162030#if BUILDFLAG(ENABLE_PLUGINS)
tommyclieb25b2a2014-11-03 19:45:092031 plugin_content_origin_whitelist_.reset(
2032 new PluginContentOriginWhitelist(this));
2033#endif
2034
[email protected]d1198fd2012-08-13 22:50:192035 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:212036 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
2037 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:102038
leon.hane4db177a2017-02-07 14:19:162039 screen_orientation_provider_.reset(new ScreenOrientationProvider(this));
[email protected]01f83f92014-06-17 14:41:542040
mlamouriefdca9d2014-09-16 16:55:402041 manifest_manager_host_.reset(new ManifestManagerHost(this));
2042
mfomitchev2b8b066a2016-01-28 19:23:152043#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:102044 date_time_chooser_.reset(new DateTimeChooserAndroid());
2045#endif
fsamuel7310a4262014-12-05 05:06:442046
2047 // BrowserPluginGuest::Init needs to be called after this WebContents has
2048 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
2049 if (browser_plugin_guest_)
2050 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:372051
2052 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
2053 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:562054
2055 // If the WebContents creation was renderer-initiated, it means that the
2056 // corresponding RenderView and main RenderFrame have already been created.
2057 // Ensure observers are notified about this.
2058 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:432059 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
Alex Moshchuk27caae82017-09-11 23:11:182060 GetRenderViewHost()->DispatchRenderViewCreated();
naskob21fe4872015-02-24 14:15:562061 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
2062 }
naskof5940b9f2015-03-02 23:04:052063
lof84501da082016-05-23 21:22:542064 // Create the renderer process in advance if requested.
Lukasz Anforowicz3caa8372018-06-05 17:22:072065 if (params.desired_renderer_state ==
2066 CreateParams::kInitializeAndWarmupRendererProcess) {
lof84501da082016-05-23 21:22:542067 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
2068 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
2069 }
2070 }
2071
naskof5940b9f2015-03-02 23:04:052072 // Ensure that observers are notified of the creation of this WebContents's
2073 // main RenderFrameHost. It must be done here for main frames, since the
2074 // NotifySwappedFromRenderManager expects view_ to already be created and that
2075 // happens after RenderFrameHostManager::Init.
2076 NotifySwappedFromRenderManager(
2077 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:192078}
2079
[email protected]7fff43e2013-05-21 20:21:102080void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
2081 RemoveDestructionObserver(web_contents);
2082
[email protected]ceee8cd2013-03-08 04:59:512083 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:532084 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:512085 ++iter) {
erikchenbee5c9622018-04-27 19:30:252086 if (iter->second.get() != web_contents)
[email protected]ceee8cd2013-03-08 04:59:512087 continue;
erikchenbee5c9622018-04-27 19:30:252088
2089 // Someone else has deleted the WebContents. That should never happen!
2090 // TODO(erikchen): Fix semantics here. https://crbug.com/832879.
2091 iter->second.release();
[email protected]ceee8cd2013-03-08 04:59:512092 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:512093 return;
2094 }
2095 NOTREACHED();
[email protected]14392a52012-05-02 20:28:442096}
2097
[email protected]7fff43e2013-05-21 20:21:102098void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
2099 if (!ContainsKey(destruction_observers_, web_contents)) {
2100 destruction_observers_[web_contents] =
Jeremy Roman04f27c372017-10-27 15:20:552101 std::make_unique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:102102 }
2103}
2104
2105void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:462106 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:102107}
2108
[email protected]b172aee2012-04-10 17:05:262109void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312110 observers_.AddObserver(observer);
2111}
2112
[email protected]b172aee2012-04-10 17:05:262113void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312114 observers_.RemoveObserver(observer);
2115}
2116
[email protected]948481d2014-06-11 18:32:222117std::set<RenderWidgetHostView*>
2118WebContentsImpl::GetRenderWidgetHostViewsInTree() {
2119 std::set<RenderWidgetHostView*> set;
2120 if (ShowingInterstitialPage()) {
lfgf949e0e2017-05-10 22:18:112121 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView())
2122 set.insert(rwhv);
[email protected]948481d2014-06-11 18:32:222123 } else {
dchengafb53e22016-02-04 08:11:082124 for (RenderFrameHost* rfh : GetAllFrames()) {
lfgf949e0e2017-05-10 22:18:112125 if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
2126 ->frame_tree_node()
2127 ->render_manager()
2128 ->GetRenderWidgetHostView()) {
2129 set.insert(rwhv);
2130 }
dchengafb53e22016-02-04 08:11:082131 }
[email protected]948481d2014-06-11 18:32:222132 }
[email protected]de3c5d82014-05-28 22:12:592133 return set;
2134}
2135
[email protected]b172aee2012-04-10 17:05:262136void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:342137 if (delegate_)
2138 delegate_->ActivateContents(this);
2139}
2140
avi3e4b8512015-11-11 01:55:492141void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
2142 if (!RenderViewHostImpl::From(render_widget_host))
2143 return;
2144
[email protected]63954792011-07-11 04:17:482145 if (delegate_)
2146 delegate_->LostCapture();
2147}
2148
Steven Holte38041342018-06-22 22:00:572149ukm::SourceId WebContentsImpl::GetUkmSourceIdForLastCommittedSource() const {
2150 return last_committed_source_id_;
2151}
2152
lazyboy63f5b312015-11-23 20:19:522153void WebContentsImpl::RenderWidgetCreated(
2154 RenderWidgetHostImpl* render_widget_host) {
2155 created_widgets_.insert(render_widget_host);
2156}
2157
[email protected]b24b68a2012-09-24 21:57:262158void WebContentsImpl::RenderWidgetDeleted(
2159 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:522160 // Note that |is_being_destroyed_| can be true at this point as
2161 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
2162 // us here.
2163 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262164
lazyboy63f5b312015-11-23 20:19:522165 if (is_being_destroyed_)
2166 return;
[email protected]44470a22013-01-24 01:21:542167
2168 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:372169 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
2170 render_widget_host->GetProcess()->GetID() ==
2171 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:492172 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:532173 delegate_->ExitFullscreenModeForTab(this);
ericwilligersde386342016-10-19 02:35:092174 for (auto& observer : observers_)
2175 observer.DidDestroyFullscreenWidget();
alexmosc9e76ec2016-05-16 22:59:372176 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:542177 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:032178 if (fullscreen_widget_had_focus_at_shutdown_)
2179 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:542180 }
lfgbee1e0a2016-06-08 21:24:212181
lfg7d4caad2017-03-22 09:01:452182 if (render_widget_host == mouse_lock_widget_)
lfgff8dfc8d2016-10-21 17:42:322183 LostMouseLock(mouse_lock_widget_);
Joe Downing192998b22018-03-22 15:51:362184
Joe Downingc1a57efe2018-05-09 18:23:542185 CancelKeyboardLock(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262186}
2187
miu9e14e492014-10-25 02:39:042188void WebContentsImpl::RenderWidgetGotFocus(
2189 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:372190 // Notify the observers if an embedded fullscreen widget was focused.
2191 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2192 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
Michael Thiessen896405db2017-07-20 17:52:322193 NotifyWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:372194 }
miu9e14e492014-10-25 02:39:042195}
2196
zijiehe3bee08e22017-05-17 04:14:462197void WebContentsImpl::RenderWidgetLostFocus(
2198 RenderWidgetHostImpl* render_widget_host) {
Michael Thiessen896405db2017-07-20 17:52:322199 // Notify the observers if an embedded fullscreen widget lost focus.
2200 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2201 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
2202 NotifyWebContentsLostFocus(render_widget_host);
2203 }
zijiehe3bee08e22017-05-17 04:14:462204}
2205
estaded0a0c992015-01-21 14:12:062206void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:312207 RenderWidgetHostImpl* render_widget_host,
Christopher Cameron07f666b2018-02-13 23:41:192208 const ScreenInfo& screen_info,
rouslan2f5993f2015-01-29 00:18:312209 bool width_changed) {
creisc014b402015-04-23 16:41:452210 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:292211 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:062212 return;
estaded0a0c992015-01-21 14:12:062213
lfg8d649cc2017-04-28 18:04:302214 SendPageMessage(new PageMsg_UpdateScreenInfo(MSG_ROUTING_NONE, screen_info));
2215
ericwilligersde386342016-10-19 02:35:092216 for (auto& observer : observers_)
2217 observer.MainFrameWasResized(width_changed);
estaded0a0c992015-01-21 14:12:062218}
2219
skyf65d9bb2017-03-24 02:26:392220KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(
2221 const NativeWebKeyboardEvent& event) {
2222 return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event)
2223 : KeyboardEventProcessingResult::NOT_HANDLED;
[email protected]63954792011-07-11 04:17:482224}
2225
[email protected]b172aee2012-04-10 17:05:262226void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:102227 if (browser_plugin_embedder_ &&
2228 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
2229 return;
2230 }
[email protected]63954792011-07-11 04:17:482231 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132232 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:482233}
2234
[email protected]d92026ef2014-03-03 21:04:132235bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:462236 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:192237#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:332238 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
2239 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:192240 // -the OS already has a gesture to do this through pinch-zoom
2241 // -if a user starts an inertial scroll, let's go, and presses control
2242 // (i.e. control+tab) then the OS's buffered scroll events will come in
2243 // with control key set which isn't what the user wants
Blink Reformat1c4d759e2017-04-09 16:34:542244 if (delegate_ && event.wheel_ticks_y &&
chongz4a9751942016-08-17 17:49:392245 !ui::WebInputEventTraits::CanCauseScroll(event)) {
w.shackleton49bcd392016-01-06 17:38:222246 // Count only integer cumulative scrolls as zoom events; this handles
2247 // smooth scroll and regular scroll device behavior.
Blink Reformat1c4d759e2017-04-09 16:34:542248 zoom_scroll_remainder_ += event.wheel_ticks_y;
w.shackleton49bcd392016-01-06 17:38:222249 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
2250 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
2251 if (whole_zoom_scroll_remainder_ != 0) {
2252 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
2253 }
[email protected]fb3f066e2013-02-12 19:12:522254 return true;
2255 }
[email protected]bccc4472013-04-18 16:37:192256#endif
[email protected]fb3f066e2013-02-12 19:12:522257 return false;
2258}
2259
[email protected]04bce562014-01-30 05:34:542260bool WebContentsImpl::PreHandleGestureEvent(
2261 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:032262 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:542263}
2264
kenrb2a565f82015-09-02 20:24:592265RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:452266 if (!is_being_destroyed_ && GetOuterWebContents())
2267 return GetOuterWebContents()->GetInputEventRouter();
2268
2269 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:592270 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
2271 return rwh_input_event_router_.get();
2272}
2273
alexmos3fcd0ca2015-10-23 18:18:332274void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
2275 // Focus loss may occur while this WebContents is being destroyed. Don't
2276 // send the message in this case, as the main frame's RenderFrameHost and
2277 // other state has already been cleared.
2278 if (is_being_destroyed_)
2279 return;
2280
2281 frame_tree_.ReplicatePageFocus(is_focused);
2282}
2283
alexmosc4cbacb2015-11-21 01:29:222284RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
2285 RenderWidgetHostImpl* receiving_widget) {
alexmosc4cbacb2015-11-21 01:29:222286 // Events for widgets other than the main frame (e.g., popup menus) should be
2287 // forwarded directly to the widget they arrived on.
2288 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
2289 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522290
lfg1453e412017-04-11 00:48:502291 WebContentsImpl* focused_contents = GetFocusedWebContents();
2292
2293 // If the focused WebContents is showing an interstitial, return the
2294 // interstitial's widget.
2295 if (focused_contents->ShowingInterstitialPage()) {
2296 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112297 focused_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502298 ->GetRenderWidgetHost();
2299 }
2300
paulmeyerfeafc2d2017-04-25 21:46:402301 // If the focused WebContents is a guest WebContents, then get the focused
2302 // frame in the embedder WebContents instead.
2303 FrameTreeNode* focused_frame = nullptr;
2304 if (focused_contents->browser_plugin_guest_ &&
2305 !GuestMode::IsCrossProcessFrameGuest(focused_contents)) {
2306 focused_frame = frame_tree_.GetFocusedFrame();
2307 } else {
2308 focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
2309 }
lfg1453e412017-04-11 00:48:502310
alexmosc4d183e2015-11-06 00:46:522311 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:222312 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522313
alexmos732ca3a2015-12-08 02:01:022314 // The view may be null if a subframe's renderer process has crashed while
2315 // the subframe has focus. Drop the event in that case. Do not give
2316 // it to the main frame, so that the user doesn't unexpectedly type into the
2317 // wrong frame if a focused subframe renderer crashes while they type.
2318 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
2319 if (!view)
2320 return nullptr;
2321
2322 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:522323}
2324
avallee9993fca2016-11-17 06:16:502325RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
lfg1453e412017-04-11 00:48:502326 WebContentsImpl* focused_web_contents = GetFocusedWebContents();
2327
2328 if (focused_web_contents->ShowingInterstitialPage()) {
2329 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112330 focused_web_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502331 ->GetRenderWidgetHost();
2332 }
Alex Valléedc80ae2ed2017-09-06 21:55:442333 if (!GuestMode::IsCrossProcessFrameGuest(focused_web_contents) &&
2334 focused_web_contents->browser_plugin_guest_) {
2335 // If this is a guest, we need to be controlled by our embedder.
2336 return focused_web_contents->GetOuterWebContents()
2337 ->GetMainFrame()
2338 ->GetRenderWidgetHost();
2339 }
lfg1453e412017-04-11 00:48:502340
2341 return focused_web_contents->GetMainFrame()->GetRenderWidgetHost();
avallee9993fca2016-11-17 06:16:502342}
2343
Dave Tapuska3ed44192018-05-01 18:53:302344void WebContentsImpl::EnterFullscreenMode(
2345 const GURL& origin,
2346 const blink::WebFullscreenOptions& options) {
mlamouri7a78d6fd2015-01-17 13:23:532347 // This method is being called to enter renderer-initiated fullscreen mode.
2348 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:492349 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372350 if (widget_view) {
2351 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2352 ->ShutdownAndDestroyWidget(true);
2353 }
[email protected]4aebbca2013-09-17 22:26:492354
Joe Downing13dd76b2018-04-09 18:32:152355 if (delegate_) {
Dave Tapuska3ed44192018-05-01 18:53:302356 delegate_->EnterFullscreenModeForTab(this, origin, options);
mlamouri7a78d6fd2015-01-17 13:23:532357
Joe Downing13dd76b2018-04-09 18:32:152358 if (keyboard_lock_widget_)
2359 delegate_->RequestKeyboardLock(this, esc_key_locked_);
2360 }
2361
ericwilligersde386342016-10-19 02:35:092362 for (auto& observer : observers_)
2363 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false);
mlamouri7a78d6fd2015-01-17 13:23:532364}
2365
bokanece34a82016-01-28 19:49:462366void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532367 // This method is being called to leave renderer-initiated fullscreen mode.
2368 // Make sure any existing fullscreen widget is shut down first.
2369 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372370 if (widget_view) {
2371 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2372 ->ShutdownAndDestroyWidget(true);
2373 }
mlamouri7a78d6fd2015-01-17 13:23:532374
hugo.holgersson61288e6c2015-01-28 17:04:402375#if defined(OS_ANDROID)
2376 ContentVideoView* video_view = ContentVideoView::GetInstance();
2377 if (video_view != NULL)
watk98292292016-01-19 22:24:082378 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:402379#endif
2380
Joe Downing13dd76b2018-04-09 18:32:152381 if (delegate_) {
mlamouri7a78d6fd2015-01-17 13:23:532382 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:372383
Joe Downing13dd76b2018-04-09 18:32:152384 if (keyboard_lock_widget_)
2385 delegate_->CancelKeyboardLockRequest(this);
2386 }
2387
bokanece34a82016-01-28 19:49:462388 // The fullscreen state is communicated to the renderer through a resize
2389 // message. If the change in fullscreen state doesn't cause a view resize
2390 // then we must ensure web contents exit the fullscreen state by explicitly
2391 // sending a resize message. This is required for the situation of the browser
2392 // moving the view into a "browser fullscreen" state and then the contents
2393 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
2394 // have the side effect of the view resizing, hence the explicit call here is
2395 // required.
2396 if (!will_cause_resize) {
2397 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
2398 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:162399 render_widget_host->SynchronizeVisualProperties();
bokanece34a82016-01-28 19:49:462400 }
scheib3dcb6c932015-02-23 10:55:582401 }
2402
Becca Hughese9e27952018-06-25 17:08:272403 // Clear the current fullscreen frame ID.
2404 current_fullscreen_frame_tree_node_id_ = RenderFrameHost::kNoFrameTreeNodeId;
2405
ericwilligersde386342016-10-19 02:35:092406 for (auto& observer : observers_) {
2407 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
2408 will_cause_resize);
2409 }
[email protected]8a5e0ca2011-08-25 06:30:472410}
2411
Becca Hughesfd5d8f892018-06-14 18:23:362412void WebContentsImpl::FullscreenStateChanged(RenderFrameHost* rfh,
2413 bool is_fullscreen) {
2414 int frame_tree_node_id = rfh->GetFrameTreeNodeId();
2415 auto it = fullscreen_frame_tree_nodes_.find(frame_tree_node_id);
2416 bool changed = false;
2417
2418 if (is_fullscreen) {
2419 // If we are fullscreen then add the FrameTreeNode ID to the set.
2420 if (it == fullscreen_frame_tree_nodes_.end()) {
2421 fullscreen_frame_tree_nodes_.insert(frame_tree_node_id);
2422 changed = true;
2423 }
2424 } else {
2425 FrameTreeNode* ancestor =
2426 static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node();
2427 DCHECK(ancestor);
2428
2429 // If we are not fullscreen then remove this frame and any descendants
2430 // from the set.
2431 for (it = fullscreen_frame_tree_nodes_.begin();
2432 it != fullscreen_frame_tree_nodes_.end();) {
2433 FrameTreeNode* node = FrameTreeNode::GloballyFindByID(*it);
2434
2435 if (!node || frame_tree_node_id == *it ||
2436 node->IsDescendantOf(ancestor)) {
2437 it = fullscreen_frame_tree_nodes_.erase(it);
2438 changed = true;
2439 } else {
2440 ++it;
2441 }
2442 }
2443 }
2444
2445 // If we have changed then find the current fullscreen FrameTreeNode
2446 // and call the observers. If we have exited fullscreen then this
2447 // will be the last frame that was fullscreen.
2448 if (changed && fullscreen_frame_tree_nodes_.size() > 0) {
2449 unsigned int max_depth = 0;
2450 RenderFrameHost* max_depth_rfh = nullptr;
2451
2452 for (auto node_id : fullscreen_frame_tree_nodes_) {
2453 FrameTreeNode* fullscreen_node = FrameTreeNode::GloballyFindByID(node_id);
2454 DCHECK(fullscreen_node);
2455
2456 if (max_depth_rfh == nullptr || fullscreen_node->depth() > max_depth) {
2457 max_depth = fullscreen_node->depth();
2458 max_depth_rfh = fullscreen_node->current_frame_host();
2459 }
2460 }
2461
2462 // If we have already notified observers about this frame then we should not
2463 // fire the observers again.
2464 DCHECK(max_depth_rfh);
2465 if (max_depth_rfh->GetFrameTreeNodeId() ==
2466 current_fullscreen_frame_tree_node_id_)
2467 return;
2468
2469 current_fullscreen_frame_tree_node_id_ =
2470 max_depth_rfh->GetFrameTreeNodeId();
2471
2472 for (auto& observer : observers_)
2473 observer.DidAcquireFullscreen(max_depth_rfh);
2474 } else if (fullscreen_frame_tree_nodes_.size() == 0) {
2475 current_fullscreen_frame_tree_node_id_ =
2476 RenderFrameHost::kNoFrameTreeNodeId;
2477 }
2478}
2479
alexmos5dd617d2016-06-07 04:21:152480bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:382481 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:122482}
2483
billorr21c005d2016-11-17 03:57:042484bool WebContentsImpl::IsFullscreen() {
2485 return IsFullscreenForCurrentTab();
2486}
2487
avibf58fa0c2015-11-11 01:45:522488blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
2489 RenderWidgetHostImpl* render_widget_host) const {
2490 if (!RenderViewHostImpl::From(render_widget_host))
Blink Reformat1c4d759e2017-04-09 16:34:542491 return blink::kWebDisplayModeBrowser;
avibf58fa0c2015-11-11 01:45:522492
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122493 return delegate_ ? delegate_->GetDisplayMode(this)
Blink Reformat1c4d759e2017-04-09 16:34:542494 : blink::kWebDisplayModeBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122495}
2496
avic3aa8422015-11-09 20:57:222497void WebContentsImpl::RequestToLockMouse(
2498 RenderWidgetHostImpl* render_widget_host,
2499 bool user_gesture,
lfgad8244352016-07-13 16:55:512500 bool last_unlocked_by_target,
2501 bool privileged) {
lfgf0cd46e2017-01-04 00:05:232502 for (WebContentsImpl* current = this; current;
2503 current = current->GetOuterWebContents()) {
2504 if (current->mouse_lock_widget_) {
2505 render_widget_host->GotResponseToLockMouseRequest(false);
2506 return;
2507 }
[email protected]e9621112011-10-17 05:38:372508 }
avic3aa8422015-11-09 20:57:222509
lfgad8244352016-07-13 16:55:512510 if (privileged) {
lfgf0cd46e2017-01-04 00:05:232511 DCHECK(!GetOuterWebContents());
lfgad8244352016-07-13 16:55:512512 mouse_lock_widget_ = render_widget_host;
2513 render_widget_host->GotResponseToLockMouseRequest(true);
2514 return;
2515 }
2516
lfgbee1e0a2016-06-08 21:24:212517 bool widget_in_frame_tree = false;
2518 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2519 if (node->current_frame_host()->GetRenderWidgetHost() ==
2520 render_widget_host) {
2521 widget_in_frame_tree = true;
2522 break;
2523 }
2524 }
2525
2526 if (widget_in_frame_tree && delegate_) {
lfgf0cd46e2017-01-04 00:05:232527 for (WebContentsImpl* current = this; current;
2528 current = current->GetOuterWebContents()) {
2529 current->mouse_lock_widget_ = render_widget_host;
2530 }
2531
avic3aa8422015-11-09 20:57:222532 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:212533 } else {
2534 render_widget_host->GotResponseToLockMouseRequest(false);
2535 }
[email protected]e9621112011-10-17 05:38:372536}
2537
avi3e4b8512015-11-11 01:55:492538void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:212539 CHECK(mouse_lock_widget_);
lfgf0cd46e2017-01-04 00:05:232540
2541 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this)
2542 return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host);
2543
lfgbee1e0a2016-06-08 21:24:212544 mouse_lock_widget_->SendMouseLockLost();
lfgf0cd46e2017-01-04 00:05:232545 for (WebContentsImpl* current = this; current;
2546 current = current->GetOuterWebContents()) {
2547 current->mouse_lock_widget_ = nullptr;
2548 }
avi3e4b8512015-11-11 01:55:492549
[email protected]e9621112011-10-17 05:38:372550 if (delegate_)
2551 delegate_->LostMouseLock();
2552}
2553
lfgad8244352016-07-13 16:55:512554bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
2555 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
2556 // assigned to the widget that requested the mouse lock, and the top-level
2557 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
2558 return mouse_lock_widget_ == render_widget_host &&
2559 GetTopLevelRenderWidgetHostView()->IsMouseLocked();
2560}
2561
lfg84763c92017-02-16 18:55:152562RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() {
lfge2176fb2017-03-26 00:45:472563 if (GetTopLevelRenderWidgetHostView()->IsMouseLocked() ||
2564 (GetFullscreenRenderWidgetHostView() &&
2565 GetFullscreenRenderWidgetHostView()->IsMouseLocked()))
lfg84763c92017-02-16 18:55:152566 return mouse_lock_widget_;
2567
2568 return nullptr;
2569}
2570
Joe Downing192998b22018-03-22 15:51:362571bool WebContentsImpl::RequestKeyboardLock(
Joe Downing13dd76b2018-04-09 18:32:152572 RenderWidgetHostImpl* render_widget_host,
2573 bool esc_key_locked) {
Joe Downing192998b22018-03-22 15:51:362574 DCHECK(render_widget_host);
Joe Downing192998b22018-03-22 15:51:362575 if (render_widget_host->delegate()->GetAsWebContents() != this) {
2576 NOTREACHED();
2577 return false;
2578 }
2579
2580 // KeyboardLock is only supported when called by the top-level browsing
2581 // context and is not supported in embedded content scenarios.
2582 if (GetOuterWebContents())
2583 return false;
2584
Joe Downing13dd76b2018-04-09 18:32:152585 esc_key_locked_ = esc_key_locked;
Joe Downing192998b22018-03-22 15:51:362586 keyboard_lock_widget_ = render_widget_host;
2587
Joe Downing13dd76b2018-04-09 18:32:152588 if (delegate_)
2589 delegate_->RequestKeyboardLock(this, esc_key_locked_);
Joe Downing192998b22018-03-22 15:51:362590 return true;
2591}
2592
2593void WebContentsImpl::CancelKeyboardLock(
2594 RenderWidgetHostImpl* render_widget_host) {
2595 if (!keyboard_lock_widget_ || render_widget_host != keyboard_lock_widget_)
2596 return;
2597
2598 RenderWidgetHostImpl* old_keyboard_lock_widget = keyboard_lock_widget_;
2599 keyboard_lock_widget_ = nullptr;
2600
Joe Downing13dd76b2018-04-09 18:32:152601 if (delegate_)
2602 delegate_->CancelKeyboardLockRequest(this);
2603
Joe Downing192998b22018-03-22 15:51:362604 old_keyboard_lock_widget->CancelKeyboardLock();
2605}
2606
2607RenderWidgetHostImpl* WebContentsImpl::GetKeyboardLockWidget() {
2608 return keyboard_lock_widget_;
2609}
2610
ekaramada4f42692016-02-11 19:48:372611void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
lfg9462cef2016-07-18 23:51:062612 if (visible && !GetOuterWebContents()->IsHidden())
ekaramada4f42692016-02-11 19:48:372613 WasShown();
lfg9462cef2016-07-18 23:51:062614 else if (!visible)
ekaramada4f42692016-02-11 19:48:372615 WasHidden();
2616}
2617
[email protected]bafe6cd2012-05-23 23:09:502618void WebContentsImpl::CreateNewWindow(
csharrison95f01e922017-04-24 18:52:352619 RenderFrameHost* opener,
nick5ae4d2d2017-01-06 01:18:352620 int32_t render_view_route_id,
dcheng3ce04b62015-10-26 23:30:552621 int32_t main_frame_route_id,
2622 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:182623 const mojom::CreateNewWindowParams& params,
[email protected]97714c82012-06-06 10:15:132624 SessionStorageNamespace* session_storage_namespace) {
nick5ae4d2d2017-01-06 01:18:352625 // We should have zero valid routing ids, or three valid routing IDs.
2626 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2627 (main_frame_route_id == MSG_ROUTING_NONE));
2628 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2629 (main_frame_widget_route_id == MSG_ROUTING_NONE));
csharrison95f01e922017-04-24 18:52:352630 DCHECK(opener);
nick5ae4d2d2017-01-06 01:18:352631
csharrison95f01e922017-04-24 18:52:352632 int render_process_id = opener->GetProcess()->GetID();
2633 SiteInstance* source_site_instance = opener->GetSiteInstance();
2634
2635 // The route IDs passed into this function can be trusted not to already
2636 // be in use; they were allocated by the RenderWidgetHelper by the caller.
nick5ae4d2d2017-01-06 01:18:352637 DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id));
2638
[email protected]bafe6cd2012-05-23 23:09:502639 // We usually create the new window in the same BrowsingInstance (group of
2640 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:552641 // if the opener is being suppressed (in a non-guest), we create a new
2642 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:252643 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:552644
[email protected]04cbd3d2013-12-04 04:58:202645 // If the opener is to be suppressed, the new window can be in any process.
2646 // Since routing ids are process specific, we must not have one passed in
2647 // as argument here.
nick5ae4d2d2017-01-06 01:18:352648 DCHECK(!params.opener_suppressed || render_view_route_id == MSG_ROUTING_NONE);
[email protected]04cbd3d2013-12-04 04:58:202649
[email protected]bafe6cd2012-05-23 23:09:502650 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:432651 params.opener_suppressed && !is_guest
2652 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
2653 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:502654
[email protected]d1198fd2012-08-13 22:50:192655 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:342656 //
2657 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:302658 const std::string& partition_id =
2659 GetContentClient()->browser()->
2660 GetStoragePartitionIdForSite(GetBrowserContext(),
2661 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:462662 StoragePartition* partition = BrowserContext::GetStoragePartition(
2663 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:412664 DOMStorageContextWrapper* dom_storage_context =
2665 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:192666 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2667 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2668 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:372669
2670 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:552671 !delegate_->ShouldCreateWebContents(
lukasza6f8ac622017-06-06 03:10:202672 this, opener, source_site_instance, render_view_route_id,
2673 main_frame_route_id, main_frame_widget_route_id,
2674 params.window_container_type, opener->GetLastCommittedURL(),
2675 params.frame_name, params.target_url, partition_id,
2676 session_storage_namespace)) {
jambaaab3a2016-11-05 00:46:182677 // Note: even though we're not creating a WebContents here, it could have
2678 // been created by the embedder so ensure that the RenderFrameHost is
2679 // properly initialized.
csharrisona2280cd2016-02-03 23:21:152680 // It's safe to only target the frame because the render process will not
2681 // have a chance to create more frames at this point.
jambaaab3a2016-11-05 00:46:182682 RenderFrameHostImpl* rfh =
2683 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id);
nick5ae4d2d2017-01-06 01:18:352684 if (rfh) {
2685 DCHECK(rfh->IsRenderFrameLive());
jambaaab3a2016-11-05 00:46:182686 rfh->Init();
nick5ae4d2d2017-01-06 01:18:352687 }
[email protected]dd6730412013-08-14 15:03:372688 return;
2689 }
2690
2691 // Create the new web contents. This will automatically create the new
2692 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462693 CreateParams create_params(GetBrowserContext(), site_instance.get());
nick5ae4d2d2017-01-06 01:18:352694 create_params.routing_id = render_view_route_id;
[email protected]227692c52013-05-31 22:43:042695 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:552696 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:122697 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432698 create_params.opener_render_process_id = render_process_id;
csharrison95f01e922017-04-24 18:52:352699 create_params.opener_render_frame_id = opener->GetRoutingID();
[email protected]50d326e2014-05-20 17:59:062700 create_params.opener_suppressed = params.opener_suppressed;
nick3b04f322016-08-31 19:29:192701 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
[email protected]50d326e2014-05-20 17:59:062702 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:192703 create_params.renderer_initiated_creation =
2704 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:062705
erikchenbee5c9622018-04-27 19:30:252706 std::unique_ptr<WebContents> new_contents;
[email protected]c4538072013-03-18 02:17:552707 if (!is_guest) {
2708 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:452709 create_params.initial_size = GetContainerBounds().size();
Erik Chenbb8e738e2018-04-28 14:10:432710 new_contents = WebContents::Create(create_params);
[email protected]4858e432014-06-23 18:14:172711 } else {
erikchenbee5c9622018-04-27 19:30:252712 new_contents = base::WrapUnique(
2713 GetBrowserPluginGuest()->CreateNewGuestWindow(create_params));
[email protected]c4538072013-03-18 02:17:552714 }
erikchenbee5c9622018-04-27 19:30:252715 WebContentsImpl* raw_new_contents =
2716 static_cast<WebContentsImpl*>(new_contents.get());
2717 raw_new_contents->GetController().SetSessionStorageNamespace(
2718 partition_id, session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192719
alexmos646fec02015-07-25 00:11:492720 // If the new frame has a name, make sure any SiteInstances that can find
2721 // this named frame have proxies for it. Must be called after
2722 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2723 // GetSessionStorageNamespace.
2724 if (!params.frame_name.empty())
erikchenbee5c9622018-04-27 19:30:252725 raw_new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
alexmos646fec02015-07-25 00:11:492726
[email protected]c4538072013-03-18 02:17:552727 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342728 // will be shown immediately).
2729 if (!params.opener_suppressed) {
2730 if (!is_guest) {
erikchenbee5c9622018-04-27 19:30:252731 WebContentsView* new_view = raw_new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502732
[email protected]d70bea92013-04-05 04:23:342733 // TODO(brettw): It seems bogus that we have to call this function on the
2734 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:432735 new_view->CreateViewForWidget(
2736 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:342737 }
[email protected]bafe6cd2012-05-23 23:09:502738 // Save the created window associated with the route so we can show it
2739 // later.
nick5ae4d2d2017-01-06 01:18:352740 DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id);
erikchenbee5c9622018-04-27 19:30:252741 pending_contents_[std::make_pair(render_process_id,
2742 main_frame_widget_route_id)] =
2743 std::move(new_contents);
2744 AddDestructionObserver(raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502745 }
2746
2747 if (delegate_) {
Bryan McQuaded2b93c02017-07-14 22:26:312748 delegate_->WebContentsCreated(this, render_process_id,
2749 opener->GetRoutingID(), params.frame_name,
erikchenbee5c9622018-04-27 19:30:252750 params.target_url, raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502751 }
2752
csharrison95f01e922017-04-24 18:52:352753 if (opener) {
pnolandaae574e2017-03-06 21:04:212754 for (auto& observer : observers_) {
erikchenbee5c9622018-04-27 19:30:252755 observer.DidOpenRequestedURL(raw_new_contents, opener, params.target_url,
csharrison95f01e922017-04-24 18:52:352756 params.referrer, params.disposition,
2757 ui::PAGE_TRANSITION_LINK,
pnolandaae574e2017-03-06 21:04:212758 false, // started_from_context_menu
2759 true); // renderer_initiated
2760 }
2761 }
2762
Avi Drissmanba3b1b342017-08-29 18:16:132763 // Any new WebContents opened while this WebContents is in fullscreen can be
2764 // used to confuse the user, so drop fullscreen.
2765 if (IsFullscreenForCurrentTab())
2766 ExitFullscreen(true);
2767
[email protected]bafe6cd2012-05-23 23:09:502768 if (params.opener_suppressed) {
2769 // When the opener is suppressed, the original renderer cannot access the
2770 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002771 bool was_blocked = false;
erikchenbee5c9622018-04-27 19:30:252772
2773 base::WeakPtr<WebContentsImpl> weak_new_contents =
2774 raw_new_contents->weak_factory_.GetWeakPtr();
[email protected]eda238a12012-09-07 23:44:002775 if (delegate_) {
bokan107a47f2015-02-03 23:23:392776 gfx::Rect initial_rect;
nick0d558482017-02-13 22:27:222777
erikchenbee5c9622018-04-27 19:30:252778 delegate_->AddNewContents(this, std::move(new_contents),
2779 params.disposition, initial_rect,
Mustaq Ahmedc4cb7162018-06-05 16:28:362780 params.mimic_user_gesture, &was_blocked);
nick0d558482017-02-13 22:27:222781 if (!weak_new_contents)
2782 return; // The delegate deleted |new_contents| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002783 }
erikchenbee5c9622018-04-27 19:30:252784
[email protected]eda238a12012-09-07 23:44:002785 if (!was_blocked) {
nick3b04f322016-08-31 19:29:192786 OpenURLParams open_params(params.target_url, params.referrer,
2787 WindowOpenDisposition::CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352788 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212789 true /* is_renderer_initiated */);
Mustaq Ahmedc4cb7162018-06-05 16:28:362790 open_params.user_gesture = params.mimic_user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372791
2792 if (delegate_ && !is_guest &&
2793 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
erikchenbee5c9622018-04-27 19:30:252794 DCHECK(weak_new_contents);
mariakhomenkoa4971c12015-07-21 19:04:372795 // We are in asynchronous add new contents path, delay opening url
erikchenbee5c9622018-04-27 19:30:252796 weak_new_contents->delayed_open_url_params_.reset(
mariakhomenkoa4971c12015-07-21 19:04:372797 new OpenURLParams(open_params));
2798 } else {
erikchenbee5c9622018-04-27 19:30:252799 weak_new_contents->OpenURL(open_params);
mariakhomenkoa4971c12015-07-21 19:04:372800 }
[email protected]eda238a12012-09-07 23:44:002801 }
[email protected]bafe6cd2012-05-23 23:09:502802 }
2803}
2804
avib7348942015-12-25 20:57:102805void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2806 int32_t route_id,
Dave Tapuska1bdf1832017-07-07 18:07:192807 mojom::WidgetPtr widget,
[email protected]180ef242013-11-07 06:50:462808 blink::WebPopupType popup_type) {
Dave Tapuska1bdf1832017-07-07 18:07:192809 CreateNewWidget(render_process_id, route_id, false, std::move(widget),
2810 popup_type);
[email protected]bafe6cd2012-05-23 23:09:502811}
2812
avib7348942015-12-25 20:57:102813void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
Dave Tapuska1bdf1832017-07-07 18:07:192814 int32_t route_id,
2815 mojom::WidgetPtr widget) {
2816 CreateNewWidget(render_process_id, route_id, true, std::move(widget),
2817 blink::kWebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502818}
2819
avib7348942015-12-25 20:57:102820void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2821 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502822 bool is_fullscreen,
Dave Tapuska1bdf1832017-07-07 18:07:192823 mojom::WidgetPtr widget,
[email protected]180ef242013-11-07 06:50:462824 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252825 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232826 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512827 // this WebContentsImpl instance. If any other process sends the request,
2828 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382829 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
Lukasz Anforowicz6f746282018-01-04 23:24:512830 ReceivedBadMessage(process, bad_message::WCI_NEW_WIDGET_PROCESS_MISMATCH);
[email protected]a8504022013-12-04 20:23:512831 return;
2832 }
2833
Dave Tapuska485aca92017-08-08 00:47:582834 RenderWidgetHostImpl* widget_host = new RenderWidgetHostImpl(
2835 this, process, route_id, std::move(widget), IsHidden());
[email protected]b24b68a2012-09-24 21:57:262836
[email protected]cfd80b02014-05-01 17:46:482837 RenderWidgetHostViewBase* widget_view =
2838 static_cast<RenderWidgetHostViewBase*>(
2839 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192840 if (!widget_view)
2841 return;
[email protected]bafe6cd2012-05-23 23:09:502842 if (!is_fullscreen) {
2843 // Popups should not get activated.
2844 widget_view->SetPopupType(popup_type);
2845 }
2846 // Save the created widget associated with the route so we can show it later.
alexmosc2a8cec2016-05-23 22:19:532847 pending_widget_views_[std::make_pair(render_process_id, route_id)] =
2848 widget_view;
[email protected]bafe6cd2012-05-23 23:09:502849}
2850
alexmosc2a8cec2016-05-23 22:19:532851void WebContentsImpl::ShowCreatedWindow(int process_id,
nick5ae4d2d2017-01-06 01:18:352852 int main_frame_widget_route_id,
[email protected]bafe6cd2012-05-23 23:09:502853 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392854 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502855 bool user_gesture) {
erikchenbee5c9622018-04-27 19:30:252856 std::unique_ptr<WebContents> popup =
nick5ae4d2d2017-01-06 01:18:352857 GetCreatedWindow(process_id, main_frame_widget_route_id);
nick0d558482017-02-13 22:27:222858 if (popup) {
erikchenbee5c9622018-04-27 19:30:252859 WebContentsImpl* raw_popup = static_cast<WebContentsImpl*>(popup.get());
[email protected]eda238a12012-09-07 23:44:002860 WebContentsDelegate* delegate = GetDelegate();
erikchenbee5c9622018-04-27 19:30:252861 raw_popup->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382862 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
erikchenbee5c9622018-04-27 19:30:252863 raw_popup->ResumeLoadingCreatedWebContents();
mariakhomenko44bdc4732015-04-29 01:55:382864
erikchenbee5c9622018-04-27 19:30:252865 base::WeakPtr<WebContentsImpl> weak_popup =
2866 raw_popup->weak_factory_.GetWeakPtr();
[email protected]eda238a12012-09-07 23:44:002867 if (delegate) {
erikchenbee5c9622018-04-27 19:30:252868 delegate->AddNewContents(this, std::move(popup), disposition,
2869 initial_rect, user_gesture, nullptr);
nick0d558482017-02-13 22:27:222870 if (!weak_popup)
2871 return; // The delegate deleted |popup| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002872 }
nick5ae4d2d2017-01-06 01:18:352873
erikchenbee5c9622018-04-27 19:30:252874 RenderWidgetHostImpl* rwh =
2875 weak_popup->GetMainFrame()->GetRenderWidgetHost();
nick0d558482017-02-13 22:27:222876 DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID());
Avi Drissman014dec72018-06-07 02:34:012877 rwh->Send(new ViewMsg_SetBounds_ACK(rwh->GetRoutingID()));
[email protected]eda238a12012-09-07 23:44:002878 }
[email protected]bafe6cd2012-05-23 23:09:502879}
2880
alexmosc2a8cec2016-05-23 22:19:532881void WebContentsImpl::ShowCreatedWidget(int process_id,
2882 int route_id,
bokan107a47f2015-02-03 23:23:392883 const gfx::Rect& initial_rect) {
alexmosc2a8cec2016-05-23 22:19:532884 ShowCreatedWidget(process_id, route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502885}
2886
alexmosc2a8cec2016-05-23 22:19:532887void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
2888 int route_id) {
2889 ShowCreatedWidget(process_id, route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:502890}
2891
alexmosc2a8cec2016-05-23 22:19:532892void WebContentsImpl::ShowCreatedWidget(int process_id,
2893 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502894 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392895 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482896 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:532897 static_cast<RenderWidgetHostViewBase*>(
2898 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502899 if (!widget_host_view)
2900 return;
[email protected]cfd80b02014-05-01 17:46:482901
Ivan Kotenkov2c0d2bb32017-11-01 15:41:282902 RenderWidgetHostView* view = nullptr;
lfgc740d4b22016-04-15 16:45:332903 if (GetOuterWebContents()) {
2904 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482905 } else {
2906 view = GetRenderWidgetHostView();
2907 }
2908
[email protected]4aebbca2013-09-17 22:26:492909 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312910 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032911 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:372912 fullscreen_widget_process_id_ =
2913 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:312914 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492915 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2916 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
Dave Tapuska3ed44192018-05-01 18:53:302917 delegate_->EnterFullscreenModeForTab(this, GURL(),
2918 blink::WebFullscreenOptions());
[email protected]4aebbca2013-09-17 22:26:492919 } else {
[email protected]cfd80b02014-05-01 17:46:482920 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492921 }
ericwilligersde386342016-10-19 02:35:092922 for (auto& observer : observers_)
2923 observer.DidShowFullscreenWidget();
[email protected]4aebbca2013-09-17 22:26:492924 if (!widget_host_view->HasFocus())
2925 widget_host_view->Focus();
2926 } else {
bokan107a47f2015-02-03 23:23:392927 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492928 }
[email protected]89054502012-06-03 10:29:242929
yiyixcb1fbc4f2018-03-16 19:54:082930 RenderWidgetHostImpl* render_widget_host_impl = widget_host_view->host();
[email protected]89054502012-06-03 10:29:242931 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312932 // Only allow privileged mouse lock for fullscreen render widget, which is
2933 // used to implement Pepper Flash fullscreen.
2934 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502935}
2936
erikchenbee5c9622018-04-27 19:30:252937std::unique_ptr<WebContents> WebContentsImpl::GetCreatedWindow(
nick5ae4d2d2017-01-06 01:18:352938 int process_id,
2939 int main_frame_widget_route_id) {
2940 auto key = std::make_pair(process_id, main_frame_widget_route_id);
2941 auto iter = pending_contents_.find(key);
[email protected]bafe6cd2012-05-23 23:09:502942
2943 // Certain systems can block the creation of new windows. If we didn't succeed
2944 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:532945 if (iter == pending_contents_.end())
2946 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502947
erikchenbee5c9622018-04-27 19:30:252948 std::unique_ptr<WebContents> new_contents = std::move(iter->second);
nick5ae4d2d2017-01-06 01:18:352949 pending_contents_.erase(key);
erikchenbee5c9622018-04-27 19:30:252950 WebContentsImpl* raw_new_contents =
2951 static_cast<WebContentsImpl*>(new_contents.get());
2952 RemoveDestructionObserver(raw_new_contents);
[email protected]bafe6cd2012-05-23 23:09:502953
[email protected]d70bea92013-04-05 04:23:342954 // Don't initialize the guest WebContents immediately.
erikchenbee5c9622018-04-27 19:30:252955 if (BrowserPluginGuest::IsGuest(raw_new_contents))
[email protected]d70bea92013-04-05 04:23:342956 return new_contents;
2957
Lukasz Anforowicz5510ed652018-06-06 16:16:192958 if (!new_contents->GetMainFrame()->GetProcess()->IsInitializedAndNotDead() ||
nick5ae4d2d2017-01-06 01:18:352959 !new_contents->GetMainFrame()->GetView()) {
alexmosc2a8cec2016-05-23 22:19:532960 return nullptr;
nick5ae4d2d2017-01-06 01:18:352961 }
[email protected]bafe6cd2012-05-23 23:09:502962
[email protected]bafe6cd2012-05-23 23:09:502963 return new_contents;
2964}
2965
alexmosc2a8cec2016-05-23 22:19:532966RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
2967 int route_id) {
2968 auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502969 if (iter == pending_widget_views_.end()) {
2970 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:532971 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502972 }
2973
2974 RenderWidgetHostView* widget_host_view = iter->second;
alexmosc2a8cec2016-05-23 22:19:532975 pending_widget_views_.erase(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502976
2977 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
Lukasz Anforowicz5510ed652018-06-06 16:16:192978 if (!widget_host->GetProcess()->IsInitializedAndNotDead()) {
[email protected]bafe6cd2012-05-23 23:09:502979 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:532980 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502981 }
2982
2983 return widget_host_view;
2984}
2985
[email protected]f13b4202012-06-12 23:53:232986void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092987 const MediaStreamRequest& request,
Mark Pilgrim57499082018-06-12 12:38:302988 MediaResponseCallback callback) {
[email protected]d19b84b2014-03-14 11:52:372989 if (delegate_) {
Mark Pilgrim57499082018-06-12 12:38:302990 delegate_->RequestMediaAccessPermission(this, request, std::move(callback));
[email protected]d19b84b2014-03-14 11:52:372991 } else {
Mark Pilgrim57499082018-06-12 12:38:302992 std::move(callback).Run(MediaStreamDevices(),
2993 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2994 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372995 }
[email protected]f13b4202012-06-12 23:53:232996}
2997
Chandan Padhia4b8bcb72017-09-12 16:41:042998bool WebContentsImpl::CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:582999 RenderFrameHost* render_frame_host,
Chandan Padhia4b8bcb72017-09-12 16:41:043000 const url::Origin& security_origin,
3001 MediaStreamType type) {
grunell657d4d82014-09-18 00:09:433002 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
3003 type == MEDIA_DEVICE_VIDEO_CAPTURE);
Chandan Padhia4b8bcb72017-09-12 16:41:043004 return delegate_ && delegate_->CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:583005 render_frame_host, security_origin.GetURL(), type);
grunell657d4d82014-09-18 00:09:433006}
3007
guidou8a440b842017-01-30 13:58:433008std::string WebContentsImpl::GetDefaultMediaDeviceID(MediaStreamType type) {
3009 if (!delegate_)
3010 return std::string();
3011 return delegate_->GetDefaultMediaDeviceID(this, type);
3012}
3013
[email protected]cc9200432013-07-23 23:02:403014SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
3015 SiteInstance* instance) {
3016 return controller_.GetSessionStorageNamespace(instance);
3017}
3018
[email protected]6de7fc482014-06-06 10:46:443019SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
3020 return controller_.GetSessionStorageNamespaceMap();
3021}
3022
[email protected]9b159a52013-10-03 17:24:553023FrameTree* WebContentsImpl::GetFrameTree() {
3024 return &frame_tree_;
3025}
3026
aelias5252baa2016-04-10 01:18:023027bool WebContentsImpl::IsOverridingUserAgent() {
3028 return GetController().GetVisibleEntry() &&
3029 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
3030}
3031
avi85ee8362016-10-08 02:09:083032bool WebContentsImpl::IsJavaScriptDialogShowing() const {
3033 return is_showing_javascript_dialog_;
3034}
3035
avic031d392017-03-03 03:09:423036bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() {
3037 // Ignore unresponsive renderers if the debugger is attached to them since the
3038 // unresponsiveness might be a result of the renderer sitting on a breakpoint.
3039 //
3040 // TODO(pfeldman): Fix this to only return true if the renderer is *actually*
3041 // sitting on a breakpoint. https://crbug.com/684202
3042 return DevToolsAgentHost::IsDebuggerAttached(this);
3043}
3044
Doug Turner63f3c7b2017-07-29 05:10:013045ui::AXMode WebContentsImpl::GetAccessibilityMode() const {
[email protected]95640212014-07-26 18:14:303046 return accessibility_mode_;
3047}
3048
Dominic Mazzonia7b0edb22017-08-09 16:32:513049void WebContentsImpl::AccessibilityEventReceived(
Dominic Mazzoniccbaa9b2018-06-06 07:44:233050 const AXEventNotificationDetails& details) {
ericwilligersde386342016-10-19 02:35:093051 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513052 observer.AccessibilityEventReceived(details);
[email protected]31a71eaf2014-03-13 01:47:363053}
3054
dmazzoni2400c462016-08-23 15:07:133055void WebContentsImpl::AccessibilityLocationChangesReceived(
3056 const std::vector<AXLocationChangeNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:093057 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513058 observer.AccessibilityLocationChangesReceived(details);
dmazzoni2400c462016-08-23 15:07:133059}
3060
dmazzonia656928e2014-09-15 20:28:543061RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:403062 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:543063 int browser_plugin_instance_id) {
3064 BrowserPluginGuestManager* guest_manager =
3065 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:203066 if (!guest_manager)
3067 return nullptr;
3068
dmazzonia656928e2014-09-15 20:28:543069 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:443070 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:543071 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:203072 return nullptr;
3073
dmazzonia656928e2014-09-15 20:28:543074 return guest->GetMainFrame();
3075}
3076
Ke He7319dbe2017-11-09 05:54:443077device::mojom::GeolocationContext* WebContentsImpl::GetGeolocationContext() {
3078 if (geolocation_context_)
3079 return geolocation_context_.get();
3080
3081 auto request = mojo::MakeRequest(&geolocation_context_);
3082 if (!ServiceManagerConnection::GetForProcess())
3083 return geolocation_context_.get();
3084
3085 service_manager::Connector* connector =
3086 ServiceManagerConnection::GetForProcess()->GetConnector();
3087 connector->BindInterface(device::mojom::kServiceName, std::move(request));
Conley Owens6894c4f2017-07-10 19:29:133088 return geolocation_context_.get();
blundellc57b93f2014-10-29 13:19:573089}
3090
ke.he98b761e2017-05-09 05:59:173091device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() {
blundelld8cd72b2017-03-28 07:18:383092 if (!wake_lock_context_host_)
3093 wake_lock_context_host_.reset(new WakeLockContextHost(this));
blundelle75a8f92017-03-27 08:11:173094 return wake_lock_context_host_->GetWakeLockContext();
alogvinovf50445a2015-10-30 13:00:123095}
3096
juncai8e8d6ec2017-06-06 20:48:183097device::mojom::WakeLock* WebContentsImpl::GetRendererWakeLock() {
3098 // WebContents creates a long-lived connection to one WakeLock.
ke.he98b761e2017-05-09 05:59:173099 // All the frames' requests will be added into the BindingSet of
juncai8e8d6ec2017-06-06 20:48:183100 // WakeLock via this connection.
ke.he98b761e2017-05-09 05:59:173101 if (!renderer_wake_lock_) {
3102 device::mojom::WakeLockContext* wake_lock_context = GetWakeLockContext();
3103 if (!wake_lock_context) {
3104 return nullptr;
3105 }
ke.hef435c1e82017-05-11 04:09:103106 wake_lock_context->GetWakeLock(
Daniel Erat28922ba2017-11-08 16:18:263107 device::mojom::WakeLockType::kPreventDisplaySleep,
3108 device::mojom::WakeLockReason::kOther, "Wake Lock API",
ke.hef435c1e82017-05-11 04:09:103109 mojo::MakeRequest(&renderer_wake_lock_));
ke.he98b761e2017-05-09 05:59:173110 }
3111 return renderer_wake_lock_.get();
3112}
3113
blundellf5316fc2017-05-15 11:49:033114#if defined(OS_ANDROID)
Han Leonf6a2e5f2017-05-23 13:40:473115void WebContentsImpl::GetNFC(device::mojom::NFCRequest request) {
blundellf5316fc2017-05-15 11:49:033116 if (!nfc_host_)
3117 nfc_host_.reset(new NFCHost(this));
3118 nfc_host_->GetNFC(std::move(request));
3119}
3120#endif
3121
Evan Stade5e750ad02017-08-07 21:59:273122void WebContentsImpl::SetNotWaitingForResponse() {
3123 if (waiting_for_response_ == false)
3124 return;
3125
3126 waiting_for_response_ = false;
3127 if (delegate_)
3128 delegate_->LoadingStateChanged(this, is_load_to_different_document_);
Chris Hamiltonf82f2a702018-02-15 19:37:293129 for (auto& observer : observers_)
3130 observer.DidReceiveResponse();
Evan Stade5e750ad02017-08-07 21:59:273131}
3132
lfgbb9c28a2016-03-01 03:19:493133void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:373134 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:403135 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:373136 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
3137 }
lfgbb9c28a2016-03-01 03:19:493138
lfgdb5c4ed2016-03-04 23:09:073139 RenderWidgetHostViewBase* rwhv =
3140 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3141 if (rwhv) {
3142 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
3143 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
3144 }
3145
avallee9f43b012016-11-26 07:02:103146 if (browser_plugin_embedder_ && !is_being_destroyed_)
[email protected]a7568e62013-06-14 07:50:443147 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:043148}
3149
ekaramadadd882292016-06-08 15:22:563150TextInputManager* WebContentsImpl::GetTextInputManager() {
3151 if (GetOuterWebContents())
3152 return GetOuterWebContents()->GetTextInputManager();
3153
Darren Shenca53d5f2018-05-15 04:56:013154 if (!text_input_manager_) {
3155 text_input_manager_.reset(new TextInputManager(
3156 GetBrowserContext() &&
3157 !GetBrowserContext()->IsOffTheRecord()) /* should_do_learning */);
3158 }
ekaramadadd882292016-06-08 15:22:563159
3160 return text_input_manager_.get();
3161}
3162
paulmeyer7f6f1d4f2016-11-15 00:00:273163bool WebContentsImpl::OnUpdateDragCursor() {
3164 if (browser_plugin_embedder_)
3165 return browser_plugin_embedder_->OnUpdateDragCursor();
3166 return false;
3167}
3168
kenrb11f213a2017-03-24 18:12:063169bool WebContentsImpl::IsWidgetForMainFrame(
3170 RenderWidgetHostImpl* render_widget_host) {
3171 return render_widget_host == GetMainFrame()->GetRenderWidgetHost();
3172}
3173
[email protected]95640212014-07-26 18:14:303174BrowserAccessibilityManager*
3175 WebContentsImpl::GetRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223176 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3177 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3178 : GetMainFrame());
creisc014b402015-04-23 16:41:453179 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:303180}
3181
3182BrowserAccessibilityManager*
3183 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223184 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3185 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3186 : GetMainFrame());
creisc014b402015-04-23 16:41:453187 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:303188}
3189
Dave Tapuskab336b922017-07-06 19:24:053190void WebContentsImpl::ExecuteEditCommand(
3191 const std::string& command,
3192 const base::Optional<base::string16>& value) {
3193 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
3194 if (!focused_frame)
3195 return;
3196
3197 focused_frame->GetFrameInputHandler()->ExecuteEditCommand(command, value);
3198}
3199
mohsen7ab1ec16ec2015-07-02 18:26:233200void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:053201 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:233202 if (!focused_frame)
3203 return;
3204
dtapuska9d46ef7d2017-05-26 19:06:063205 focused_frame->GetFrameInputHandler()->MoveRangeSelectionExtent(extent);
mohsen7ab1ec16ec2015-07-02 18:26:233206}
3207
3208void WebContentsImpl::SelectRange(const gfx::Point& base,
3209 const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:053210 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:233211 if (!focused_frame)
3212 return;
3213
dtapuska9d46ef7d2017-05-26 19:06:063214 focused_frame->GetFrameInputHandler()->SelectRange(base, extent);
mohsen7ab1ec16ec2015-07-02 18:26:233215}
3216
Tessa Nijssenc4b101232018-06-25 20:28:083217#if defined(OS_MACOSX)
Tessa Nijssendbef4742018-06-29 21:02:083218void WebContentsImpl::DidChangeTextSelection(const base::string16& text,
3219 const gfx::Range& range) {
3220 for (auto& observer : observers_)
3221 observer.DidChangeTextSelection(text, range);
Tessa Nijssenc4b101232018-06-25 20:28:083222}
3223#endif
3224
Dave Tapuskab336b922017-07-06 19:24:053225void WebContentsImpl::MoveCaret(const gfx::Point& extent) {
3226 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
3227 if (!focused_frame)
3228 return;
3229
3230 focused_frame->GetFrameInputHandler()->MoveCaret(extent);
3231}
3232
Shimi Zhang37deeb22017-09-28 00:59:013233void WebContentsImpl::AdjustSelectionByCharacterOffset(
3234 int start_adjust,
3235 int end_adjust,
3236 bool show_selection_menu) {
Dave Tapuskab336b922017-07-06 19:24:053237 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
aurimasab0319022015-07-10 21:57:383238 if (!focused_frame)
3239 return;
3240
Shimi Zhang37deeb22017-09-28 00:59:013241 using blink::mojom::SelectionMenuBehavior;
dtapuska9d46ef7d2017-05-26 19:06:063242 focused_frame->GetFrameInputHandler()->AdjustSelectionByCharacterOffset(
Shimi Zhang37deeb22017-09-28 00:59:013243 start_adjust, end_adjust,
3244 show_selection_menu ? SelectionMenuBehavior::kShow
3245 : SelectionMenuBehavior::kHide);
aurimasab0319022015-07-10 21:57:383246}
3247
[email protected]b172aee2012-04-10 17:05:263248void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:493249 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:233250 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:493251 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:333252}
3253
avic3aa8422015-11-09 20:57:223254void WebContentsImpl::ResizeDueToAutoResize(
3255 RenderWidgetHostImpl* render_widget_host,
Fady Samuel97947112018-05-05 16:24:543256 const gfx::Size& new_size) {
avic3aa8422015-11-09 20:57:223257 if (render_widget_host != GetRenderViewHost()->GetWidget())
3258 return;
3259
kenrbe4f91082017-06-02 20:32:083260 auto_resize_size_ = new_size;
3261
3262 // Out-of-process iframe visible viewport sizes usually come from the
3263 // top-level RenderWidgetHostView, but when auto-resize is enabled on the
3264 // top frame then that size is used instead.
3265 for (FrameTreeNode* node : frame_tree_.Nodes()) {
3266 if (node->current_frame_host()->is_local_root()) {
3267 RenderWidgetHostImpl* host =
3268 node->current_frame_host()->GetRenderWidgetHost();
3269 if (host != render_widget_host)
Fady Samuel0b911822018-04-25 13:22:163270 host->SynchronizeVisualProperties();
kenrbe4f91082017-06-02 20:32:083271 }
3272 }
3273
[email protected]61e2b3cc2012-03-02 16:13:343274 if (delegate_)
3275 delegate_->ResizeDueToAutoResize(this, new_size);
3276}
3277
kenrbe4f91082017-06-02 20:32:083278gfx::Size WebContentsImpl::GetAutoResizeSize() {
3279 return auto_resize_size_;
3280}
3281
3282void WebContentsImpl::ResetAutoResizeSize() {
3283 auto_resize_size_ = gfx::Size();
3284}
3285
[email protected]b172aee2012-04-10 17:05:263286WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
Bo Liu300c6052018-06-12 04:46:073287 if (!delegate_) {
3288 // Embedder can delay setting a delegate on new WebContents with
3289 // WebContentsDelegate::ShouldResumeRequestsForCreatedWindow. In the mean
3290 // time, navigations, including the initial one, that goes through OpenURL
3291 // should be delayed until embedder is ready to resume loading.
3292 delayed_open_url_params_ = std::make_unique<OpenURLParams>(params);
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283293 return nullptr;
Bo Liu300c6052018-06-12 04:46:073294 }
[email protected]00c37fc2011-08-02 00:22:503295
[email protected]e5d549d2011-12-28 01:29:203296 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
pnoland488944652017-02-22 18:58:543297
3298 RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID(
3299 params.source_render_process_id, params.source_render_frame_id);
3300
3301 if (source_render_frame_host && params.source_site_instance) {
3302 CHECK_EQ(source_render_frame_host->GetSiteInstance(),
3303 params.source_site_instance.get());
3304 }
3305
3306 if (new_contents && source_render_frame_host && new_contents != this) {
3307 for (auto& observer : observers_) {
3308 observer.DidOpenRequestedURL(new_contents, source_render_frame_host,
3309 params.url, params.referrer,
3310 params.disposition, params.transition,
pnolandaae574e2017-03-06 21:04:213311 params.started_from_context_menu, false);
pnoland488944652017-02-22 18:58:543312 }
3313 }
3314
[email protected]e5d549d2011-12-28 01:29:203315 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:343316}
3317
[email protected]a86c0e962013-12-17 17:10:393318void WebContentsImpl::RenderFrameForInterstitialPageCreated(
3319 RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:093320 for (auto& observer : observers_)
3321 observer.RenderFrameForInterstitialPageCreated(render_frame_host);
[email protected]ba45bfd2012-05-22 21:51:443322}
3323
[email protected]20ca0382013-02-28 19:50:073324void WebContentsImpl::AttachInterstitialPage(
3325 InterstitialPageImpl* interstitial_page) {
creisadca9862017-06-16 19:12:113326 DCHECK(!interstitial_page_ && interstitial_page);
3327 interstitial_page_ = interstitial_page;
[email protected]90fb08ed2013-09-24 17:43:293328
3329 // Cancel any visible dialogs so that they don't interfere with the
3330 // interstitial.
creis89a0f782015-05-27 16:13:173331 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:293332
ericwilligersde386342016-10-19 02:35:093333 for (auto& observer : observers_)
3334 observer.DidAttachInterstitialPage();
clamy44e84ce2016-02-22 15:38:253335
3336 // Stop the throbber if needed while the interstitial page is shown.
3337 if (frame_tree_.IsLoading())
3338 LoadingStateChanged(true, true, nullptr);
lfg1453e412017-04-11 00:48:503339
3340 // Connect to outer WebContents if necessary.
3341 if (node_.OuterContentsFrameTreeNode()) {
3342 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3343 DCHECK(
3344 static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView())
3345 ->IsRenderWidgetHostViewChildFrame());
3346 RenderWidgetHostViewChildFrame* view =
3347 static_cast<RenderWidgetHostViewChildFrame*>(
3348 interstitial_page->GetView());
3349 GetRenderManager()->SetRWHViewForInnerContents(view);
3350 }
3351 }
Bo Liu7c6779e92017-08-16 02:02:283352
Bo Liu168c8642017-08-28 18:26:023353#if defined(OS_ANDROID)
Bo Liu7c6779e92017-08-16 02:02:283354 // Update importance of the interstitial.
3355 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
3356 ->GetRenderWidgetHost()
3357 ->SetImportance(GetMainFrame()->GetRenderWidgetHost()->importance());
Bo Liu168c8642017-08-28 18:26:023358#endif
Dominic Mazzoniefb5f9e32017-12-21 01:08:223359
3360 if (accessibility_mode_.has_mode(ui::AXMode::kNativeAPIs)) {
3361 // Make sure that the main page's accessibility tree is hidden and the
3362 // interstitial gets focus.
3363 RenderFrameHostImpl* rfh =
3364 static_cast<RenderFrameHostImpl*>(GetMainFrame());
3365 if (rfh) {
3366 BrowserAccessibilityManager* accessibility_manager =
3367 rfh->browser_accessibility_manager();
3368 if (accessibility_manager)
3369 accessibility_manager->set_hidden_by_interstitial_page(true);
3370 }
3371 rfh = static_cast<RenderFrameHostImpl*>(
3372 GetInterstitialPage()->GetMainFrame());
3373 if (rfh) {
3374 BrowserAccessibilityManager* accessibility_manager =
3375 rfh->GetOrCreateBrowserAccessibilityManager();
3376 if (accessibility_manager)
3377 accessibility_manager->OnWindowFocused();
3378 }
3379 }
clamy44e84ce2016-02-22 15:38:253380}
3381
3382void WebContentsImpl::DidProceedOnInterstitial() {
3383 // The interstitial page should no longer be pausing the throbber.
creisadca9862017-06-16 19:12:113384 DCHECK(!(ShowingInterstitialPage() && interstitial_page_->pause_throbber()));
clamy44e84ce2016-02-22 15:38:253385
3386 // Restart the throbber now that the interstitial page no longer pauses it.
3387 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
3388 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073389}
3390
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043391void WebContentsImpl::DetachInterstitialPage(bool has_focus) {
Lucas Furukawa Gadani69b609192017-07-10 17:08:343392 bool interstitial_pausing_throbber =
3393 ShowingInterstitialPage() && interstitial_page_->pause_throbber();
3394 if (ShowingInterstitialPage())
3395 interstitial_page_ = nullptr;
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043396
Dominic Mazzoniefb5f9e32017-12-21 01:08:223397 // Make sure that the main page's accessibility tree is no longer
3398 // suppressed.
3399 RenderFrameHostImpl* rfh = GetMainFrame();
3400 if (rfh) {
3401 BrowserAccessibilityManager* accessibility_manager =
3402 rfh->browser_accessibility_manager();
3403 if (accessibility_manager)
3404 accessibility_manager->set_hidden_by_interstitial_page(false);
3405 }
3406
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043407 // If the focus was on the interstitial, let's keep it to the page.
3408 // (Note that in unit-tests the RVH may not have a view).
3409 if (has_focus && GetRenderViewHost()->GetWidget()->GetView())
3410 GetRenderViewHost()->GetWidget()->GetView()->Focus();
3411
Lucas Furukawa Gadani69b609192017-07-10 17:08:343412 for (auto& observer : observers_)
3413 observer.DidDetachInterstitialPage();
3414
3415 // Disconnect from outer WebContents if necessary. This must happen after the
3416 // interstitial page is cleared above, since the call to
3417 // SetRWHViewForInnerContents below may loop over all the
3418 // RenderWidgetHostViews in the tree (otherwise, including the now-deleted
3419 // view for the interstitial).
lfg1453e412017-04-11 00:48:503420 if (node_.OuterContentsFrameTreeNode()) {
3421 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3422 DCHECK(static_cast<RenderWidgetHostViewBase*>(
3423 GetRenderManager()->current_frame_host()->GetView())
3424 ->IsRenderWidgetHostViewChildFrame());
3425 RenderWidgetHostViewChildFrame* view =
3426 static_cast<RenderWidgetHostViewChildFrame*>(
3427 GetRenderManager()->current_frame_host()->GetView());
3428 GetRenderManager()->SetRWHViewForInnerContents(view);
3429 }
3430 }
3431
clamy44e84ce2016-02-22 15:38:253432 // Restart the throbber if needed now that the interstitial page is going
3433 // away.
3434 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
3435 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073436}
3437
avi2b177592014-12-10 02:08:023438void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
3439 int history_length) {
alexmos136fd6e62016-08-15 20:58:413440 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
3441 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:023442}
3443
3444void WebContentsImpl::SetHistoryOffsetAndLengthForView(
3445 RenderViewHost* render_view_host,
3446 int history_offset,
3447 int history_length) {
alexmos136fd6e62016-08-15 20:58:413448 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:023449 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:143450}
3451
toyoshim24a4c7ab2016-04-05 09:24:143452void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:173453 RenderFrameHost* focused_frame = GetFocusedFrame();
3454 if (!focused_frame)
3455 return;
3456
[email protected]959be4c2014-04-08 15:01:333457 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:143458 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:333459}
3460
megjablon3f5941072016-02-04 23:27:523461void WebContentsImpl::ReloadLoFiImages() {
3462 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
3463}
3464
Ryan Sturmc65dbe42018-05-31 20:37:043465std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr>
3466WebContentsImpl::PauseSubresourceLoading() {
3467 std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr> handles;
3468 for (RenderFrameHost* rfh : GetAllFrames()) {
3469 if (!rfh->IsRenderFrameLive())
3470 continue;
3471 handles.push_back(rfh->PauseSubresourceLoading());
3472 }
3473 return handles;
3474}
3475
[email protected]959be4c2014-04-08 15:01:333476void WebContentsImpl::Undo() {
Dave Tapuskab336b922017-07-06 19:24:053477 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333478 if (!focused_frame)
3479 return;
3480
dtapuska9d46ef7d2017-05-26 19:06:063481 focused_frame->GetFrameInputHandler()->Undo();
[email protected]959be4c2014-04-08 15:01:333482 RecordAction(base::UserMetricsAction("Undo"));
3483}
3484
3485void WebContentsImpl::Redo() {
Dave Tapuskab336b922017-07-06 19:24:053486 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333487 if (!focused_frame)
3488 return;
dtapuska9d46ef7d2017-05-26 19:06:063489 focused_frame->GetFrameInputHandler()->Redo();
[email protected]959be4c2014-04-08 15:01:333490 RecordAction(base::UserMetricsAction("Redo"));
3491}
3492
3493void WebContentsImpl::Cut() {
Dave Tapuskab336b922017-07-06 19:24:053494 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333495 if (!focused_frame)
3496 return;
3497
dtapuska9d46ef7d2017-05-26 19:06:063498 focused_frame->GetFrameInputHandler()->Cut();
[email protected]959be4c2014-04-08 15:01:333499 RecordAction(base::UserMetricsAction("Cut"));
3500}
3501
3502void WebContentsImpl::Copy() {
Dave Tapuskab336b922017-07-06 19:24:053503 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333504 if (!focused_frame)
3505 return;
3506
dtapuska9d46ef7d2017-05-26 19:06:063507 focused_frame->GetFrameInputHandler()->Copy();
[email protected]959be4c2014-04-08 15:01:333508 RecordAction(base::UserMetricsAction("Copy"));
3509}
3510
3511void WebContentsImpl::CopyToFindPboard() {
3512#if defined(OS_MACOSX)
Dave Tapuskab336b922017-07-06 19:24:053513 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333514 if (!focused_frame)
3515 return;
3516
3517 // Windows/Linux don't have the concept of a find pasteboard.
dtapuska9d46ef7d2017-05-26 19:06:063518 focused_frame->GetFrameInputHandler()->CopyToFindPboard();
[email protected]959be4c2014-04-08 15:01:333519 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
3520#endif
3521}
3522
3523void WebContentsImpl::Paste() {
Dave Tapuskab336b922017-07-06 19:24:053524 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333525 if (!focused_frame)
3526 return;
3527
dtapuska9d46ef7d2017-05-26 19:06:063528 focused_frame->GetFrameInputHandler()->Paste();
[email protected]959be4c2014-04-08 15:01:333529 RecordAction(base::UserMetricsAction("Paste"));
3530}
3531
3532void WebContentsImpl::PasteAndMatchStyle() {
Dave Tapuskab336b922017-07-06 19:24:053533 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333534 if (!focused_frame)
3535 return;
3536
dtapuska9d46ef7d2017-05-26 19:06:063537 focused_frame->GetFrameInputHandler()->PasteAndMatchStyle();
[email protected]959be4c2014-04-08 15:01:333538 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
3539}
3540
3541void WebContentsImpl::Delete() {
Dave Tapuskab336b922017-07-06 19:24:053542 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333543 if (!focused_frame)
3544 return;
3545
dtapuska9d46ef7d2017-05-26 19:06:063546 focused_frame->GetFrameInputHandler()->Delete();
[email protected]959be4c2014-04-08 15:01:333547 RecordAction(base::UserMetricsAction("DeleteSelection"));
3548}
3549
3550void WebContentsImpl::SelectAll() {
Dave Tapuskab336b922017-07-06 19:24:053551 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333552 if (!focused_frame)
3553 return;
3554
dtapuska9d46ef7d2017-05-26 19:06:063555 focused_frame->GetFrameInputHandler()->SelectAll();
[email protected]959be4c2014-04-08 15:01:333556 RecordAction(base::UserMetricsAction("SelectAll"));
3557}
3558
yabinh351e7ec2017-03-10 02:43:243559void WebContentsImpl::CollapseSelection() {
Dave Tapuskab336b922017-07-06 19:24:053560 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333561 if (!focused_frame)
3562 return;
3563
dtapuska9d46ef7d2017-05-26 19:06:063564 focused_frame->GetFrameInputHandler()->CollapseSelection();
[email protected]1f3fc1d2014-04-03 14:50:173565}
3566
3567void WebContentsImpl::Replace(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053568 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173569 if (!focused_frame)
3570 return;
3571
dtapuska9d46ef7d2017-05-26 19:06:063572 focused_frame->GetFrameInputHandler()->Replace(word);
[email protected]1f3fc1d2014-04-03 14:50:173573}
3574
3575void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053576 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173577 if (!focused_frame)
3578 return;
3579
dtapuska9d46ef7d2017-05-26 19:06:063580 focused_frame->GetFrameInputHandler()->ReplaceMisspelling(word);
[email protected]959be4c2014-04-08 15:01:333581}
3582
3583void WebContentsImpl::NotifyContextMenuClosed(
3584 const CustomContextMenuContext& context) {
3585 RenderFrameHost* focused_frame = GetFocusedFrame();
3586 if (!focused_frame)
3587 return;
3588
3589 focused_frame->Send(new FrameMsg_ContextMenuClosed(
3590 focused_frame->GetRoutingID(), context));
3591}
3592
3593void WebContentsImpl::ExecuteCustomContextMenuCommand(
3594 int action, const CustomContextMenuContext& context) {
3595 RenderFrameHost* focused_frame = GetFocusedFrame();
3596 if (!focused_frame)
3597 return;
3598
3599 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
3600 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:003601}
3602
[email protected]fc2b46b2014-05-03 16:33:453603gfx::NativeView WebContentsImpl::GetNativeView() {
3604 return view_->GetNativeView();
3605}
3606
3607gfx::NativeView WebContentsImpl::GetContentNativeView() {
3608 return view_->GetContentNativeView();
3609}
3610
3611gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
3612 return view_->GetTopLevelNativeWindow();
3613}
3614
3615gfx::Rect WebContentsImpl::GetViewBounds() {
3616 return view_->GetViewBounds();
3617}
3618
3619gfx::Rect WebContentsImpl::GetContainerBounds() {
3620 gfx::Rect rv;
3621 view_->GetContainerBounds(&rv);
3622 return rv;
3623}
3624
3625DropData* WebContentsImpl::GetDropData() {
3626 return view_->GetDropData();
3627}
3628
3629void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:043630 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:453631}
3632
3633void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:043634 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:453635}
3636
3637void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:043638 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453639}
3640
3641void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:043642 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453643}
3644
[email protected]b172aee2012-04-10 17:05:263645void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
Maxim Podgorodskiya926c4ff2017-11-20 02:06:393646 view_->FocusThroughTabTraversal(reverse);
[email protected]96d185d2009-04-24 03:28:543647}
3648
[email protected]b172aee2012-04-10 17:05:263649bool WebContentsImpl::ShowingInterstitialPage() const {
creisadca9862017-06-16 19:12:113650 return interstitial_page_ != nullptr;
[email protected]96d185d2009-04-24 03:28:543651}
3652
Pete Williamson89aa1402017-07-07 19:58:413653void WebContentsImpl::AdjustPreviewsStateForNavigation(
3654 PreviewsState* previews_state) {
3655 if (delegate_)
Doug Arnettc681bbe2018-04-06 04:04:463656 delegate_->AdjustPreviewsStateForNavigation(this, previews_state);
Pete Williamson89aa1402017-07-07 19:58:413657}
3658
Maxim Podgorodskiya926c4ff2017-11-20 02:06:393659InterstitialPageImpl* WebContentsImpl::GetInterstitialPage() const {
creisadca9862017-06-16 19:12:113660 return interstitial_page_;
[email protected]686493142011-07-15 21:47:223661}
3662
Gyuyoung Kim80143f5e2018-04-02 02:40:253663void WebContentsImpl::PausePageScheduledTasks(bool paused) {
3664 SendPageMessage(
3665 new PageMsg_PausePageScheduledTasks(MSG_ROUTING_NONE, paused));
3666}
3667
[email protected]b172aee2012-04-10 17:05:263668bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:163669 // WebKit creates Document object when MIME type is application/xhtml+xml,
3670 // so we also support this MIME type.
3671 return contents_mime_type_ == "text/html" ||
3672 contents_mime_type_ == "text/xml" ||
3673 contents_mime_type_ == "application/xhtml+xml" ||
3674 contents_mime_type_ == "text/plain" ||
3675 contents_mime_type_ == "text/css" ||
Kinuko Yasuda74702f92017-07-31 03:27:533676 blink::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:163677}
3678
[email protected]b172aee2012-04-10 17:05:263679void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:593680 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:163681 if (!IsSavable()) {
Min Qinda0ed2062018-02-23 22:00:533682 download::RecordSavePackageEvent(
3683 download::SAVE_PACKAGE_DOWNLOAD_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:193684 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:143685 return;
[email protected]c7dd2f62011-07-18 15:57:593686 }
3687
3688 Stop();
3689
3690 // Create the save package and possibly prompt the user for the name to save
3691 // the page as. The user prompt is an asynchronous operation that runs on
3692 // another thread.
3693 save_package_ = new SavePackage(this);
3694 save_package_->GetSaveInfo();
3695}
3696
3697// Used in automated testing to bypass prompting the user for file names.
3698// Instead, the names and paths are hard coded rather than running them through
3699// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:343700bool WebContentsImpl::SavePage(const base::FilePath& main_file,
3701 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:213702 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:593703 // Stop the page from navigating.
3704 Stop();
3705
3706 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:213707 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:593708}
3709
[email protected]3c71576ce2013-07-23 02:00:013710void WebContentsImpl::SaveFrame(const GURL& url,
3711 const Referrer& referrer) {
Xing Liu10329bf2018-03-20 19:22:143712 SaveFrameWithHeaders(url, referrer, std::string(), base::string16());
kundaji6c7f9692015-03-09 18:00:373713}
3714
Xing Liu10329bf2018-03-20 19:22:143715void WebContentsImpl::SaveFrameWithHeaders(
3716 const GURL& url,
3717 const Referrer& referrer,
3718 const std::string& headers,
3719 const base::string16& suggested_filename) {
nasko89ad7742015-03-05 22:14:193720 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:013721 return;
sammc92af61552014-11-19 23:27:403722 if (delegate_ && delegate_->SaveFrame(url, referrer))
3723 return;
3724
nasko89ad7742015-03-05 22:14:193725 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:223726 // by explicitly passing in which frame this method should target. This would
3727 // indicate whether it's the main frame, and also tell us the frame pointer
3728 // to use for routing.
nasko89ad7742015-03-05 22:14:193729 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:223730 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:013731
brettw760f7442016-05-23 21:19:223732 StoragePartition* storage_partition = BrowserContext::GetStoragePartition(
3733 GetBrowserContext(), frame_host->GetSiteInstance());
avib7348942015-12-25 20:57:103734 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:013735 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:273736 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:013737 if (entry)
3738 post_id = entry->GetPostID();
3739 }
Ramin Halavati24e21012017-07-10 12:56:063740 net::NetworkTrafficAnnotationTag traffic_annotation =
3741 net::DefineNetworkTrafficAnnotation("download_web_contents_frame", R"(
3742 semantics {
3743 sender: "Save Page Action"
3744 description:
3745 "Saves the given frame's URL to the local file system."
3746 trigger:
3747 "The user has triggered a save operation on the frame through a "
3748 "context menu or other mechanism."
3749 data: "None."
3750 destination: WEBSITE
3751 }
3752 policy {
Ramin Halavati3b979782017-07-21 11:40:263753 cookies_allowed: YES
Ramin Halavati24e21012017-07-10 12:56:063754 cookies_store: "user"
3755 setting:
3756 "This feature cannot be disabled by settings, but it's is only "
3757 "triggered by user request."
3758 policy_exception_justification: "Not implemented."
3759 })");
Min Qina904f3302018-02-13 23:33:343760 auto params = std::make_unique<download::DownloadUrlParameters>(
brettw760f7442016-05-23 21:19:223761 url, frame_host->GetProcess()->GetID(),
3762 frame_host->GetRenderViewHost()->GetRoutingID(),
Ramin Halavati03efa732017-06-12 09:28:203763 frame_host->GetRoutingID(), storage_partition->GetURLRequestContext(),
Ramin Halavati24e21012017-07-10 12:56:063764 traffic_annotation);
Min Qina904f3302018-02-13 23:33:343765 params->set_referrer(referrer.url);
3766 params->set_referrer_policy(
3767 Referrer::ReferrerPolicyForUrlRequest(referrer.policy));
[email protected]3c71576ce2013-07-23 02:00:013768 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:013769 if (post_id >= 0)
3770 params->set_method("POST");
3771 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:373772
3773 if (headers.empty()) {
3774 params->set_prefer_cache(true);
3775 } else {
Min Qina904f3302018-02-13 23:33:343776 for (download::DownloadUrlParameters::RequestHeadersNameValuePair
3777 key_value : ParseDownloadHeaders(headers)) {
Megan Jablonski2f6a4c52017-07-10 23:01:253778 params->add_request_header(key_value.first, key_value.second);
kundaji6c7f9692015-03-09 18:00:373779 }
3780 }
Xing Liu10329bf2018-03-20 19:22:143781 params->set_suggested_name(suggested_filename);
Min Qin0ca8e1ee2018-01-31 00:49:353782 params->set_download_source(download::DownloadSource::WEB_CONTENTS_API);
thestig859c78892017-05-15 21:17:063783 BrowserContext::GetDownloadManager(GetBrowserContext())
Ramin Halavati03efa732017-06-12 09:28:203784 ->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:013785}
3786
[email protected]b172aee2012-04-10 17:05:263787void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:473788 const MHTMLGenerationParams& params,
Avi Drissman149b7832018-03-23 14:31:493789 base::OnceCallback<void(int64_t)> callback) {
3790 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params,
3791 std::move(callback));
[email protected]aa4f3972012-03-01 18:12:123792}
3793
[email protected]b172aee2012-04-10 17:05:263794const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:273795 return contents_mime_type_;
3796}
3797
[email protected]b172aee2012-04-10 17:05:263798bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:273799 return notify_disconnection_;
3800}
3801
[email protected]8ff00d72012-10-23 19:12:213802RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:273803 return &renderer_preferences_;
3804}
3805
[email protected]e35ccd52012-05-23 16:22:473806void WebContentsImpl::Close() {
3807 Close(GetRenderViewHost());
3808}
3809
Ella Ge80a52dce2017-11-15 18:01:523810void WebContentsImpl::DragSourceEndedAt(float client_x,
3811 float client_y,
3812 float screen_x,
3813 float screen_y,
Paul Meyer0c58c3712016-11-17 22:59:513814 blink::WebDragOperation operation,
3815 RenderWidgetHost* source_rwh) {
[email protected]cf200a562013-05-03 16:24:293816 if (browser_plugin_embedder_.get())
paulmeyer8fc8ea92016-11-15 05:12:213817 browser_plugin_embedder_->DragSourceEndedAt(
3818 client_x, client_y, screen_x, screen_y, operation);
Paul Meyer0c58c3712016-11-17 22:59:513819 if (source_rwh) {
Ella Ge80a52dce2017-11-15 18:01:523820 source_rwh->DragSourceEndedAt(gfx::PointF(client_x, client_y),
3821 gfx::PointF(screen_x, screen_y), operation);
Paul Meyer0c58c3712016-11-17 22:59:513822 }
[email protected]cf200a562013-05-03 16:24:293823}
3824
jam73f892642016-09-11 06:04:063825void WebContentsImpl::LoadStateChanged(
Charles Harrison911fa062018-03-06 21:01:463826 const std::string& host,
jam73f892642016-09-11 06:04:063827 const net::LoadStateWithParam& load_state,
3828 uint64_t upload_position,
3829 uint64_t upload_size) {
Charles Harrison911fa062018-03-06 21:01:463830 base::string16 host16 = url_formatter::IDNToUnicode(host);
Elly Fong-Jonescad9c3d12018-01-31 17:26:103831 // Drop no-op updates.
3832 if (load_state_.state == load_state.state &&
3833 load_state_.param == load_state.param &&
3834 upload_position_ == upload_position && upload_size_ == upload_size &&
Charles Harrison911fa062018-03-06 21:01:463835 load_state_host_ == host16) {
Elly Fong-Jonescad9c3d12018-01-31 17:26:103836 return;
3837 }
jam73f892642016-09-11 06:04:063838 load_state_ = load_state;
3839 upload_position_ = upload_position;
3840 upload_size_ = upload_size;
Charles Harrison911fa062018-03-06 21:01:463841 load_state_host_ = host16;
jam73f892642016-09-11 06:04:063842 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
3843 SetNotWaitingForResponse();
3844 if (IsLoading()) {
3845 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
3846 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
3847 }
3848}
3849
Francois Doraye6161152018-03-27 22:05:373850void WebContentsImpl::SetVisibility(Visibility visibility) {
3851 const Visibility previous_visibility = visibility_;
3852 visibility_ = visibility;
3853
Francois Dorayfe4a1772018-02-17 04:17:093854 // Notify observers if the visibility changed or if WasShown() is being called
3855 // for the first time.
Francois Dorayfe4a1772018-02-17 04:17:093856 if (visibility != previous_visibility ||
3857 (visibility == Visibility::VISIBLE && !did_first_set_visible_)) {
3858 for (auto& observer : observers_)
3859 observer.OnVisibilityChanged(visibility);
3860 }
3861}
3862
Michael Thiessen896405db2017-07-20 17:52:323863void WebContentsImpl::NotifyWebContentsFocused(
3864 RenderWidgetHost* render_widget_host) {
ericwilligersde386342016-10-19 02:35:093865 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323866 observer.OnWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:373867}
3868
Michael Thiessen896405db2017-07-20 17:52:323869void WebContentsImpl::NotifyWebContentsLostFocus(
3870 RenderWidgetHost* render_widget_host) {
zijiehe3bee08e22017-05-17 04:14:463871 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323872 observer.OnWebContentsLostFocus(render_widget_host);
zijiehe3bee08e22017-05-17 04:14:463873}
3874
Paul Meyer0c58c3712016-11-17 22:59:513875void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) {
3876 if (source_rwh)
3877 source_rwh->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:293878 if (browser_plugin_embedder_.get())
3879 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:343880}
3881
Daniel Cheng90196c82018-04-25 21:49:143882void WebContentsImpl::NavigatedByUser() {
3883 OnUserInteraction(blink::WebInputEvent::kUndefined);
[email protected]e35ccd52012-05-23 16:22:473884}
3885
[email protected]b172aee2012-04-10 17:05:263886void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:273887 closed_by_user_gesture_ = value;
3888}
3889
[email protected]b172aee2012-04-10 17:05:263890bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:273891 return closed_by_user_gesture_;
3892}
3893
[email protected]b172aee2012-04-10 17:05:263894int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273895 return minimum_zoom_percent_;
3896}
3897
[email protected]b172aee2012-04-10 17:05:263898int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273899 return maximum_zoom_percent_;
3900}
3901
mcnee432e47d2015-11-09 19:37:463902void WebContentsImpl::SetPageScale(float page_scale_factor) {
Lukasz Anforowiczf4357ca2017-09-07 01:43:323903 GetRenderViewHost()->Send(new ViewMsg_SetPageScale(
3904 GetRenderViewHost()->GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:243905}
3906
[email protected]b172aee2012-04-10 17:05:263907gfx::Size WebContentsImpl::GetPreferredSize() const {
Francois Doray24fc62c2017-12-11 17:27:333908 return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_;
[email protected]bcd2815602012-01-14 18:17:233909}
3910
[email protected]b172aee2012-04-10 17:05:263911bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
lfgf0cd46e2017-01-04 00:05:233912 if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) &&
3913 GetBrowserPluginGuest())
[email protected]660f18e2014-05-15 20:53:053914 return GetBrowserPluginGuest()->LockMouse(allowed);
3915
lfgf0cd46e2017-01-04 00:05:233916 if (mouse_lock_widget_) {
3917 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
3918 return mouse_lock_widget_->delegate()
3919 ->GetAsWebContents()
3920 ->GotResponseToLockMouseRequest(allowed);
3921 }
lfgad8244352016-07-13 16:55:513922
lfgf0cd46e2017-01-04 00:05:233923 if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3924 return true;
3925 }
3926
3927 for (WebContentsImpl* current = this; current;
3928 current = current->GetOuterWebContents()) {
3929 current->mouse_lock_widget_ = nullptr;
3930 }
3931
lfgbee1e0a2016-06-08 21:24:213932 return false;
[email protected]0bfbf882011-12-22 18:19:273933}
3934
Joe Downing13dd76b2018-04-09 18:32:153935bool WebContentsImpl::GotResponseToKeyboardLockRequest(bool allowed) {
3936 if (!keyboard_lock_widget_)
3937 return false;
3938
3939 if (keyboard_lock_widget_->delegate()->GetAsWebContents() != this) {
3940 NOTREACHED();
3941 return false;
3942 }
3943
3944 // KeyboardLock is only supported when called by the top-level browsing
3945 // context and is not supported in embedded content scenarios.
3946 if (GetOuterWebContents())
3947 return false;
3948
3949 keyboard_lock_widget_->GotResponseToKeyboardLockRequest(allowed);
3950 return true;
3951}
3952
[email protected]b172aee2012-04-10 17:05:263953bool WebContentsImpl::HasOpener() const {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283954 return GetOpener() != nullptr;
[email protected]a0358d72012-03-09 14:06:503955}
3956
lukasza6f8ac622017-06-06 03:10:203957RenderFrameHostImpl* WebContentsImpl::GetOpener() const {
alexmose201c7cd2015-06-10 17:14:213958 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
lukasza6f8ac622017-06-06 03:10:203959 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen55ff3502014-12-18 20:52:573960}
3961
jochen6004a362017-02-04 00:11:403962bool WebContentsImpl::HasOriginalOpener() const {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283963 return GetOriginalOpener() != nullptr;
jochen6004a362017-02-04 00:11:403964}
3965
lukasza6f8ac622017-06-06 03:10:203966RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() const {
jochen6004a362017-02-04 00:11:403967 FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener();
lukasza6f8ac622017-06-06 03:10:203968 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen6004a362017-02-04 00:11:403969}
3970
[email protected]cb805452013-05-22 15:16:213971void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
Joel Hockey85b379d2017-12-11 10:42:133972 color_chooser_->DidChooseColorInColorChooser(color);
[email protected]da8543762012-03-20 08:52:203973}
3974
[email protected]cb805452013-05-22 15:16:213975void WebContentsImpl::DidEndColorChooser() {
Joel Hockey85b379d2017-12-11 10:42:133976 color_chooser_.reset();
[email protected]da8543762012-03-20 08:52:203977}
3978
halton.huoca2eabd2015-07-06 08:17:403979int WebContentsImpl::DownloadImage(
3980 const GURL& url,
3981 bool is_favicon,
3982 uint32_t max_bitmap_size,
3983 bool bypass_cache,
Avi Drissmana5a52dd2018-03-27 03:39:023984 WebContents::ImageDownloadCallback callback) {
amistry9f01b772015-07-29 01:54:553985 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:403986 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:063987 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:403988 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:553989 const int download_id = ++next_image_download_id;
3990 if (!mojo_image_downloader) {
3991 // If the renderer process is dead (i.e. crash, or memory pressure on
3992 // Android), the downloader service will be invalid. Pre-Mojo, this would
Avi Drissmana5a52dd2018-03-27 03:39:023993 // hang the callback indefinitely since the IPC would be dropped. Now,
amistry9f01b772015-07-29 01:54:553994 // respond with a 400 HTTP error code to indicate that something went wrong.
3995 BrowserThread::PostTask(
3996 BrowserThread::UI, FROM_HERE,
tzike2aca992017-09-05 08:50:543997 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:023998 weak_factory_.GetWeakPtr(), std::move(callback),
3999 download_id, url, 400, std::vector<SkBitmap>(),
4000 std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:554001 return download_id;
4002 }
4003
halton.huoca2eabd2015-07-06 08:17:404004 mojo_image_downloader->DownloadImage(
sammcf6f4fcf2016-06-21 05:39:394005 url, is_favicon, max_bitmap_size, bypass_cache,
tzike2aca992017-09-05 08:50:544006 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:024007 weak_factory_.GetWeakPtr(), std::move(callback),
4008 download_id, url));
amistry9f01b772015-07-29 01:54:554009 return download_id;
[email protected]795c28972012-12-06 06:13:394010}
4011
[email protected]36ec24f2014-01-09 00:32:084012void WebContentsImpl::Find(int request_id,
4013 const base::string16& search_text,
4014 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:334015 // Cowardly refuse to search for no text.
4016 if (search_text.empty()) {
4017 NOTREACHED();
4018 return;
4019 }
4020
paulmeyerc0b762b2016-04-13 11:55:174021 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:084022}
4023
4024void WebContentsImpl::StopFinding(StopFindAction action) {
paulmeyerfeafc2d2017-04-25 21:46:404025 if (FindRequestManager* manager = GetFindRequestManager())
4026 manager->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:084027}
4028
Tommy Steimel18360512017-11-01 00:38:194029bool WebContentsImpl::WasEverAudible() {
4030 return was_ever_audible_;
4031}
4032
Avi Drissmana5a52dd2018-03-27 03:39:024033void WebContentsImpl::GetManifest(GetManifestCallback callback) {
4034 manifest_manager_host_->GetManifest(std::move(callback));
mlamouriefdca9d2014-09-16 16:55:404035}
4036
bokanece34a82016-01-28 19:49:464037void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:534038 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:434039 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:464040 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:534041}
4042
mariakhomenko44bdc4732015-04-29 01:55:384043void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:374044 if (delayed_open_url_params_.get()) {
4045 OpenURL(*delayed_open_url_params_.get());
4046 delayed_open_url_params_.reset(nullptr);
4047 return;
4048 }
4049
mariakhomenko44bdc4732015-04-29 01:55:384050 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
4051 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:164052 if (is_resume_pending_) {
4053 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:134054 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:164055 GetMainFrame()->Init();
4056 }
mariakhomenko44bdc4732015-04-29 01:55:384057}
4058
[email protected]b172aee2012-04-10 17:05:264059bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:264060 // When the browser is started with about:blank as the startup URL, focus
4061 // the location bar (which will also select its contents) so people can
4062 // simply begin typing to navigate elsewhere.
4063 //
4064 // We need to be careful not to trigger this for anything other than the
4065 // startup navigation. In particular, if we allow an attacker to open a
4066 // popup to about:blank, then navigate, focusing the Omnibox will cause the
4067 // end of the new URL to be scrolled into view instead of the start,
4068 // allowing the attacker to spoof other URLs. The conditions checked here
4069 // are all aimed at ensuring no such attacker-controlled navigation can
4070 // trigger this.
4071 //
4072 // Note that we check the pending entry instead of the visible one; for the
4073 // startup URL case these are the same, but for the attacker-controlled
4074 // navigation case the visible entry is the committed "about:blank" URL and
4075 // the pending entry is the problematic navigation elsewhere.
4076 NavigationEntryImpl* entry = controller_.GetPendingEntry();
4077 if (controller_.IsInitialNavigation() && entry &&
4078 !entry->is_renderer_initiated() &&
csharrisona3bd0b32016-10-19 18:40:484079 entry->GetURL() == url::kAboutBlankURL) {
[email protected]0c9406632013-02-08 01:13:334080 return true;
palmerc70cb1f2016-03-04 23:41:264081 }
[email protected]0c9406632013-02-08 01:13:334082 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:274083}
4084
[email protected]b172aee2012-04-10 17:05:264085void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:274086 if (delegate_)
4087 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:214088}
4089
clamy0e119882015-07-31 16:12:334090void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484091 TRACE_EVENT1("navigation", "WebContentsImpl::DidStartNavigation",
4092 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094093 for (auto& observer : observers_)
4094 observer.DidStartNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:334095}
4096
4097void WebContentsImpl::DidRedirectNavigation(
4098 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484099 TRACE_EVENT1("navigation", "WebContentsImpl::DidRedirectNavigation",
4100 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094101 for (auto& observer : observers_)
4102 observer.DidRedirectNavigation(navigation_handle);
jam5f358e52017-02-13 16:37:034103
4104 // Notify accessibility if this is a reload. This has to called on the
4105 // BrowserAccessibilityManager associated with the old RFHI.
4106 if (navigation_handle->GetReloadType() != ReloadType::NONE) {
4107 NavigationHandleImpl* nhi =
4108 static_cast<NavigationHandleImpl*>(navigation_handle);
4109 BrowserAccessibilityManager* manager =
4110 nhi->frame_tree_node()
4111 ->current_frame_host()
4112 ->browser_accessibility_manager();
4113 if (manager)
4114 manager->UserIsReloading();
4115 }
clamy0e119882015-07-31 16:12:334116}
4117
clamyefca29e2015-09-17 00:22:114118void WebContentsImpl::ReadyToCommitNavigation(
4119 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484120 TRACE_EVENT1("navigation", "WebContentsImpl::ReadyToCommitNavigation",
4121 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094122 for (auto& observer : observers_)
4123 observer.ReadyToCommitNavigation(navigation_handle);
John Abd-El-Malekd4882642017-12-04 21:45:194124
Kenneth Russell954ed9ce2018-04-12 23:07:014125 // If any domains are blocked from accessing 3D APIs because they may
4126 // have caused the GPU to reset recently, unblock them here if the user
4127 // initiated this navigation. This implies that the user was involved in
4128 // the decision to navigate, so there's no concern about
4129 // denial-of-service issues. Want to do this as early as
4130 // possible to avoid race conditions with pages attempting to access
4131 // WebGL early on.
4132 //
4133 // TODO(crbug.com/617904): currently navigations initiated by the browser
4134 // (reload button, reload menu option, pressing return in the Omnibox)
4135 // return false from HasUserGesture(). If or when that is addressed,
4136 // remove the check for IsRendererInitiated() below.
4137 //
4138 // TODO(crbug.com/832180): HasUserGesture comes from the renderer
4139 // process and isn't validated. Until it is, don't trust it.
4140 if (!navigation_handle->IsRendererInitiated()) {
4141 GpuDataManagerImpl::GetInstance()->UnblockDomainFrom3DAPIs(
4142 navigation_handle->GetURL());
4143 }
4144
John Abd-El-Malekfde08e6da2017-12-05 04:06:244145 if (navigation_handle->IsSameDocument())
4146 return;
4147
John Abd-El-Malekd4882642017-12-04 21:45:194148 controller_.ssl_manager()->DidStartResourceResponse(
4149 navigation_handle->GetURL(),
4150 net::IsCertStatusError(navigation_handle->GetSSLInfo().cert_status));
John Abd-El-Malekfde08e6da2017-12-05 04:06:244151
4152 SetNotWaitingForResponse();
Becca Hughes6fe54e432018-06-09 04:18:564153
4154 // Reset the viewport fit
4155 display_cutout_host_impl_->ViewportFitChangedForFrame(
4156 navigation_handle->GetRenderFrameHost(),
4157 blink::mojom::ViewportFit::kAuto);
clamyefca29e2015-09-17 00:22:114158}
4159
clamy0e119882015-07-31 16:12:334160void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484161 TRACE_EVENT1("navigation", "WebContentsImpl::DidFinishNavigation",
4162 "navigation_handle", navigation_handle);
Steven Holte38041342018-06-22 22:00:574163
ericwilligersde386342016-10-19 02:35:094164 for (auto& observer : observers_)
4165 observer.DidFinishNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:334166
jam5f358e52017-02-13 16:37:034167 if (navigation_handle->HasCommitted()) {
dmazzonibf8cec42015-02-08 08:28:084168 BrowserAccessibilityManager* manager =
jam5f358e52017-02-13 16:37:034169 static_cast<RenderFrameHostImpl*>(
4170 navigation_handle->GetRenderFrameHost())
4171 ->browser_accessibility_manager();
4172 if (manager) {
4173 if (navigation_handle->IsErrorPage()) {
4174 manager->NavigationFailed();
4175 } else {
4176 manager->NavigationSucceeded();
4177 }
4178 }
Tommy Steimel18360512017-11-01 00:38:194179
4180 if (navigation_handle->IsInMainFrame() &&
4181 !navigation_handle->IsSameDocument()) {
4182 was_ever_audible_ = false;
Steven Holte38041342018-06-22 22:00:574183 last_committed_source_id_ =
4184 ukm::ConvertToSourceId(navigation_handle->GetNavigationId(),
4185 ukm::SourceIdType::NAVIGATION_ID);
Tommy Steimel18360512017-11-01 00:38:194186 }
dmazzonibf8cec42015-02-08 08:28:084187 }
[email protected]400992b2012-06-14 00:03:544188}
4189
[email protected]b80624c2014-02-09 02:46:554190void WebContentsImpl::DidFailLoadWithError(
4191 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:554192 const GURL& url,
[email protected]b80624c2014-02-09 02:46:554193 int error_code,
Yutaka Hirano16d3c5d2017-07-31 06:17:304194 const base::string16& error_description) {
ericwilligersde386342016-10-19 02:35:094195 for (auto& observer : observers_) {
Yutaka Hirano16d3c5d2017-07-31 06:17:304196 observer.DidFailLoad(render_frame_host, url, error_code, error_description);
ericwilligersde386342016-10-19 02:35:094197 }
[email protected]b80624c2014-02-09 02:46:554198}
4199
[email protected]52913802013-12-10 05:52:184200void WebContentsImpl::NotifyChangedNavigationState(
4201 InvalidateTypes changed_flags) {
4202 NotifyNavigationStateChanged(changed_flags);
4203}
4204
toyoshim0df1d3a2016-09-09 09:52:484205void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
4206 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:204207 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094208 for (auto& observer : observers_)
4209 observer.DidStartNavigationToPendingEntry(url, reload_type);
[email protected]3691e5cf2014-01-22 10:16:204210}
4211
lukasza1d025732016-09-28 21:36:084212bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:224213 if (!delegate_)
4214 return true;
lukasza1d025732016-09-28 21:36:084215 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:224216}
4217
[email protected]aa62afd2014-04-22 19:22:464218bool WebContentsImpl::ShouldPreserveAbortedURLs() {
4219 if (!delegate_)
4220 return false;
4221 return delegate_->ShouldPreserveAbortedURLs(this);
4222}
4223
[email protected]0d0f4c492014-04-02 06:42:574224void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:234225 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:574226 // Ensure fullscreen mode is exited before committing the navigation to a
4227 // different page. The next page will not start out assuming it is in
4228 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:234229 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:194230 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:574231 return;
4232 }
alexmos5dd617d2016-06-07 04:21:154233 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464234 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:154235 DCHECK(!IsFullscreenForCurrentTab());
Joe Downingc1a57efe2018-05-09 18:23:544236
4237 // Clean up keyboard lock state when navigating.
4238 CancelKeyboardLock(keyboard_lock_widget_);
[email protected]0d0f4c492014-04-02 06:42:574239}
4240
[email protected]37567b432014-02-12 01:12:224241void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:284242 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:224243 const LoadCommittedDetails& details,
4244 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
4245 if (details.is_navigation_to_different_page()) {
4246 // Clear the status bubble. This is a workaround for a bug where WebKit
4247 // doesn't let us know that the cursor left an element during a
4248 // transition (this is also why the mouse cursor remains as a hand after
4249 // clicking on a link); see bugs 1184641 and 980803. We don't want to
4250 // clear the bubble when a user navigates to a named anchor in the same
4251 // page.
Lukasz Anforowiczfd707142018-02-07 19:46:134252 ClearTargetURL();
lanwei9d343ad22015-02-11 01:46:004253
4254 RenderWidgetHostViewBase* rwhvb =
4255 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
4256 if (rwhvb)
4257 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:284258
peter90afaba2015-06-01 12:05:294259 did_first_visually_non_empty_paint_ = false;
4260
yusufod41c5f92015-03-06 00:14:284261 // Reset theme color on navigation to new page.
4262 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:224263 }
4264
[email protected]e85165c642014-06-10 14:34:314265 if (delegate_)
[email protected]37567b432014-02-12 01:12:224266 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:314267 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:224268}
4269
4270void WebContentsImpl::DidNavigateAnyFramePostCommit(
4271 RenderFrameHostImpl* render_frame_host,
4272 const LoadCommittedDetails& details,
4273 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:104274 // Now that something has committed, we don't need to track whether the
4275 // initial page has been accessed.
4276 has_accessed_initial_document_ = false;
4277
[email protected]37567b432014-02-12 01:12:224278 // If we navigate off the page, close all JavaScript dialogs.
eugenebutee08663a2017-04-27 17:43:124279 if (!details.is_same_document)
creis89a0f782015-05-27 16:13:174280 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:224281
avid53461d2016-02-25 17:15:044282 // If this is a user-initiated navigation, start allowing JavaScript dialogs
4283 // again.
avi5d3b8692016-10-12 22:00:464284 if (params.gesture == NavigationGestureUser && dialog_manager_) {
avi6879fcf2017-01-21 05:27:534285 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:464286 }
[email protected]37567b432014-02-12 01:12:224287}
4288
4289void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
4290 contents_mime_type_ = mime_type;
4291}
4292
[email protected]277857a2014-06-03 10:38:014293bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:314294 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:054295 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:314296 return false;
4297
[email protected]37567b432014-02-12 01:12:224298 if (delegate_)
4299 return delegate_->CanOverscrollContent();
4300
4301 return false;
4302}
4303
nicka0ac8382016-12-15 23:59:234304void WebContentsImpl::OnThemeColorChanged(RenderFrameHostImpl* source,
4305 SkColor theme_color) {
4306 if (source != GetMainFrame()) {
4307 // Only the main frame may control the theme.
4308 return;
4309 }
4310
peter90afaba2015-06-01 12:05:294311 // Update the theme color. This is to be published to observers after the
4312 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:284313 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:294314
4315 if (did_first_visually_non_empty_paint_ &&
4316 last_sent_theme_color_ != theme_color_) {
ericwilligersde386342016-10-19 02:35:094317 for (auto& observer : observers_)
4318 observer.DidChangeThemeColor(theme_color_);
peter90afaba2015-06-01 12:05:294319 last_sent_theme_color_ = theme_color_;
4320 }
[email protected]e7104762014-06-20 19:17:254321}
4322
[email protected]b172aee2012-04-10 17:05:264323void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
nicka0ac8382016-12-15 23:59:234324 RenderFrameHostImpl* source,
[email protected]724159a2010-12-30 01:11:184325 const GURL& url,
[email protected]70435962011-08-02 20:13:284326 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:184327 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:404328 ResourceType resource_type) {
ericwilligersde386342016-10-19 02:35:094329 for (auto& observer : observers_)
4330 observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type);
[email protected]b0f724c2013-09-05 04:21:134331
[email protected]8bfc8272013-09-09 20:10:534332 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
nicka0ac8382016-12-15 23:59:234333 StoragePartition* partition = source->GetProcess()->GetStoragePartition();
[email protected]8bfc8272013-09-09 20:10:534334 scoped_refptr<net::URLRequestContextGetter> request_context(
nicka0ac8382016-12-15 23:59:234335 resource_type == RESOURCE_TYPE_MEDIA
4336 ? partition->GetMediaURLRequestContext()
4337 : partition->GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:534338 BrowserThread::PostTask(
nicka0ac8382016-12-15 23:59:234339 BrowserThread::IO, FROM_HERE,
tzike2aca992017-09-05 08:50:544340 base::BindOnce(&NotifyCacheOnIO, request_context, url, http_method));
[email protected]8bfc8272013-09-09 20:10:534341 }
[email protected]724159a2010-12-30 01:11:184342}
4343
nicka0ac8382016-12-15 23:59:234344void WebContentsImpl::OnDidDisplayInsecureContent(RenderFrameHostImpl* source) {
4345 // Any frame can trigger display of insecure content, so we don't check
4346 // |source| here.
carloskd9d97942017-02-16 08:58:094347 DidDisplayInsecureContent();
4348}
4349
4350void WebContentsImpl::DidDisplayInsecureContent() {
estarkc2273502016-10-12 22:03:024351 controller_.ssl_manager()->DidDisplayMixedContent();
[email protected]724159a2010-12-30 01:11:184352}
4353
elawrenceb2ac2a232017-03-27 21:46:254354void WebContentsImpl::OnDidContainInsecureFormAction(
4355 RenderFrameHostImpl* source) {
4356 controller_.ssl_manager()->DidContainInsecureFormAction();
4357}
4358
nicka0ac8382016-12-15 23:59:234359void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source,
4360 const GURL& security_origin,
estark910b4572015-12-09 20:55:414361 const GURL& target_url) {
nicka0ac8382016-12-15 23:59:234362 // TODO(nick, estark): Should we call FilterURL using |source|'s process on
4363 // these parameters? |target_url| seems unused, except for a log message. And
4364 // |security_origin| might be replaceable with the origin of the main frame.
carloskd9d97942017-02-16 08:58:094365 DidRunInsecureContent(security_origin, target_url);
4366}
4367
4368void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin,
4369 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:584370 LOG(WARNING) << security_origin << " ran insecure content from "
4371 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:394372 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:414373 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:294374 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:394375 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
estarkc2273502016-10-12 22:03:024376 controller_.ssl_manager()->DidRunMixedContent(security_origin);
[email protected]724159a2010-12-30 01:11:184377}
4378
carloskd9d97942017-02-16 08:58:094379void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364380 if (delegate_) {
4381 delegate_->PassiveInsecureContentFound(resource_url);
4382 }
carloskd9d97942017-02-16 08:58:094383}
4384
4385bool WebContentsImpl::ShouldAllowRunningInsecureContent(
4386 WebContents* web_contents,
4387 bool allowed_per_prefs,
4388 const url::Origin& origin,
4389 const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364390 if (delegate_) {
4391 return delegate_->ShouldAllowRunningInsecureContent(
4392 web_contents, allowed_per_prefs, origin, resource_url);
4393 }
4394
4395 return allowed_per_prefs;
carloskd9d97942017-02-16 08:58:094396}
4397
Lukasz Anforowicze1b954d92017-10-30 21:28:064398void WebContentsImpl::ViewSource(RenderFrameHostImpl* frame) {
4399 DCHECK_EQ(this, WebContents::FromRenderFrameHost(frame));
4400
4401 // Don't do anything if there is no |delegate_| that could accept and show the
4402 // new WebContents containing the view-source.
4403 if (!delegate_)
4404 return;
4405
4406 // Use the last committed entry, since the pending entry hasn't loaded yet and
4407 // won't be copied into the cloned tab.
4408 NavigationEntryImpl* last_committed_entry =
4409 static_cast<NavigationEntryImpl*>(frame->frame_tree_node()
4410 ->navigator()
4411 ->GetController()
4412 ->GetLastCommittedEntry());
4413 if (!last_committed_entry)
4414 return;
4415
4416 FrameNavigationEntry* frame_entry =
4417 last_committed_entry->GetFrameEntry(frame->frame_tree_node());
4418 if (!frame_entry)
4419 return;
4420
4421 // Any new WebContents opened while this WebContents is in fullscreen can be
4422 // used to confuse the user, so drop fullscreen.
4423 if (IsFullscreenForCurrentTab())
4424 ExitFullscreen(true);
4425
4426 // We intentionally don't share the SiteInstance with the original frame so
4427 // that view source has a consistent process model and always ends up in a new
4428 // process (https://crbug.com/699493).
4429 scoped_refptr<SiteInstanceImpl> site_instance_for_view_source = nullptr;
4430 // Referrer is not important, because view-source should not hit the network,
4431 // but should be served from the cache instead.
4432 Referrer referrer_for_view_source;
4433 // Do not restore title, derive it from the url.
4434 base::string16 title_for_view_source;
4435 auto navigation_entry = std::make_unique<NavigationEntryImpl>(
4436 site_instance_for_view_source, frame_entry->url(),
4437 referrer_for_view_source, title_for_view_source, ui::PAGE_TRANSITION_LINK,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:094438 /* is_renderer_initiated = */ false,
4439 /* blob_url_loader_factory = */ nullptr);
Lukasz Anforowicze1b954d92017-10-30 21:28:064440 navigation_entry->SetVirtualURL(GURL(content::kViewSourceScheme +
4441 std::string(":") +
4442 frame_entry->url().spec()));
4443
4444 // Do not restore scroller position.
4445 // TODO(creis, lukasza, arthursonzogni): Do not reuse the original PageState,
4446 // but start from a new one and only copy the needed data.
4447 const PageState& new_page_state =
4448 frame_entry->page_state().RemoveScrollOffset();
4449
4450 scoped_refptr<FrameNavigationEntry> new_frame_entry =
4451 navigation_entry->root_node()->frame_entry;
4452 new_frame_entry->set_method(frame_entry->method());
4453 new_frame_entry->SetPageState(new_page_state);
4454
4455 // Create a new WebContents, which is used to display the source code.
erikchenbee5c9622018-04-27 19:30:254456 std::unique_ptr<WebContents> view_source_contents =
Erik Chenbb8e738e2018-04-28 14:10:434457 Create(CreateParams(GetBrowserContext()));
Lukasz Anforowicze1b954d92017-10-30 21:28:064458
4459 // Restore the previously created NavigationEntry.
4460 std::vector<std::unique_ptr<NavigationEntry>> navigation_entries;
4461 navigation_entries.push_back(std::move(navigation_entry));
4462 view_source_contents->GetController().Restore(0, RestoreType::CURRENT_SESSION,
4463 &navigation_entries);
4464
4465 // Add |view_source_contents| as a new tab.
4466 gfx::Rect initial_rect;
4467 constexpr bool kUserGesture = true;
4468 bool ignored_was_blocked;
erikchenbee5c9622018-04-27 19:30:254469 delegate_->AddNewContents(this, std::move(view_source_contents),
Lukasz Anforowicze1b954d92017-10-30 21:28:064470 WindowOpenDisposition::NEW_FOREGROUND_TAB,
4471 initial_rect, kUserGesture, &ignored_was_blocked);
4472 // Note that the |delegate_| could have deleted |view_source_contents| during
4473 // AddNewContents method call.
4474}
4475
Jay Civellid5904f02018-03-23 19:43:574476void WebContentsImpl::SubresourceResponseStarted(const GURL& url,
4477 net::CertStatus cert_status) {
4478 controller_.ssl_manager()->DidStartResourceResponse(url, cert_status);
4479 SetNotWaitingForResponse();
4480}
4481
Jay Civelli116683f2018-03-27 19:56:234482void WebContentsImpl::ResourceLoadComplete(
Jay Civelli52a63302018-04-30 22:39:554483 RenderFrameHost* render_frame_host,
Jay Civelli116683f2018-03-27 19:56:234484 mojom::ResourceLoadInfoPtr resource_load_info) {
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254485 for (auto& observer : observers_) {
Jay Civelli718fd6c02018-05-11 21:04:274486 observer.ResourceLoadComplete(render_frame_host, *resource_load_info);
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254487 }
John Abd-El-Malekd4882642017-12-04 21:45:194488}
4489
Wei Li5bb659742018-02-14 03:07:584490void WebContentsImpl::PrintCrossProcessSubframe(
4491 const gfx::Rect& rect,
4492 int document_cookie,
4493 RenderFrameHost* subframe_host) {
Wei Li5c0b4d12018-03-22 15:05:224494 auto* outer_contents = GetOuterWebContents();
4495 if (outer_contents) {
4496 // When an extension or app page is printed, the content should be
4497 // composited with outer content, so the outer contents should handle the
4498 // print request.
4499 outer_contents->PrintCrossProcessSubframe(rect, document_cookie,
4500 subframe_host);
4501 return;
4502 }
4503
Wei Li5bb659742018-02-14 03:07:584504 // If there is no delegate such as in tests or during deletion, do nothing.
4505 if (!delegate_)
4506 return;
4507
4508 delegate_->PrintCrossProcessSubframe(this, rect, document_cookie,
4509 subframe_host);
4510}
4511
rob.buis300b0872017-03-10 20:43:584512#if defined(OS_ANDROID)
4513base::android::ScopedJavaLocalRef<jobject>
4514WebContentsImpl::GetJavaRenderFrameHostDelegate() {
4515 return GetJavaWebContents();
4516}
4517#endif
4518
estark910b4572015-12-09 20:55:414519void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004520 RenderFrameHostImpl* source) {
estarkc2273502016-10-12 22:03:024521 controller_.ssl_manager()->DidDisplayContentWithCertErrors();
estark910b4572015-12-09 20:55:414522}
4523
4524void WebContentsImpl::OnDidRunContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004525 RenderFrameHostImpl* source) {
nicka0ac8382016-12-15 23:59:234526 // TODO(nick, estark): Do we need to consider |source| here somehow?
estarkcd2e30c2016-08-12 06:51:154527 NavigationEntry* entry = controller_.GetVisibleEntry();
4528 if (!entry)
estarkaeda1422016-05-10 02:31:124529 return;
4530
estarkaeda1422016-05-10 02:31:124531 // TODO(estark): check that this does something reasonable for
4532 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:154533 controller_.ssl_manager()->DidRunContentWithCertErrors(
4534 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:414535}
4536
nicka0ac8382016-12-15 23:59:234537void WebContentsImpl::OnDocumentLoadedInFrame(RenderFrameHostImpl* source) {
ericwilligersde386342016-10-19 02:35:094538 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:234539 observer.DocumentLoadedInFrame(source);
[email protected]724159a2010-12-30 01:11:184540}
4541
nicka0ac8382016-12-15 23:59:234542void WebContentsImpl::OnDidFinishLoad(RenderFrameHostImpl* source,
4543 const GURL& url) {
[email protected]8b3af1e2014-01-24 13:29:124544 GURL validated_url(url);
nicka0ac8382016-12-15 23:59:234545 source->GetProcess()->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:374546
ericwilligersde386342016-10-19 02:35:094547 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:234548 observer.DidFinishLoad(source, validated_url);
[email protected]1a55c5be2011-11-29 11:36:314549}
4550
nicka0ac8382016-12-15 23:59:234551void WebContentsImpl::OnGoToEntryAtOffset(RenderViewHostImpl* source,
4552 int offset) {
4553 // All frames are allowed to navigate the global history.
avi6ddfcae2015-06-30 15:50:574554 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
4555 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:264556}
4557
nicka0ac8382016-12-15 23:59:234558void WebContentsImpl::OnUpdateZoomLimits(RenderViewHostImpl* source,
4559 int minimum_percent,
[email protected]fce823222014-05-30 16:24:304560 int maximum_percent) {
[email protected]216813952011-05-19 22:21:264561 minimum_zoom_percent_ = minimum_percent;
4562 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:264563}
4564
nicka0ac8382016-12-15 23:59:234565void WebContentsImpl::OnPageScaleFactorChanged(RenderViewHostImpl* source,
4566 float page_scale_factor) {
mcnee336ea2c2017-05-23 22:50:594567#if !defined(OS_ANDROID)
4568 // While page scale factor is used on mobile, this PageScaleFactorIsOne logic
4569 // is only needed on desktop.
mcnee432e47d2015-11-09 19:37:464570 bool is_one = page_scale_factor == 1.f;
4571 if (is_one != page_scale_factor_is_one_) {
4572 page_scale_factor_is_one_ = is_one;
4573
4574 HostZoomMapImpl* host_zoom_map =
4575 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
4576
nicka0ac8382016-12-15 23:59:234577 if (host_zoom_map) {
mcnee432e47d2015-11-09 19:37:464578 host_zoom_map->SetPageScaleFactorIsOneForView(
nicka0ac8382016-12-15 23:59:234579 source->GetProcess()->GetID(), source->GetRoutingID(),
mcnee432e47d2015-11-09 19:37:464580 page_scale_factor_is_one_);
4581 }
4582 }
mcnee336ea2c2017-05-23 22:50:594583#endif // !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:464584
ericwilligersde386342016-10-19 02:35:094585 for (auto& observer : observers_)
4586 observer.OnPageScaleFactorChanged(page_scale_factor);
mcnee432e47d2015-11-09 19:37:464587}
4588
nicka0ac8382016-12-15 23:59:234589void WebContentsImpl::OnEnumerateDirectory(RenderViewHostImpl* source,
4590 int request_id,
[email protected]2dec8ec2013-02-07 19:20:344591 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:434592 if (!delegate_)
4593 return;
4594
[email protected]b9535422012-02-09 01:47:594595 ChildProcessSecurityPolicyImpl* policy =
4596 ChildProcessSecurityPolicyImpl::GetInstance();
nicka0ac8382016-12-15 23:59:234597 if (policy->CanReadFile(source->GetProcess()->GetID(), path)) {
4598 // TODO(nick): |this| param in the call below ought to be a RenderFrameHost.
[email protected]b9535422012-02-09 01:47:594599 delegate_->EnumerateDirectory(this, request_id, path);
nicka0ac8382016-12-15 23:59:234600 }
[email protected]3a29a6e2011-08-24 18:26:214601}
4602
nicka0ac8382016-12-15 23:59:234603void WebContentsImpl::OnRegisterProtocolHandler(RenderFrameHostImpl* source,
4604 const std::string& protocol,
[email protected]b172aee2012-04-10 17:05:264605 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:264606 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:364607 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234608 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4609 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]e5f2de02012-07-20 22:15:434610 if (!delegate_)
4611 return;
4612
[email protected]b9535422012-02-09 01:47:594613 ChildProcessSecurityPolicyImpl* policy =
4614 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:324615 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:594616 return;
[email protected]8f810632013-06-06 22:33:324617
[email protected]c125e532014-05-10 20:39:064618 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:204619}
4620
nicka0ac8382016-12-15 23:59:234621void WebContentsImpl::OnUnregisterProtocolHandler(RenderFrameHostImpl* source,
4622 const std::string& protocol,
[email protected]f5273e52014-07-14 16:30:204623 const GURL& url,
4624 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234625 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4626 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]f5273e52014-07-14 16:30:204627 if (!delegate_)
4628 return;
4629
4630 ChildProcessSecurityPolicyImpl* policy =
4631 ChildProcessSecurityPolicyImpl::GetInstance();
4632 if (policy->IsPseudoScheme(protocol))
4633 return;
4634
4635 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
4636}
4637
kouhei40f03cb2015-09-24 07:47:014638void WebContentsImpl::OnUpdatePageImportanceSignals(
nicka0ac8382016-12-15 23:59:234639 RenderFrameHostImpl* source,
kouhei40f03cb2015-09-24 07:47:014640 const PageImportanceSignals& signals) {
nicka0ac8382016-12-15 23:59:234641 // TODO(nick, kouhei): Fix this for oopifs; currently all frames' state gets
4642 // written to this one field.
kouhei40f03cb2015-09-24 07:47:014643 page_importance_signals_ = signals;
4644}
4645
nicka0ac8382016-12-15 23:59:234646void WebContentsImpl::OnFindReply(RenderFrameHostImpl* source,
4647 int request_id,
[email protected]b172aee2012-04-10 17:05:264648 int number_of_matches,
4649 const gfx::Rect& selection_rect,
4650 int active_match_ordinal,
4651 bool final_update) {
paulmeyerfeafc2d2017-04-25 21:46:404652 if (active_match_ordinal > 0)
4653 SetFocusedFrame(source->frame_tree_node(), source->GetSiteInstance());
4654
paulmeyerc0b762b2016-04-13 11:55:174655 // Forward the find reply to the FindRequestManager, along with the
4656 // RenderFrameHost associated with the frame that the reply came from.
nicka0ac8382016-12-15 23:59:234657 GetOrCreateFindRequestManager()->OnFindReply(
4658 source, request_id, number_of_matches, selection_rect,
4659 active_match_ordinal, final_update);
[email protected]b888919c2011-09-02 00:32:164660}
4661
mfomitchev2b8b066a2016-01-28 19:23:154662#if defined(OS_ANDROID)
[email protected]1ff427972013-02-07 21:14:074663void WebContentsImpl::OnOpenDateTimeDialog(
nicka0ac8382016-12-15 23:59:234664 RenderViewHostImpl* source,
[email protected]1ff427972013-02-07 21:14:074665 const ViewHostMsg_DateTimeDialogValue_Params& value) {
nicka0ac8382016-12-15 23:59:234666 date_time_chooser_->ShowDialog(
4667 GetTopLevelNativeWindow(), source, value.dialog_type, value.dialog_value,
4668 value.minimum, value.maximum, value.step, value.suggestions);
[email protected]583418cc2013-01-17 14:01:104669}
[email protected]59363fc92012-09-05 03:46:314670#endif
4671
nicka0ac8382016-12-15 23:59:234672void WebContentsImpl::OnDomOperationResponse(RenderFrameHostImpl* source,
4673 const std::string& json_string) {
4674 // TODO(nick, lukasza): The notification below should probably be updated to
4675 // include |source|.
avi60bd4902015-09-23 20:39:244676 std::string json = json_string;
4677 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
4678 Source<WebContents>(this),
4679 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:404680}
4681
nicka0ac8382016-12-15 23:59:234682void WebContentsImpl::OnAppCacheAccessed(RenderViewHostImpl* source,
4683 const GURL& manifest_url,
[email protected]b172aee2012-04-10 17:05:264684 bool blocked_by_policy) {
nicka0ac8382016-12-15 23:59:234685 // TODO(nick): Should we consider |source| here? Should we call FilterURL on
4686 // |manifest_url|?
4687
[email protected]7fc4bbb2011-09-08 21:23:104688 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094689 for (auto& observer : observers_)
4690 observer.AppCacheAccessed(manifest_url, blocked_by_policy);
[email protected]7fc4bbb2011-09-08 21:23:104691}
4692
Joel Hockey85b379d2017-12-11 10:42:134693void WebContentsImpl::OnColorChooserFactoryRequest(
Joel Hockey163835a2017-12-20 11:51:574694 blink::mojom::ColorChooserFactoryRequest request) {
Joel Hockey85b379d2017-12-11 10:42:134695 color_chooser_factory_bindings_.AddBinding(this, std::move(request));
4696}
4697
4698void WebContentsImpl::OpenColorChooser(
Joel Hockey163835a2017-12-20 11:51:574699 blink::mojom::ColorChooserRequest chooser_request,
4700 blink::mojom::ColorChooserClientPtr client,
[email protected]8ed16472014-04-11 19:02:484701 SkColor color,
Joel Hockey163835a2017-12-20 11:51:574702 std::vector<blink::mojom::ColorSuggestionPtr> suggestions) {
Joel Hockey85b379d2017-12-11 10:42:134703 content::ColorChooser* new_color_chooser =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:284704 delegate_ ? delegate_->OpenColorChooser(this, color, suggestions)
4705 : nullptr;
[email protected]820957a2014-01-14 14:56:304706 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:214707 return;
[email protected]8ed16472014-04-11 19:02:484708
Joel Hockey85b379d2017-12-11 10:42:134709 color_chooser_.reset();
4710 color_chooser_ = std::make_unique<ColorChooser>(
4711 new_color_chooser, std::move(chooser_request), std::move(client));
[email protected]da8543762012-03-20 08:52:204712}
4713
brettw4b461082016-11-19 18:55:164714#if BUILDFLAG(ENABLE_PLUGINS)
nicka0ac8382016-12-15 23:59:234715void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source,
4716 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094717 for (auto& observer : observers_)
4718 observer.PepperInstanceCreated();
nicka0ac8382016-12-15 23:59:234719 pepper_playback_observer_->PepperInstanceCreated(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004720}
4721
nicka0ac8382016-12-15 23:59:234722void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source,
4723 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094724 for (auto& observer : observers_)
4725 observer.PepperInstanceDeleted();
nicka0ac8382016-12-15 23:59:234726 pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004727}
4728
nicka0ac8382016-12-15 23:59:234729void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source,
4730 int plugin_child_id,
tommyclie6633ca72014-10-31 00:40:424731 const base::FilePath& path,
4732 bool is_hung) {
4733 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
4734
ericwilligersde386342016-10-19 02:35:094735 for (auto& observer : observers_)
4736 observer.PluginHungStatusChanged(plugin_child_id, path, is_hung);
tommyclie6633ca72014-10-31 00:40:424737}
4738
nicka0ac8382016-12-15 23:59:234739void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source,
4740 int32_t pp_instance) {
4741 pepper_playback_observer_->PepperStartsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174742}
4743
nicka0ac8382016-12-15 23:59:234744void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source,
4745 int32_t pp_instance) {
4746 pepper_playback_observer_->PepperStopsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174747}
4748
nicka0ac8382016-12-15 23:59:234749void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source,
4750 const base::FilePath& plugin_path,
tommyclie6633ca72014-10-31 00:40:424751 base::ProcessId plugin_pid) {
nicka0ac8382016-12-15 23:59:234752 // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted,
4753 // and is only used by BlinkTestController.
ericwilligersde386342016-10-19 02:35:094754 for (auto& observer : observers_)
4755 observer.PluginCrashed(plugin_path, plugin_pid);
tommyclie6633ca72014-10-31 00:40:424756}
4757
[email protected]d8415ad92012-08-23 14:40:504758void WebContentsImpl::OnRequestPpapiBrokerPermission(
nicka0ac8382016-12-15 23:59:234759 RenderViewHostImpl* source,
4760 int ppb_broker_route_id,
[email protected]d8415ad92012-08-23 14:40:504761 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:344762 const base::FilePath& plugin_path) {
nicka0ac8382016-12-15 23:59:234763 base::Callback<void(bool)> permission_result_callback = base::Bind(
4764 &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this),
4765 source->GetProcess()->GetID(), ppb_broker_route_id);
[email protected]8c8fc292012-11-23 18:57:164766 if (!delegate_) {
Tommy Nyquist4b749d02018-03-20 21:46:294767 std::move(permission_result_callback).Run(false);
[email protected]8c8fc292012-11-23 18:57:164768 return;
[email protected]d8415ad92012-08-23 14:40:504769 }
4770
nicka0ac8382016-12-15 23:59:234771 if (!delegate_->RequestPpapiBrokerPermission(this, url, plugin_path,
4772 permission_result_callback)) {
[email protected]8c8fc292012-11-23 18:57:164773 NOTIMPLEMENTED();
Tommy Nyquist4b749d02018-03-20 21:46:294774 std::move(permission_result_callback).Run(false);
[email protected]8c8fc292012-11-23 18:57:164775 }
[email protected]d8415ad92012-08-23 14:40:504776}
4777
nicka0ac8382016-12-15 23:59:234778void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id,
4779 int ppb_broker_route_id,
4780 bool result) {
4781 RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
4782 if (rph) {
4783 // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it
4784 // is not routed to a RenderView.
4785 rph->Send(
4786 new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result));
4787 }
[email protected]d8415ad92012-08-23 14:40:504788}
4789
fsamuel833ee7c2015-02-13 23:40:404790void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
4791 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:394792 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:144793 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:404794 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:374795}
brettw4b461082016-11-19 18:55:164796#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:374797
[email protected]795c28972012-12-06 06:13:394798void WebContentsImpl::OnUpdateFaviconURL(
lukasza178ff092017-06-07 23:39:504799 RenderFrameHostImpl* source,
[email protected]795c28972012-12-06 06:13:394800 const std::vector<FaviconURL>& candidates) {
lukasza178ff092017-06-07 23:39:504801 // Ignore favicons for non-main frame.
4802 if (source->GetParent()) {
4803 NOTREACHED();
4804 return;
4805 }
4806
pkotwiczf9bc20592015-04-21 18:57:064807 // We get updated favicon URLs after the page stops loading. If a cross-site
4808 // navigation occurs while a page is still loading, the initial page
4809 // may stop loading and send us updated favicon URLs after the navigation
4810 // for the new page has committed.
lukasza178ff092017-06-07 23:39:504811 if (!source->IsCurrent())
pkotwiczf9bc20592015-04-21 18:57:064812 return;
4813
ericwilligersde386342016-10-19 02:35:094814 for (auto& observer : observers_)
4815 observer.DidUpdateFaviconURL(candidates);
[email protected]795c28972012-12-06 06:13:394816}
4817
qinmin72e8bd02016-10-21 19:35:374818void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) {
4819 is_overlay_content_ = is_overlay_content;
4820}
4821
nicka0ac8382016-12-15 23:59:234822void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(RenderViewHostImpl* source) {
4823 // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if
4824 // |source| is the main frame.
ericwilligersde386342016-10-19 02:35:094825 for (auto& observer : observers_)
4826 observer.DidFirstVisuallyNonEmptyPaint();
yusufod41c5f92015-03-06 00:14:284827
peter90afaba2015-06-01 12:05:294828 did_first_visually_non_empty_paint_ = true;
4829
yusufod41c5f92015-03-06 00:14:284830 if (theme_color_ != last_sent_theme_color_) {
4831 // Theme color should have updated by now if there was one.
ericwilligersde386342016-10-19 02:35:094832 for (auto& observer : observers_)
4833 observer.DidChangeThemeColor(theme_color_);
yusufod41c5f92015-03-06 00:14:284834 last_sent_theme_color_ = theme_color_;
4835 }
[email protected]9f268072013-11-07 00:02:154836}
[email protected]d9030b82013-07-19 08:26:064837
[email protected]17e286e2013-03-01 23:29:394838void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
ericwilligersde386342016-10-19 02:35:094839 for (auto& observer : observers_)
4840 observer.BeforeFormRepostWarningShow();
[email protected]17e286e2013-03-01 23:29:394841}
4842
[email protected]ec6c05f2013-10-23 18:41:574843void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
4844 Activate();
4845 if (delegate_)
4846 delegate_->ShowRepostFormWarningDialog(this);
4847}
4848
[email protected]b4c84012014-04-28 19:51:104849bool WebContentsImpl::HasAccessedInitialDocument() {
4850 return has_accessed_initial_document_;
4851}
4852
afakhry6f0c1ec22016-07-14 13:55:134853void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:264854 const base::string16& title) {
[email protected]fcf75d42013-12-03 20:11:264855 base::string16 final_title;
Avi Drissman93002212017-09-27 03:20:524856 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:324857
[email protected]987fc3a2011-05-26 14:18:094858 // If a page is created via window.open and never navigated,
4859 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:554860 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:094861 if (entry) {
[email protected]36fc0392011-12-25 03:59:514862 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:134863 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:324864
[email protected]36fc0392011-12-25 03:59:514865 entry->SetTitle(final_title);
Avi Drissman93002212017-09-27 03:20:524866
4867 // The title for display may differ from the title just set; grab it.
4868 final_title = entry->GetTitleForDisplay();
[email protected]987fc3a2011-05-26 14:18:094869 } else {
4870 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:134871 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:094872
4873 page_title_when_no_navigation_entry_ = final_title;
4874 }
[email protected]420ae012009-04-24 05:16:324875
[email protected]420ae012009-04-24 05:16:324876 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:234877 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:324878
ericwilligersde386342016-10-19 02:35:094879 for (auto& observer : observers_)
Avi Drissman93002212017-09-27 03:20:524880 observer.TitleWasSet(entry);
[email protected]66798902013-10-01 18:40:164881
afakhry6f0c1ec22016-07-14 13:55:134882 // Broadcast notifications when the UI should be updated.
4883 if (entry == controller_.GetEntryAtOffset(0))
4884 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:324885}
4886
fdegansa696e5112015-04-17 01:57:594887void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:004888 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:004889 if (delegate_)
fdegansa696e5112015-04-17 01:57:594890 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:004891}
4892
4893void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:344894 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:004895 loading_weak_factory_.InvalidateWeakPtrs();
4896 loading_last_progress_update_ = base::TimeTicks();
4897}
4898
clamy44e84ce2016-02-22 15:38:254899// Notifies the RenderWidgetHost instance about the fact that the page is
4900// loading, or done loading.
4901void WebContentsImpl::LoadingStateChanged(bool to_different_document,
4902 bool due_to_interstitial,
4903 LoadNotificationDetails* details) {
4904 // Do not send notifications about loading changes in the FrameTree while the
4905 // interstitial page is pausing the throbber.
creisadca9862017-06-16 19:12:114906 if (ShowingInterstitialPage() && interstitial_page_->pause_throbber() &&
clamy44e84ce2016-02-22 15:38:254907 !due_to_interstitial) {
4908 return;
4909 }
4910
4911 bool is_loading = IsLoading();
4912
4913 if (!is_loading) {
4914 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
4915 base::string16());
4916 load_state_host_.clear();
4917 upload_size_ = 0;
4918 upload_position_ = 0;
4919 }
4920
4921 GetRenderManager()->SetIsLoading(is_loading);
4922
4923 waiting_for_response_ = is_loading;
4924 is_load_to_different_document_ = to_different_document;
4925
4926 if (delegate_)
4927 delegate_->LoadingStateChanged(this, to_different_document);
4928 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
4929
4930 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
4931 if (is_loading) {
4932 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
4933 this, "URL", url, "Main FrameTreeNode id",
4934 GetFrameTree()->root()->frame_tree_node_id());
ericwilligersde386342016-10-19 02:35:094935 for (auto& observer : observers_)
4936 observer.DidStartLoading();
clamy44e84ce2016-02-22 15:38:254937 } else {
4938 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
4939 this, "URL", url);
ericwilligersde386342016-10-19 02:35:094940 for (auto& observer : observers_)
4941 observer.DidStopLoading();
clamy44e84ce2016-02-22 15:38:254942 }
4943
4944 // TODO(avi): Remove. http://crbug.com/170921
4945 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
4946 NotificationDetails det = NotificationService::NoDetails();
4947 if (details)
4948 det = Details<LoadNotificationDetails>(details);
4949 NotificationService::current()->Notify(
4950 type, Source<NavigationController>(&controller_), det);
4951}
4952
[email protected]02d7b6e2014-06-24 21:01:504953void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
4954 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:324955 // After sending out a swap notification, we need to send a disconnect
4956 // notification so that clients that pick up a pointer to |this| can NULL the
4957 // pointer. See Bug 1230284.
4958 notify_disconnection_ = true;
ericwilligersde386342016-10-19 02:35:094959 for (auto& observer : observers_)
4960 observer.RenderViewHostChanged(old_host, new_host);
[email protected]da7a7182013-09-06 08:11:114961
[email protected]7a846df2012-09-20 19:17:394962 // Ensure that the associated embedder gets cleared after a RenderViewHost
4963 // gets swapped, so we don't reuse the same embedder next time a
4964 // RenderViewHost is attached to this WebContents.
4965 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:324966}
4967
[email protected]02d7b6e2014-06-24 21:01:504968void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
4969 RenderFrameHost* new_host) {
Bo Liu168c8642017-08-28 18:26:024970#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:504971 // Copy importance from |old_host| if |new_host| is a main frame.
4972 if (old_host && !new_host->GetParent()) {
Bo Liu7c6779e92017-08-16 02:02:284973 static_cast<RenderFrameHostImpl*>(new_host)
4974 ->GetRenderWidgetHost()
Bo Liu16dd7b8322018-05-02 21:19:504975 ->SetImportance(static_cast<RenderFrameHostImpl*>(old_host)
4976 ->GetRenderWidgetHost()
4977 ->importance());
Bo Liu7c6779e92017-08-16 02:02:284978 }
Bo Liu168c8642017-08-28 18:26:024979#endif
ericwilligersde386342016-10-19 02:35:094980 for (auto& observer : observers_)
4981 observer.RenderFrameHostChanged(old_host, new_host);
[email protected]02d7b6e2014-06-24 21:01:504982}
4983
[email protected]da7a7182013-09-06 08:11:114984// TODO(avi): Remove this entire function because this notification is already
4985// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:264986void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:324987 if (!notify_disconnection_)
4988 return;
4989
4990 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:214991 NotificationService::current()->Notify(
4992 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
4993 Source<WebContents>(this),
4994 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:324995}
4996
[email protected]cbb1ef592013-06-05 19:49:464997void WebContentsImpl::NotifyNavigationEntryCommitted(
4998 const LoadCommittedDetails& load_details) {
ericwilligersde386342016-10-19 02:35:094999 for (auto& observer : observers_)
5000 observer.NavigationEntryCommitted(load_details);
[email protected]cbb1ef592013-06-05 19:49:465001}
5002
Sam McNally5c087a32017-08-25 01:46:145003void WebContentsImpl::NotifyNavigationEntryChanged(
5004 const EntryChangedDetails& change_details) {
5005 for (auto& observer : observers_)
5006 observer.NavigationEntryChanged(change_details);
5007}
5008
5009void WebContentsImpl::NotifyNavigationListPruned(
5010 const PrunedDetails& pruned_details) {
5011 for (auto& observer : observers_)
5012 observer.NavigationListPruned(pruned_details);
5013}
5014
Christian Dullweber1af31e62018-02-22 11:49:485015void WebContentsImpl::NotifyNavigationEntriesDeleted() {
5016 for (auto& observer : observers_)
5017 observer.NavigationEntriesDeleted();
5018}
5019
rockotf62002a2016-09-15 00:08:595020void WebContentsImpl::OnAssociatedInterfaceRequest(
5021 RenderFrameHost* render_frame_host,
5022 const std::string& interface_name,
5023 mojo::ScopedInterfaceEndpointHandle handle) {
5024 auto it = binding_sets_.find(interface_name);
5025 if (it != binding_sets_.end())
5026 it->second->OnRequestForFrame(render_frame_host, std::move(handle));
5027}
5028
Ben Goodger9e24929e2017-07-21 03:13:405029void WebContentsImpl::OnInterfaceRequest(
5030 RenderFrameHost* render_frame_host,
5031 const std::string& interface_name,
5032 mojo::ScopedMessagePipeHandle* interface_pipe) {
Joel Hockey85b379d2017-12-11 10:42:135033 registry_.TryBindInterface(interface_name, interface_pipe);
Ben Goodger9e24929e2017-07-21 03:13:405034 for (auto& observer : observers_) {
5035 observer.OnInterfaceRequestFromFrame(render_frame_host, interface_name,
5036 interface_pipe);
5037 if (!interface_pipe->is_valid())
5038 break;
5039 }
5040}
5041
Nicolas Dossou-gbetebcab2472017-09-09 12:28:405042void WebContentsImpl::OnDidBlockFramebust(const GURL& url) {
5043 if (delegate_)
5044 delegate_->OnDidBlockFramebust(this, url);
5045}
5046
[email protected]c31a84802014-04-03 15:55:495047const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
5048 return GetLastCommittedURL();
5049}
5050
[email protected]b849847b2013-12-10 21:57:585051void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:095052 for (auto& observer : observers_)
5053 observer.RenderFrameCreated(render_frame_host);
dmazzonif8a31042016-12-03 00:52:135054 UpdateAccessibilityModeOnFrame(render_frame_host);
clamy91b7abf2016-03-24 15:17:455055
5056 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
5057 return;
5058
5059 NavigationEntry* entry = controller_.GetPendingEntry();
5060 if (entry && entry->IsViewSourceMode()) {
5061 // Put the renderer in view source mode.
5062 render_frame_host->Send(
5063 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
5064 }
[email protected]b849847b2013-12-10 21:57:585065}
5066
5067void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
creis3638897452017-05-09 22:07:505068 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095069 for (auto& observer : observers_)
5070 observer.RenderFrameDeleted(render_frame_host);
creis3638897452017-05-09 22:07:505071 is_notifying_observers_ = false;
zqzhang7b6f4f02016-12-07 22:10:225072#if BUILDFLAG(ENABLE_PLUGINS)
5073 pepper_playback_observer_->RenderFrameDeleted(render_frame_host);
5074#endif
Becca Hughesfd5d8f892018-06-14 18:23:365075
5076 // Remove any fullscreen state that the frame has stored.
5077 FullscreenStateChanged(render_frame_host, false /* is_fullscreen */);
[email protected]b849847b2013-12-10 21:57:585078}
5079
[email protected]a09d53ce2014-01-31 00:46:425080void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
5081 const ContextMenuParams& params) {
avie9fd8722017-04-10 16:17:585082 // If a renderer fires off a second command to show a context menu before the
5083 // first context menu is closed, just ignore it. https://crbug.com/707534
ekaramadf6750aa2017-06-06 18:29:425084 if (showing_context_menu_)
avie9fd8722017-04-10 16:17:585085 return;
5086
[email protected]077e704b2014-05-23 19:24:105087 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:425088 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:105089 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:425090 return;
5091
[email protected]077e704b2014-05-23 19:24:105092 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
5093 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:425094}
5095
avi777ff452017-02-09 19:04:485096void WebContentsImpl::RunJavaScriptDialog(RenderFrameHost* render_frame_host,
5097 const base::string16& message,
5098 const base::string16& default_prompt,
avi777ff452017-02-09 19:04:485099 JavaScriptDialogType dialog_type,
5100 IPC::Message* reply_msg) {
Avi Drissman2ccbb402018-03-20 21:11:365101 // Ensure that if showing a dialog is the first thing that a page does, that
5102 // the contents of the previous page aren't shown behind it. This is required
5103 // because showing a dialog freezes the renderer, so no frames will be coming
5104 // from it. https://crbug.com/823353
5105 auto* render_widget_host_impl =
5106 static_cast<RenderFrameHostImpl*>(render_frame_host)
5107 ->GetRenderWidgetHost();
5108 if (render_widget_host_impl)
5109 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5110
avi0720b02e2017-06-13 03:22:135111 // Running a dialog causes an exit to webpage-initiated fullscreen.
5112 // http://crbug.com/728276
5113 if (IsFullscreenForCurrentTab())
5114 ExitFullscreen(true);
5115
Avi Drissmane04d3992017-10-05 15:11:365116 auto callback =
5117 base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
5118 render_frame_host->GetProcess()->GetID(),
5119 render_frame_host->GetRoutingID(), reply_msg);
Pavel Feldman3c1842b2017-08-02 05:00:165120
Pavel Feldman3c1842b2017-08-02 05:00:165121 std::vector<protocol::PageHandler*> page_handlers =
5122 protocol::PageHandler::EnabledForWebContents(this);
5123
Pavel Feldmanfab3cb62017-10-05 01:02:015124 if (delegate_)
5125 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5126
5127 // Suppress JavaScript dialogs when requested. Also suppress messages when
5128 // showing an interstitial as it's shown over the previous page and we don't
5129 // want the hidden page's dialogs to interfere with the interstitial.
5130 bool should_suppress = ShowingInterstitialPage() ||
5131 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055132 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5133 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015134 bool suppress_this_message = should_suppress || !has_handlers;
5135
5136 if (suppress_this_message) {
Avi Drissmane04d3992017-10-05 15:11:365137 std::move(callback).Run(true, false, base::string16());
Pavel Feldman3c1842b2017-08-02 05:00:165138 return;
5139 }
5140
5141 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365142 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165143
5144 is_showing_javascript_dialog_ = true;
5145
5146 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365147 handler->DidRunJavaScriptDialog(
Avi Drissman2fefc4b2018-02-22 20:41:015148 render_frame_host->GetLastCommittedURL(), message, default_prompt,
Pavel Feldman1c587bc52018-04-04 21:16:055149 dialog_type, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365150 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165151 }
5152
5153 if (dialog_manager_) {
[email protected]87de04b02014-04-08 22:14:495154 dialog_manager_->RunJavaScriptDialog(
Avi Drissman2fefc4b2018-02-22 20:41:015155 this, render_frame_host, dialog_type, message, default_prompt,
Avi Drissmane04d3992017-10-05 15:11:365156 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false),
5157 &suppress_this_message);
[email protected]87de04b02014-04-08 22:14:495158 }
5159
5160 if (suppress_this_message) {
5161 // If we are suppressing messages, just reply as if the user immediately
5162 // pressed "Cancel", passing true to |dialog_was_suppressed|.
Avi Drissmane04d3992017-10-05 15:11:365163 wrapper->Run(true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:495164 }
[email protected]87de04b02014-04-08 22:14:495165}
5166
5167void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:015168 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:495169 bool is_reload,
5170 IPC::Message* reply_msg) {
Avi Drissman2ccbb402018-03-20 21:11:365171 // Ensure that if showing a dialog is the first thing that a page does, that
5172 // the contents of the previous page aren't shown behind it. This is required
5173 // because showing a dialog freezes the renderer, so no frames will be coming
5174 // from it. https://crbug.com/823353
5175 auto* render_widget_host_impl =
5176 static_cast<RenderFrameHostImpl*>(render_frame_host)
5177 ->GetRenderWidgetHost();
5178 if (render_widget_host_impl)
5179 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5180
avi0720b02e2017-06-13 03:22:135181 // Running a dialog causes an exit to webpage-initiated fullscreen.
5182 // http://crbug.com/728276
5183 if (IsFullscreenForCurrentTab())
5184 ExitFullscreen(true);
5185
[email protected]39f2f9252014-05-03 00:54:015186 RenderFrameHostImpl* rfhi =
5187 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:495188 if (delegate_)
5189 delegate_->WillRunBeforeUnloadConfirm();
5190
Avi Drissmane04d3992017-10-05 15:11:365191 auto callback =
5192 base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
5193 render_frame_host->GetProcess()->GetID(),
5194 render_frame_host->GetRoutingID(), reply_msg);
Pavel Feldman3c1842b2017-08-02 05:00:165195
Pavel Feldman3c1842b2017-08-02 05:00:165196 std::vector<protocol::PageHandler*> page_handlers =
5197 protocol::PageHandler::EnabledForWebContents(this);
5198
Pavel Feldmanfab3cb62017-10-05 01:02:015199 if (delegate_)
5200 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5201
5202 bool should_suppress = ShowingInterstitialPage() || !rfhi->is_active() ||
5203 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055204 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5205 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015206 if (should_suppress || !has_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365207 std::move(callback).Run(false, true, base::string16());
[email protected]87de04b02014-04-08 22:14:495208 return;
5209 }
5210
5211 is_showing_before_unload_dialog_ = true;
Pavel Feldman3c1842b2017-08-02 05:00:165212
5213 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365214 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165215
5216 GURL frame_url = rfhi->GetLastCommittedURL();
5217 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365218 handler->DidRunBeforeUnloadConfirm(
Pavel Feldman1c587bc52018-04-04 21:16:055219 frame_url, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365220 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165221 }
5222
5223 if (dialog_manager_) {
Avi Drissmane04d3992017-10-05 15:11:365224 dialog_manager_->RunBeforeUnloadDialog(
Avi Drissmanff9ed752017-11-28 21:18:125225 this, render_frame_host, is_reload,
Avi Drissmane04d3992017-10-05 15:11:365226 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165227 }
[email protected]87de04b02014-04-08 22:14:495228}
5229
naskoada75b22016-06-11 16:09:465230void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host,
5231 const FileChooserParams& params) {
5232 if (delegate_)
5233 delegate_->RunFileChooser(render_frame_host, params);
5234}
5235
[email protected]a86c0e962013-12-17 17:10:395236WebContents* WebContentsImpl::GetAsWebContents() {
5237 return this;
5238}
5239
mcnee336ea2c2017-05-23 22:50:595240#if !defined(OS_ANDROID)
akabac6bd1212018-06-25 20:10:485241double WebContentsImpl::GetPendingPageZoomLevel() const {
wjmaclean64951902016-04-29 20:59:125242 NavigationEntry* pending_entry = GetController().GetPendingEntry();
5243 if (!pending_entry)
5244 return HostZoomMap::GetZoomLevel(this);
5245
5246 GURL url = pending_entry->GetURL();
5247 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
5248 url.scheme(), net::GetHostOrSpecFromURL(url));
5249}
mcnee336ea2c2017-05-23 22:50:595250#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:125251
qinmin72e8bd02016-10-21 19:35:375252bool WebContentsImpl::HideDownloadUI() const {
5253 return is_overlay_content_;
5254}
5255
mlamouri5cd9ae82017-02-18 11:05:095256bool WebContentsImpl::HasPersistentVideo() const {
5257 return has_persistent_video_;
5258}
5259
Alex Moshchuk27caae82017-09-11 23:11:185260RenderFrameHost* WebContentsImpl::GetPendingMainFrame() {
clamy610c63b32017-12-22 15:05:185261 return GetRenderManager()->speculative_frame_host();
Alex Moshchuk27caae82017-09-11 23:11:185262}
5263
mlamourie52c1b542017-02-23 14:57:505264bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const {
5265 return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo();
5266}
5267
François Beaufortad6c5232018-02-26 11:00:445268bool WebContentsImpl::IsPictureInPictureAllowedForFullscreenVideo() const {
5269 return media_web_contents_observer_
5270 ->IsPictureInPictureAllowedForFullscreenVideo();
5271}
5272
ekaramada110f642016-12-21 19:47:285273bool WebContentsImpl::IsFocusedElementEditable() {
5274 RenderFrameHostImpl* frame = GetFocusedFrame();
5275 return frame && frame->has_focused_editable_element();
5276}
5277
ekaramadf6750aa2017-06-06 18:29:425278bool WebContentsImpl::IsShowingContextMenu() const {
5279 return showing_context_menu_;
5280}
5281
5282void WebContentsImpl::SetShowingContextMenu(bool showing) {
5283 DCHECK_NE(showing_context_menu_, showing);
5284 showing_context_menu_ = showing;
5285
5286 if (auto* view = GetRenderWidgetHostView()) {
5287 // Notify the main frame's RWHV to run the platform-specific code, if any.
5288 static_cast<RenderWidgetHostViewBase*>(view)->SetShowingContextMenu(
5289 showing);
5290 }
5291}
5292
ekaramada110f642016-12-21 19:47:285293void WebContentsImpl::ClearFocusedElement() {
5294 if (auto* frame = GetFocusedFrame())
5295 frame->ClearFocusedElement();
5296}
5297
[email protected]7912e822014-04-16 02:37:035298bool WebContentsImpl::IsNeverVisible() {
5299 if (!delegate_)
5300 return false;
5301 return delegate_->IsNeverVisible(this);
5302}
5303
[email protected]5a3bdf52012-05-24 15:12:575304RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
5305 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:325306}
5307
[email protected]8ff00d72012-10-23 19:12:215308RendererPreferences WebContentsImpl::GetRendererPrefs(
5309 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:465310 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:515311}
5312
[email protected]7a846df2012-09-20 19:17:395313void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:275314 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:395315 browser_plugin_embedder_.reset();
5316}
5317
avallee0206f782016-07-28 18:55:335318WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
lfg601233692017-03-06 22:45:445319 if (GuestMode::IsCrossProcessFrameGuest(this))
5320 return node_.outer_web_contents();
ekaramad1beabecc2016-09-23 20:18:175321
5322 if (browser_plugin_guest_)
5323 return browser_plugin_guest_->embedder_web_contents();
5324
Lucas Furukawa Gadani105de1e812018-05-31 19:38:395325 return node_.outer_web_contents();
avallee0206f782016-07-28 18:55:335326}
5327
5328WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
lfg601233692017-03-06 22:45:445329 return GetOutermostWebContents()->node_.focused_web_contents();
avallee0206f782016-07-28 18:55:335330}
5331
avallee9993fca2016-11-17 06:16:505332bool WebContentsImpl::ContainsOrIsFocusedWebContents() {
5333 for (WebContentsImpl* focused_contents = GetFocusedWebContents();
5334 focused_contents;
5335 focused_contents = focused_contents->GetOuterWebContents()) {
5336 if (focused_contents == this)
5337 return true;
5338 }
5339
5340 return false;
5341}
5342
avallee0206f782016-07-28 18:55:335343WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
5344 WebContentsImpl* root = this;
5345 while (root->GetOuterWebContents())
5346 root = root->GetOuterWebContents();
5347 return root;
5348}
5349
avalleed68cdd12017-06-21 22:07:275350void WebContentsImpl::FocusOuterAttachmentFrameChain() {
5351 WebContentsImpl* outer_contents = GetOuterWebContents();
5352 if (!outer_contents)
5353 return;
5354
5355 FrameTreeNode* outer_node =
5356 FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId());
5357 outer_contents->frame_tree_.SetFocusedFrame(outer_node, nullptr);
5358
5359 // For a browser initiated focus change, let embedding renderer know of the
5360 // change. Otherwise, if the currently focused element is just across a
5361 // process boundary in focus order, it will not be possible to move across
5362 // that boundary. This is because the target element will already be focused
5363 // (that renderer was not notified) and drop the event.
5364 if (GetRenderManager()->GetProxyToOuterDelegate())
5365 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame();
5366
5367 outer_contents->FocusOuterAttachmentFrameChain();
5368}
5369
[email protected]b172aee2012-04-10 17:05:265370void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]86f98a22013-03-20 14:35:005371 if (delegate_)
[email protected]e85165c642014-06-10 14:34:315372 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:085373
[email protected]8ff00d72012-10-23 19:12:215374 NotificationService::current()->Notify(
5375 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
5376 Source<WebContents>(this),
5377 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:325378
[email protected]60780f412013-02-25 16:34:105379 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:265380
ericwilligersde386342016-10-19 02:35:095381 for (auto& observer : observers_)
5382 observer.RenderViewCreated(render_view_host);
Joel Einbinder848001c2017-09-19 21:39:315383 if (delegate_)
5384 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]420ae012009-04-24 05:16:325385}
5386
[email protected]b172aee2012-04-10 17:05:265387void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:525388 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325389 // Don't notify the world, since this came from a renderer in the
5390 // background.
5391 return;
5392 }
5393
dmazzoni62111452017-04-28 23:46:555394 RenderWidgetHostViewBase* rwhv =
5395 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5396 if (rwhv)
5397 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
5398
[email protected]da7a7182013-09-06 08:11:115399 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:115400
[email protected]be1f56ab2011-12-22 06:55:315401 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:235402 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:305403
5404 // Restore the focus to the tab (otherwise the focus will be on the top
5405 // window).
[email protected]484ae5912010-09-29 19:16:145406 if (was_crashed && !FocusLocationBarByDefault() &&
5407 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:065408 view_->Focus();
[email protected]484ae5912010-09-29 19:16:145409 }
[email protected]32ded2212011-11-10 18:51:435410
ericwilligersde386342016-10-19 02:35:095411 for (auto& observer : observers_)
5412 observer.RenderViewReady();
[email protected]420ae012009-04-24 05:16:325413}
5414
[email protected]ec6a7eb2013-04-22 17:34:225415void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
5416 base::TerminationStatus status,
5417 int error_code) {
[email protected]151a63d2011-12-20 22:32:525418 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325419 // The pending page's RenderViewHost is gone.
5420 return;
5421 }
5422
[email protected]2fcdcc32014-03-05 02:14:075423 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
5424 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:155425 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:465426 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:075427
Jennifer Apacibleb4b972a2018-06-07 04:41:025428 // Ensure any video in Picture-in-Picture is exited in the |delegate_| since
5429 // a crashed renderer may not have made a clean exit.
5430 if (HasPictureInPictureVideo())
5431 ExitPictureInPicture();
5432
[email protected]698191dc2014-02-25 01:06:135433 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:175434 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:135435
dalecurtis3d1e1302017-02-20 22:33:255436 audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID());
5437
[email protected]960b0372014-05-19 18:01:005438 // Reset the loading progress. TODO(avi): What does it mean to have a
5439 // "renderer crash" when there is more than one renderer process serving a
5440 // webpage? Once this function is called at a more granular frame level, we
5441 // probably will need to more granularly reset the state here.
5442 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:255443 NotifyDisconnected();
5444 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:005445
ericwilligersde386342016-10-19 02:35:095446 for (auto& observer : observers_)
5447 observer.RenderProcessGone(GetCrashedStatus());
[email protected]420ae012009-04-24 05:16:325448}
5449
[email protected]b172aee2012-04-10 17:05:265450void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
ericwilligersde386342016-10-19 02:35:095451 for (auto& observer : observers_)
5452 observer.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:065453}
5454
sky8b00392d2015-01-10 00:30:285455void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
5456 const GURL& url) {
5457 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
Lukasz Anforowiczfd707142018-02-07 19:46:135458 // If we're in flash fullscreen (i.e. Pepper plugin fullscreen) only update
5459 // the url if it's from the fullscreen renderer.
sky8b00392d2015-01-10 00:30:285460 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:445461 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:285462 return;
5463 }
Lukasz Anforowiczfd707142018-02-07 19:46:135464
5465 // In case of racey updates from multiple RenderViewHosts, the last URL should
5466 // be shown - see also some discussion in https://crbug.com/807776.
5467 if (!url.is_valid() && render_view_host != view_that_set_last_target_url_)
5468 return;
5469 view_that_set_last_target_url_ = url.is_valid() ? render_view_host : nullptr;
5470
[email protected]6934a702011-12-20 00:04:515471 if (delegate_)
avi450ce00e2014-09-24 01:58:525472 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:325473}
5474
Lukasz Anforowiczfd707142018-02-07 19:46:135475void WebContentsImpl::ClearTargetURL() {
5476 view_that_set_last_target_url_ = nullptr;
5477 if (delegate_)
5478 delegate_->UpdateTargetURL(this, GURL());
5479}
5480
[email protected]b172aee2012-04-10 17:05:265481void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:105482#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:295483 // The UI may be in an event-tracking loop, such as between the
5484 // mouse-down and mouse-up in text selection or a button click.
5485 // Defer the close until after tracking is complete, so that we
5486 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:295487 // TODO(shess): This could get more fine-grained. For instance,
5488 // closing a tab in another window while selecting text in the
5489 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:105490 if (view_->IsEventTracking()) {
5491 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:295492 return;
5493 }
[email protected]60780f412013-02-25 16:34:105494#endif
[email protected]07707302009-11-06 00:50:295495
[email protected]420ae012009-04-24 05:16:325496 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:525497 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:515498 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:325499}
5500
Avi Drissman014dec72018-06-07 02:34:015501void WebContentsImpl::RequestSetBounds(const gfx::Rect& new_bounds) {
5502 if (delegate_)
5503 delegate_->SetContentsBounds(this, new_bounds);
[email protected]420ae012009-04-24 05:16:325504}
5505
fdegansa696e5112015-04-17 01:57:595506void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:095507 bool to_different_document) {
Evan Stadec3b26022017-07-14 19:50:245508 LoadingStateChanged(frame_tree_node->IsMainFrame() && to_different_document,
5509 false, nullptr);
dmazzonibf8cec42015-02-08 08:28:085510
5511 // Notify accessibility that the user is navigating away from the
5512 // current document.
5513 //
5514 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:085515 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:595516 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:085517 if (manager)
5518 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:325519}
5520
fdegansc73eec22015-03-19 14:47:545521void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:085522 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:325523
[email protected]9595fd82013-04-19 21:28:495524 // Use the last committed entry rather than the active one, in case a
5525 // pending entry has been created.
5526 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:205527 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:495528
[email protected]420ae012009-04-24 05:16:325529 // An entry may not exist for a stop when loading an initial blank page or
5530 // if an iframe injected by script into a blank page finishes loading.
5531 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:205532 base::TimeDelta elapsed =
5533 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:325534
5535 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:515536 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:325537 elapsed,
5538 &controller_,
5539 controller_.GetCurrentEntryIndex()));
5540 }
5541
clamy44e84ce2016-02-22 15:38:255542 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:325543}
5544
fdegansa696e5112015-04-17 01:57:595545void WebContentsImpl::DidChangeLoadProgress() {
5546 double load_progress = frame_tree_.load_progress();
5547
5548 // The delegate is notified immediately for the first and last updates. Also,
5549 // since the message loop may be pretty busy when a page is loaded, it might
5550 // not execute a posted task in a timely manner so the progress report is sent
5551 // immediately if enough time has passed.
5552 base::TimeDelta min_delay =
5553 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
5554 bool delay_elapsed = loading_last_progress_update_.is_null() ||
5555 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
5556
5557 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
5558 // If there is a pending task to send progress, it is now obsolete.
5559 loading_weak_factory_.InvalidateWeakPtrs();
5560
5561 // Notify the load progress change.
5562 SendChangeLoadProgress();
5563
5564 // Clean-up the states if needed.
5565 if (load_progress == 1.0)
5566 ResetLoadProgressState();
5567 return;
5568 }
5569
5570 if (loading_weak_factory_.HasWeakPtrs())
5571 return;
5572
skyostil95082a62015-06-05 19:53:075573 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
tzike2aca992017-09-05 08:50:545574 FROM_HERE,
5575 base::BindOnce(&WebContentsImpl::SendChangeLoadProgress,
5576 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:595577 min_delay);
5578}
5579
avid6d88b912017-01-13 00:16:005580std::vector<std::unique_ptr<NavigationThrottle>>
5581WebContentsImpl::CreateThrottlesForNavigation(
clamycbf524d42016-09-27 12:48:355582 NavigationHandle* navigation_handle) {
5583 return GetContentClient()->browser()->CreateThrottlesForNavigation(
5584 navigation_handle);
5585}
5586
clamy1e5574e2016-09-29 16:48:445587std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
5588 NavigationHandle* navigation_handle) {
5589 DCHECK(IsBrowserSideNavigationEnabled());
5590 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
5591}
5592
pdr15f5b5b2017-06-20 00:58:005593void WebContentsImpl::DidCancelLoading() {
5594 controller_.DiscardNonCommittedEntries();
5595
5596 // Update the URL display.
5597 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
5598}
5599
[email protected]59167c22013-06-03 18:07:325600void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:105601 has_accessed_initial_document_ = true;
5602
[email protected]d1371bf8e2014-04-19 03:26:245603 // We may have left a failed browser-initiated navigation in the address bar
5604 // to let the user edit it and try again. Clear it now that content might
5605 // show up underneath it.
5606 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:455607 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:245608
[email protected]59167c22013-06-03 18:07:325609 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:505610 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:325611}
5612
alexmosbe2f4c32015-03-10 02:30:235613void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
5614 const std::string& name) {
ericwilligersde386342016-10-19 02:35:095615 for (auto& observer : observers_)
5616 observer.FrameNameChanged(render_frame_host, name);
alexmosbe2f4c32015-03-10 02:30:235617}
5618
[email protected]39f2f9252014-05-03 00:54:015619void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:295620 RenderFrameHost* render_frame_host) {
falken52a56e32016-12-08 05:02:405621 ShowInsecureLocalhostWarningIfNeeded();
5622
creis97867aa2017-02-17 18:39:455623 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095624 for (auto& observer : observers_)
5625 observer.DocumentOnLoadCompletedInMainFrame();
creis97867aa2017-02-17 18:39:455626 is_notifying_observers_ = false;
[email protected]6578fef2013-10-14 02:35:095627
5628 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:215629 NotificationService::current()->Notify(
5630 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
5631 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:295632 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:085633}
5634
creis8eb8ef22015-11-04 22:51:385635void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
5636 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:385637 // The state update affects the last NavigationEntry associated with the given
5638 // |render_frame_host|. This may not be the last committed NavigationEntry (as
5639 // in the case of an UpdateState from a frame being swapped out). We track
5640 // which entry this is in the RenderFrameHost's nav_entry_id.
5641 RenderFrameHostImpl* rfhi =
5642 static_cast<RenderFrameHostImpl*>(render_frame_host);
5643 NavigationEntryImpl* entry =
5644 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
5645 if (!entry)
5646 return;
5647
5648 FrameNavigationEntry* frame_entry =
5649 entry->GetFrameEntry(rfhi->frame_tree_node());
5650 if (!frame_entry)
5651 return;
5652
creisd06a9422015-11-11 03:08:455653 // The SiteInstance might not match if we do a cross-process navigation with
5654 // replacement (e.g., auto-subframe), in which case the swap out of the old
5655 // RenderFrameHost runs in the background after the old FrameNavigationEntry
5656 // has already been replaced and destroyed.
5657 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
5658 return;
5659
creis8eb8ef22015-11-04 22:51:385660 if (page_state == frame_entry->page_state())
5661 return; // Nothing to update.
5662
creis0cade2e2017-02-28 06:37:475663 DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState.";
nasko34634672016-07-29 18:46:065664
5665 // The document_sequence_number and item_sequence_number recorded in the
5666 // FrameNavigationEntry should not differ from the one coming with the update,
5667 // since it must come from the same document. Do not update it if a difference
5668 // is detected, as this indicates that |frame_entry| is not the correct one.
5669 ExplodedPageState exploded_state;
5670 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
5671 return;
5672
5673 if (exploded_state.top.document_sequence_number !=
5674 frame_entry->document_sequence_number() ||
5675 exploded_state.top.item_sequence_number !=
5676 frame_entry->item_sequence_number()) {
5677 return;
5678 }
5679
nasko04a322f25a2016-09-01 00:00:345680 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:385681 controller_.NotifyEntryChanged(entry);
5682}
5683
[email protected]ef3adfc2014-05-11 00:04:545684void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
[email protected]ef3adfc2014-05-11 00:04:545685 const base::string16& title,
5686 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:545687 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:585688 // For example, it might be from a recently swapped out RFH.
avi1edc8552016-10-13 21:37:165689 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
creisad8c31a2016-05-24 17:07:045690 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
[email protected]ef3adfc2014-05-11 00:04:545691
5692 // We can handle title updates when we don't have an entry in
5693 // UpdateTitleForEntry, but only if the update is from the current RVH.
5694 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:585695 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:545696 return;
5697
5698 // TODO(evan): make use of title_direction.
5699 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:135700 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:545701}
5702
5703void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
5704 const std::string& encoding) {
5705 SetEncoding(encoding);
5706}
5707
[email protected]39f2f9252014-05-03 00:54:015708void WebContentsImpl::DocumentAvailableInMainFrame(
5709 RenderViewHost* render_view_host) {
ericwilligersde386342016-10-19 02:35:095710 for (auto& observer : observers_)
5711 observer.DocumentAvailableInMainFrame();
[email protected]39f2f9252014-05-03 00:54:015712}
naskoc0fceff2015-04-30 15:53:525713
[email protected]e1c3a552012-05-04 20:51:325714void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
5715 // Tell the active RenderViewHost to run unload handlers and close, as long
5716 // as the request came from a RenderViewHost in the same BrowsingInstance.
5717 // In most cases, we receive this from a swapped out RenderViewHost.
5718 // It is possible to receive it from one that has just been swapped in,
5719 // in which case we might as well deliver the message anyway.
5720 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:525721 ClosePage();
[email protected]e1c3a552012-05-04 20:51:325722}
5723
alexmose7da5a12015-04-09 02:22:165724bool WebContentsImpl::ShouldRouteMessageEvent(
5725 RenderFrameHost* target_rfh,
5726 SiteInstance* source_site_instance) const {
5727 // Allow the message if this WebContents is dedicated to a browser plugin
5728 // guest.
[email protected]0eba810b2012-10-18 03:19:365729 // Note: This check means that an embedder could theoretically receive a
5730 // postMessage from anyone (not just its own guests). However, this is
5731 // probably not a risk for apps since other pages won't have references
5732 // to App windows.
alexmose7da5a12015-04-09 02:22:165733 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
5734}
[email protected]f546640b2012-05-15 00:03:495735
alexmos58729042015-06-18 23:20:005736void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:165737 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
5738 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:495739
alexmose7da5a12015-04-09 02:22:165740 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:145741 // If this message is going to outer WebContents from inner WebContents,
5742 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
5743 // already created a RenderFrameProxyHost for that purpose.
5744 if (GetBrowserPluginEmbedder() &&
ekaramad1beabecc2016-09-23 20:18:175745 GuestMode::IsCrossProcessFrameGuest(source_web_contents)) {
lazyboy6ec48b2a2015-06-29 15:18:145746 return;
5747 }
5748
lfg812874d2016-02-09 22:26:135749 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:065750 // We create a RenderFrameProxyHost for the embedder in the guest's render
5751 // process but we intentionally do not expose the embedder's opener chain
5752 // to it.
5753 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
5754 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:495755 } else {
alexmos58729042015-06-18 23:20:005756 RenderFrameHostImpl* source_rfhi =
5757 static_cast<RenderFrameHostImpl*>(source_rfh);
5758 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:395759 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:495760 }
5761 }
[email protected]f546640b2012-05-15 00:03:495762}
5763
avallee9993fca2016-11-17 06:16:505764void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
5765 // Only change focus if we are not currently focused.
5766 WebContentsImpl* old_contents = GetFocusedWebContents();
5767 if (old_contents == this)
5768 return;
5769
paulmeyerfeafc2d2017-04-25 21:46:405770 GetOutermostWebContents()->node_.SetFocusedWebContents(this);
5771
Greg Thompsonfb957602017-09-04 10:25:525772 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
paulmeyerfeafc2d2017-04-25 21:46:405773 return;
5774
avallee9993fca2016-11-17 06:16:505775 // Send a page level blur to the old contents so that it displays inactive UI
5776 // and focus this contents to activate it.
5777 if (old_contents)
5778 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
avalleec2ff1ef2017-01-21 00:12:305779
5780 // Make sure the outer web contents knows our frame is focused. Otherwise, the
5781 // outer renderer could have the element before or after the frame element
5782 // focused which would return early without actually advancing focus.
avalleed68cdd12017-06-21 22:07:275783 FocusOuterAttachmentFrameChain();
avalleec2ff1ef2017-01-21 00:12:305784
lfg1453e412017-04-11 00:48:505785 if (ShowingInterstitialPage()) {
creisadca9862017-06-16 19:12:115786 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:505787 ->GetRenderWidgetHost()
5788 ->SetPageFocus(true);
5789 } else {
5790 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
5791 }
avallee9993fca2016-11-17 06:16:505792}
5793
avallee0206f782016-07-28 18:55:335794void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
5795 SiteInstance* source) {
avallee0206f782016-07-28 18:55:335796 frame_tree_.SetFocusedFrame(node, source);
avalleed68cdd12017-06-21 22:07:275797
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:575798 if (auto* inner_contents = node_.GetInnerWebContentsInFrame(node)) {
5799 // |this| is an outer WebContents and |node| represents an inner
5800 // WebContents. Transfer the focus to the inner contents if |this| is
5801 // focused.
5802 if (GetFocusedWebContents() == this)
5803 inner_contents->SetAsFocusedWebContentsIfNecessary();
5804 } else if (node_.OuterContentsFrameTreeNode() &&
5805 node_.OuterContentsFrameTreeNode()
5806 ->current_frame_host()
5807 ->GetSiteInstance() == source) {
5808 // |this| is an inner WebContents, |node| is its main FrameTreeNode and
5809 // the outer WebContents FrameTreeNode is at |source|'s SiteInstance.
5810 // Transfer the focus to the inner WebContents if the outer WebContents is
5811 // focused. This branch is used when an inner WebContents is focused through
5812 // its RenderFrameProxyHost (via FrameHostMsg_FrameFocused IPC, used to
5813 // implement the window.focus() API).
5814 if (GetFocusedWebContents() == GetOuterWebContents())
5815 SetAsFocusedWebContentsIfNecessary();
5816 } else if (!GetOuterWebContents()) {
5817 // This is an outermost WebContents.
5818 SetAsFocusedWebContentsIfNecessary();
5819 } else if (!GuestMode::IsCrossProcessFrameGuest(this) &&
5820 GetOuterWebContents()) {
5821 // TODO(lfg, paulmeyer): Allows BrowserPlugins to set themselves as the
5822 // focused WebContents. This works around a bug in FindRequestManager that
5823 // doesn't support properly traversing BrowserPlugins.
5824 SetAsFocusedWebContentsIfNecessary();
5825 }
avalleed68cdd12017-06-21 22:07:275826}
5827
Avi Drissman36f801f2018-02-01 20:06:045828void WebContentsImpl::DidCallFocus() {
5829 // Any explicit focusing of another window while this WebContents is in
5830 // fullscreen can be used to confuse the user, so drop fullscreen.
5831 if (IsFullscreenForCurrentTab())
5832 ExitFullscreen(true);
5833}
5834
avalleed68cdd12017-06-21 22:07:275835RenderFrameHost* WebContentsImpl::GetFocusedFrameIncludingInnerWebContents() {
5836 WebContentsImpl* contents = this;
5837 FrameTreeNode* focused_node = contents->frame_tree_.GetFocusedFrame();
5838
5839 // If there is no focused frame in the outer WebContents, we need to return
5840 // null.
5841 if (!focused_node)
5842 return nullptr;
5843
5844 // If the focused frame is embedding an inner WebContents, we must descend
5845 // into that contents. If the current WebContents does not have a focused
5846 // frame, return the main frame of this contents instead of the focused empty
5847 // frame embedding this contents.
5848 while (true) {
5849 contents = contents->node_.GetInnerWebContentsInFrame(focused_node);
5850 if (!contents)
5851 return focused_node->current_frame_host();
5852
5853 focused_node = contents->frame_tree_.GetFocusedFrame();
5854 if (!focused_node)
5855 return contents->GetMainFrame();
5856 }
avallee0206f782016-07-28 18:55:335857}
5858
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:575859void WebContentsImpl::OnAdvanceFocus(RenderFrameHostImpl* source_rfh) {
5860 // When a RenderFrame needs to advance focus to a RenderFrameProxy (by hitting
5861 // TAB), the RenderFrameProxy sends an IPC to RenderFrameProxyHost. When this
5862 // RenderFrameProxyHost represents an inner WebContents, the outer WebContents
5863 // needs to focus the inner WebContents.
5864 if (GetOuterWebContents() &&
5865 GetOuterWebContents() == source_rfh->delegate()->GetAsWebContents() &&
5866 GetFocusedWebContents() == GetOuterWebContents()) {
5867 SetAsFocusedWebContentsIfNecessary();
5868 }
5869}
5870
ekaramada110f642016-12-21 19:47:285871void WebContentsImpl::OnFocusedElementChangedInFrame(
5872 RenderFrameHostImpl* frame,
5873 const gfx::Rect& bounds_in_root_view) {
5874 RenderWidgetHostViewBase* root_view =
5875 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5876 if (!root_view || !frame->GetView())
5877 return;
5878
5879 // Converting to screen coordinates.
5880 gfx::Point origin = bounds_in_root_view.origin();
5881 origin += root_view->GetViewBounds().OffsetFromOrigin();
5882 gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size());
5883
5884 root_view->FocusedNodeChanged(frame->has_focused_editable_element(),
5885 bounds_in_screen);
5886
5887 FocusedNodeDetails details = {frame->has_focused_editable_element(),
5888 bounds_in_screen};
5889
5890 // TODO(ekaramad): We should replace this with an observer notification
5891 // (https://crbug.com/675975).
5892 NotificationService::current()->Notify(
5893 NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
5894 Source<RenderViewHost>(GetRenderViewHost()),
5895 Details<FocusedNodeDetails>(&details));
5896}
5897
avia90ae4e2016-11-11 20:49:335898bool WebContentsImpl::DidAddMessageToConsole(int32_t level,
5899 const base::string16& message,
5900 int32_t line_no,
5901 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:255902 if (!delegate_)
5903 return false;
avia90ae4e2016-11-11 20:49:335904 return delegate_->DidAddMessageToConsole(this, level, message, line_no,
5905 source_id);
[email protected]a796f202012-05-30 14:14:255906}
5907
Daniel Cheng90196c82018-04-25 21:49:145908void WebContentsImpl::DidReceiveInputEvent(
dominickn9c7ceaa32016-02-27 01:52:535909 RenderWidgetHostImpl* render_widget_host,
5910 const blink::WebInputEvent::Type type) {
Daniel Cheng90196c82018-04-25 21:49:145911 // Ideally, this list would be based more off of
5912 // https://whatwg.org/C/interaction.html#triggered-by-user-activation.
5913 if (type != blink::WebInputEvent::kMouseDown &&
5914 type != blink::WebInputEvent::kGestureScrollBegin &&
5915 type != blink::WebInputEvent::kTouchStart &&
5916 type != blink::WebInputEvent::kRawKeyDown)
5917 return;
5918
kenrb19221852016-04-29 17:21:405919 // Ignore unless the widget is currently in the frame tree.
5920 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:225921 return;
5922
Daniel Cheng90196c82018-04-25 21:49:145923 if (type != blink::WebInputEvent::kGestureScrollBegin)
5924 last_interactive_input_event_time_ = ui::EventTimeForNow();
dominickn9c7ceaa32016-02-27 01:52:535925
Daniel Cheng90196c82018-04-25 21:49:145926 OnUserInteraction(type);
dominickn2dd142dd2015-10-29 05:30:505927}
5928
avallee9993fca2016-11-17 06:16:505929void WebContentsImpl::FocusOwningWebContents(
5930 RenderWidgetHostImpl* render_widget_host) {
5931 // The PDF plugin still runs as a BrowserPlugin and must go through the
5932 // input redirection mechanism. It must not become focused direcly.
5933 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
5934 return;
5935
5936 RenderWidgetHostImpl* focused_widget =
5937 GetFocusedRenderWidgetHost(render_widget_host);
5938
5939 if (focused_widget != render_widget_host &&
avallee8e881592016-11-19 00:39:305940 (!focused_widget ||
5941 focused_widget->delegate() != render_widget_host->delegate())) {
avallee9993fca2016-11-17 06:16:505942 SetAsFocusedWebContentsIfNecessary();
5943 }
5944}
5945
[email protected]b172aee2012-04-10 17:05:265946void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:445947 // Notify observers.
ericwilligersde386342016-10-19 02:35:095948 for (auto& observer : observers_)
5949 observer.DidGetIgnoredUIEvent();
[email protected]fa1cf0b82010-01-15 21:49:445950}
5951
avic3aa8422015-11-09 20:57:225952void WebContentsImpl::RendererUnresponsive(
Lukasz Anforowicz52b93722018-06-20 16:11:395953 RenderWidgetHostImpl* render_widget_host,
5954 base::RepeatingClosure hang_monitor_restarter) {
ericwilligersde386342016-10-19 02:35:095955 for (auto& observer : observers_)
Avi Drissman1572e8c3c2018-02-02 19:06:365956 observer.OnRendererUnresponsive(render_widget_host->GetProcess());
afakhry98241832016-03-11 19:27:475957
avic031d392017-03-03 03:09:425958 if (ShouldIgnoreUnresponsiveRenderer())
[email protected]e5fc1632011-08-08 07:51:535959 return;
5960
Avi Drissman8920def2018-01-31 19:53:365961 if (!render_widget_host->renderer_initialized())
[email protected]55452902011-06-01 21:57:475962 return;
5963
Dave Tapuskac6146c52017-12-20 22:48:155964 if (delegate_)
Lukasz Anforowicz52b93722018-06-20 16:11:395965 delegate_->RendererUnresponsive(this, render_widget_host,
5966 std::move(hang_monitor_restarter));
[email protected]420ae012009-04-24 05:16:325967}
5968
avic3aa8422015-11-09 20:57:225969void WebContentsImpl::RendererResponsive(
5970 RenderWidgetHostImpl* render_widget_host) {
[email protected]6934a702011-12-20 00:04:515971 if (delegate_)
Avi Drissman1572e8c3c2018-02-02 19:06:365972 delegate_->RendererResponsive(this, render_widget_host);
[email protected]420ae012009-04-24 05:16:325973}
5974
[email protected]b172aee2012-04-10 17:05:265975void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:555976 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:325977 bool* proceed_to_fire_unload) {
ericwilligersde386342016-10-19 02:35:095978 for (auto& observer : observers_)
5979 observer.BeforeUnloadFired(proceed_time);
[email protected]6934a702011-12-20 00:04:515980 if (delegate_)
5981 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:095982 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:325983}
5984
[email protected]58d5cfe2013-07-10 02:40:525985void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:545986 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:235987 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:225988 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:545989}
5990
Jianzhou Fengd8720c72018-01-18 03:06:305991void WebContentsImpl::UpdateRenderViewSizeForRenderManager(bool is_main_frame) {
[email protected]8643e6d2012-01-18 20:26:105992 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
Jianzhou Fengd8720c72018-01-18 03:06:305993 gfx::Size size = GetSizeForNewRenderView(is_main_frame);
[email protected]0323ee42010-02-17 22:03:265994 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
5995 // here during container initialization and normal window size will be set
5996 // later. In case of tab duplication this resizing to 0x0 prevents setting
5997 // normal size later so just ignore it.
5998 if (!size.IsEmpty())
5999 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:326000}
6001
[email protected]af905902013-10-01 21:38:516002void WebContentsImpl::CancelModalDialogsForRenderManager() {
6003 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:546004 // deferrer would prevent us from swapping out. We also clear the state
6005 // because this is a cross-process navigation, which means that it's a new
6006 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:176007 //
6008 // Note that we don't bother telling browser_plugin_embedder_ because the
6009 // cross-process navigation will either destroy the browser plugins or not
6010 // require their dialogs to close.
avi5d3b8692016-10-12 22:00:466011 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:536012 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:466013 }
[email protected]af905902013-10-01 21:38:516014}
6015
[email protected]02d7b6e2014-06-24 21:01:506016void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
6017 RenderFrameHost* new_host,
6018 bool is_main_frame) {
6019 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:056020 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:506021 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:086022
[email protected]02d7b6e2014-06-24 21:01:506023 // Make sure the visible RVH reflects the new delegate's preferences.
6024 if (delegate_)
6025 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:396026
[email protected]02d7b6e2014-06-24 21:01:506027 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
dmazzoni62111452017-04-28 23:46:556028
6029 RenderWidgetHostViewBase* rwhv =
6030 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
6031 if (rwhv)
6032 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
[email protected]02d7b6e2014-06-24 21:01:506033 }
6034
6035 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:546036}
6037
naskof5940b9f2015-03-02 23:04:056038void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
6039 RenderViewHost* old_host,
6040 RenderViewHost* new_host) {
6041 NotifyViewSwapped(old_host, new_host);
6042}
6043
[email protected]b172aee2012-04-10 17:05:266044NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:196045 return GetController();
[email protected]3a3d47472010-07-15 21:03:546046}
6047
dcheng59716272016-04-09 05:19:086048std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:296049 const GURL& url) {
Dan Beam055fe8f2017-10-04 23:23:366050 return CreateWebUI(url);
[email protected]420ae012009-04-24 05:16:326051}
6052
[email protected]10f417c52011-12-28 21:04:236053NavigationEntry*
[email protected]b172aee2012-04-10 17:05:266054 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:326055 return controller_.GetLastCommittedEntry();
6056}
6057
creisadca9862017-06-16 19:12:116058InterstitialPageImpl* WebContentsImpl::GetInterstitialForRenderManager() {
6059 return interstitial_page_;
6060}
6061
lfgbede6392015-09-11 21:54:066062void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
6063 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:336064 RenderWidgetHostViewBase* rwh_view =
6065 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:526066
[email protected]420ae012009-04-24 05:16:326067 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:446068 if (rwh_view)
Jianzhou Fengd8720c72018-01-18 03:06:306069 rwh_view->SetSize(GetSizeForNewRenderView(true));
lfgbede6392015-09-11 21:54:066070}
6071
6072bool WebContentsImpl::CreateRenderViewForRenderManager(
6073 RenderViewHost* render_view_host,
6074 int opener_frame_routing_id,
6075 int proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066076 const base::UnguessableToken& devtools_frame_token,
lfgbede6392015-09-11 21:54:066077 const FrameReplicationState& replicated_frame_state) {
6078 TRACE_EVENT0("browser,navigation",
6079 "WebContentsImpl::CreateRenderViewForRenderManager");
6080
piman00cf9402017-04-03 17:09:206081 if (proxy_routing_id == MSG_ROUTING_NONE)
lfg9431efd2016-12-14 14:45:266082 CreateRenderWidgetHostViewForRenderManager(render_view_host);
lfg9431efd2016-12-14 14:45:266083
piman00cf9402017-04-03 17:09:206084 if (!static_cast<RenderViewHostImpl*>(render_view_host)
6085 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066086 devtools_frame_token, replicated_frame_state,
6087 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:526088 return false;
[email protected]14392a52012-05-02 20:28:446089 }
[email protected]a4127722011-04-27 23:13:526090
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:146091 if (proxy_routing_id == MSG_ROUTING_NONE && node_.outer_web_contents())
6092 ReattachToOuterWebContentsFrame();
6093
avi2b177592014-12-10 02:08:026094 SetHistoryOffsetAndLengthForView(render_view_host,
6095 controller_.GetLastCommittedEntryIndex(),
6096 controller_.GetEntryCount());
6097
[email protected]a220b5932013-09-21 03:47:446098#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:506099 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
6100 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:446101 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:446102 if (rwh_view) {
6103 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:166104 render_widget_host->SynchronizeVisualProperties();
[email protected]245f7d52011-11-28 15:36:446105 }
[email protected]f8233cc2011-05-31 20:24:506106#endif
6107
[email protected]420ae012009-04-24 05:16:326108 return true;
6109}
6110
[email protected]82307f6b2014-08-07 03:30:126111bool WebContentsImpl::CreateRenderFrameForRenderManager(
6112 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:046113 int proxy_routing_id,
6114 int opener_routing_id,
japhete6adf142014-10-31 00:01:496115 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:046116 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:436117 TRACE_EVENT0("browser,navigation",
6118 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:126119
6120 RenderFrameHostImpl* rfh =
6121 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:046122 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
6123 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:126124 return false;
6125
6126 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
6127 // RenderFrameHost will have to be associated with the appropriate
6128 // RenderWidgetHostView or a new one should be created here.
6129
6130 return true;
6131}
6132
mfomitchev2b8b066a2016-01-28 19:23:156133#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:456134
[email protected]155c7f22013-12-09 17:07:186135base::android::ScopedJavaLocalRef<jobject>
6136WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:406137 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:566138 return GetWebContentsAndroid()->GetJavaObject();
6139}
[email protected]155c7f22013-12-09 17:07:186140
[email protected]0e813a52014-08-13 10:34:566141WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:186142 WebContentsAndroid* web_contents_android =
6143 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
6144 if (!web_contents_android) {
6145 web_contents_android = new WebContentsAndroid(this);
avicb129c02017-05-03 06:49:296146 SetUserData(kWebContentsAndroidKey, base::WrapUnique(web_contents_android));
[email protected]155c7f22013-12-09 17:07:186147 }
[email protected]0e813a52014-08-13 10:34:566148 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:186149}
6150
paulmeyerc0b762b2016-04-13 11:55:176151void WebContentsImpl::ActivateNearestFindResult(float x,
6152 float y) {
6153 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
6154}
6155
6156void WebContentsImpl::RequestFindMatchRects(int current_version) {
6157 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
6158}
6159
[email protected]7d244f12013-08-22 21:41:516160bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:066161 return CreateRenderViewForRenderManager(
6162 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
Pavel Feldman25234722017-10-11 02:49:066163 frame_tree_.root()->devtools_frame_token(),
lfgbede6392015-09-11 21:54:066164 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:516165}
[email protected]fc2b46b2014-05-03 16:33:456166
rockot400ea35b2016-10-15 19:15:326167service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
sammcf5f1b0f2016-09-20 23:05:116168 if (!java_interfaces_) {
rockot400ea35b2016-10-15 19:15:326169 service_manager::mojom::InterfaceProviderPtr provider;
blundelle0a9f1582016-12-20 11:23:326170 BindInterfaceRegistryForWebContents(mojo::MakeRequest(&provider), this);
rockot400ea35b2016-10-15 19:15:326171 java_interfaces_.reset(new service_manager::InterfaceProvider);
sammcf5f1b0f2016-09-20 23:05:116172 java_interfaces_->Bind(std::move(provider));
6173 }
6174 return java_interfaces_.get();
6175}
6176
[email protected]fc2b46b2014-05-03 16:33:456177#elif defined(OS_MACOSX)
6178
[email protected]75f4df72014-07-16 22:39:426179void WebContentsImpl::SetAllowOtherViews(bool allow) {
6180 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:456181}
6182
[email protected]75f4df72014-07-16 22:39:426183bool WebContentsImpl::GetAllowOtherViews() {
6184 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:456185}
6186
spqchane72c3cb2017-06-30 23:02:106187bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() const {
6188 return did_first_visually_non_empty_paint_;
6189}
6190
[email protected]7d244f12013-08-22 21:41:516191#endif
6192
pkotwicz75ca8ffd2016-02-16 23:10:196193void WebContentsImpl::OnDidDownloadImage(
Avi Drissmana5a52dd2018-03-27 03:39:026194 ImageDownloadCallback callback,
pkotwicz75ca8ffd2016-02-16 23:10:196195 int id,
6196 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:526197 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:186198 const std::vector<SkBitmap>& images,
6199 const std::vector<gfx::Size>& original_image_sizes) {
Avi Drissmana5a52dd2018-03-27 03:39:026200 std::move(callback).Run(id, http_status_code, image_url, images,
6201 original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:196202}
6203
[email protected]6fba26d2014-04-29 09:38:286204void WebContentsImpl::OnDialogClosed(int render_process_id,
6205 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:266206 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:496207 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:266208 bool success,
[email protected]fcf75d42013-12-03 20:11:266209 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:286210 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
6211 render_frame_id);
[email protected]87de04b02014-04-08 22:14:496212 last_dialog_suppressed_ = dialog_was_suppressed;
6213
[email protected]beb440c2009-11-06 04:08:546214 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:236215 // It is possible for the current RenderFrameHost to have changed in the
6216 // meantime. Do not reset the navigation state in that case.
6217 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:256218 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:236219 controller_.DiscardNonCommittedEntries();
6220 }
[email protected]ec8e8b02013-06-19 04:57:106221
Charles Reis15d60b132017-11-03 17:43:476222 // Update the URL display either way, to avoid showing a stale URL.
6223 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
6224
ericwilligersde386342016-10-19 02:35:096225 for (auto& observer : observers_)
6226 observer.BeforeUnloadDialogCancelled();
[email protected]beb440c2009-11-06 04:08:546227 }
[email protected]87de04b02014-04-08 22:14:496228
[email protected]6fba26d2014-04-29 09:38:286229 if (rfh) {
avi44acfaa82017-05-03 22:55:356230 rfh->JavaScriptDialogClosed(reply_msg, success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:166231
6232 std::vector<protocol::PageHandler*> page_handlers =
6233 protocol::PageHandler::EnabledForWebContents(this);
6234 for (auto* handler : page_handlers)
6235 handler->DidCloseJavaScriptDialog(success, user_input);
6236
[email protected]6fba26d2014-04-29 09:38:286237 } else {
6238 // Don't leak the sync IPC reply if the RFH or process is gone.
6239 delete reply_msg;
6240 }
avi1c51fb62017-02-27 20:43:036241
6242 is_showing_javascript_dialog_ = false;
6243 is_showing_before_unload_dialog_ = false;
[email protected]beb440c2009-11-06 04:08:546244}
6245
[email protected]b172aee2012-04-10 17:05:266246void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:546247 if (encoding == last_reported_encoding_)
6248 return;
6249 last_reported_encoding_ = encoding;
6250
jinsukkim79df88a2017-01-04 06:26:156251 canonical_encoding_ = base::GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:106252}
[email protected]f45d2a72010-03-08 23:28:356253
[email protected]1ac10dca2013-08-20 20:47:046254bool WebContentsImpl::IsHidden() {
Francois Doraye6161152018-03-27 22:05:376255 return !IsBeingCaptured() && visibility_ != Visibility::VISIBLE;
[email protected]1ac10dca2013-08-20 20:47:046256}
6257
rob97250742015-12-10 17:45:156258int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lfg601233692017-03-06 22:45:446259 return node_.outer_contents_frame_tree_node_id();
lazyboy6ec48b2a2015-06-29 15:18:146260}
6261
ekaramadaeb3c5c2016-11-09 03:22:356262RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const {
6263 return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
6264 fullscreen_widget_routing_id_);
6265}
6266
[email protected]b0936d22013-11-28 06:47:366267RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:216268 return frame_tree_.root()->render_manager();
6269}
6270
[email protected]f8497342013-02-05 22:15:026271BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:396272 return browser_plugin_guest_.get();
6273}
6274
[email protected]738f57a2013-06-29 21:06:546275void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
6276 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:146277 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:546278 browser_plugin_guest_.reset(guest);
6279}
6280
[email protected]f8497342013-02-05 22:15:026281BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:396282 return browser_plugin_embedder_.get();
6283}
[email protected]8ff00d72012-10-23 19:12:216284
fsamuel60b42282015-03-10 03:29:146285void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
6286 if (browser_plugin_embedder_)
6287 return;
6288 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
6289}
6290
Jianzhou Fengd8720c72018-01-18 03:06:306291gfx::Size WebContentsImpl::GetSizeForNewRenderView(bool is_main_frame) {
[email protected]dc0fd432013-08-27 15:29:216292 gfx::Size size;
Jianzhou Fengd8720c72018-01-18 03:06:306293 if (is_main_frame)
6294 size = device_emulation_size_;
6295 if (size.IsEmpty() && delegate_)
[email protected]dc0fd432013-08-27 15:29:216296 size = delegate_->GetSizeForNewRenderView(this);
6297 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:456298 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:216299 return size;
6300}
6301
[email protected]ae7eeda2014-07-04 01:53:266302void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:096303 for (auto& observer : observers_)
6304 observer.FrameDeleted(render_frame_host);
[email protected]9b159a52013-10-03 17:24:556305}
6306
[email protected]222f5822014-02-05 23:40:496307void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
6308 if (!delegate_)
6309 return;
6310 const gfx::Size new_size = GetPreferredSize();
6311 if (new_size != old_size)
6312 delegate_->UpdatePreferredSize(this, new_size);
6313}
6314
Daniel Cheng90196c82018-04-25 21:49:146315void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) {
6316 for (auto& observer : observers_)
6317 observer.DidGetUserInteraction(type);
6318
6319 // TODO(https://crbug.com/827659): This used to check if type != kMouseWheel.
6320 // However, due to the caller already filtering event types, this would never
6321 // be called with type == kMouseWheel so checking for that here is pointless.
6322 // However, mouse wheel events *also* generate a kGestureScrollBegin event...
6323 // which is *not* filtered out. Maybe they should be?
6324 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
6325 if (rdh) // null in unittests. =(
6326 rdh->OnUserGesture();
6327}
6328
Dan Beam055fe8f2017-10-04 23:23:366329std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI(const GURL& url) {
Jeremy Roman04f27c372017-10-27 15:20:556330 std::unique_ptr<WebUIImpl> web_ui = std::make_unique<WebUIImpl>(this);
Lei Zhangee3b63ad2018-06-06 23:25:316331 std::unique_ptr<WebUIController> controller(
avie865b1d2016-10-24 19:42:596332 WebUIControllerFactoryRegistry::GetInstance()
Lei Zhangee3b63ad2018-06-06 23:25:316333 ->CreateWebUIControllerForURL(web_ui.get(), url));
dbeama1b926a2015-08-31 23:17:516334 if (controller) {
Jeremy Roman04f27c372017-10-27 15:20:556335 web_ui->AddMessageHandler(std::make_unique<GenericHandler>());
Lei Zhangee3b63ad2018-06-06 23:25:316336 web_ui->SetController(std::move(controller));
dbeama1b926a2015-08-31 23:17:516337 return web_ui;
6338 }
6339
avie865b1d2016-10-24 19:42:596340 return nullptr;
dbeama1b926a2015-08-31 23:17:516341}
6342
paulmeyerfeafc2d2017-04-25 21:46:406343FindRequestManager* WebContentsImpl::GetFindRequestManager() {
6344 for (WebContentsImpl* contents = this; contents;
6345 contents = contents->GetOuterWebContents()) {
6346 if (contents->find_request_manager_)
6347 return contents->find_request_manager_.get();
6348 }
6349
6350 return nullptr;
6351}
6352
paulmeyerc0b762b2016-04-13 11:55:176353FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
paulmeyerfeafc2d2017-04-25 21:46:406354 if (FindRequestManager* manager = GetFindRequestManager())
6355 return manager;
6356
6357 // No existing FindRequestManager found, so one must be created.
6358 find_request_manager_.reset(new FindRequestManager(this));
6359
6360 // Concurrent find sessions must not overlap, so destroy any existing
6361 // FindRequestManagers in any inner WebContentses.
6362 for (WebContentsImpl* contents : GetWebContentsAndAllInner()) {
6363 if (contents == this)
6364 continue;
6365 if (contents->find_request_manager_) {
6366 contents->find_request_manager_->StopFinding(
6367 content::STOP_FIND_ACTION_CLEAR_SELECTION);
6368 contents->find_request_manager_.release();
6369 }
6370 }
paulmeyerc0b762b2016-04-13 11:55:176371
6372 return find_request_manager_.get();
6373}
6374
6375void WebContentsImpl::NotifyFindReply(int request_id,
6376 int number_of_matches,
6377 const gfx::Rect& selection_rect,
6378 int active_match_ordinal,
6379 bool final_update) {
Sebastien Marchandcf97ed52017-07-24 23:50:346380 if (delegate_ && !is_being_destroyed_ &&
Lukasz Anforowicze9ae3722017-09-29 17:37:386381 !GetMainFrame()->GetProcess()->FastShutdownStarted()) {
paulmeyerc0b762b2016-04-13 11:55:176382 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
6383 active_match_ordinal, final_update);
6384 }
6385}
6386
ortuno467e5792016-06-10 04:32:396387void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
6388 // Trying to invalidate the tab state while being destroyed could result in a
6389 // use after free.
6390 if (IsBeingDestroyed()) {
6391 return;
6392 }
6393 // Notify for UI updates if the state changes.
6394 bluetooth_connected_device_count_++;
6395 if (bluetooth_connected_device_count_ == 1) {
6396 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6397 }
6398}
6399
6400void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
6401 // Trying to invalidate the tab state while being destroyed could result in a
6402 // use after free.
6403 if (IsBeingDestroyed()) {
6404 return;
6405 }
6406 // Notify for UI updates if the state changes.
Lukasz Anforowicze9ae3722017-09-29 17:37:386407 DCHECK_NE(bluetooth_connected_device_count_, 0u);
ortuno467e5792016-06-10 04:32:396408 bluetooth_connected_device_count_--;
6409 if (bluetooth_connected_device_count_ == 0) {
6410 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6411 }
6412}
6413
zqzhang8ac49002017-03-16 21:51:356414void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) {
6415 if (has_persistent_video_ == has_persistent_video)
mlamouri5cd9ae82017-02-18 11:05:096416 return;
6417
zqzhang8ac49002017-03-16 21:51:356418 has_persistent_video_ = has_persistent_video;
mlamouri5cd9ae82017-02-18 11:05:096419 NotifyPreferencesChanged();
zqzhang8ac49002017-03-16 21:51:356420 media_web_contents_observer()->RequestPersistentVideo(has_persistent_video);
mlamouri5cd9ae82017-02-18 11:05:096421}
6422
paulmeyerfeafc2d2017-04-25 21:46:406423void WebContentsImpl::BrowserPluginGuestWillDetach() {
6424 WebContentsImpl* outermost = GetOutermostWebContents();
6425 if (this != outermost && ContainsOrIsFocusedWebContents())
6426 outermost->SetAsFocusedWebContentsIfNecessary();
6427}
6428
Mounir Lamouri11e9ef42018-05-22 03:10:166429gfx::Size WebContentsImpl::EnterPictureInPicture(
6430 const viz::SurfaceId& surface_id,
6431 const gfx::Size& natural_size) {
6432 return delegate_ ? delegate_->EnterPictureInPicture(surface_id, natural_size)
6433 : gfx::Size();
6434}
6435
Mounir Lamouri6d759e12018-05-16 20:01:306436void WebContentsImpl::ExitPictureInPicture() {
6437 if (delegate_)
6438 delegate_->ExitPictureInPicture();
6439}
6440
paulmeyerc0b762b2016-04-13 11:55:176441#if defined(OS_ANDROID)
6442void WebContentsImpl::NotifyFindMatchRectsReply(
6443 int version,
6444 const std::vector<gfx::RectF>& rects,
6445 const gfx::RectF& active_rect) {
6446 if (delegate_)
6447 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
6448}
6449#endif
6450
[email protected]34ff1cfc2014-08-20 06:16:056451void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
6452 force_disable_overscroll_content_ = force_disable;
6453 if (view_)
6454 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
6455}
6456
Jianzhou Fengd8720c72018-01-18 03:06:306457bool WebContentsImpl::SetDeviceEmulationSize(const gfx::Size& new_size) {
6458 device_emulation_size_ = new_size;
6459 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
6460
6461 const gfx::Size current_size = rwhv->GetViewBounds().size();
6462 if (view_size_before_emulation_.IsEmpty())
6463 view_size_before_emulation_ = current_size;
6464
6465 if (current_size != new_size)
6466 rwhv->SetSize(new_size);
6467
6468 return current_size != new_size;
6469}
6470
6471void WebContentsImpl::ClearDeviceEmulationSize() {
6472 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
6473 // WebContentsView could get resized during emulation, which also resizes
6474 // RWHV. If it happens, assume user would like to keep using the size after
6475 // emulation.
6476 // TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when
6477 // WebContentsView size changes).
Dmitry Gozmanc63707182018-03-06 00:09:396478 if (!view_size_before_emulation_.IsEmpty() && rwhv &&
6479 rwhv->GetViewBounds().size() == device_emulation_size_) {
Jianzhou Fengd8720c72018-01-18 03:06:306480 rwhv->SetSize(view_size_before_emulation_);
Dmitry Gozmanc63707182018-03-06 00:09:396481 }
Jianzhou Fengd8720c72018-01-18 03:06:306482 device_emulation_size_ = gfx::Size();
6483 view_size_before_emulation_ = gfx::Size();
6484}
6485
Max Morin5bc74f52018-05-09 07:00:216486ForwardingAudioStreamFactory* WebContentsImpl::GetAudioStreamFactory() {
6487 if (!audio_stream_factory_) {
6488 audio_stream_factory_.emplace(
6489 this,
6490 content::ServiceManagerConnection::GetForProcess()
6491 ->GetConnector()
6492 ->Clone(),
6493 AudioStreamBrokerFactory::CreateImpl());
6494 }
6495
6496 return &*audio_stream_factory_;
6497}
6498
dalecurtis88c240072015-12-09 02:11:186499void WebContentsImpl::MediaStartedPlaying(
billorr21c005d2016-11-17 03:57:046500 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:186501 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:046502 if (media_info.has_video)
6503 currently_playing_video_count_++;
6504
ericwilligersde386342016-10-19 02:35:096505 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:046506 observer.MediaStartedPlaying(media_info, id);
dalecurtis88c240072015-12-09 02:11:186507}
6508
6509void WebContentsImpl::MediaStoppedPlaying(
billorr21c005d2016-11-17 03:57:046510 const WebContentsObserver::MediaPlayerInfo& media_info,
Becca Hughes220bfc102017-11-14 18:24:076511 const WebContentsObserver::MediaPlayerId& id,
6512 WebContentsObserver::MediaStoppedReason reason) {
billorr21c005d2016-11-17 03:57:046513 if (media_info.has_video)
6514 currently_playing_video_count_--;
6515
ericwilligersde386342016-10-19 02:35:096516 for (auto& observer : observers_)
Becca Hughes220bfc102017-11-14 18:24:076517 observer.MediaStoppedPlaying(media_info, id, reason);
billorr21c005d2016-11-17 03:57:046518}
6519
peconn257951522017-06-09 18:24:596520void WebContentsImpl::MediaResized(
6521 const gfx::Size& size,
6522 const WebContentsObserver::MediaPlayerId& id) {
6523 cached_video_sizes_[id] = size;
6524
6525 for (auto& observer : observers_)
6526 observer.MediaResized(size, id);
6527}
6528
Peter E Conneccb34c22017-09-08 09:37:586529void WebContentsImpl::MediaEffectivelyFullscreenChanged(bool is_fullscreen) {
6530 for (auto& observer : observers_)
6531 observer.MediaEffectivelyFullscreenChanged(is_fullscreen);
6532}
6533
Peter Conn31c726a2017-08-17 11:07:346534base::Optional<gfx::Size> WebContentsImpl::GetFullscreenVideoSize() {
6535 base::Optional<WebContentsObserver::MediaPlayerId> id =
6536 media_web_contents_observer_->GetFullscreenVideoMediaPlayerId();
6537 if (id && cached_video_sizes_.count(id.value()))
6538 return base::Optional<gfx::Size>(cached_video_sizes_[id.value()]);
6539 return base::Optional<gfx::Size>();
peconn257951522017-06-09 18:24:596540}
6541
billorr21c005d2016-11-17 03:57:046542int WebContentsImpl::GetCurrentlyPlayingVideoCount() {
6543 return currently_playing_video_count_;
dalecurtis88c240072015-12-09 02:11:186544}
6545
Francois Doraye6161152018-03-27 22:05:376546void WebContentsImpl::UpdateWebContentsVisibility(Visibility visibility) {
Francois Doray3f2afbd2018-04-06 19:18:186547 // Occlusion is disabled when |features::kWebContentsOcclusion| is disabled
6548 // (for power and speed impact assessment) or when
6549 // |switches::kDisableBackgroundingOccludedWindowsForTesting| is specified on
6550 // the command line (to avoid flakiness in browser tests).
6551 const bool occlusion_is_disabled =
6552 !base::FeatureList::IsEnabled(features::kWebContentsOcclusion) ||
Francois Doraye6161152018-03-27 22:05:376553 base::CommandLine::ForCurrentProcess()->HasSwitch(
6554 switches::kDisableBackgroundingOccludedWindowsForTesting);
6555 if (occlusion_is_disabled && visibility == Visibility::OCCLUDED)
6556 visibility = Visibility::VISIBLE;
6557
tapted65ff2ea72016-03-01 23:39:006558 if (!did_first_set_visible_) {
Francois Doraye6161152018-03-27 22:05:376559 if (visibility == Visibility::VISIBLE) {
6560 // A WebContents created with CreateParams::initially_hidden = false
6561 // starts with GetVisibility() == Visibility::VISIBLE even though it is
6562 // not really visible. Call WasShown() when it becomes visible for real as
6563 // the page load mechanism and some WebContentsObserver rely on that.
tapted65ff2ea72016-03-01 23:39:006564 WasShown();
Francois Dorayfe4a1772018-02-17 04:17:096565 did_first_set_visible_ = true;
tapted65ff2ea72016-03-01 23:39:006566 }
Francois Doraye6161152018-03-27 22:05:376567
6568 // Trust the initial visibility of the WebContents and do not switch it to
6569 // HIDDEN or OCCLUDED before it becomes VISIBLE for real. Doing so would
6570 // result in destroying resources that would immediately be recreated (e.g.
6571 // UpdateWebContents(HIDDEN) can be called when a WebContents is added to a
6572 // hidden window that is about to be shown).
6573
tapted65ff2ea72016-03-01 23:39:006574 return;
6575 }
Francois Doraye6161152018-03-27 22:05:376576
6577 if (visibility == visibility_)
tapted65ff2ea72016-03-01 23:39:006578 return;
6579
Francois Doraye6161152018-03-27 22:05:376580 if (visibility == Visibility::VISIBLE)
tapted65ff2ea72016-03-01 23:39:006581 WasShown();
Francois Doraye6161152018-03-27 22:05:376582 else if (visibility == Visibility::OCCLUDED)
6583 WasOccluded();
tapted65ff2ea72016-03-01 23:39:006584 else
6585 WasHidden();
6586}
6587
aelias5252baa2016-04-10 01:18:026588void WebContentsImpl::UpdateOverridingUserAgent() {
mlamouri5cd9ae82017-02-18 11:05:096589 NotifyPreferencesChanged();
aelias5252baa2016-04-10 01:18:026590}
6591
avid53461d2016-02-25 17:15:046592void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
6593 JavaScriptDialogManager* dialog_manager) {
6594 dialog_manager_ = dialog_manager;
6595}
6596
rockotf62002a2016-09-15 00:08:596597void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) {
6598 auto it = binding_sets_.find(interface_name);
6599 if (it != binding_sets_.end())
6600 binding_sets_.erase(it);
6601}
6602
nzolghadrd87a308d2016-12-07 15:45:566603bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) {
nzolghadrbbffc6c2017-05-25 17:56:396604 // Here we associate this metric to the main frame URL regardless of what
6605 // caused it.
nzolghadrd87a308d2016-12-07 15:45:566606 sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL(
6607 GetLastCommittedURL()));
nzolghadrd87a308d2016-12-07 15:45:566608 return true;
6609}
6610
ekaramada110f642016-12-21 19:47:286611void WebContentsImpl::FocusedNodeTouched(bool editable) {
6612#if defined(OS_WIN)
ekaramada110f642016-12-21 19:47:286613 RenderWidgetHostView* view = GetRenderWidgetHostView();
6614 if (!view)
6615 return;
Dave Tapuska2315d8f2018-03-06 17:52:556616 view->FocusedNodeTouched(editable);
ekaramada110f642016-12-21 19:47:286617#endif
6618}
6619
samans90fb8162017-04-04 22:30:456620void WebContentsImpl::DidReceiveCompositorFrame() {
6621 for (auto& observer : observers_)
6622 observer.DidReceiveCompositorFrame();
6623}
6624
falken52a56e32016-12-08 05:02:406625void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() {
6626 bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch(
6627 switches::kAllowInsecureLocalhost);
6628 if (!allow_localhost)
6629 return;
6630
6631 content::NavigationEntry* entry = GetController().GetLastCommittedEntry();
Rob Wuf79b3ba2018-01-14 01:54:316632 if (!entry || !net::IsLocalhost(entry->GetURL()))
falken52a56e32016-12-08 05:02:406633 return;
6634
6635 content::SSLStatus ssl_status = entry->GetSSL();
6636 bool is_cert_error = net::IsCertStatusError(ssl_status.cert_status) &&
6637 !net::IsCertStatusMinorError(ssl_status.cert_status);
6638 if (!is_cert_error)
6639 return;
6640
6641 GetMainFrame()->AddMessageToConsole(
6642 content::CONSOLE_MESSAGE_LEVEL_WARNING,
6643 base::StringPrintf("This site does not have a valid SSL "
6644 "certificate! Without SSL, your site's and "
6645 "visitors' data is vulnerable to theft and "
6646 "tampering. Get a valid SSL certificate before"
6647 " releasing your website to the public."));
6648}
6649
ekaramadf6750aa2017-06-06 18:29:426650bool WebContentsImpl::IsShowingContextMenuOnPage() const {
6651 return showing_context_menu_;
6652}
6653
Min Qina904f3302018-02-13 23:33:346654download::DownloadUrlParameters::RequestHeadersType
6655WebContentsImpl::ParseDownloadHeaders(const std::string& headers) {
6656 download::DownloadUrlParameters::RequestHeadersType request_headers;
Megan Jablonski2f6a4c52017-07-10 23:01:256657 for (const base::StringPiece& key_value : base::SplitStringPiece(
6658 headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
6659 std::vector<std::string> pair = base::SplitString(
6660 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
6661 if (2ul == pair.size())
6662 request_headers.push_back(make_pair(pair[0], pair[1]));
6663 }
6664 return request_headers;
6665}
6666
lukasza6f8ac622017-06-06 03:10:206667void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener,
6668 bool opener_suppressed) {
6669 if (opener) {
6670 FrameTreeNode* new_root = GetFrameTree()->root();
6671
6672 // For the "original opener", track the opener's main frame instead, because
6673 // if the opener is a subframe, the opener tracking could be easily bypassed
6674 // by spawning from a subframe and deleting the subframe.
6675 // https://crbug.com/705316
6676 new_root->SetOriginalOpener(opener->frame_tree()->root());
6677
6678 if (!opener_suppressed) {
6679 new_root->SetOpener(opener);
6680 created_with_opener_ = true;
6681 }
6682 }
6683}
6684
Becca Hughes9f6fd4b82017-06-15 10:01:406685void WebContentsImpl::MediaMutedStatusChanged(
6686 const WebContentsObserver::MediaPlayerId& id,
6687 bool muted) {
6688 for (auto& observer : observers_)
6689 observer.MediaMutedStatusChanged(id, muted);
6690}
6691
EhsanK2075c7e2017-08-21 02:42:396692void WebContentsImpl::SetVisibilityForChildViews(bool visible) {
6693 GetMainFrame()->SetVisibilityForChildViews(visible);
6694}
6695
[email protected]8ff00d72012-10-23 19:12:216696} // namespace content