blob: f5d3d5fc78be4b138b813b8751bb3418757716de [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"
erikchen35629cc2015-03-10 20:43:2226#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0727#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5128#include "base/strings/string16.h"
29#include "base/strings/string_number_conversions.h"
30#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0031#include "base/strings/utf_string_conversions.h"
gab30f26df2016-05-11 19:37:5532#include "base/threading/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3733#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4234#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1035#include "build/build_config.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]8bd9e562011-08-16 23:55:4647#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1248#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1649#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1750#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1651#include "content/browser/frame_host/cross_process_frame_connector.h"
ananta4b7467a52016-09-23 01:42:3852#include "content/browser/frame_host/frame_tree_node.h"
[email protected]d4a8ca482013-10-30 21:06:4053#include "content/browser/frame_host/interstitial_page_impl.h"
54#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3355#include "content/browser/frame_host/navigation_handle_impl.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"
[email protected]bffc8302014-01-23 20:52:1659#include "content/browser/frame_host/render_widget_host_view_child_frame.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"
dalecurtisbc6572e12014-09-12 19:22:3063#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5264#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1865#include "content/browser/media/media_web_contents_observer.h"
zqzhang1adf3cb2016-11-01 11:26:4566#include "content/browser/media/session/media_session_impl.h"
tommyclieb25b2a2014-11-03 19:45:0967#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3068#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5069#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3270#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5071#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5972#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4873#include "content/browser/renderer_host/render_widget_host_view_base.h"
ekaramadadd882292016-06-08 15:22:5674#include "content/browser/renderer_host/text_input_manager.h"
leon.han552e9de2017-02-09 14:37:3075#include "content/browser/screen_orientation/screen_orientation_provider.h"
[email protected]b6583592012-01-25 19:52:3376#include "content/browser/site_instance_impl.h"
lfgc740d4b22016-04-15 16:45:3377#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1178#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5879#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0380#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5681#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1482#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4283#include "content/common/browser_plugin/browser_plugin_messages.h"
Paul Meyer0c58c3712016-11-17 22:59:5184#include "content/common/drag_messages.h"
[email protected]f114fa42013-12-06 17:06:4485#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1786#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0787#include "content/common/page_messages.h"
nasko34634672016-07-29 18:46:0688#include "content/common/page_state_serialization.h"
rockot5c478a72016-09-28 23:14:1889#include "content/common/render_message_filter.mojom.h"
avi286019ce2015-07-29 01:26:5890#include "content/common/site_isolation_policy.h"
[email protected]2c5569662011-03-22 20:45:0291#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3692#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1193#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2894#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4495#include "content/public/browser/content_browser_client.h"
[email protected]e582fdd2011-12-20 16:48:1796#include "content/public/browser/download_manager.h"
ekaramada110f642016-12-21 19:47:2897#include "content/public/browser/focused_node_details.h"
ekaramad1beabecc2016-09-23 20:18:1798#include "content/public/browser/guest_mode.h"
[email protected]d9083482012-01-06 00:38:4699#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:15100#include "content/public/browser/javascript_dialog_manager.h"
skyf65d9bb2017-03-24 02:26:39101#include "content/public/browser/keyboard_event_processing_result.h"
[email protected]09d31d52012-03-11 22:30:27102#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:00103#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:37104#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:14105#include "content/public/browser/notification_service.h"
scottmg011d96e32016-06-29 19:15:08106#include "content/public/browser/notification_types.h"
[email protected]95640212014-07-26 18:14:30107#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:32108#include "content/public/browser/resource_request_details.h"
estark5ea80e52015-06-19 18:43:12109#include "content/public/browser/security_style_explanations.h"
falken52a56e32016-12-08 05:02:40110#include "content/public/browser/ssl_status.h"
[email protected]4c3a23582012-08-18 08:54:34111#include "content/public/browser/storage_partition.h"
rockotf62002a2016-09-15 00:08:59112#include "content/public/browser/web_contents_binding_set.h"
[email protected]674bc592011-12-20 23:00:42113#include "content/public/browser/web_contents_delegate.h"
dtapuskae99ec6e52016-10-18 00:15:42114#include "content/public/browser/web_contents_unresponsive_state.h"
[email protected]e091df82011-10-11 18:13:21115#include "content/public/common/bindings_policy.h"
carloskd80262f52015-12-16 14:40:35116#include "content/public/common/browser_side_navigation_policy.h"
alexmosc9e76ec2016-05-16 22:59:37117#include "content/public/common/child_process_host.h"
[email protected]54087fe2011-10-28 22:02:48118#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54119#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49120#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20121#include "content/public/common/result_codes.h"
[email protected]f16cc6782013-12-16 23:42:57122#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05123#include "content/public/common/web_preferences.h"
Conley Owens6894c4f2017-07-10 19:29:13124#include "device/geolocation/geolocation_context.h"
wjmaclean64951902016-04-29 20:59:12125#include "net/base/url_util.h"
[email protected]8bfc8272013-09-09 20:10:53126#include "net/http/http_cache.h"
127#include "net/http/http_transaction_factory.h"
rhalavati0fbaeef32017-06-01 15:56:30128#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]8bfc8272013-09-09 20:10:53129#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34130#include "net/url_request/url_request_context_getter.h"
brettw4b461082016-11-19 18:55:16131#include "ppapi/features/features.h"
Mounir Lamourifd9dcefa2017-07-06 10:26:55132#include "services/metrics/public/cpp/ukm_recorder.h"
rockot734fb662016-10-15 16:41:30133#include "services/service_manager/public/cpp/interface_provider.h"
Kinuko Yasuda74702f92017-07-31 03:27:53134#include "third_party/WebKit/common/mime_util/mime_util.h"
estark47ba9c7d2016-10-11 15:40:11135#include "third_party/WebKit/public/platform/WebSecurityStyle.h"
alexmosaedfc6f2016-01-21 23:57:38136#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40137#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39138#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56139#include "ui/base/layout.h"
chongz4a9751942016-08-17 17:49:39140#include "ui/events/blink/web_input_event_traits.h"
[email protected]66bd5512012-08-01 02:02:52141#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31142
ekaramada110f642016-12-21 19:47:28143#if defined(OS_WIN)
144#include "content/browser/renderer_host/dip_util.h"
145#include "ui/gfx/geometry/dip_util.h"
146#endif
147
[email protected]583418cc2013-01-17 14:01:10148#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40149#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15150#include "content/browser/android/date_time_chooser_android.h"
sammcf5f1b0f2016-09-20 23:05:11151#include "content/browser/android/java_interfaces_impl.h"
dalecurtisc85ed632016-01-13 00:22:46152#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18153#include "content/browser/web_contents/web_contents_android.h"
leon.han02ed4aeb2017-05-23 06:33:33154#include "services/device/public/interfaces/nfc.mojom.h"
mcnee336ea2c2017-05-23 22:50:59155#else // !OS_ANDROID
156#include "content/browser/host_zoom_map_impl.h"
157#include "content/browser/host_zoom_map_observer.h"
mfomitchev2b8b066a2016-01-28 19:23:15158#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10159
[email protected]f66df822012-05-18 16:52:17160#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50161#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57162#endif
[email protected]3e45ba92009-02-20 21:09:00163
sadrul943e3b32016-08-04 18:22:59164#if defined(USE_AURA)
bend32292b2016-10-07 00:21:58165#include "content/public/common/service_manager_connection.h"
fsamuel9cf7bdf2015-11-20 02:19:32166#endif
167
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"
170#endif // ENABLE_PLUGINS
171
[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;
[email protected]155c7f22013-12-09 17:07:18180#endif // OS_ANDROID
181
scottmg5e65e3a2017-03-08 08:48:46182base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback>>::
183 DestructorAtExit g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
[email protected]cbb1ef592013-06-05 19:49:46184
[email protected]8bfc8272013-09-09 20:10:53185void NotifyCacheOnIO(
186 scoped_refptr<net::URLRequestContextGetter> request_context,
187 const GURL& url,
188 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58189 net::HttpCache* cache = request_context->GetURLRequestContext()->
190 http_transaction_factory()->GetCache();
191 if (cache)
192 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53193}
194
dcheng57e39e22016-01-21 00:25:38195bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
196 for (FrameTreeNode* node : tree->Nodes()) {
197 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
198 return true;
alexmos4cf2aa32015-07-15 23:40:43199 }
dcheng57e39e22016-01-21 00:25:38200 return false;
[email protected]95640212014-07-26 18:14:30201}
202
kenrb19221852016-04-29 17:21:40203bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) {
204 // This method scans the frame tree rather than checking whether
205 // host->delegate() == this, which allows it to return false when the host
206 // for a frame that is pending or pending deletion.
207 if (!host)
208 return false;
209
210 for (FrameTreeNode* node : tree->Nodes()) {
211 if (node->current_frame_host()->GetRenderWidgetHost() == host)
212 return true;
213 }
214 return false;
215}
216
dmazzonif8a31042016-12-03 00:52:13217void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) {
218 static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode();
[email protected]95640212014-07-26 18:14:30219}
220
dtseng0dd3fa12015-07-22 19:00:52221void ResetAccessibility(RenderFrameHost* rfh) {
222 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
223}
224
dmazzonid95ae842016-04-12 21:17:39225using AXTreeSnapshotCallback =
226 base::Callback<void(const ui::AXTreeUpdate&)>;
227
228// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
229// Handles the callbacks from parallel snapshot requests to each frame,
230// and feeds the results to an AXTreeCombiner, which converts them into a
231// single combined accessibility tree.
232class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
233 public:
234 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
235 : callback_(callback) {
236 }
237
238 AXTreeSnapshotCallback AddFrame(bool is_root) {
239 // Adds a reference to |this|.
240 return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot,
241 this,
242 is_root);
243 }
244
245 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
246 combiner_.AddTree(snapshot, is_root);
247 }
248
249 private:
250 friend class base::RefCounted<AXTreeSnapshotCombiner>;
251
252 // This is called automatically after the last call to ReceiveSnapshot
253 // when there are no more references to this object.
254 ~AXTreeSnapshotCombiner() {
255 combiner_.Combine();
256 callback_.Run(combiner_.combined());
257 }
258
259 ui::AXTreeCombiner combiner_;
260 AXTreeSnapshotCallback callback_;
261};
262
paulmeyerfeafc2d2017-04-25 21:46:40263// Helper for GetInnerWebContents().
264bool GetInnerWebContentsHelper(
265 std::vector<WebContentsImpl*>* all_guest_contents,
266 WebContents* guest_contents) {
267 all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents));
268 return false;
269}
270
lukasza6f8ac622017-06-06 03:10:20271FrameTreeNode* FindOpener(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21272 FrameTreeNode* opener_node = nullptr;
273 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
274 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
275 params.opener_render_process_id, params.opener_render_frame_id);
276 if (opener_rfh)
277 opener_node = opener_rfh->frame_tree_node();
278 }
lukasza6f8ac622017-06-06 03:10:20279 return opener_node;
280}
281
Pavel Feldman3c1842b2017-08-02 05:00:16282// Ensures that OnDialogClosed is only called once.
283class CloseDialogCallbackWrapper
284 : public base::RefCountedThreadSafe<CloseDialogCallbackWrapper> {
285 public:
286 CloseDialogCallbackWrapper(
287 const base::Callback<void(bool, bool, const base::string16&)> callback)
288 : callback_(callback) {}
289
290 void Run(bool dialog_was_suppressed,
291 bool success,
292 const base::string16& user_input) {
293 if (already_fired_)
294 return;
295 already_fired_ = true;
296 callback_.Run(dialog_was_suppressed, success, user_input);
297 }
298
299 private:
300 friend class base::RefCountedThreadSafe<CloseDialogCallbackWrapper>;
301 ~CloseDialogCallbackWrapper() {}
302 bool already_fired_ = false;
303 base::Callback<void(bool, bool, const base::string16&)> callback_;
304};
305
lukasza6f8ac622017-06-06 03:10:20306} // namespace
307
308WebContents* WebContents::Create(const WebContents::CreateParams& params) {
309 return WebContentsImpl::CreateWithOpener(params, FindOpener(params));
[email protected]d1198fd2012-08-13 22:50:19310}
311
312WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59313 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30314 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21315 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
lukasza6f8ac622017-06-06 03:10:20316 new_contents->SetOpenerForNewContents(FindOpener(params),
317 params.opener_suppressed);
[email protected]fdac6ade2013-07-20 01:06:30318
319 for (SessionStorageNamespaceMap::const_iterator it =
320 session_storage_namespace_map.begin();
321 it != session_storage_namespace_map.end();
322 ++it) {
323 new_contents->GetController()
324 .SetSessionStorageNamespace(it->first, it->second.get());
325 }
326
[email protected]54944cde2012-12-09 09:24:59327 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19328 return new_contents;
[email protected]a81343d232011-12-27 07:39:20329}
[email protected]746d3052012-05-22 15:15:47330
benwells5e7260d2017-03-20 23:36:33331void WebContentsImpl::FriendWrapper::AddCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37332 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46333 g_created_callbacks.Get().push_back(callback);
334}
335
benwells5e7260d2017-03-20 23:36:33336void WebContentsImpl::FriendWrapper::RemoveCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37337 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46338 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
339 if (g_created_callbacks.Get().at(i).Equals(callback)) {
340 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
341 return;
342 }
343 }
344}
345
avidf38c952015-10-27 13:45:13346WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
347 if (!rvh)
348 return nullptr;
[email protected]746d3052012-05-22 15:15:47349 return rvh->GetDelegate()->GetAsWebContents();
350}
351
[email protected]a86c0e962013-12-17 17:10:39352WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13353 if (!rfh)
354 return nullptr;
355 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39356}
357
ananta4b7467a52016-09-23 01:42:38358WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) {
359 FrameTreeNode* frame_tree_node =
360 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
anantab8cfa3b2016-10-14 22:43:19361 if (!frame_tree_node)
362 return nullptr;
jam8c4edd02017-05-06 18:50:33363 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
ananta4b7467a52016-09-23 01:42:38364}
365
leon.han552e9de2017-02-09 14:37:30366void WebContents::SetScreenOrientationDelegate(
367 ScreenOrientationDelegate* delegate) {
368 ScreenOrientationProvider::SetDelegate(delegate);
369}
370
[email protected]7fff43e2013-05-21 20:21:10371// WebContentsImpl::DestructionObserver ----------------------------------------
372
373class WebContentsImpl::DestructionObserver : public WebContentsObserver {
374 public:
375 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
376 : WebContentsObserver(watched_contents),
377 owner_(owner) {
378 }
379
380 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58381 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58382 owner_->OnWebContentsDestroyed(
383 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10384 }
385
386 private:
387 WebContentsImpl* owner_;
388
389 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
390};
391
[email protected]8ed16472014-04-11 19:02:48392WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
393 int render_frame_id,
394 ColorChooser* chooser,
395 int identifier)
396 : render_process_id(render_process_id),
397 render_frame_id(render_frame_id),
398 chooser(chooser),
399 identifier(identifier) {
400}
401
402WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
403}
404
nicka0ac8382016-12-15 23:59:23405bool WebContentsImpl::ColorChooserInfo::Matches(
406 RenderFrameHostImpl* render_frame_host,
407 int color_chooser_id) {
408 return this->render_process_id == render_frame_host->GetProcess()->GetID() &&
409 this->render_frame_id == render_frame_host->GetRoutingID() &&
410 this->identifier == color_chooser_id;
411}
412
lazyboy6ec48b2a2015-06-29 15:18:14413// WebContentsImpl::WebContentsTreeNode ----------------------------------------
lfg601233692017-03-06 22:45:44414WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode(
415 WebContentsImpl* current_web_contents)
416 : current_web_contents_(current_web_contents),
417 outer_web_contents_(nullptr),
lazyboy6ec48b2a2015-06-29 15:18:14418 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33419 FrameTreeNode::kFrameTreeNodeInvalidId),
lfg601233692017-03-06 22:45:44420 focused_web_contents_(current_web_contents) {}
lazyboy6ec48b2a2015-06-29 15:18:14421
422WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
lfga3e2bdc2017-03-07 20:44:01423 if (OuterContentsFrameTreeNode())
424 OuterContentsFrameTreeNode()->RemoveObserver(this);
paulmeyerfeafc2d2017-04-25 21:46:40425
426 if (outer_web_contents_)
427 outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_);
lazyboy6ec48b2a2015-06-29 15:18:14428}
429
430void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
431 WebContentsImpl* outer_web_contents,
432 RenderFrameHostImpl* outer_contents_frame) {
lfg601233692017-03-06 22:45:44433 focused_web_contents_ = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:14434 outer_web_contents_ = outer_web_contents;
435 outer_contents_frame_tree_node_id_ =
436 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
437
paulmeyerfeafc2d2017-04-25 21:46:40438 outer_web_contents_->node_.AttachInnerWebContents(current_web_contents_);
lfga3e2bdc2017-03-07 20:44:01439 outer_contents_frame->frame_tree_node()->AddObserver(this);
lfg601233692017-03-06 22:45:44440}
lazyboy6ec48b2a2015-06-29 15:18:14441
paulmeyerfeafc2d2017-04-25 21:46:40442void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents(
443 WebContentsImpl* inner_web_contents) {
444 inner_web_contents_.push_back(inner_web_contents);
445}
446
447void WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents(
448 WebContentsImpl* inner_web_contents) {
449 DCHECK(std::find(inner_web_contents_.begin(), inner_web_contents_.end(),
450 inner_web_contents) != inner_web_contents_.end());
451 inner_web_contents_.erase(
452 std::remove(inner_web_contents_.begin(), inner_web_contents_.end(),
453 inner_web_contents),
454 inner_web_contents_.end());
455}
456
lfga3e2bdc2017-03-07 20:44:01457FrameTreeNode*
458WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const {
459 return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_);
lfg601233692017-03-06 22:45:44460}
461
lfga3e2bdc2017-03-07 20:44:01462void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed(
463 FrameTreeNode* node) {
464 DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id())
465 << "WebContentsTreeNode should only receive notifications for the "
466 "FrameTreeNode in its outer WebContents that hosts it.";
467 delete current_web_contents_; // deletes |this| too.
lazyboy6ec48b2a2015-06-29 15:18:14468}
469
avallee0206f782016-07-28 18:55:33470void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
471 WebContentsImpl* web_contents) {
472 DCHECK(!outer_web_contents())
473 << "Only the outermost WebContents tracks focus.";
474 focused_web_contents_ = web_contents;
475}
476
paulmeyerfeafc2d2017-04-25 21:46:40477WebContentsImpl*
478WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame(
479 const FrameTreeNode* frame) {
480 auto ftn_id = frame->frame_tree_node_id();
481 for (WebContentsImpl* contents : inner_web_contents_) {
482 if (contents->node_.outer_contents_frame_tree_node_id() == ftn_id) {
483 return contents;
484 }
485 }
486 return nullptr;
487}
488
489const std::vector<WebContentsImpl*>&
490WebContentsImpl::WebContentsTreeNode::inner_web_contents() const {
491 return inner_web_contents_;
492}
493
[email protected]b172aee2012-04-10 17:05:26494// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32495
alexmose201c7cd2015-06-10 17:14:21496WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42497 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22498 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57499 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21500 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01501 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57502 this,
503 this,
504 this,
505 this),
lfg601233692017-03-06 22:45:44506 node_(this),
[email protected]6dfed692014-05-22 04:18:03507 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23508 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
509 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34510 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26511 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56512 upload_size_(0),
513 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16514 is_resume_pending_(false),
creisadca9862017-06-16 19:12:11515 interstitial_page_(nullptr),
[email protected]b4c84012014-04-28 19:51:10516 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28517 theme_color_(SK_ColorTRANSPARENT),
518 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29519 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55520 capturer_count_(0),
521 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00522 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57523 is_being_destroyed_(false),
creis97867aa2017-02-17 18:39:45524 is_notifying_observers_(false),
[email protected]fdd61c62009-04-22 19:22:57525 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15526 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01527 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39528 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38529 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21530 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
531 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22532 zoom_scroll_remainder_(0),
alexmosc9e76ec2016-05-16 22:59:37533 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42534 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03535 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49536 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05537 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30538 last_dialog_suppressed_(false),
Conley Owens6894c4f2017-07-10 19:29:13539 geolocation_context_(new device::GeolocationContext()),
waffles1c12bf402016-02-10 17:45:48540 accessibility_mode_(
541 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15542 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35543 bluetooth_connected_device_count_(0),
mohan.reddyaae039a2014-11-21 17:39:50544 virtual_keyboard_requested_(false),
mcnee336ea2c2017-05-23 22:50:59545#if !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:46546 page_scale_factor_is_one_(true),
mcnee336ea2c2017-05-23 22:50:59547#endif // !defined(OS_ANDROID)
lfgbee1e0a2016-06-08 21:24:21548 mouse_lock_widget_(nullptr),
qinmin72e8bd02016-10-21 19:35:37549 is_overlay_content_(false),
ekaramadf6750aa2017-06-06 18:29:42550 showing_context_menu_(false),
pkotwicz75ca8ffd2016-02-16 23:10:19551 loading_weak_factory_(this),
552 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55553 frame_tree_.SetFrameRemoveListener(
554 base::Bind(&WebContentsImpl::OnFrameRemoved,
555 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46556#if defined(OS_ANDROID)
557 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
558#else
qinmin58567c82015-01-07 21:00:20559 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46560#endif
brettw4b461082016-11-19 18:55:16561#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17562 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
563#endif
blundelle75a8f92017-03-27 08:11:17564
csharrisona2280cd2016-02-03 23:21:15565 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
mcnee336ea2c2017-05-23 22:50:59566#if !defined(OS_ANDROID)
scottmg276753cf2016-10-27 18:25:22567 host_zoom_map_observer_.reset(new HostZoomMapObserver(this));
mcnee336ea2c2017-05-23 22:50:59568#endif // !defined(OS_ANDROID)
[email protected]332af7732009-03-11 13:21:35569}
initial.commit09911bf2008-07-26 23:55:29570
[email protected]b172aee2012-04-10 17:05:26571WebContentsImpl::~WebContentsImpl() {
creisba91ba82017-05-12 22:56:19572 // Imperfect sanity check against double free, given some crashes unexpectedly
573 // observed in the wild.
574 CHECK(!is_being_destroyed_);
575
576 // We generally keep track of is_being_destroyed_ to let other features know
577 // to avoid certain actions during destruction.
[email protected]420ae012009-04-24 05:16:32578 is_being_destroyed_ = true;
579
creis97867aa2017-02-17 18:39:45580 // A WebContents should never be deleted while it is notifying observers,
creisba91ba82017-05-12 22:56:19581 // since this will lead to a use-after-free as it continues to notify later
creis97867aa2017-02-17 18:39:45582 // observers.
583 CHECK(!is_notifying_observers_);
584
kenrb2a565f82015-09-02 20:24:59585 rwh_input_event_router_.reset();
586
rockotf62002a2016-09-15 00:08:59587 for (auto& entry : binding_sets_)
588 entry.second->CloseAllBindings();
589
avallee0206f782016-07-28 18:55:33590 WebContentsImpl* outermost = GetOutermostWebContents();
avallee9993fca2016-11-17 06:16:50591 if (this != outermost && ContainsOrIsFocusedWebContents()) {
avallee0206f782016-07-28 18:55:33592 // If the current WebContents is in focus, unset it.
avallee9993fca2016-11-17 06:16:50593 outermost->SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:33594 }
595
dcheng72be33c2016-01-21 04:11:31596 for (FrameTreeNode* node : frame_tree_.Nodes()) {
597 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
598 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38599 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38600 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31601 }
carlosk35f35af2015-12-01 10:55:40602
dcheng57e39e22016-01-21 00:25:38603 for (RenderWidgetHostImpl* widget : created_widgets_)
604 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26605 created_widgets_.clear();
606
[email protected]3ab9cb82011-06-03 18:02:07607 // Clear out any JavaScript state.
avi5d3b8692016-10-12 22:00:46608 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:53609 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:46610 }
[email protected]3ab9cb82011-06-03 18:02:07611
[email protected]8ed16472014-04-11 19:02:48612 if (color_chooser_info_.get())
613 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20614
[email protected]420ae012009-04-24 05:16:32615 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32616
[email protected]ca13a442012-04-17 14:00:12617 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21618 NotificationService::current()->Notify(
619 NOTIFICATION_WEB_CONTENTS_DESTROYED,
620 Source<WebContents>(this),
621 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32622
[email protected]df0c843f2014-05-23 20:37:23623 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14624 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23625 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59626
clamy0e119882015-07-31 16:12:33627 // Manually call the observer methods for the root frame tree node. It is
628 // necessary to manually delete all objects tracking navigations
629 // (NavigationHandle, NavigationRequest) for observers to be properly
630 // notified of these navigations stopping before the WebContents is
631 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23632 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56633
clamy0e119882015-07-31 16:12:33634 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56635 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33636 root->pending_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08637 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33638 }
naskob21fe4872015-02-24 14:15:56639 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33640 root->current_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08641 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33642
643 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35644 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41645 // Do not update state as the WebContents is being destroyed.
clamya86695b2017-03-23 14:45:48646 frame_tree_.root()->ResetNavigationRequest(true, true);
clamy0e119882015-07-31 16:12:33647 if (root->speculative_frame_host()) {
648 root->speculative_frame_host()->SetRenderFrameCreated(false);
649 root->speculative_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08650 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33651 }
652 }
[email protected]f273ee52013-10-18 16:05:27653
brettw4b461082016-11-19 18:55:16654#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17655 // Call this before WebContentsDestroyed() is broadcasted since
656 // AudioFocusManager will be destroyed after that.
657 pepper_playback_observer_.reset();
658#endif // defined(ENABLED_PLUGINS)
659
ericwilligersde386342016-10-19 02:35:09660 for (auto& observer : observers_)
661 observer.FrameDeleted(root->current_frame_host());
naskoa83483fb2015-02-27 16:57:10662
[email protected]df0c843f2014-05-23 20:37:23663 if (root->pending_render_view_host()) {
ericwilligersde386342016-10-19 02:35:09664 for (auto& observer : observers_)
665 observer.RenderViewDeleted(root->pending_render_view_host());
[email protected]df0c843f2014-05-23 20:37:23666 }
[email protected]c06c58c2014-03-12 20:31:59667
ericwilligersde386342016-10-19 02:35:09668 for (auto& observer : observers_)
669 observer.RenderViewDeleted(root->current_host());
[email protected]f273ee52013-10-18 16:05:27670
ericwilligersde386342016-10-19 02:35:09671 for (auto& observer : observers_)
672 observer.WebContentsDestroyed();
[email protected]12a46832014-05-09 13:35:58673
ericwilligersde386342016-10-19 02:35:09674 for (auto& observer : observers_)
675 observer.ResetWebContents();
[email protected]232a5812011-03-04 22:42:08676
[email protected]6934a702011-12-20 00:04:51677 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42678}
679
[email protected]d1198fd2012-08-13 22:50:19680WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59681 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21682 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03683 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21684 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
lukasza6f8ac622017-06-06 03:10:20685 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
alexmose201c7cd2015-06-10 17:14:21686
alexmosaedfc6f2016-01-21 23:57:38687 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
688 // flags, and these flags take effect immediately. An exception is if the
689 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
690 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
691 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
lukasza6f8ac622017-06-06 03:10:20692 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
alexmosaedfc6f2016-01-21 23:57:38693 if (opener) {
694 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
695 const blink::WebSandboxFlags inherit_flag =
Blink Reformat1c4d759e2017-04-09 16:34:54696 blink::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts;
alexmosaedfc6f2016-01-21 23:57:38697 if ((opener_flags & inherit_flag) == inherit_flag) {
698 new_root->SetPendingSandboxFlags(opener_flags);
iclelland92f8c0b2017-04-19 12:43:05699 new_root->CommitPendingFramePolicy();
alexmosaedfc6f2016-01-21 23:57:38700 }
701 }
702
alexmose201c7cd2015-06-10 17:14:21703 // This may be true even when opener is null, such as when opening blocked
704 // popups.
alexmos090fae8e2015-05-28 17:09:28705 if (params.created_with_opener)
706 new_contents->created_with_opener_ = true;
707
[email protected]4858e432014-06-23 18:14:17708 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06709 // This makes |new_contents| act as a guest.
710 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16711 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06712 // We are instantiating a WebContents for browser plugin. Set its subframe
713 // bit to true.
714 new_contents->is_subframe_ = true;
715 }
[email protected]54944cde2012-12-09 09:24:59716 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19717 return new_contents;
718}
719
[email protected]95640212014-07-26 18:14:30720// static
721std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
722 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08723 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30724 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30725 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30726 RenderViewHost* rvh = RenderViewHost::From(rwh);
727 if (!rvh)
728 continue;
729 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
730 if (!web_contents)
731 continue;
avidf38c952015-10-27 13:45:13732 if (web_contents->GetRenderViewHost() != rvh)
733 continue;
734 // Because a WebContents can only have one current RVH at a time, there will
735 // be no duplicate WebContents here.
736 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30737 }
738 return result;
739}
740
clamya16aa8172015-05-26 13:07:25741// static
742WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
paulmeyerfeafc2d2017-04-25 21:46:40743 const FrameTreeNode* frame_tree_node) {
clamya16aa8172015-05-26 13:07:25744 return static_cast<WebContentsImpl*>(
745 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
746}
747
clamy0d32d6d2015-11-24 11:16:26748// static
749WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
750 int render_frame_host_id) {
751 DCHECK_CURRENTLY_ON(BrowserThread::UI);
752 RenderFrameHost* render_frame_host =
753 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
754 if (!render_frame_host)
755 return nullptr;
756
757 return WebContents::FromRenderFrameHost(render_frame_host);
758}
759
paulmeyerfeafc2d2017-04-25 21:46:40760// static
761WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode(
762 const FrameTreeNode* frame_tree_node) {
763 return WebContentsImpl::FromFrameTreeNode(frame_tree_node)
764 ->node_.GetInnerWebContentsInFrame(frame_tree_node);
765}
766
[email protected]b0936d22013-11-28 06:47:36767RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21768 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28769}
770
nicka0ac8382016-12-15 23:59:23771bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host,
[email protected]7bb761892012-07-20 09:32:47772 const IPC::Message& message) {
nicka0ac8382016-12-15 23:59:23773 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
774 if (main_frame) {
775 WebUIImpl* web_ui = static_cast<RenderFrameHostImpl*>(main_frame)->web_ui();
776 if (web_ui && web_ui->OnMessageReceived(message))
777 return true;
[email protected]d2353452012-01-19 19:53:56778 }
[email protected]f82d57b52011-04-27 19:13:17779
nicka0ac8382016-12-15 23:59:23780 for (auto& observer : observers_) {
781 // TODO(nick, creis): Replace all uses of this variant of OnMessageReceived
782 // with the version that takes a RenderFrameHost, and delete it.
783 if (observer.OnMessageReceived(message))
784 return true;
[email protected]64ffefa2014-05-10 12:06:33785 }
[email protected]403415a2011-01-10 18:57:53786
[email protected]724159a2010-12-30 01:11:18787 bool handled = true;
nicka0ac8382016-12-15 23:59:23788 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host)
789 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
790 OnFirstVisuallyNonEmptyPaint)
791 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
792 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
793 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
794 OnPageScaleFactorChanged)
795 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
796 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
797 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
798#if BUILDFLAG(ENABLE_PLUGINS)
799 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
800 OnRequestPpapiBrokerPermission)
801#endif
nicka0ac8382016-12-15 23:59:23802 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
803 OnShowValidationMessage)
804 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
805 OnHideValidationMessage)
806 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
807 OnMoveValidationMessage)
808#if defined(OS_ANDROID)
809 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, OnOpenDateTimeDialog)
810#endif
811 IPC_MESSAGE_UNHANDLED(handled = false)
812 IPC_END_MESSAGE_MAP()
813
814 return handled;
815}
816
817bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host,
818 const IPC::Message& message) {
819 for (auto& observer : observers_) {
820 if (observer.OnMessageReceived(message, render_frame_host))
821 return true;
822 }
823
824 bool handled = true;
825 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host)
[email protected]cfa856d62014-02-22 07:58:40826 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
827 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05828 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
829 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48830 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
831 OnDocumentLoadedInFrame)
832 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
833 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
834 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
835 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
836 OnSetSelectedColorInColorChooser)
avi7830c852015-08-31 23:46:25837 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18838 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54839 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18840 OnDidDisplayInsecureContent)
elawrenceb2ac2a232017-03-27 21:46:25841 IPC_MESSAGE_HANDLER(FrameHostMsg_DidContainInsecureFormAction,
842 OnDidContainInsecureFormAction)
avi3a3332622015-09-01 01:18:54843 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18844 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41845 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
846 OnDidDisplayContentWithCertificateErrors)
847 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
848 OnDidRunContentWithCertificateErrors)
avia23e16b2015-07-09 14:18:48849 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
850 OnRegisterProtocolHandler)
851 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
852 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01853 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
854 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52855 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
lukasza178ff092017-06-07 23:39:50856 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
brettw4b461082016-11-19 18:55:16857#if BUILDFLAG(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00858 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
859 OnPepperInstanceCreated)
860 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
861 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42862 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:17863 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
864 OnPepperStartsPlayback)
865 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
866 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:42867 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]c4538072013-03-18 02:17:55868 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40869 OnBrowserPluginMessage(render_frame_host,
870 message))
thestigc4cac8f2014-09-04 21:17:50871#endif
mfomitchev2b8b066a2016-01-28 19:23:15872#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52873 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48874 OnFindMatchRectsReply)
paulmeyerc8cb7cb2016-06-07 01:14:19875 IPC_MESSAGE_HANDLER(FrameHostMsg_GetNearestFindResult_Reply,
876 OnGetNearestFindResultReply)
[email protected]8ed16472014-04-11 19:02:48877#endif
[email protected]724159a2010-12-30 01:11:18878 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33879 IPC_END_MESSAGE_MAP()
[email protected]724159a2010-12-30 01:11:18880
[email protected]724159a2010-12-30 01:11:18881 return handled;
882}
883
[email protected]d1198fd2012-08-13 22:50:19884NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56885 return controller_;
886}
887
[email protected]d1198fd2012-08-13 22:50:19888const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56889 return controller_;
890}
891
[email protected]8ff00d72012-10-23 19:12:21892BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55893 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30894}
895
[email protected]b172aee2012-04-10 17:05:26896const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24897 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32898 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51899 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31900}
901
[email protected]a093ce02013-07-22 20:53:14902const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24903 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32904 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24905 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
906}
907
908const GURL& WebContentsImpl::GetLastCommittedURL() const {
909 // We may not have a navigation entry yet.
910 NavigationEntry* entry = controller_.GetLastCommittedEntry();
911 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
912}
913
[email protected]8ff00d72012-10-23 19:12:21914WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31915 return delegate_;
916}
917
[email protected]8ff00d72012-10-23 19:12:21918void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31919 // TODO(cbentzel): remove this debugging code?
920 if (delegate == delegate_)
921 return;
922 if (delegate_)
923 delegate_->Detach(this);
924 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08925 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31926 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08927 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00928 if (view_)
[email protected]e85165c642014-06-10 14:34:31929 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08930 }
[email protected]be1f56ab2011-12-22 06:55:31931}
932
[email protected]8ff00d72012-10-23 19:12:21933RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21934 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41935 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16936}
937
clamydf1975e2015-02-05 19:12:24938RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41939 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16940}
941
nick53d5cbf2015-04-23 22:50:14942RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
943 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
944 if (!focused_node)
945 return nullptr;
946 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07947}
948
rob3e2a0732016-01-06 21:22:09949RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
creisf71a2632017-05-04 19:03:50950 int frame_tree_node_id,
951 int process_id) {
952 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
953
954 // Sanity check that this is in the caller's expected process. Otherwise a
955 // recent cross-process navigation may have led to a privilege change that the
956 // caller is not expecting.
957 if (!frame ||
958 frame->current_frame_host()->GetProcess()->GetID() != process_id)
959 return nullptr;
960
961 return frame->current_frame_host();
962}
963
964RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId(
rob3e2a0732016-01-06 21:22:09965 int frame_tree_node_id) {
creisf71a2632017-05-04 19:03:50966 // Beware using this! The RenderFrameHost may have changed since the caller
967 // obtained frame_tree_node_id.
rob3e2a0732016-01-06 21:22:09968 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
969 return frame ? frame->current_frame_host() : nullptr;
970}
971
[email protected]a86c0e962013-12-17 17:10:39972void WebContentsImpl::ForEachFrame(
973 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38974 for (FrameTreeNode* node : frame_tree_.Nodes()) {
975 on_frame.Run(node->current_frame_host());
976 }
[email protected]a86c0e962013-12-17 17:10:39977}
978
dchengafb53e22016-02-04 08:11:08979std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
980 std::vector<RenderFrameHost*> frame_hosts;
981 for (FrameTreeNode* node : frame_tree_.Nodes())
982 frame_hosts.push_back(node->current_frame_host());
983 return frame_hosts;
984}
985
lukaszacbdf52e2016-01-15 21:19:51986int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
987 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08988 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25989 if (!rfh->IsRenderFrameLive())
990 continue;
991
dchengafb53e22016-02-04 08:11:08992 ++number_of_messages;
993 IPC::Message* message_copy = new IPC::Message(*message);
994 message_copy->set_routing_id(rfh->GetRoutingID());
995 rfh->Send(message_copy);
996 }
[email protected]a86c0e962013-12-17 17:10:39997 delete message;
lukaszacbdf52e2016-01-15 21:19:51998 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39999}
1000
lfgdb5c4ed2016-03-04 23:09:071001void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:411002 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:071003}
1004
creisc014b402015-04-23 16:41:451005RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:211006 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:311007}
1008
creis89a0f782015-05-27 16:13:171009void WebContentsImpl::CancelActiveAndPendingDialogs() {
avi5d3b8692016-10-12 22:00:461010 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:531011 dialog_manager_->CancelDialogs(this, /*reset_state=*/false);
avi5d3b8692016-10-12 22:00:461012 }
creis89a0f782015-05-27 16:13:171013 if (browser_plugin_embedder_)
1014 browser_plugin_embedder_->CancelGuestDialogs();
lukasza041634d2017-06-26 18:20:561015 if (delegate_)
1016 delegate_->HideValidationMessage(this);
creis89a0f782015-05-27 16:13:171017}
1018
naskoc0fceff2015-04-30 15:53:521019void WebContentsImpl::ClosePage() {
1020 GetRenderViewHost()->ClosePage();
1021}
1022
[email protected]b172aee2012-04-10 17:05:261023RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:211024 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:311025}
1026
lfg265a2672016-04-23 03:11:021027RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
1028 if (GetOuterWebContents())
1029 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
1030 return GetRenderManager()->GetRenderWidgetHostView();
1031}
1032
[email protected]4aebbca2013-09-17 22:26:491033RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
1034 const {
vmpstr6d9996c82017-02-23 00:43:251035 if (auto* widget_host = GetFullscreenRenderWidgetHost())
ekaramadaeb3c5c2016-11-09 03:22:351036 return widget_host->GetView();
1037 return nullptr;
[email protected]4aebbca2013-09-17 22:26:491038}
1039
[email protected]8ff00d72012-10-23 19:12:211040WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:311041 return view_.get();
1042}
1043
leon.han552e9de2017-02-09 14:37:301044void WebContentsImpl::OnScreenOrientationChange() {
1045 DCHECK(screen_orientation_provider_);
1046 return screen_orientation_provider_->OnOrientationChange();
leon.hane4db177a2017-02-07 14:19:161047}
1048
yusufod41c5f92015-03-06 00:14:281049SkColor WebContentsImpl::GetThemeColor() const {
1050 return theme_color_;
1051}
1052
Doug Turner63f3c7b2017-07-29 05:10:011053void WebContentsImpl::SetAccessibilityMode(ui::AXMode mode) {
[email protected]95640212014-07-26 18:14:301054 if (mode == accessibility_mode_)
1055 return;
1056
dmazzonif8a31042016-12-03 00:52:131057 // Don't allow accessibility to be enabled for WebContents that are never
1058 // visible, like background pages.
1059 if (IsNeverVisible())
1060 return;
1061
[email protected]95640212014-07-26 18:14:301062 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:381063
1064 for (FrameTreeNode* node : frame_tree_.Nodes()) {
dmazzonif8a31042016-12-03 00:52:131065 UpdateAccessibilityModeOnFrame(node->current_frame_host());
dcheng57e39e22016-01-21 00:25:381066 RenderFrameHost* pending_frame_host =
1067 node->render_manager()->pending_frame_host();
1068 if (pending_frame_host)
dmazzonif8a31042016-12-03 00:52:131069 UpdateAccessibilityModeOnFrame(pending_frame_host);
dcheng57e39e22016-01-21 00:25:381070 }
[email protected]95640212014-07-26 18:14:301071}
1072
Doug Turner63f3c7b2017-07-29 05:10:011073void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) {
1074 ui::AXMode new_mode(accessibility_mode_);
dougtcd3dad732017-03-14 03:26:231075 new_mode |= mode;
1076 SetAccessibilityMode(new_mode);
[email protected]95640212014-07-26 18:14:301077}
1078
muyuanlic693ba12017-04-27 19:12:401079void WebContentsImpl::RequestAXTreeSnapshot(
1080 const AXTreeSnapshotCallback& callback) {
dmazzonid95ae842016-04-12 21:17:391081 // Send a request to each of the frames in parallel. Each one will return
1082 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
1083 // them into a single tree and call |callback| with that result, then
1084 // delete |combiner|.
1085 AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback);
1086 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
1087 bool is_root = frame_tree_node->parent() == nullptr;
1088 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
1089 combiner->AddFrame(is_root));
1090 }
dmazzoni83ba5c82015-04-14 07:11:511091}
1092
mcnee336ea2c2017-05-23 22:50:591093#if !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:121094void WebContentsImpl::SetTemporaryZoomLevel(double level,
1095 bool temporary_zoom_enabled) {
1096 SendPageMessage(new PageMsg_SetZoomLevel(
1097 MSG_ROUTING_NONE,
1098 temporary_zoom_enabled ? PageMsg_SetZoomLevel_Command::SET_TEMPORARY
1099 : PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY,
1100 level));
1101}
1102
1103void WebContentsImpl::UpdateZoom(double level) {
1104 // Individual frames may still ignore the new zoom level if their RenderView
1105 // contains a plugin document or if it uses a temporary zoom level.
1106 SendPageMessage(new PageMsg_SetZoomLevel(
1107 MSG_ROUTING_NONE,
1108 PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level));
1109}
1110
1111void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
1112 const std::string& host,
1113 double level) {
1114 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1115 if (!entry)
1116 return;
1117
1118 GURL url = HostZoomMap::GetURLFromEntry(entry);
1119 if (host != net::GetHostOrSpecFromURL(url) ||
1120 (!scheme.empty() && !url.SchemeIs(scheme))) {
1121 return;
1122 }
1123
1124 UpdateZoom(level);
1125}
mcnee336ea2c2017-05-23 22:50:591126#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:121127
rockotf62002a2016-09-15 00:08:591128base::Closure WebContentsImpl::AddBindingSet(
1129 const std::string& interface_name,
1130 WebContentsBindingSet* binding_set) {
1131 auto result =
1132 binding_sets_.insert(std::make_pair(interface_name, binding_set));
1133 DCHECK(result.second);
1134 return base::Bind(&WebContentsImpl::RemoveBindingSet,
1135 weak_factory_.GetWeakPtr(), interface_name);
1136}
1137
rockot8bbad222017-03-22 04:34:051138WebContentsBindingSet* WebContentsImpl::GetBindingSet(
1139 const std::string& interface_name) {
1140 auto it = binding_sets_.find(interface_name);
1141 if (it == binding_sets_.end())
1142 return nullptr;
1143 return it->second;
1144}
1145
paulmeyerfeafc2d2017-04-25 21:46:401146std::vector<WebContentsImpl*> WebContentsImpl::GetInnerWebContents() {
1147 if (browser_plugin_embedder_) {
1148 std::vector<WebContentsImpl*> inner_contents;
1149 GetBrowserContext()->GetGuestManager()->ForEachGuest(
1150 this, base::Bind(&GetInnerWebContentsHelper, &inner_contents));
1151 return inner_contents;
1152 }
1153
1154 return node_.inner_web_contents();
1155}
1156
1157std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() {
1158 std::vector<WebContentsImpl*> all_contents(1, this);
1159
1160 for (size_t i = 0; i != all_contents.size(); ++i) {
1161 for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) {
1162 all_contents.push_back(inner_contents);
1163 }
1164 }
1165
1166 return all_contents;
1167}
1168
Sam McNally145fb172017-05-10 00:13:231169void WebContentsImpl::NotifyManifestUrlChanged(
1170 const base::Optional<GURL>& manifest_url) {
1171 for (auto& observer : observers_)
1172 observer.DidUpdateWebManifestURL(manifest_url);
1173}
1174
wjmaclean8a795f32016-08-11 23:49:581175void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) {
1176 SendPageMessage(
1177 new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor));
1178}
1179
ccameron2f451532016-09-07 21:49:271180void WebContentsImpl::GetScreenInfo(ScreenInfo* screen_info) {
wjmaclean8a795f32016-08-11 23:49:581181 if (GetView())
ccameron2f451532016-09-07 21:49:271182 GetView()->GetScreenInfo(screen_info);
wjmaclean8a795f32016-08-11 23:49:581183}
1184
avie865b1d2016-10-24 19:42:591185std::unique_ptr<WebUI> WebContentsImpl::CreateSubframeWebUI(
1186 const GURL& url,
1187 const std::string& frame_name) {
dbeama1b926a2015-08-31 23:17:511188 DCHECK(!frame_name.empty());
1189 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:221190}
1191
[email protected]8ff00d72012-10-23 19:12:211192WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:401193 WebUI* commited_web_ui = GetCommittedWebUI();
1194 return commited_web_ui ? commited_web_ui
1195 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:311196}
1197
[email protected]8ff00d72012-10-23 19:12:211198WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:401199 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341200}
1201
[email protected]86ef6a392012-05-11 22:03:111202void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:221203 if (GetUserAgentOverride() == override)
1204 return;
1205
1206 renderer_preferences_.user_agent_override = override;
1207
1208 // Send the new override string to the renderer.
1209 RenderViewHost* host = GetRenderViewHost();
1210 if (host)
1211 host->SyncRendererPrefs();
1212
1213 // Reload the page if a load is currently in progress to avoid having
1214 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271215 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:251216 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim6142d96f2016-12-19 09:07:251217 controller_.Reload(ReloadType::BYPASSING_CACHE, true);
[email protected]8d0f3312012-08-18 01:47:531218
ericwilligersde386342016-10-19 02:35:091219 for (auto& observer : observers_)
1220 observer.UserAgentOverrideSet(override);
[email protected]86ef6a392012-05-11 22:03:111221}
1222
1223const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:221224 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111225}
1226
dmazzonidd3d51a72016-12-14 18:41:011227void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() {
dougtcd3dad732017-03-14 03:26:231228 if (!GetAccessibilityMode().is_mode_off()) {
dchengafb53e22016-02-04 08:11:081229 for (RenderFrameHost* rfh : GetAllFrames())
1230 ResetAccessibility(rfh);
1231 } else {
Doug Turner63f3c7b2017-07-29 05:10:011232 AddAccessibilityMode(ui::kAXModeWebContentsOnly);
dchengafb53e22016-02-04 08:11:081233 }
[email protected]95640212014-07-26 18:14:301234}
1235
dmazzonidd3d51a72016-12-14 18:41:011236bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011237 return accessibility_mode_ == ui::kAXModeWebContentsOnly;
[email protected]95640212014-07-26 18:14:301238}
1239
1240bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
Doug Turner63f3c7b2017-07-29 05:10:011241 return accessibility_mode_ == ui::kAXModeComplete;
[email protected]95640212014-07-26 18:14:301242}
1243
kouhei40f03cb2015-09-24 07:47:011244const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
1245 return page_importance_signals_;
1246}
1247
[email protected]fcf75d42013-12-03 20:11:261248const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:551249 // Transient entries take precedence. They are used for interstitial pages
1250 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231251 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231252 if (entry) {
jshin1fb76462016-04-05 22:13:031253 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231254 }
carlosk35f35af2015-12-01 10:55:401255
1256 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
1257 WebUI* our_web_ui = navigating_web_ui
1258 ? navigating_web_ui
1259 : GetRenderManager()->current_frame_host()->web_ui();
1260
[email protected]7ade2732011-02-10 00:13:581261 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541262 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321263 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541264 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351265 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261266 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541267 if (!title.empty())
1268 return title;
1269 }
1270 }
1271
1272 // We use the title for the last committed entry rather than a pending
1273 // navigation entry. For example, when the user types in a URL, we want to
1274 // keep the old page's title until the new load has committed and we get a new
1275 // title.
[email protected]96d185d2009-04-24 03:28:541276 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321277
creis072b61f2015-09-28 20:52:241278 // We make an exception for initial navigations. We only want to use the title
1279 // from the visible entry if:
1280 // 1. The pending entry has been explicitly assigned a title to display.
1281 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1282 // which case there is a pending entry index other than -1.
1283 //
1284 // Otherwise, we want to stick with the last committed entry's title during
1285 // new navigations, which have pending entries at index -1 with no title.
1286 if (controller_.IsInitialNavigation() &&
1287 ((controller_.GetVisibleEntry() &&
1288 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1289 controller_.GetPendingEntryIndex() != -1)) {
1290 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471291 }
[email protected]59167c22013-06-03 18:07:321292
[email protected]45d0ef7f2011-01-05 13:46:231293 if (entry) {
jshin1fb76462016-04-05 22:13:031294 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231295 }
[email protected]987fc3a2011-05-26 14:18:091296
1297 // |page_title_when_no_navigation_entry_| is finally used
1298 // if no title cannot be retrieved.
1299 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541300}
1301
creiscce56cd2014-09-29 22:45:221302SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211303 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541304}
1305
creiscce56cd2014-09-29 22:45:221306SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1307 RenderViewHostImpl* dest_rvh =
1308 GetRenderManager()->pending_render_view_host() ?
1309 GetRenderManager()->pending_render_view_host() :
1310 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581311 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381312}
1313
[email protected]b172aee2012-04-10 17:05:261314bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251315 return frame_tree_.IsLoading() &&
creisadca9862017-06-16 19:12:111316 !(ShowingInterstitialPage() && interstitial_page_->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491317}
1318
[email protected]6dfed692014-05-22 04:18:031319bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251320 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031321}
1322
[email protected]b172aee2012-04-10 17:05:261323bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031324 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311325}
1326
[email protected]b172aee2012-04-10 17:05:261327const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311328 return load_state_;
1329}
1330
[email protected]fcf75d42013-12-03 20:11:261331const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311332 return load_state_host_;
1333}
1334
avib7348942015-12-25 20:57:101335uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311336 return upload_size_;
1337}
1338
avib7348942015-12-25 20:57:101339uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311340 return upload_position_;
1341}
1342
[email protected]b172aee2012-04-10 17:05:261343const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541344 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311345}
1346
[email protected]222f5822014-02-05 23:40:491347void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251348 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551349 ++capturer_count_;
1350 DVLOG(1) << "There are now " << capturer_count_
1351 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491352
1353 // Note: This provides a hint to upstream code to size the views optimally
1354 // for quality (e.g., to avoid scaling).
1355 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1356 preferred_size_for_capture_ = capture_size;
1357 OnPreferredSizeChanged(preferred_size_);
1358 }
ccameron8807c38f2015-01-17 00:29:191359
1360 // Ensure that all views are un-occluded before capture begins.
1361 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551362}
1363
1364void WebContentsImpl::DecrementCapturerCount() {
1365 --capturer_count_;
1366 DVLOG(1) << "There are now " << capturer_count_
1367 << " capturing(s) of WebContentsImpl@" << this;
1368 DCHECK_LE(0, capturer_count_);
1369
[email protected]5a652232013-02-12 06:15:251370 if (is_being_destroyed_)
1371 return;
1372
[email protected]222f5822014-02-05 23:40:491373 if (capturer_count_ == 0) {
1374 const gfx::Size old_size = preferred_size_for_capture_;
1375 preferred_size_for_capture_ = gfx::Size();
1376 OnPreferredSizeChanged(old_size);
1377 }
1378
[email protected]1ac10dca2013-08-20 20:47:041379 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551380 DVLOG(1) << "Executing delayed WasHidden().";
1381 WasHidden();
1382 }
[email protected]be1f56ab2011-12-22 06:55:311383}
1384
[email protected]f2bd40812013-07-20 04:30:441385int WebContentsImpl::GetCapturerCount() const {
1386 return capturer_count_;
1387}
1388
miu50f97892014-09-22 22:49:521389bool WebContentsImpl::IsAudioMuted() const {
1390 return audio_muter_.get() && audio_muter_->is_muting();
1391}
1392
1393void WebContentsImpl::SetAudioMuted(bool mute) {
1394 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1395 << " for WebContentsImpl@" << this;
1396
1397 if (mute == IsAudioMuted())
1398 return;
1399
1400 if (mute) {
1401 if (!audio_muter_)
1402 audio_muter_.reset(new WebContentsAudioMuter(this));
1403 audio_muter_->StartMuting();
1404 } else {
1405 DCHECK(audio_muter_);
1406 audio_muter_->StopMuting();
1407 }
1408
ericwilligersde386342016-10-19 02:35:091409 for (auto& observer : observers_)
1410 observer.DidUpdateAudioMutingState(mute);
wjmaclean2f797c782016-01-07 14:52:031411
Jan Rucka442c83f2017-08-08 13:27:541412 // Notification for UI updates in response to the changed muting state.
1413 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1414}
1415
1416bool WebContentsImpl::IsCurrentlyAudible() {
1417 return audio_stream_monitor()->IsCurrentlyAudible();
miu50f97892014-09-22 22:49:521418}
1419
ortunodf4d7982016-04-08 02:33:351420bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1421 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201422}
1423
[email protected]b172aee2012-04-10 17:05:261424bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311425 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1426 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581427 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271428#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581429 crashed_status_ ==
1430 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271431#endif
rkaplowe56a52032017-02-07 00:14:541432 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED);
[email protected]3c9e1872010-11-18 16:17:491433}
1434
[email protected]b172aee2012-04-10 17:05:261435void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1436 int error_code) {
[email protected]443b80e2010-12-14 00:42:231437 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341438 return;
1439
[email protected]443b80e2010-12-14 00:42:231440 crashed_status_ = status;
1441 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211442 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341443}
1444
[email protected]b172aee2012-04-10 17:05:261445base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311446 return crashed_status_;
1447}
1448
afakhry98241832016-03-11 19:27:471449int WebContentsImpl::GetCrashedErrorCode() const {
1450 return crashed_error_code_;
1451}
1452
[email protected]b172aee2012-04-10 17:05:261453bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311454 return is_being_destroyed_;
1455}
1456
[email protected]7f924832014-08-09 05:57:221457void WebContentsImpl::NotifyNavigationStateChanged(
1458 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541459 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1460 // is fixed.
1461 tracked_objects::ScopedTracker tracking_profile(
1462 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1463 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181464 // Notify the media observer of potential audibility changes.
1465 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271466 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301467 }
1468
[email protected]d5f942ba2008-09-26 19:30:341469 if (delegate_)
1470 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441471
1472 if (GetOuterWebContents())
1473 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341474}
1475
altiminec87fd1f2016-11-17 20:22:491476void WebContentsImpl::OnAudioStateChanged(bool is_audible) {
1477 SendPageMessage(new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_audible));
altimind8bd26c2016-11-04 11:44:541478
altiminec87fd1f2016-11-17 20:22:491479 // Notification for UI updates in response to the changed audio state.
altimind8bd26c2016-11-04 11:44:541480 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
Jan Rucka442c83f2017-08-08 13:27:541481
1482 if (delegate_)
1483 delegate_->OnAudioStateChanged(is_audible);
altimind8bd26c2016-11-04 11:44:541484}
1485
gab0dccfef2015-05-20 18:43:391486base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021487 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331488}
1489
georgesak5582cbe2015-05-22 22:08:071490void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1491 last_active_time_ = last_active_time;
1492}
1493
hajimehoshic4f226a2016-10-21 09:01:571494base::TimeTicks WebContentsImpl::GetLastHiddenTime() const {
1495 return last_hidden_time_;
1496}
1497
[email protected]9e2e4632012-07-27 16:38:411498void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541499 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591500
ccameron8807c38f2015-01-17 00:29:191501 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
lfgf949e0e2017-05-10 22:18:111502 view->Show();
[email protected]789e9152009-08-04 21:59:431503#if defined(OS_MACOSX)
lfgf949e0e2017-05-10 22:18:111504 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431505#endif
1506 }
[email protected]96d185d2009-04-24 03:28:541507
lfg717154072016-06-30 15:04:161508 SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE));
1509
gab0dccfef2015-05-20 18:43:391510 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381511
ericwilligersde386342016-10-19 02:35:091512 for (auto& observer : observers_)
1513 observer.WasShown();
[email protected]c0d9d5672013-10-09 07:38:031514
[email protected]54597982013-02-06 01:59:551515 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311516}
1517
[email protected]b172aee2012-04-10 17:05:261518void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551519 // If there are entities capturing screenshots or video (e.g., mirroring),
1520 // don't activate the "disable rendering" optimization.
1521 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521522 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551523 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261524 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521525 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331526 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521527 // calls us).
lfgf949e0e2017-05-10 22:18:111528 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1529 view->Hide();
lfg717154072016-06-30 15:04:161530
1531 SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
[email protected]96d185d2009-04-24 03:28:541532 }
1533
hajimehoshic4f226a2016-10-21 09:01:571534 last_hidden_time_ = base::TimeTicks::Now();
1535
ericwilligersde386342016-10-19 02:35:091536 for (auto& observer : observers_)
1537 observer.WasHidden();
[email protected]c0d9d5672013-10-09 07:38:031538
[email protected]54597982013-02-06 01:59:551539 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371540}
1541
zhenw6edd49c2017-07-12 05:49:451542bool WebContentsImpl::IsVisible() const {
1543 return should_normally_be_visible_;
1544}
1545
ccameron8807c38f2015-01-17 00:29:191546void WebContentsImpl::WasOccluded() {
1547 if (capturer_count_ > 0)
1548 return;
1549
lfgf949e0e2017-05-10 22:18:111550 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1551 view->WasOccluded();
ccameron8807c38f2015-01-17 00:29:191552}
1553
1554void WebContentsImpl::WasUnOccluded() {
lfgf949e0e2017-05-10 22:18:111555 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
1556 view->WasUnOccluded();
ccameron8807c38f2015-01-17 00:29:191557}
1558
[email protected]b172aee2012-04-10 17:05:261559bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311560 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451561 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
jam40444982017-04-11 03:01:411562 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311563}
1564
nasko148bb0b92016-05-10 21:03:191565void WebContentsImpl::DispatchBeforeUnload() {
1566 bool for_cross_site_transition = false;
clamybfd6a812016-05-30 16:25:171567 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false);
[email protected]1c3f80bd2014-04-08 23:02:061568}
1569
lazyboy6ec48b2a2015-06-29 15:18:141570void WebContentsImpl::AttachToOuterWebContentsFrame(
1571 WebContents* outer_web_contents,
1572 RenderFrameHost* outer_contents_frame) {
ekaramad1beabecc2016-09-23 20:18:171573 CHECK(GuestMode::IsCrossProcessFrameGuest(this));
lfg91a79e12016-04-01 23:52:191574 RenderFrameHostManager* render_manager = GetRenderManager();
1575
1576 // When the WebContents being initialized has an opener, the browser side
1577 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1578 // created. This is needed because the usual initialization happens during
1579 // the first navigation, but when attaching a new window we don't navigate
1580 // before attaching. If the browser side is already initialized, the calls
1581 // below will just early return.
1582 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1583 GetMainFrame()->Init();
1584 if (!render_manager->GetRenderWidgetHostView())
1585 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1586
avallee7529b2a2017-04-26 11:37:511587 auto* outer_web_contents_impl =
1588 static_cast<WebContentsImpl*>(outer_web_contents);
1589 auto* outer_contents_frame_impl =
1590 static_cast<RenderFrameHostImpl*>(outer_contents_frame);
lazyboy6ec48b2a2015-06-29 15:18:141591 // Create a link to our outer WebContents.
avallee7529b2a2017-04-26 11:37:511592 node_.ConnectToOuterWebContents(outer_web_contents_impl,
1593 outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141594
1595 DCHECK(outer_contents_frame);
1596
1597 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1598 // SiteInstance of the outer WebContents. The proxy will be used to send
1599 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191600 render_manager->CreateOuterDelegateProxy(
avallee7529b2a2017-04-26 11:37:511601 outer_contents_frame->GetSiteInstance(), outer_contents_frame_impl);
lazyboy6ec48b2a2015-06-29 15:18:141602
lfg91a79e12016-04-01 23:52:191603 render_manager->SetRWHViewForInnerContents(
1604 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391605
1606 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191607 render_manager->GetRenderWidgetHostView())
fsamuelb6acafa2016-10-04 03:21:521608 ->RegisterFrameSinkId();
ekaramadadd882292016-06-08 15:22:561609
avallee7529b2a2017-04-26 11:37:511610 if (outer_web_contents_impl->frame_tree_.GetFocusedFrame() ==
1611 outer_contents_frame_impl->frame_tree_node()) {
1612 SetFocusedFrame(frame_tree_.root(), nullptr);
1613 }
1614
avalleed68cdd12017-06-21 22:07:271615 // Set up the the guest's AX tree to point back at the embedder's AX tree.
1616 auto* parent_frame = outer_contents_frame->GetParent();
1617 GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(
1618 parent_frame->GetAXTreeID());
1619 GetMainFrame()->UpdateAXTreeData();
1620
ekaramadadd882292016-06-08 15:22:561621 // At this point, we should destroy the TextInputManager which will notify all
1622 // the RWHV in this WebContents. The RWHV in this WebContents should use the
1623 // TextInputManager owned by the outer WebContents.
1624 // TODO(ekaramad): Is it possible to have TextInputState before attaching to
1625 // outer WebContents? In such a case, is this still the right way to hand off
1626 // state tracking from inner WebContents's TextInputManager to that of the
1627 // outer WebContent (crbug.com/609846)?
1628 text_input_manager_.reset(nullptr);
lazyboy6ec48b2a2015-06-29 15:18:141629}
1630
dalecurtis6c58ed02016-10-28 23:02:371631void WebContentsImpl::DidChangeVisibleSecurityState() {
1632 if (delegate_) {
1633 delegate_->VisibleSecurityStateChanged(this);
cjgrant6d1d727a2016-12-09 21:16:571634 for (auto& observer : observers_)
1635 observer.DidChangeVisibleSecurityState();
dalecurtis6c58ed02016-10-28 23:02:371636 }
1637}
1638
[email protected]b172aee2012-04-10 17:05:261639void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381640 for (FrameTreeNode* node : frame_tree_.Nodes())
1641 node->StopLoading();
ericwilligersde386342016-10-19 02:35:091642 for (auto& observer : observers_)
1643 observer.NavigationStopped();
[email protected]0bfbf882011-12-22 18:19:271644}
1645
[email protected]b172aee2012-04-10 17:05:261646WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441647 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211648 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451649 // before.
[email protected]54944cde2012-12-09 09:24:591650 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451651 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211652 WebContentsImpl* tc =
1653 CreateWithOpener(create_params, frame_tree_.root()->opener());
Francois Dorayeaace782017-06-21 16:37:241654 tc->GetController().CopyStateFrom(controller_, true);
ericwilligersde386342016-10-19 02:35:091655 for (auto& observer : observers_)
1656 observer.DidCloneToNewWebContents(this, tc);
[email protected]0bfbf882011-12-22 18:19:271657 return tc;
1658}
1659
[email protected]14392a52012-05-02 20:28:441660void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211661 const NotificationSource& source,
1662 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441663 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211664 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1665 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031666 RenderWidgetHostView* view = host->GetView();
1667 if (view == GetFullscreenRenderWidgetHostView()) {
1668 // We cannot just call view_->RestoreFocus() here. On some platforms,
1669 // attempting to focus the currently-invisible WebContentsView will be
1670 // flat-out ignored. Therefore, this boolean is used to track whether
1671 // we will request focus after the fullscreen widget has been
1672 // destroyed.
1673 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1674 } else {
alexmosc2a8cec2016-05-23 22:19:531675 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:031676 i != pending_widget_views_.end(); ++i) {
1677 if (host->GetView() == i->second) {
1678 pending_widget_views_.erase(i);
1679 break;
1680 }
[email protected]bafe6cd2012-05-23 23:09:501681 }
1682 }
1683 break;
1684 }
[email protected]14392a52012-05-02 20:28:441685 default:
1686 NOTREACHED();
1687 }
1688}
1689
[email protected]ec6c05f2013-10-23 18:41:571690WebContents* WebContentsImpl::GetWebContents() {
1691 return this;
1692}
1693
[email protected]54944cde2012-12-09 09:24:591694void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211695 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361696 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211697 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431698 should_normally_be_visible_ = !params.initially_hidden;
1699
dcheng3ce04b62015-10-26 23:30:551700 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541701 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551702 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1703 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541704 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551705 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1706 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1707
1708 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1709 if (!site_instance)
1710 site_instance = SiteInstance::Create(params.browser_context);
1711
1712 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1713 // local root by definition.
1714 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1715 // longer be necessary to eagerly grab a routing ID for the view.
1716 // https://crbug.com/545684
1717 int32_t view_routing_id = params.routing_id;
1718 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1719 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1720 view_routing_id = main_frame_widget_routing_id =
1721 site_instance->GetProcess()->GetNextRoutingID();
1722 }
1723
Dave Tapuska485aca92017-08-08 00:47:581724 GetRenderManager()->Init(
1725 site_instance.get(), view_routing_id, params.main_frame_routing_id,
1726 main_frame_widget_routing_id, params.renderer_initiated_creation);
lukasza464d8692016-02-22 19:26:321727
lukasza5140a412016-09-15 21:12:301728 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
1729 // main frame - let's do the same thing here.
1730 std::string unique_name;
lukasza464d8692016-02-22 19:26:321731 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191732
[email protected]fc2b46b2014-05-03 16:33:451733 WebContentsViewDelegate* delegate =
1734 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1735
sky52a39e342016-12-17 17:23:221736 if (GuestMode::IsCrossProcessFrameGuest(this)) {
1737 view_.reset(new WebContentsViewChildFrame(
1738 this, delegate, &render_view_host_delegate_view_));
1739 } else {
1740 view_.reset(CreateWebContentsView(this, delegate,
1741 &render_view_host_delegate_view_));
fsamueladb0033602015-12-09 19:20:411742 }
fsamuel9cf7bdf2015-11-20 02:19:321743
ekaramad1beabecc2016-09-23 20:18:171744 if (browser_plugin_guest_ && !GuestMode::IsCrossProcessFrameGuest(this)) {
fsamuel9cf7bdf2015-11-20 02:19:321745 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361746 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321747 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191748 }
[email protected]fc2b46b2014-05-03 16:33:451749 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191750 CHECK(view_.get());
1751
[email protected]ed245db2012-12-18 08:00:451752 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591753 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191754
brettw4b461082016-11-19 18:55:161755#if BUILDFLAG(ENABLE_PLUGINS)
tommyclieb25b2a2014-11-03 19:45:091756 plugin_content_origin_whitelist_.reset(
1757 new PluginContentOriginWhitelist(this));
1758#endif
1759
[email protected]d1198fd2012-08-13 22:50:191760 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211761 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1762 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101763
leon.hane4db177a2017-02-07 14:19:161764 screen_orientation_provider_.reset(new ScreenOrientationProvider(this));
[email protected]01f83f92014-06-17 14:41:541765
mlamouriefdca9d2014-09-16 16:55:401766 manifest_manager_host_.reset(new ManifestManagerHost(this));
1767
mfomitchev2b8b066a2016-01-28 19:23:151768#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101769 date_time_chooser_.reset(new DateTimeChooserAndroid());
1770#endif
fsamuel7310a4262014-12-05 05:06:441771
1772 // BrowserPluginGuest::Init needs to be called after this WebContents has
1773 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1774 if (browser_plugin_guest_)
1775 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371776
1777 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1778 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561779
1780 // If the WebContents creation was renderer-initiated, it means that the
1781 // corresponding RenderView and main RenderFrame have already been created.
1782 // Ensure observers are notified about this.
1783 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431784 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561785 RenderViewCreated(GetRenderViewHost());
1786 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1787 }
naskof5940b9f2015-03-02 23:04:051788
lof84501da082016-05-23 21:22:541789 // Create the renderer process in advance if requested.
1790 if (params.initialize_renderer) {
1791 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
1792 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
1793 }
1794 }
1795
naskof5940b9f2015-03-02 23:04:051796 // Ensure that observers are notified of the creation of this WebContents's
1797 // main RenderFrameHost. It must be done here for main frames, since the
1798 // NotifySwappedFromRenderManager expects view_ to already be created and that
1799 // happens after RenderFrameHostManager::Init.
1800 NotifySwappedFromRenderManager(
1801 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191802}
1803
[email protected]7fff43e2013-05-21 20:21:101804void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1805 RemoveDestructionObserver(web_contents);
1806
[email protected]ceee8cd2013-03-08 04:59:511807 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:531808 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:511809 ++iter) {
1810 if (iter->second != web_contents)
1811 continue;
1812 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511813 return;
1814 }
1815 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441816}
1817
[email protected]7fff43e2013-05-21 20:21:101818void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1819 if (!ContainsKey(destruction_observers_, web_contents)) {
1820 destruction_observers_[web_contents] =
avia8cf81982016-08-12 20:28:461821 base::MakeUnique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:101822 }
1823}
1824
1825void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:461826 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:101827}
1828
[email protected]b172aee2012-04-10 17:05:261829void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311830 observers_.AddObserver(observer);
1831}
1832
[email protected]b172aee2012-04-10 17:05:261833void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311834 observers_.RemoveObserver(observer);
1835}
1836
[email protected]948481d2014-06-11 18:32:221837std::set<RenderWidgetHostView*>
1838WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1839 std::set<RenderWidgetHostView*> set;
1840 if (ShowingInterstitialPage()) {
lfgf949e0e2017-05-10 22:18:111841 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView())
1842 set.insert(rwhv);
[email protected]948481d2014-06-11 18:32:221843 } else {
dchengafb53e22016-02-04 08:11:081844 for (RenderFrameHost* rfh : GetAllFrames()) {
lfgf949e0e2017-05-10 22:18:111845 if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1846 ->frame_tree_node()
1847 ->render_manager()
1848 ->GetRenderWidgetHostView()) {
1849 set.insert(rwhv);
1850 }
dchengafb53e22016-02-04 08:11:081851 }
[email protected]948481d2014-06-11 18:32:221852 }
[email protected]de3c5d82014-05-28 22:12:591853 return set;
1854}
1855
[email protected]b172aee2012-04-10 17:05:261856void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341857 if (delegate_)
1858 delegate_->ActivateContents(this);
1859}
1860
avi3e4b8512015-11-11 01:55:491861void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1862 if (!RenderViewHostImpl::From(render_widget_host))
1863 return;
1864
[email protected]63954792011-07-11 04:17:481865 if (delegate_)
1866 delegate_->LostCapture();
1867}
1868
lazyboy63f5b312015-11-23 20:19:521869void WebContentsImpl::RenderWidgetCreated(
1870 RenderWidgetHostImpl* render_widget_host) {
1871 created_widgets_.insert(render_widget_host);
1872}
1873
[email protected]b24b68a2012-09-24 21:57:261874void WebContentsImpl::RenderWidgetDeleted(
1875 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521876 // Note that |is_being_destroyed_| can be true at this point as
1877 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1878 // us here.
1879 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261880
lazyboy63f5b312015-11-23 20:19:521881 if (is_being_destroyed_)
1882 return;
[email protected]44470a22013-01-24 01:21:541883
1884 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:371885 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
1886 render_widget_host->GetProcess()->GetID() ==
1887 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:491888 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531889 delegate_->ExitFullscreenModeForTab(this);
ericwilligersde386342016-10-19 02:35:091890 for (auto& observer : observers_)
1891 observer.DidDestroyFullscreenWidget();
alexmosc9e76ec2016-05-16 22:59:371892 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:541893 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031894 if (fullscreen_widget_had_focus_at_shutdown_)
1895 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541896 }
lfgbee1e0a2016-06-08 21:24:211897
lfg7d4caad2017-03-22 09:01:451898 if (render_widget_host == mouse_lock_widget_)
lfgff8dfc8d2016-10-21 17:42:321899 LostMouseLock(mouse_lock_widget_);
[email protected]b24b68a2012-09-24 21:57:261900}
1901
miu9e14e492014-10-25 02:39:041902void WebContentsImpl::RenderWidgetGotFocus(
1903 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371904 // Notify the observers if an embedded fullscreen widget was focused.
1905 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1906 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
Michael Thiessen896405db2017-07-20 17:52:321907 NotifyWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:371908 }
miu9e14e492014-10-25 02:39:041909}
1910
zijiehe3bee08e22017-05-17 04:14:461911void WebContentsImpl::RenderWidgetLostFocus(
1912 RenderWidgetHostImpl* render_widget_host) {
Michael Thiessen896405db2017-07-20 17:52:321913 // Notify the observers if an embedded fullscreen widget lost focus.
1914 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1915 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1916 NotifyWebContentsLostFocus(render_widget_host);
1917 }
zijiehe3bee08e22017-05-17 04:14:461918}
1919
estaded0a0c992015-01-21 14:12:061920void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311921 RenderWidgetHostImpl* render_widget_host,
1922 bool width_changed) {
creisc014b402015-04-23 16:41:451923 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291924 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061925 return;
estaded0a0c992015-01-21 14:12:061926
lfg8d649cc2017-04-28 18:04:301927 ScreenInfo screen_info;
1928 GetScreenInfo(&screen_info);
1929 SendPageMessage(new PageMsg_UpdateScreenInfo(MSG_ROUTING_NONE, screen_info));
1930
lfg95f00bd52017-06-08 00:03:201931 // Send resize message to subframes.
1932 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1933 if (view != rfh->GetView())
1934 view->GetRenderWidgetHost()->WasResized();
1935 }
1936
ericwilligersde386342016-10-19 02:35:091937 for (auto& observer : observers_)
1938 observer.MainFrameWasResized(width_changed);
estaded0a0c992015-01-21 14:12:061939}
1940
paulmeyer9ef6e4462015-02-24 19:15:101941void WebContentsImpl::ScreenInfoChanged() {
1942 if (browser_plugin_embedder_)
1943 browser_plugin_embedder_->ScreenInfoChanged();
1944}
1945
skyf65d9bb2017-03-24 02:26:391946KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(
1947 const NativeWebKeyboardEvent& event) {
1948 return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event)
1949 : KeyboardEventProcessingResult::NOT_HANDLED;
[email protected]63954792011-07-11 04:17:481950}
1951
[email protected]b172aee2012-04-10 17:05:261952void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101953 if (browser_plugin_embedder_ &&
1954 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1955 return;
1956 }
[email protected]63954792011-07-11 04:17:481957 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131958 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481959}
1960
[email protected]d92026ef2014-03-03 21:04:131961bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461962 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191963#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331964 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1965 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191966 // -the OS already has a gesture to do this through pinch-zoom
1967 // -if a user starts an inertial scroll, let's go, and presses control
1968 // (i.e. control+tab) then the OS's buffered scroll events will come in
1969 // with control key set which isn't what the user wants
Blink Reformat1c4d759e2017-04-09 16:34:541970 if (delegate_ && event.wheel_ticks_y &&
chongz4a9751942016-08-17 17:49:391971 !ui::WebInputEventTraits::CanCauseScroll(event)) {
w.shackleton49bcd392016-01-06 17:38:221972 // Count only integer cumulative scrolls as zoom events; this handles
1973 // smooth scroll and regular scroll device behavior.
Blink Reformat1c4d759e2017-04-09 16:34:541974 zoom_scroll_remainder_ += event.wheel_ticks_y;
w.shackleton49bcd392016-01-06 17:38:221975 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1976 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1977 if (whole_zoom_scroll_remainder_ != 0) {
1978 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1979 }
[email protected]fb3f066e2013-02-12 19:12:521980 return true;
1981 }
[email protected]bccc4472013-04-18 16:37:191982#endif
[email protected]fb3f066e2013-02-12 19:12:521983 return false;
1984}
1985
[email protected]04bce562014-01-30 05:34:541986bool WebContentsImpl::PreHandleGestureEvent(
1987 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031988 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541989}
1990
kenrb2a565f82015-09-02 20:24:591991RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451992 if (!is_being_destroyed_ && GetOuterWebContents())
1993 return GetOuterWebContents()->GetInputEventRouter();
1994
1995 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591996 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1997 return rwh_input_event_router_.get();
1998}
1999
alexmos3fcd0ca2015-10-23 18:18:332000void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
2001 // Focus loss may occur while this WebContents is being destroyed. Don't
2002 // send the message in this case, as the main frame's RenderFrameHost and
2003 // other state has already been cleared.
2004 if (is_being_destroyed_)
2005 return;
2006
2007 frame_tree_.ReplicatePageFocus(is_focused);
2008}
2009
alexmosc4cbacb2015-11-21 01:29:222010RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
2011 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:522012 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:222013 return receiving_widget;
2014
2015 // Events for widgets other than the main frame (e.g., popup menus) should be
2016 // forwarded directly to the widget they arrived on.
2017 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
2018 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522019
lfg1453e412017-04-11 00:48:502020 WebContentsImpl* focused_contents = GetFocusedWebContents();
2021
2022 // If the focused WebContents is showing an interstitial, return the
2023 // interstitial's widget.
2024 if (focused_contents->ShowingInterstitialPage()) {
2025 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112026 focused_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502027 ->GetRenderWidgetHost();
2028 }
2029
paulmeyerfeafc2d2017-04-25 21:46:402030 // If the focused WebContents is a guest WebContents, then get the focused
2031 // frame in the embedder WebContents instead.
2032 FrameTreeNode* focused_frame = nullptr;
2033 if (focused_contents->browser_plugin_guest_ &&
2034 !GuestMode::IsCrossProcessFrameGuest(focused_contents)) {
2035 focused_frame = frame_tree_.GetFocusedFrame();
2036 } else {
2037 focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
2038 }
lfg1453e412017-04-11 00:48:502039
alexmosc4d183e2015-11-06 00:46:522040 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:222041 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522042
alexmos732ca3a2015-12-08 02:01:022043 // The view may be null if a subframe's renderer process has crashed while
2044 // the subframe has focus. Drop the event in that case. Do not give
2045 // it to the main frame, so that the user doesn't unexpectedly type into the
2046 // wrong frame if a focused subframe renderer crashes while they type.
2047 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
2048 if (!view)
2049 return nullptr;
2050
2051 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:522052}
2053
avallee9993fca2016-11-17 06:16:502054RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
lfg1453e412017-04-11 00:48:502055 WebContentsImpl* focused_web_contents = GetFocusedWebContents();
2056
2057 if (focused_web_contents->ShowingInterstitialPage()) {
2058 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112059 focused_web_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502060 ->GetRenderWidgetHost();
2061 }
2062
2063 return focused_web_contents->GetMainFrame()->GetRenderWidgetHost();
avallee9993fca2016-11-17 06:16:502064}
2065
mlamouri7a78d6fd2015-01-17 13:23:532066void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
2067 // This method is being called to enter renderer-initiated fullscreen mode.
2068 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:492069 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372070 if (widget_view) {
2071 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2072 ->ShutdownAndDestroyWidget(true);
2073 }
[email protected]4aebbca2013-09-17 22:26:492074
[email protected]8a5e0ca2011-08-25 06:30:472075 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:532076 delegate_->EnterFullscreenModeForTab(this, origin);
2077
ericwilligersde386342016-10-19 02:35:092078 for (auto& observer : observers_)
2079 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false);
mlamouri7a78d6fd2015-01-17 13:23:532080}
2081
bokanece34a82016-01-28 19:49:462082void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532083 // This method is being called to leave renderer-initiated fullscreen mode.
2084 // Make sure any existing fullscreen widget is shut down first.
2085 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372086 if (widget_view) {
2087 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2088 ->ShutdownAndDestroyWidget(true);
2089 }
mlamouri7a78d6fd2015-01-17 13:23:532090
hugo.holgersson61288e6c2015-01-28 17:04:402091#if defined(OS_ANDROID)
2092 ContentVideoView* video_view = ContentVideoView::GetInstance();
2093 if (video_view != NULL)
watk98292292016-01-19 22:24:082094 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:402095#endif
2096
mlamouri7a78d6fd2015-01-17 13:23:532097 if (delegate_)
2098 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:372099
bokanece34a82016-01-28 19:49:462100 // The fullscreen state is communicated to the renderer through a resize
2101 // message. If the change in fullscreen state doesn't cause a view resize
2102 // then we must ensure web contents exit the fullscreen state by explicitly
2103 // sending a resize message. This is required for the situation of the browser
2104 // moving the view into a "browser fullscreen" state and then the contents
2105 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
2106 // have the side effect of the view resizing, hence the explicit call here is
2107 // required.
2108 if (!will_cause_resize) {
2109 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
2110 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
2111 render_widget_host->WasResized();
2112 }
scheib3dcb6c932015-02-23 10:55:582113 }
2114
ericwilligersde386342016-10-19 02:35:092115 for (auto& observer : observers_) {
2116 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
2117 will_cause_resize);
2118 }
[email protected]8a5e0ca2011-08-25 06:30:472119}
2120
alexmos5dd617d2016-06-07 04:21:152121bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:382122 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:122123}
2124
billorr21c005d2016-11-17 03:57:042125bool WebContentsImpl::IsFullscreen() {
2126 return IsFullscreenForCurrentTab();
2127}
2128
avibf58fa0c2015-11-11 01:45:522129blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
2130 RenderWidgetHostImpl* render_widget_host) const {
2131 if (!RenderViewHostImpl::From(render_widget_host))
Blink Reformat1c4d759e2017-04-09 16:34:542132 return blink::kWebDisplayModeBrowser;
avibf58fa0c2015-11-11 01:45:522133
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122134 return delegate_ ? delegate_->GetDisplayMode(this)
Blink Reformat1c4d759e2017-04-09 16:34:542135 : blink::kWebDisplayModeBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122136}
2137
avic3aa8422015-11-09 20:57:222138void WebContentsImpl::RequestToLockMouse(
2139 RenderWidgetHostImpl* render_widget_host,
2140 bool user_gesture,
lfgad8244352016-07-13 16:55:512141 bool last_unlocked_by_target,
2142 bool privileged) {
lfgf0cd46e2017-01-04 00:05:232143 for (WebContentsImpl* current = this; current;
2144 current = current->GetOuterWebContents()) {
2145 if (current->mouse_lock_widget_) {
2146 render_widget_host->GotResponseToLockMouseRequest(false);
2147 return;
2148 }
[email protected]e9621112011-10-17 05:38:372149 }
avic3aa8422015-11-09 20:57:222150
lfgad8244352016-07-13 16:55:512151 if (privileged) {
lfgf0cd46e2017-01-04 00:05:232152 DCHECK(!GetOuterWebContents());
lfgad8244352016-07-13 16:55:512153 mouse_lock_widget_ = render_widget_host;
2154 render_widget_host->GotResponseToLockMouseRequest(true);
2155 return;
2156 }
2157
lfgbee1e0a2016-06-08 21:24:212158 bool widget_in_frame_tree = false;
2159 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2160 if (node->current_frame_host()->GetRenderWidgetHost() ==
2161 render_widget_host) {
2162 widget_in_frame_tree = true;
2163 break;
2164 }
2165 }
2166
2167 if (widget_in_frame_tree && delegate_) {
lfgf0cd46e2017-01-04 00:05:232168 for (WebContentsImpl* current = this; current;
2169 current = current->GetOuterWebContents()) {
2170 current->mouse_lock_widget_ = render_widget_host;
2171 }
2172
avic3aa8422015-11-09 20:57:222173 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:212174 } else {
2175 render_widget_host->GotResponseToLockMouseRequest(false);
2176 }
[email protected]e9621112011-10-17 05:38:372177}
2178
avi3e4b8512015-11-11 01:55:492179void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:212180 CHECK(mouse_lock_widget_);
lfgf0cd46e2017-01-04 00:05:232181
2182 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this)
2183 return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host);
2184
lfgbee1e0a2016-06-08 21:24:212185 mouse_lock_widget_->SendMouseLockLost();
lfgf0cd46e2017-01-04 00:05:232186 for (WebContentsImpl* current = this; current;
2187 current = current->GetOuterWebContents()) {
2188 current->mouse_lock_widget_ = nullptr;
2189 }
avi3e4b8512015-11-11 01:55:492190
[email protected]e9621112011-10-17 05:38:372191 if (delegate_)
2192 delegate_->LostMouseLock();
2193}
2194
lfgad8244352016-07-13 16:55:512195bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
2196 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
2197 // assigned to the widget that requested the mouse lock, and the top-level
2198 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
2199 return mouse_lock_widget_ == render_widget_host &&
2200 GetTopLevelRenderWidgetHostView()->IsMouseLocked();
2201}
2202
lfg84763c92017-02-16 18:55:152203RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() {
lfge2176fb2017-03-26 00:45:472204 if (GetTopLevelRenderWidgetHostView()->IsMouseLocked() ||
2205 (GetFullscreenRenderWidgetHostView() &&
2206 GetFullscreenRenderWidgetHostView()->IsMouseLocked()))
lfg84763c92017-02-16 18:55:152207 return mouse_lock_widget_;
2208
2209 return nullptr;
2210}
2211
ekaramada4f42692016-02-11 19:48:372212void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
lfg9462cef2016-07-18 23:51:062213 if (visible && !GetOuterWebContents()->IsHidden())
ekaramada4f42692016-02-11 19:48:372214 WasShown();
lfg9462cef2016-07-18 23:51:062215 else if (!visible)
ekaramada4f42692016-02-11 19:48:372216 WasHidden();
2217}
2218
[email protected]bafe6cd2012-05-23 23:09:502219void WebContentsImpl::CreateNewWindow(
csharrison95f01e922017-04-24 18:52:352220 RenderFrameHost* opener,
nick5ae4d2d2017-01-06 01:18:352221 int32_t render_view_route_id,
dcheng3ce04b62015-10-26 23:30:552222 int32_t main_frame_route_id,
2223 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:182224 const mojom::CreateNewWindowParams& params,
[email protected]97714c82012-06-06 10:15:132225 SessionStorageNamespace* session_storage_namespace) {
nick5ae4d2d2017-01-06 01:18:352226 // We should have zero valid routing ids, or three valid routing IDs.
2227 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2228 (main_frame_route_id == MSG_ROUTING_NONE));
2229 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2230 (main_frame_widget_route_id == MSG_ROUTING_NONE));
csharrison95f01e922017-04-24 18:52:352231 DCHECK(opener);
nick5ae4d2d2017-01-06 01:18:352232
csharrison95f01e922017-04-24 18:52:352233 int render_process_id = opener->GetProcess()->GetID();
2234 SiteInstance* source_site_instance = opener->GetSiteInstance();
2235
2236 // The route IDs passed into this function can be trusted not to already
2237 // be in use; they were allocated by the RenderWidgetHelper by the caller.
nick5ae4d2d2017-01-06 01:18:352238 DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id));
2239
[email protected]bafe6cd2012-05-23 23:09:502240 // We usually create the new window in the same BrowsingInstance (group of
2241 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:552242 // if the opener is being suppressed (in a non-guest), we create a new
2243 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:252244 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:552245
[email protected]04cbd3d2013-12-04 04:58:202246 // If the opener is to be suppressed, the new window can be in any process.
2247 // Since routing ids are process specific, we must not have one passed in
2248 // as argument here.
nick5ae4d2d2017-01-06 01:18:352249 DCHECK(!params.opener_suppressed || render_view_route_id == MSG_ROUTING_NONE);
[email protected]04cbd3d2013-12-04 04:58:202250
[email protected]bafe6cd2012-05-23 23:09:502251 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:432252 params.opener_suppressed && !is_guest
2253 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
2254 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:502255
[email protected]d1198fd2012-08-13 22:50:192256 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:342257 //
2258 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:302259 const std::string& partition_id =
2260 GetContentClient()->browser()->
2261 GetStoragePartitionIdForSite(GetBrowserContext(),
2262 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:462263 StoragePartition* partition = BrowserContext::GetStoragePartition(
2264 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:412265 DOMStorageContextWrapper* dom_storage_context =
2266 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:192267 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2268 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2269 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:372270
2271 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:552272 !delegate_->ShouldCreateWebContents(
lukasza6f8ac622017-06-06 03:10:202273 this, opener, source_site_instance, render_view_route_id,
2274 main_frame_route_id, main_frame_widget_route_id,
2275 params.window_container_type, opener->GetLastCommittedURL(),
2276 params.frame_name, params.target_url, partition_id,
2277 session_storage_namespace)) {
jambaaab3a2016-11-05 00:46:182278 // Note: even though we're not creating a WebContents here, it could have
2279 // been created by the embedder so ensure that the RenderFrameHost is
2280 // properly initialized.
csharrisona2280cd2016-02-03 23:21:152281 // It's safe to only target the frame because the render process will not
2282 // have a chance to create more frames at this point.
jambaaab3a2016-11-05 00:46:182283 RenderFrameHostImpl* rfh =
2284 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id);
nick5ae4d2d2017-01-06 01:18:352285 if (rfh) {
2286 DCHECK(rfh->IsRenderFrameLive());
jambaaab3a2016-11-05 00:46:182287 rfh->Init();
nick5ae4d2d2017-01-06 01:18:352288 }
[email protected]dd6730412013-08-14 15:03:372289 return;
2290 }
2291
2292 // Create the new web contents. This will automatically create the new
2293 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462294 CreateParams create_params(GetBrowserContext(), site_instance.get());
nick5ae4d2d2017-01-06 01:18:352295 create_params.routing_id = render_view_route_id;
[email protected]227692c52013-05-31 22:43:042296 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:552297 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:122298 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432299 create_params.opener_render_process_id = render_process_id;
csharrison95f01e922017-04-24 18:52:352300 create_params.opener_render_frame_id = opener->GetRoutingID();
[email protected]50d326e2014-05-20 17:59:062301 create_params.opener_suppressed = params.opener_suppressed;
nick3b04f322016-08-31 19:29:192302 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
[email protected]50d326e2014-05-20 17:59:062303 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:192304 create_params.renderer_initiated_creation =
2305 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:062306
[email protected]4858e432014-06-23 18:14:172307 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:552308 if (!is_guest) {
2309 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:452310 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:172311 new_contents = static_cast<WebContentsImpl*>(
2312 WebContents::Create(create_params));
2313 } else {
2314 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:552315 }
[email protected]50d326e2014-05-20 17:59:062316 new_contents->GetController().SetSessionStorageNamespace(
2317 partition_id,
2318 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192319
alexmos646fec02015-07-25 00:11:492320 // If the new frame has a name, make sure any SiteInstances that can find
2321 // this named frame have proxies for it. Must be called after
2322 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2323 // GetSessionStorageNamespace.
2324 if (!params.frame_name.empty())
2325 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
2326
[email protected]c4538072013-03-18 02:17:552327 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342328 // will be shown immediately).
2329 if (!params.opener_suppressed) {
2330 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:452331 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502332
[email protected]d70bea92013-04-05 04:23:342333 // TODO(brettw): It seems bogus that we have to call this function on the
2334 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:432335 new_view->CreateViewForWidget(
2336 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:342337 }
[email protected]bafe6cd2012-05-23 23:09:502338 // Save the created window associated with the route so we can show it
2339 // later.
nick5ae4d2d2017-01-06 01:18:352340 DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id);
2341 pending_contents_[std::make_pair(
2342 render_process_id, main_frame_widget_route_id)] = new_contents;
[email protected]7fff43e2013-05-21 20:21:102343 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502344 }
2345
2346 if (delegate_) {
Bryan McQuaded2b93c02017-07-14 22:26:312347 delegate_->WebContentsCreated(this, render_process_id,
2348 opener->GetRoutingID(), params.frame_name,
2349 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:502350 }
2351
csharrison95f01e922017-04-24 18:52:352352 if (opener) {
pnolandaae574e2017-03-06 21:04:212353 for (auto& observer : observers_) {
csharrison95f01e922017-04-24 18:52:352354 observer.DidOpenRequestedURL(new_contents, opener, params.target_url,
2355 params.referrer, params.disposition,
2356 ui::PAGE_TRANSITION_LINK,
pnolandaae574e2017-03-06 21:04:212357 false, // started_from_context_menu
2358 true); // renderer_initiated
2359 }
2360 }
2361
[email protected]bafe6cd2012-05-23 23:09:502362 if (params.opener_suppressed) {
2363 // When the opener is suppressed, the original renderer cannot access the
2364 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002365 bool was_blocked = false;
2366 if (delegate_) {
bokan107a47f2015-02-03 23:23:392367 gfx::Rect initial_rect;
nick0d558482017-02-13 22:27:222368 base::WeakPtr<WebContentsImpl> weak_new_contents =
2369 new_contents->weak_factory_.GetWeakPtr();
2370
[email protected]eda238a12012-09-07 23:44:002371 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:392372 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:002373 params.user_gesture, &was_blocked);
nick0d558482017-02-13 22:27:222374
2375 if (!weak_new_contents)
2376 return; // The delegate deleted |new_contents| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002377 }
2378 if (!was_blocked) {
nick3b04f322016-08-31 19:29:192379 OpenURLParams open_params(params.target_url, params.referrer,
2380 WindowOpenDisposition::CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352381 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212382 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:302383 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372384
2385 if (delegate_ && !is_guest &&
2386 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
2387 // We are in asynchronous add new contents path, delay opening url
2388 new_contents->delayed_open_url_params_.reset(
2389 new OpenURLParams(open_params));
2390 } else {
2391 new_contents->OpenURL(open_params);
2392 }
[email protected]eda238a12012-09-07 23:44:002393 }
[email protected]bafe6cd2012-05-23 23:09:502394 }
2395}
2396
avib7348942015-12-25 20:57:102397void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2398 int32_t route_id,
Dave Tapuska1bdf1832017-07-07 18:07:192399 mojom::WidgetPtr widget,
[email protected]180ef242013-11-07 06:50:462400 blink::WebPopupType popup_type) {
Dave Tapuska1bdf1832017-07-07 18:07:192401 CreateNewWidget(render_process_id, route_id, false, std::move(widget),
2402 popup_type);
[email protected]bafe6cd2012-05-23 23:09:502403}
2404
avib7348942015-12-25 20:57:102405void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
Dave Tapuska1bdf1832017-07-07 18:07:192406 int32_t route_id,
2407 mojom::WidgetPtr widget) {
2408 CreateNewWidget(render_process_id, route_id, true, std::move(widget),
2409 blink::kWebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502410}
2411
avib7348942015-12-25 20:57:102412void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2413 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502414 bool is_fullscreen,
Dave Tapuska1bdf1832017-07-07 18:07:192415 mojom::WidgetPtr widget,
[email protected]180ef242013-11-07 06:50:462416 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252417 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232418 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512419 // this WebContentsImpl instance. If any other process sends the request,
2420 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382421 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:252422 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:512423 if (process_handle != base::kNullProcessHandle) {
2424 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392425 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252426 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512427 }
2428 return;
2429 }
2430
Dave Tapuska485aca92017-08-08 00:47:582431 RenderWidgetHostImpl* widget_host = new RenderWidgetHostImpl(
2432 this, process, route_id, std::move(widget), IsHidden());
[email protected]b24b68a2012-09-24 21:57:262433
[email protected]cfd80b02014-05-01 17:46:482434 RenderWidgetHostViewBase* widget_view =
2435 static_cast<RenderWidgetHostViewBase*>(
2436 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192437 if (!widget_view)
2438 return;
[email protected]bafe6cd2012-05-23 23:09:502439 if (!is_fullscreen) {
2440 // Popups should not get activated.
2441 widget_view->SetPopupType(popup_type);
2442 }
2443 // Save the created widget associated with the route so we can show it later.
alexmosc2a8cec2016-05-23 22:19:532444 pending_widget_views_[std::make_pair(render_process_id, route_id)] =
2445 widget_view;
[email protected]bafe6cd2012-05-23 23:09:502446
2447#if defined(OS_MACOSX)
2448 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2449 // to allow it to survive the trip without being hosted.
2450 base::mac::NSObjectRetain(widget_view->GetNativeView());
2451#endif
2452}
2453
alexmosc2a8cec2016-05-23 22:19:532454void WebContentsImpl::ShowCreatedWindow(int process_id,
nick5ae4d2d2017-01-06 01:18:352455 int main_frame_widget_route_id,
[email protected]bafe6cd2012-05-23 23:09:502456 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392457 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502458 bool user_gesture) {
nick0d558482017-02-13 22:27:222459 WebContentsImpl* popup =
nick5ae4d2d2017-01-06 01:18:352460 GetCreatedWindow(process_id, main_frame_widget_route_id);
nick0d558482017-02-13 22:27:222461 if (popup) {
[email protected]eda238a12012-09-07 23:44:002462 WebContentsDelegate* delegate = GetDelegate();
nick0d558482017-02-13 22:27:222463 popup->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382464 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
nick0d558482017-02-13 22:27:222465 popup->ResumeLoadingCreatedWebContents();
mariakhomenko44bdc4732015-04-29 01:55:382466
[email protected]eda238a12012-09-07 23:44:002467 if (delegate) {
nick0d558482017-02-13 22:27:222468 base::WeakPtr<WebContentsImpl> weak_popup =
2469 popup->weak_factory_.GetWeakPtr();
2470 delegate->AddNewContents(this, popup, disposition, initial_rect,
2471 user_gesture, nullptr);
2472 if (!weak_popup)
2473 return; // The delegate deleted |popup| during AddNewContents().
[email protected]eda238a12012-09-07 23:44:002474 }
nick5ae4d2d2017-01-06 01:18:352475
nick0d558482017-02-13 22:27:222476 RenderWidgetHostImpl* rwh = popup->GetMainFrame()->GetRenderWidgetHost();
2477 DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID());
nick5ae4d2d2017-01-06 01:18:352478 rwh->Send(new ViewMsg_Move_ACK(rwh->GetRoutingID()));
[email protected]eda238a12012-09-07 23:44:002479 }
[email protected]bafe6cd2012-05-23 23:09:502480}
2481
alexmosc2a8cec2016-05-23 22:19:532482void WebContentsImpl::ShowCreatedWidget(int process_id,
2483 int route_id,
bokan107a47f2015-02-03 23:23:392484 const gfx::Rect& initial_rect) {
alexmosc2a8cec2016-05-23 22:19:532485 ShowCreatedWidget(process_id, route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502486}
2487
alexmosc2a8cec2016-05-23 22:19:532488void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
2489 int route_id) {
2490 ShowCreatedWidget(process_id, route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:502491}
2492
alexmosc2a8cec2016-05-23 22:19:532493void WebContentsImpl::ShowCreatedWidget(int process_id,
2494 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502495 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392496 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482497 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:532498 static_cast<RenderWidgetHostViewBase*>(
2499 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502500 if (!widget_host_view)
2501 return;
[email protected]cfd80b02014-05-01 17:46:482502
2503 RenderWidgetHostView* view = NULL;
lfgc740d4b22016-04-15 16:45:332504 if (GetOuterWebContents()) {
2505 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482506 } else {
2507 view = GetRenderWidgetHostView();
2508 }
2509
[email protected]4aebbca2013-09-17 22:26:492510 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312511 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032512 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:372513 fullscreen_widget_process_id_ =
2514 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:312515 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492516 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2517 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532518 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492519 } else {
[email protected]cfd80b02014-05-01 17:46:482520 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492521 }
ericwilligersde386342016-10-19 02:35:092522 for (auto& observer : observers_)
2523 observer.DidShowFullscreenWidget();
[email protected]4aebbca2013-09-17 22:26:492524 if (!widget_host_view->HasFocus())
2525 widget_host_view->Focus();
2526 } else {
bokan107a47f2015-02-03 23:23:392527 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492528 }
[email protected]89054502012-06-03 10:29:242529
2530 RenderWidgetHostImpl* render_widget_host_impl =
2531 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2532 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312533 // Only allow privileged mouse lock for fullscreen render widget, which is
2534 // used to implement Pepper Flash fullscreen.
2535 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502536
2537#if defined(OS_MACOSX)
2538 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2539 // properly embedded (or purposefully ignored) we can release the retain we
2540 // took in CreateNewWidget().
2541 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2542#endif
2543}
2544
nick5ae4d2d2017-01-06 01:18:352545WebContentsImpl* WebContentsImpl::GetCreatedWindow(
2546 int process_id,
2547 int main_frame_widget_route_id) {
2548 auto key = std::make_pair(process_id, main_frame_widget_route_id);
2549 auto iter = pending_contents_.find(key);
[email protected]bafe6cd2012-05-23 23:09:502550
2551 // Certain systems can block the creation of new windows. If we didn't succeed
2552 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:532553 if (iter == pending_contents_.end())
2554 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502555
2556 WebContentsImpl* new_contents = iter->second;
nick5ae4d2d2017-01-06 01:18:352557 pending_contents_.erase(key);
[email protected]7fff43e2013-05-21 20:21:102558 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502559
[email protected]d70bea92013-04-05 04:23:342560 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252561 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342562 return new_contents;
2563
nick5ae4d2d2017-01-06 01:18:352564 if (!new_contents->GetMainFrame()->GetProcess()->HasConnection() ||
2565 !new_contents->GetMainFrame()->GetView()) {
2566 // TODO(nick): http://crbug.com/674318 -- Who deletes |new_contents|?
alexmosc2a8cec2016-05-23 22:19:532567 return nullptr;
nick5ae4d2d2017-01-06 01:18:352568 }
[email protected]bafe6cd2012-05-23 23:09:502569
[email protected]bafe6cd2012-05-23 23:09:502570 return new_contents;
2571}
2572
alexmosc2a8cec2016-05-23 22:19:532573RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
2574 int route_id) {
2575 auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502576 if (iter == pending_widget_views_.end()) {
2577 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:532578 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502579 }
2580
2581 RenderWidgetHostView* widget_host_view = iter->second;
alexmosc2a8cec2016-05-23 22:19:532582 pending_widget_views_.erase(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502583
2584 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2585 if (!widget_host->GetProcess()->HasConnection()) {
2586 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:532587 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502588 }
2589
2590 return widget_host_view;
2591}
2592
[email protected]f13b4202012-06-12 23:53:232593void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092594 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212595 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372596 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232597 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372598 } else {
dcheng59716272016-04-09 05:19:082599 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2600 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372601 }
[email protected]f13b4202012-06-12 23:53:232602}
2603
grunell657d4d82014-09-18 00:09:432604bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2605 MediaStreamType type) {
2606 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2607 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2608 return delegate_ &&
2609 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2610}
2611
guidou8a440b842017-01-30 13:58:432612std::string WebContentsImpl::GetDefaultMediaDeviceID(MediaStreamType type) {
2613 if (!delegate_)
2614 return std::string();
2615 return delegate_->GetDefaultMediaDeviceID(this, type);
2616}
2617
[email protected]cc9200432013-07-23 23:02:402618SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2619 SiteInstance* instance) {
2620 return controller_.GetSessionStorageNamespace(instance);
2621}
2622
[email protected]6de7fc482014-06-06 10:46:442623SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2624 return controller_.GetSessionStorageNamespaceMap();
2625}
2626
[email protected]9b159a52013-10-03 17:24:552627FrameTree* WebContentsImpl::GetFrameTree() {
2628 return &frame_tree_;
2629}
2630
lukendc35e7f2014-11-10 19:06:142631void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2632 virtual_keyboard_requested_ = requested;
2633}
2634
2635bool WebContentsImpl::IsVirtualKeyboardRequested() {
2636 return virtual_keyboard_requested_;
2637}
2638
aelias5252baa2016-04-10 01:18:022639bool WebContentsImpl::IsOverridingUserAgent() {
2640 return GetController().GetVisibleEntry() &&
2641 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2642}
2643
avi85ee8362016-10-08 02:09:082644bool WebContentsImpl::IsJavaScriptDialogShowing() const {
2645 return is_showing_javascript_dialog_;
2646}
2647
avic031d392017-03-03 03:09:422648bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() {
2649 // Ignore unresponsive renderers if the debugger is attached to them since the
2650 // unresponsiveness might be a result of the renderer sitting on a breakpoint.
2651 //
2652 // TODO(pfeldman): Fix this to only return true if the renderer is *actually*
2653 // sitting on a breakpoint. https://crbug.com/684202
2654 return DevToolsAgentHost::IsDebuggerAttached(this);
2655}
2656
Doug Turner63f3c7b2017-07-29 05:10:012657ui::AXMode WebContentsImpl::GetAccessibilityMode() const {
[email protected]95640212014-07-26 18:14:302658 return accessibility_mode_;
2659}
2660
Dominic Mazzonib8160a952017-08-07 07:23:062661void WebContentsImpl::AccessibilityEventsReceived(
2662 ui::AXTreeIDRegistry::AXTreeID ax_tree_id,
2663 const ui::AXTreeUpdate& update,
2664 const std::vector<AXEventNotificationDetails>& events) {
ericwilligersde386342016-10-19 02:35:092665 for (auto& observer : observers_)
Dominic Mazzonib8160a952017-08-07 07:23:062666 observer.AccessibilityEventsReceived(ax_tree_id, update, events);
[email protected]31a71eaf2014-03-13 01:47:362667}
2668
dmazzoni2400c462016-08-23 15:07:132669void WebContentsImpl::AccessibilityLocationChangesReceived(
Dominic Mazzonib8160a952017-08-07 07:23:062670 ui::AXTreeIDRegistry::AXTreeID ax_tree_id,
dmazzoni2400c462016-08-23 15:07:132671 const std::vector<AXLocationChangeNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:092672 for (auto& observer : observers_)
Dominic Mazzonib8160a952017-08-07 07:23:062673 observer.AccessibilityLocationChangesReceived(ax_tree_id, details);
dmazzoni2400c462016-08-23 15:07:132674}
2675
dmazzonia656928e2014-09-15 20:28:542676RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402677 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542678 int browser_plugin_instance_id) {
2679 BrowserPluginGuestManager* guest_manager =
2680 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202681 if (!guest_manager)
2682 return nullptr;
2683
dmazzonia656928e2014-09-15 20:28:542684 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442685 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542686 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202687 return nullptr;
2688
dmazzonia656928e2014-09-15 20:28:542689 return guest->GetMainFrame();
2690}
2691
Conley Owens6894c4f2017-07-10 19:29:132692device::GeolocationContext* WebContentsImpl::GetGeolocationContext() {
2693 return geolocation_context_.get();
blundellc57b93f2014-10-29 13:19:572694}
2695
ke.he98b761e2017-05-09 05:59:172696device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() {
blundelld8cd72b2017-03-28 07:18:382697 if (!wake_lock_context_host_)
2698 wake_lock_context_host_.reset(new WakeLockContextHost(this));
blundelle75a8f92017-03-27 08:11:172699 return wake_lock_context_host_->GetWakeLockContext();
alogvinovf50445a2015-10-30 13:00:122700}
2701
juncai8e8d6ec2017-06-06 20:48:182702device::mojom::WakeLock* WebContentsImpl::GetRendererWakeLock() {
2703 // WebContents creates a long-lived connection to one WakeLock.
ke.he98b761e2017-05-09 05:59:172704 // All the frames' requests will be added into the BindingSet of
juncai8e8d6ec2017-06-06 20:48:182705 // WakeLock via this connection.
ke.he98b761e2017-05-09 05:59:172706 if (!renderer_wake_lock_) {
2707 device::mojom::WakeLockContext* wake_lock_context = GetWakeLockContext();
2708 if (!wake_lock_context) {
2709 return nullptr;
2710 }
ke.hef435c1e82017-05-11 04:09:102711 wake_lock_context->GetWakeLock(
2712 device::mojom::WakeLockType::PreventDisplaySleep,
2713 device::mojom::WakeLockReason::ReasonOther, "Wake Lock API",
2714 mojo::MakeRequest(&renderer_wake_lock_));
ke.he98b761e2017-05-09 05:59:172715 }
2716 return renderer_wake_lock_.get();
2717}
2718
blundellf5316fc2017-05-15 11:49:032719#if defined(OS_ANDROID)
Han Leonf6a2e5f2017-05-23 13:40:472720void WebContentsImpl::GetNFC(device::mojom::NFCRequest request) {
blundellf5316fc2017-05-15 11:49:032721 if (!nfc_host_)
2722 nfc_host_.reset(new NFCHost(this));
2723 nfc_host_->GetNFC(std::move(request));
2724}
2725#endif
2726
[email protected]edc3af82013-12-12 21:24:072727void WebContentsImpl::OnShowValidationMessage(
nicka0ac8382016-12-15 23:59:232728 RenderViewHostImpl* source,
[email protected]edc3af82013-12-12 21:24:072729 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292730 const base::string16& main_text,
2731 const base::string16& sub_text) {
nicka0ac8382016-12-15 23:59:232732 // TODO(nick): Should we consider |source| here or pass it to the delegate?
[email protected]edc3af82013-12-12 21:24:072733 if (delegate_)
2734 delegate_->ShowValidationMessage(
2735 this, anchor_in_root_view, main_text, sub_text);
2736}
2737
nicka0ac8382016-12-15 23:59:232738void WebContentsImpl::OnHideValidationMessage(RenderViewHostImpl* source) {
2739 // TODO(nick): Should we consider |source| here or pass it to the delegate?
[email protected]edc3af82013-12-12 21:24:072740 if (delegate_)
2741 delegate_->HideValidationMessage(this);
2742}
2743
2744void WebContentsImpl::OnMoveValidationMessage(
nicka0ac8382016-12-15 23:59:232745 RenderViewHostImpl* source,
[email protected]edc3af82013-12-12 21:24:072746 const gfx::Rect& anchor_in_root_view) {
nicka0ac8382016-12-15 23:59:232747 // TODO(nick): Should we consider |source| here or pass it to the delegate?
[email protected]edc3af82013-12-12 21:24:072748 if (delegate_)
2749 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2750}
2751
Evan Stade5e750ad02017-08-07 21:59:272752void WebContentsImpl::SetNotWaitingForResponse() {
2753 if (waiting_for_response_ == false)
2754 return;
2755
2756 waiting_for_response_ = false;
2757 if (delegate_)
2758 delegate_->LoadingStateChanged(this, is_load_to_different_document_);
2759}
2760
lfgbb9c28a2016-03-01 03:19:492761void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372762 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:402763 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:372764 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2765 }
lfgbb9c28a2016-03-01 03:19:492766
lfgdb5c4ed2016-03-04 23:09:072767 RenderWidgetHostViewBase* rwhv =
2768 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2769 if (rwhv) {
2770 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2771 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2772 }
2773
avallee9f43b012016-11-26 07:02:102774 if (browser_plugin_embedder_ && !is_being_destroyed_)
[email protected]a7568e62013-06-14 07:50:442775 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042776}
2777
ekaramadadd882292016-06-08 15:22:562778TextInputManager* WebContentsImpl::GetTextInputManager() {
2779 if (GetOuterWebContents())
2780 return GetOuterWebContents()->GetTextInputManager();
2781
2782 if (!text_input_manager_)
2783 text_input_manager_.reset(new TextInputManager());
2784
2785 return text_input_manager_.get();
2786}
2787
paulmeyer7f6f1d4f2016-11-15 00:00:272788bool WebContentsImpl::OnUpdateDragCursor() {
2789 if (browser_plugin_embedder_)
2790 return browser_plugin_embedder_->OnUpdateDragCursor();
2791 return false;
2792}
2793
kenrb11f213a2017-03-24 18:12:062794bool WebContentsImpl::IsWidgetForMainFrame(
2795 RenderWidgetHostImpl* render_widget_host) {
2796 return render_widget_host == GetMainFrame()->GetRenderWidgetHost();
2797}
2798
[email protected]95640212014-07-26 18:14:302799BrowserAccessibilityManager*
2800 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452801 RenderFrameHostImpl* rfh = GetMainFrame();
2802 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302803}
2804
2805BrowserAccessibilityManager*
2806 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452807 RenderFrameHostImpl* rfh = GetMainFrame();
2808 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302809}
2810
Dave Tapuskab336b922017-07-06 19:24:052811void WebContentsImpl::ExecuteEditCommand(
2812 const std::string& command,
2813 const base::Optional<base::string16>& value) {
2814 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
2815 if (!focused_frame)
2816 return;
2817
2818 focused_frame->GetFrameInputHandler()->ExecuteEditCommand(command, value);
2819}
2820
mohsen7ab1ec16ec2015-07-02 18:26:232821void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:052822 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:232823 if (!focused_frame)
2824 return;
2825
dtapuska9d46ef7d2017-05-26 19:06:062826 focused_frame->GetFrameInputHandler()->MoveRangeSelectionExtent(extent);
mohsen7ab1ec16ec2015-07-02 18:26:232827}
2828
2829void WebContentsImpl::SelectRange(const gfx::Point& base,
2830 const gfx::Point& extent) {
Dave Tapuskab336b922017-07-06 19:24:052831 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
mohsen7ab1ec16ec2015-07-02 18:26:232832 if (!focused_frame)
2833 return;
2834
dtapuska9d46ef7d2017-05-26 19:06:062835 focused_frame->GetFrameInputHandler()->SelectRange(base, extent);
mohsen7ab1ec16ec2015-07-02 18:26:232836}
2837
Dave Tapuskab336b922017-07-06 19:24:052838void WebContentsImpl::MoveCaret(const gfx::Point& extent) {
2839 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
2840 if (!focused_frame)
2841 return;
2842
2843 focused_frame->GetFrameInputHandler()->MoveCaret(extent);
2844}
2845
aurimasab0319022015-07-10 21:57:382846void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2847 int end_adjust) {
Dave Tapuskab336b922017-07-06 19:24:052848 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
aurimasab0319022015-07-10 21:57:382849 if (!focused_frame)
2850 return;
2851
dtapuska9d46ef7d2017-05-26 19:06:062852 focused_frame->GetFrameInputHandler()->AdjustSelectionByCharacterOffset(
2853 start_adjust, end_adjust);
aurimasab0319022015-07-10 21:57:382854}
2855
[email protected]b172aee2012-04-10 17:05:262856void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492857 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232858 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492859 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332860}
2861
avic3aa8422015-11-09 20:57:222862void WebContentsImpl::ResizeDueToAutoResize(
2863 RenderWidgetHostImpl* render_widget_host,
2864 const gfx::Size& new_size) {
2865 if (render_widget_host != GetRenderViewHost()->GetWidget())
2866 return;
2867
kenrbe4f91082017-06-02 20:32:082868 auto_resize_size_ = new_size;
2869
2870 // Out-of-process iframe visible viewport sizes usually come from the
2871 // top-level RenderWidgetHostView, but when auto-resize is enabled on the
2872 // top frame then that size is used instead.
2873 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2874 if (node->current_frame_host()->is_local_root()) {
2875 RenderWidgetHostImpl* host =
2876 node->current_frame_host()->GetRenderWidgetHost();
2877 if (host != render_widget_host)
2878 host->WasResized();
2879 }
2880 }
2881
[email protected]61e2b3cc2012-03-02 16:13:342882 if (delegate_)
2883 delegate_->ResizeDueToAutoResize(this, new_size);
2884}
2885
kenrbe4f91082017-06-02 20:32:082886gfx::Size WebContentsImpl::GetAutoResizeSize() {
2887 return auto_resize_size_;
2888}
2889
2890void WebContentsImpl::ResetAutoResizeSize() {
2891 auto_resize_size_ = gfx::Size();
2892}
2893
[email protected]b172aee2012-04-10 17:05:262894WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202895 if (!delegate_)
2896 return NULL;
[email protected]00c37fc2011-08-02 00:22:502897
[email protected]e5d549d2011-12-28 01:29:202898 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
pnoland488944652017-02-22 18:58:542899
2900 RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID(
2901 params.source_render_process_id, params.source_render_frame_id);
2902
2903 if (source_render_frame_host && params.source_site_instance) {
2904 CHECK_EQ(source_render_frame_host->GetSiteInstance(),
2905 params.source_site_instance.get());
2906 }
2907
2908 if (new_contents && source_render_frame_host && new_contents != this) {
2909 for (auto& observer : observers_) {
2910 observer.DidOpenRequestedURL(new_contents, source_render_frame_host,
2911 params.url, params.referrer,
2912 params.disposition, params.transition,
pnolandaae574e2017-03-06 21:04:212913 params.started_from_context_menu, false);
pnoland488944652017-02-22 18:58:542914 }
2915 }
2916
[email protected]e5d549d2011-12-28 01:29:202917 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342918}
2919
[email protected]6b618e62012-08-16 12:59:182920bool WebContentsImpl::Send(IPC::Message* message) {
2921 if (!GetRenderViewHost()) {
2922 delete message;
2923 return false;
2924 }
2925
2926 return GetRenderViewHost()->Send(message);
2927}
2928
[email protected]a86c0e962013-12-17 17:10:392929void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2930 RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:092931 for (auto& observer : observers_)
2932 observer.RenderFrameForInterstitialPageCreated(render_frame_host);
[email protected]ba45bfd2012-05-22 21:51:442933}
2934
[email protected]20ca0382013-02-28 19:50:072935void WebContentsImpl::AttachInterstitialPage(
2936 InterstitialPageImpl* interstitial_page) {
creisadca9862017-06-16 19:12:112937 DCHECK(!interstitial_page_ && interstitial_page);
2938 interstitial_page_ = interstitial_page;
[email protected]90fb08ed2013-09-24 17:43:292939
2940 // Cancel any visible dialogs so that they don't interfere with the
2941 // interstitial.
creis89a0f782015-05-27 16:13:172942 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292943
ericwilligersde386342016-10-19 02:35:092944 for (auto& observer : observers_)
2945 observer.DidAttachInterstitialPage();
clamy44e84ce2016-02-22 15:38:252946
2947 // Stop the throbber if needed while the interstitial page is shown.
2948 if (frame_tree_.IsLoading())
2949 LoadingStateChanged(true, true, nullptr);
lfg1453e412017-04-11 00:48:502950
2951 // Connect to outer WebContents if necessary.
2952 if (node_.OuterContentsFrameTreeNode()) {
2953 if (GetRenderManager()->GetProxyToOuterDelegate()) {
2954 DCHECK(
2955 static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView())
2956 ->IsRenderWidgetHostViewChildFrame());
2957 RenderWidgetHostViewChildFrame* view =
2958 static_cast<RenderWidgetHostViewChildFrame*>(
2959 interstitial_page->GetView());
2960 GetRenderManager()->SetRWHViewForInnerContents(view);
2961 }
2962 }
clamy44e84ce2016-02-22 15:38:252963}
2964
2965void WebContentsImpl::DidProceedOnInterstitial() {
2966 // The interstitial page should no longer be pausing the throbber.
creisadca9862017-06-16 19:12:112967 DCHECK(!(ShowingInterstitialPage() && interstitial_page_->pause_throbber()));
clamy44e84ce2016-02-22 15:38:252968
2969 // Restart the throbber now that the interstitial page no longer pauses it.
2970 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2971 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072972}
2973
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:042974void WebContentsImpl::DetachInterstitialPage(bool has_focus) {
Lucas Furukawa Gadani69b609192017-07-10 17:08:342975 bool interstitial_pausing_throbber =
2976 ShowingInterstitialPage() && interstitial_page_->pause_throbber();
2977 if (ShowingInterstitialPage())
2978 interstitial_page_ = nullptr;
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:042979
2980 // If the focus was on the interstitial, let's keep it to the page.
2981 // (Note that in unit-tests the RVH may not have a view).
2982 if (has_focus && GetRenderViewHost()->GetWidget()->GetView())
2983 GetRenderViewHost()->GetWidget()->GetView()->Focus();
2984
Lucas Furukawa Gadani69b609192017-07-10 17:08:342985 for (auto& observer : observers_)
2986 observer.DidDetachInterstitialPage();
2987
2988 // Disconnect from outer WebContents if necessary. This must happen after the
2989 // interstitial page is cleared above, since the call to
2990 // SetRWHViewForInnerContents below may loop over all the
2991 // RenderWidgetHostViews in the tree (otherwise, including the now-deleted
2992 // view for the interstitial).
lfg1453e412017-04-11 00:48:502993 if (node_.OuterContentsFrameTreeNode()) {
2994 if (GetRenderManager()->GetProxyToOuterDelegate()) {
2995 DCHECK(static_cast<RenderWidgetHostViewBase*>(
2996 GetRenderManager()->current_frame_host()->GetView())
2997 ->IsRenderWidgetHostViewChildFrame());
2998 RenderWidgetHostViewChildFrame* view =
2999 static_cast<RenderWidgetHostViewChildFrame*>(
3000 GetRenderManager()->current_frame_host()->GetView());
3001 GetRenderManager()->SetRWHViewForInnerContents(view);
3002 }
3003 }
3004
clamy44e84ce2016-02-22 15:38:253005 // Restart the throbber if needed now that the interstitial page is going
3006 // away.
3007 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
3008 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073009}
3010
avi2b177592014-12-10 02:08:023011void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
3012 int history_length) {
alexmos136fd6e62016-08-15 20:58:413013 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
3014 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:023015}
3016
3017void WebContentsImpl::SetHistoryOffsetAndLengthForView(
3018 RenderViewHost* render_view_host,
3019 int history_offset,
3020 int history_length) {
alexmos136fd6e62016-08-15 20:58:413021 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:023022 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:143023}
3024
toyoshim24a4c7ab2016-04-05 09:24:143025void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:173026 RenderFrameHost* focused_frame = GetFocusedFrame();
3027 if (!focused_frame)
3028 return;
3029
[email protected]959be4c2014-04-08 15:01:333030 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:143031 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:333032}
3033
megjablon3f5941072016-02-04 23:27:523034void WebContentsImpl::ReloadLoFiImages() {
3035 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
3036}
3037
[email protected]959be4c2014-04-08 15:01:333038void WebContentsImpl::Undo() {
Dave Tapuskab336b922017-07-06 19:24:053039 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333040 if (!focused_frame)
3041 return;
3042
dtapuska9d46ef7d2017-05-26 19:06:063043 focused_frame->GetFrameInputHandler()->Undo();
[email protected]959be4c2014-04-08 15:01:333044 RecordAction(base::UserMetricsAction("Undo"));
3045}
3046
3047void WebContentsImpl::Redo() {
Dave Tapuskab336b922017-07-06 19:24:053048 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333049 if (!focused_frame)
3050 return;
dtapuska9d46ef7d2017-05-26 19:06:063051 focused_frame->GetFrameInputHandler()->Redo();
[email protected]959be4c2014-04-08 15:01:333052 RecordAction(base::UserMetricsAction("Redo"));
3053}
3054
3055void WebContentsImpl::Cut() {
Dave Tapuskab336b922017-07-06 19:24:053056 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333057 if (!focused_frame)
3058 return;
3059
dtapuska9d46ef7d2017-05-26 19:06:063060 focused_frame->GetFrameInputHandler()->Cut();
[email protected]959be4c2014-04-08 15:01:333061 RecordAction(base::UserMetricsAction("Cut"));
3062}
3063
3064void WebContentsImpl::Copy() {
Dave Tapuskab336b922017-07-06 19:24:053065 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333066 if (!focused_frame)
3067 return;
3068
dtapuska9d46ef7d2017-05-26 19:06:063069 focused_frame->GetFrameInputHandler()->Copy();
[email protected]959be4c2014-04-08 15:01:333070 RecordAction(base::UserMetricsAction("Copy"));
3071}
3072
3073void WebContentsImpl::CopyToFindPboard() {
3074#if defined(OS_MACOSX)
Dave Tapuskab336b922017-07-06 19:24:053075 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333076 if (!focused_frame)
3077 return;
3078
3079 // Windows/Linux don't have the concept of a find pasteboard.
dtapuska9d46ef7d2017-05-26 19:06:063080 focused_frame->GetFrameInputHandler()->CopyToFindPboard();
[email protected]959be4c2014-04-08 15:01:333081 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
3082#endif
3083}
3084
3085void WebContentsImpl::Paste() {
Dave Tapuskab336b922017-07-06 19:24:053086 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333087 if (!focused_frame)
3088 return;
3089
dtapuska9d46ef7d2017-05-26 19:06:063090 focused_frame->GetFrameInputHandler()->Paste();
[email protected]959be4c2014-04-08 15:01:333091 RecordAction(base::UserMetricsAction("Paste"));
3092}
3093
3094void WebContentsImpl::PasteAndMatchStyle() {
Dave Tapuskab336b922017-07-06 19:24:053095 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333096 if (!focused_frame)
3097 return;
3098
dtapuska9d46ef7d2017-05-26 19:06:063099 focused_frame->GetFrameInputHandler()->PasteAndMatchStyle();
[email protected]959be4c2014-04-08 15:01:333100 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
3101}
3102
3103void WebContentsImpl::Delete() {
Dave Tapuskab336b922017-07-06 19:24:053104 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333105 if (!focused_frame)
3106 return;
3107
dtapuska9d46ef7d2017-05-26 19:06:063108 focused_frame->GetFrameInputHandler()->Delete();
[email protected]959be4c2014-04-08 15:01:333109 RecordAction(base::UserMetricsAction("DeleteSelection"));
3110}
3111
3112void WebContentsImpl::SelectAll() {
Dave Tapuskab336b922017-07-06 19:24:053113 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333114 if (!focused_frame)
3115 return;
3116
dtapuska9d46ef7d2017-05-26 19:06:063117 focused_frame->GetFrameInputHandler()->SelectAll();
[email protected]959be4c2014-04-08 15:01:333118 RecordAction(base::UserMetricsAction("SelectAll"));
3119}
3120
yabinh351e7ec2017-03-10 02:43:243121void WebContentsImpl::CollapseSelection() {
Dave Tapuskab336b922017-07-06 19:24:053122 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]959be4c2014-04-08 15:01:333123 if (!focused_frame)
3124 return;
3125
dtapuska9d46ef7d2017-05-26 19:06:063126 focused_frame->GetFrameInputHandler()->CollapseSelection();
[email protected]1f3fc1d2014-04-03 14:50:173127}
3128
3129void WebContentsImpl::Replace(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053130 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173131 if (!focused_frame)
3132 return;
3133
dtapuska9d46ef7d2017-05-26 19:06:063134 focused_frame->GetFrameInputHandler()->Replace(word);
[email protected]1f3fc1d2014-04-03 14:50:173135}
3136
3137void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
Dave Tapuskab336b922017-07-06 19:24:053138 RenderFrameHostImpl* focused_frame = GetFocusedFrame();
[email protected]1f3fc1d2014-04-03 14:50:173139 if (!focused_frame)
3140 return;
3141
dtapuska9d46ef7d2017-05-26 19:06:063142 focused_frame->GetFrameInputHandler()->ReplaceMisspelling(word);
[email protected]959be4c2014-04-08 15:01:333143}
3144
3145void WebContentsImpl::NotifyContextMenuClosed(
3146 const CustomContextMenuContext& context) {
3147 RenderFrameHost* focused_frame = GetFocusedFrame();
3148 if (!focused_frame)
3149 return;
3150
3151 focused_frame->Send(new FrameMsg_ContextMenuClosed(
3152 focused_frame->GetRoutingID(), context));
3153}
3154
3155void WebContentsImpl::ExecuteCustomContextMenuCommand(
3156 int action, const CustomContextMenuContext& context) {
3157 RenderFrameHost* focused_frame = GetFocusedFrame();
3158 if (!focused_frame)
3159 return;
3160
3161 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
3162 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:003163}
3164
[email protected]fc2b46b2014-05-03 16:33:453165gfx::NativeView WebContentsImpl::GetNativeView() {
3166 return view_->GetNativeView();
3167}
3168
3169gfx::NativeView WebContentsImpl::GetContentNativeView() {
3170 return view_->GetContentNativeView();
3171}
3172
3173gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
3174 return view_->GetTopLevelNativeWindow();
3175}
3176
3177gfx::Rect WebContentsImpl::GetViewBounds() {
3178 return view_->GetViewBounds();
3179}
3180
3181gfx::Rect WebContentsImpl::GetContainerBounds() {
3182 gfx::Rect rv;
3183 view_->GetContainerBounds(&rv);
3184 return rv;
3185}
3186
3187DropData* WebContentsImpl::GetDropData() {
3188 return view_->GetDropData();
3189}
3190
3191void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:043192 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:453193}
3194
3195void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:043196 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:453197}
3198
3199void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:043200 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453201}
3202
3203void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:043204 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453205}
3206
[email protected]b172aee2012-04-10 17:05:263207void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:273208 if (ShowingInterstitialPage()) {
creisadca9862017-06-16 19:12:113209 interstitial_page_->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:543210 return;
3211 }
[email protected]0b431992014-06-24 00:08:033212 RenderWidgetHostView* const fullscreen_view =
3213 GetFullscreenRenderWidgetHostView();
3214 if (fullscreen_view) {
3215 fullscreen_view->Focus();
3216 return;
3217 }
creisc014b402015-04-23 16:41:453218 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:543219}
3220
[email protected]b172aee2012-04-10 17:05:263221bool WebContentsImpl::ShowingInterstitialPage() const {
creisadca9862017-06-16 19:12:113222 return interstitial_page_ != nullptr;
[email protected]96d185d2009-04-24 03:28:543223}
3224
Pete Williamson89aa1402017-07-07 19:58:413225void WebContentsImpl::AdjustPreviewsStateForNavigation(
3226 PreviewsState* previews_state) {
3227 if (delegate_)
3228 delegate_->AdjustPreviewsStateForNavigation(previews_state);
3229}
3230
[email protected]b172aee2012-04-10 17:05:263231InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
creisadca9862017-06-16 19:12:113232 return interstitial_page_;
[email protected]686493142011-07-15 21:47:223233}
3234
[email protected]b172aee2012-04-10 17:05:263235bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:163236 // WebKit creates Document object when MIME type is application/xhtml+xml,
3237 // so we also support this MIME type.
3238 return contents_mime_type_ == "text/html" ||
3239 contents_mime_type_ == "text/xml" ||
3240 contents_mime_type_ == "application/xhtml+xml" ||
3241 contents_mime_type_ == "text/plain" ||
3242 contents_mime_type_ == "text/css" ||
Kinuko Yasuda74702f92017-07-31 03:27:533243 blink::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:163244}
3245
[email protected]b172aee2012-04-10 17:05:263246void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:593247 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:163248 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:553249 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:193250 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:143251 return;
[email protected]c7dd2f62011-07-18 15:57:593252 }
3253
3254 Stop();
3255
3256 // Create the save package and possibly prompt the user for the name to save
3257 // the page as. The user prompt is an asynchronous operation that runs on
3258 // another thread.
3259 save_package_ = new SavePackage(this);
3260 save_package_->GetSaveInfo();
3261}
3262
3263// Used in automated testing to bypass prompting the user for file names.
3264// Instead, the names and paths are hard coded rather than running them through
3265// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:343266bool WebContentsImpl::SavePage(const base::FilePath& main_file,
3267 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:213268 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:593269 // Stop the page from navigating.
3270 Stop();
3271
3272 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:213273 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:593274}
3275
[email protected]3c71576ce2013-07-23 02:00:013276void WebContentsImpl::SaveFrame(const GURL& url,
3277 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:373278 SaveFrameWithHeaders(url, referrer, std::string());
3279}
3280
3281void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
3282 const Referrer& referrer,
3283 const std::string& headers) {
nasko89ad7742015-03-05 22:14:193284 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:013285 return;
sammc92af61552014-11-19 23:27:403286 if (delegate_ && delegate_->SaveFrame(url, referrer))
3287 return;
3288
nasko89ad7742015-03-05 22:14:193289 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:223290 // by explicitly passing in which frame this method should target. This would
3291 // indicate whether it's the main frame, and also tell us the frame pointer
3292 // to use for routing.
nasko89ad7742015-03-05 22:14:193293 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:223294 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:013295
brettw760f7442016-05-23 21:19:223296 StoragePartition* storage_partition = BrowserContext::GetStoragePartition(
3297 GetBrowserContext(), frame_host->GetSiteInstance());
avib7348942015-12-25 20:57:103298 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:013299 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:273300 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:013301 if (entry)
3302 post_id = entry->GetPostID();
3303 }
Ramin Halavati24e21012017-07-10 12:56:063304 net::NetworkTrafficAnnotationTag traffic_annotation =
3305 net::DefineNetworkTrafficAnnotation("download_web_contents_frame", R"(
3306 semantics {
3307 sender: "Save Page Action"
3308 description:
3309 "Saves the given frame's URL to the local file system."
3310 trigger:
3311 "The user has triggered a save operation on the frame through a "
3312 "context menu or other mechanism."
3313 data: "None."
3314 destination: WEBSITE
3315 }
3316 policy {
Ramin Halavati3b979782017-07-21 11:40:263317 cookies_allowed: YES
Ramin Halavati24e21012017-07-10 12:56:063318 cookies_store: "user"
3319 setting:
3320 "This feature cannot be disabled by settings, but it's is only "
3321 "triggered by user request."
3322 policy_exception_justification: "Not implemented."
3323 })");
thestig859c78892017-05-15 21:17:063324 auto params = base::MakeUnique<DownloadUrlParameters>(
brettw760f7442016-05-23 21:19:223325 url, frame_host->GetProcess()->GetID(),
3326 frame_host->GetRenderViewHost()->GetRoutingID(),
Ramin Halavati03efa732017-06-12 09:28:203327 frame_host->GetRoutingID(), storage_partition->GetURLRequestContext(),
Ramin Halavati24e21012017-07-10 12:56:063328 traffic_annotation);
[email protected]3c71576ce2013-07-23 02:00:013329 params->set_referrer(referrer);
3330 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:013331 if (post_id >= 0)
3332 params->set_method("POST");
3333 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:373334
3335 if (headers.empty()) {
3336 params->set_prefer_cache(true);
3337 } else {
Megan Jablonski2f6a4c52017-07-10 23:01:253338 for (DownloadUrlParameters::RequestHeadersNameValuePair key_value :
3339 ParseDownloadHeaders(headers)) {
3340 params->add_request_header(key_value.first, key_value.second);
kundaji6c7f9692015-03-09 18:00:373341 }
3342 }
thestig859c78892017-05-15 21:17:063343 BrowserContext::GetDownloadManager(GetBrowserContext())
Ramin Halavati03efa732017-06-12 09:28:203344 ->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:013345}
3346
[email protected]b172aee2012-04-10 17:05:263347void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:473348 const MHTMLGenerationParams& params,
avib7348942015-12-25 20:57:103349 const base::Callback<void(int64_t)>& callback) {
dewittj6dc5747a2016-05-17 01:48:473350 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, callback);
[email protected]aa4f3972012-03-01 18:12:123351}
3352
[email protected]b172aee2012-04-10 17:05:263353const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:273354 return contents_mime_type_;
3355}
3356
[email protected]b172aee2012-04-10 17:05:263357bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:273358 return notify_disconnection_;
3359}
3360
[email protected]8ff00d72012-10-23 19:12:213361RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:273362 return &renderer_preferences_;
3363}
3364
[email protected]e35ccd52012-05-23 16:22:473365void WebContentsImpl::Close() {
3366 Close(GetRenderViewHost());
3367}
3368
paulmeyer8fc8ea92016-11-15 05:12:213369void WebContentsImpl::DragSourceEndedAt(int client_x,
3370 int client_y,
3371 int screen_x,
3372 int screen_y,
Paul Meyer0c58c3712016-11-17 22:59:513373 blink::WebDragOperation operation,
3374 RenderWidgetHost* source_rwh) {
[email protected]cf200a562013-05-03 16:24:293375 if (browser_plugin_embedder_.get())
paulmeyer8fc8ea92016-11-15 05:12:213376 browser_plugin_embedder_->DragSourceEndedAt(
3377 client_x, client_y, screen_x, screen_y, operation);
Paul Meyer0c58c3712016-11-17 22:59:513378 if (source_rwh) {
3379 source_rwh->DragSourceEndedAt(gfx::Point(client_x, client_y),
3380 gfx::Point(screen_x, screen_y),
3381 operation);
3382 }
[email protected]cf200a562013-05-03 16:24:293383}
3384
jam73f892642016-09-11 06:04:063385void WebContentsImpl::LoadStateChanged(
3386 const GURL& url,
3387 const net::LoadStateWithParam& load_state,
3388 uint64_t upload_position,
3389 uint64_t upload_size) {
3390 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
3391 // is fixed.
3392 tracked_objects::ScopedTracker tracking_profile1(
3393 FROM_HERE_WITH_EXPLICIT_FUNCTION(
3394 "466285 WebContentsImpl::LoadStateChanged::Start"));
3395 load_state_ = load_state;
3396 upload_position_ = upload_position;
3397 upload_size_ = upload_size;
3398 load_state_host_ = url_formatter::IDNToUnicode(url.host());
3399 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
3400 SetNotWaitingForResponse();
3401 if (IsLoading()) {
3402 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
3403 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
3404 }
3405}
3406
[email protected]d60f3702013-12-26 16:30:243407void WebContentsImpl::DidGetResourceResponseStart(
3408 const ResourceRequestDetails& details) {
estarkf83ac122016-10-05 19:06:063409 controller_.ssl_manager()->DidStartResourceResponse(
3410 details.url, details.has_certificate, details.ssl_cert_status);
[email protected]d60f3702013-12-26 16:30:243411
ericwilligersde386342016-10-19 02:35:093412 for (auto& observer : observers_)
3413 observer.DidGetResourceResponseStart(details);
[email protected]d60f3702013-12-26 16:30:243414}
3415
3416void WebContentsImpl::DidGetRedirectForResourceRequest(
[email protected]d60f3702013-12-26 16:30:243417 const ResourceRedirectDetails& details) {
ericwilligersde386342016-10-19 02:35:093418 for (auto& observer : observers_)
3419 observer.DidGetRedirectForResourceRequest(details);
[email protected]d60f3702013-12-26 16:30:243420
3421 // TODO(avi): Remove. http://crbug.com/170921
3422 NotificationService::current()->Notify(
3423 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
3424 Source<WebContents>(this),
3425 Details<const ResourceRedirectDetails>(&details));
3426}
3427
Michael Thiessen896405db2017-07-20 17:52:323428void WebContentsImpl::NotifyWebContentsFocused(
3429 RenderWidgetHost* render_widget_host) {
ericwilligersde386342016-10-19 02:35:093430 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323431 observer.OnWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:373432}
3433
Michael Thiessen896405db2017-07-20 17:52:323434void WebContentsImpl::NotifyWebContentsLostFocus(
3435 RenderWidgetHost* render_widget_host) {
zijiehe3bee08e22017-05-17 04:14:463436 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:323437 observer.OnWebContentsLostFocus(render_widget_host);
zijiehe3bee08e22017-05-17 04:14:463438}
3439
Paul Meyer0c58c3712016-11-17 22:59:513440void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) {
3441 if (source_rwh)
3442 source_rwh->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:293443 if (browser_plugin_embedder_.get())
3444 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:343445}
3446
[email protected]e35ccd52012-05-23 16:22:473447void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:533448 OnUserInteraction(GetRenderViewHost()->GetWidget(),
Blink Reformat1c4d759e2017-04-09 16:34:543449 blink::WebInputEvent::kUndefined);
[email protected]e35ccd52012-05-23 16:22:473450}
3451
[email protected]b172aee2012-04-10 17:05:263452void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:273453 closed_by_user_gesture_ = value;
3454}
3455
[email protected]b172aee2012-04-10 17:05:263456bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:273457 return closed_by_user_gesture_;
3458}
3459
[email protected]b172aee2012-04-10 17:05:263460void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:503461 if (!delegate_)
3462 return;
3463
[email protected]6286a372013-10-09 04:03:273464 NavigationEntry* entry = GetController().GetLastCommittedEntry();
3465 if (!entry)
[email protected]1788e772010-12-15 16:40:503466 return;
3467
[email protected]6286a372013-10-09 04:03:273468 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:123469}
3470
[email protected]b172aee2012-04-10 17:05:263471void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:043472 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:273473 if (!delegate_)
3474 return;
3475
[email protected]691aa2f2013-05-28 22:52:043476 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:273477}
3478
[email protected]b172aee2012-04-10 17:05:263479int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273480 return minimum_zoom_percent_;
3481}
3482
[email protected]b172aee2012-04-10 17:05:263483int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273484 return maximum_zoom_percent_;
3485}
3486
mcnee432e47d2015-11-09 19:37:463487void WebContentsImpl::SetPageScale(float page_scale_factor) {
davidsac996be112016-11-30 08:56:383488 Send(new ViewMsg_SetPageScale(GetRenderViewHost()->GetRoutingID(),
3489 page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:243490}
3491
[email protected]b172aee2012-04-10 17:05:263492gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:493493 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:233494}
3495
[email protected]b172aee2012-04-10 17:05:263496bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
lfgf0cd46e2017-01-04 00:05:233497 if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) &&
3498 GetBrowserPluginGuest())
[email protected]660f18e2014-05-15 20:53:053499 return GetBrowserPluginGuest()->LockMouse(allowed);
3500
lfgf0cd46e2017-01-04 00:05:233501 if (mouse_lock_widget_) {
3502 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
3503 return mouse_lock_widget_->delegate()
3504 ->GetAsWebContents()
3505 ->GotResponseToLockMouseRequest(allowed);
3506 }
lfgad8244352016-07-13 16:55:513507
lfgf0cd46e2017-01-04 00:05:233508 if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3509 return true;
3510 }
3511
3512 for (WebContentsImpl* current = this; current;
3513 current = current->GetOuterWebContents()) {
3514 current->mouse_lock_widget_ = nullptr;
3515 }
3516
lfgbee1e0a2016-06-08 21:24:213517 return false;
[email protected]0bfbf882011-12-22 18:19:273518}
3519
[email protected]b172aee2012-04-10 17:05:263520bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:213521 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:503522}
3523
lukasza6f8ac622017-06-06 03:10:203524RenderFrameHostImpl* WebContentsImpl::GetOpener() const {
alexmose201c7cd2015-06-10 17:14:213525 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
lukasza6f8ac622017-06-06 03:10:203526 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen55ff3502014-12-18 20:52:573527}
3528
jochen6004a362017-02-04 00:11:403529bool WebContentsImpl::HasOriginalOpener() const {
3530 return GetOriginalOpener() != NULL;
3531}
3532
lukasza6f8ac622017-06-06 03:10:203533RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() const {
jochen6004a362017-02-04 00:11:403534 FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener();
lukasza6f8ac622017-06-06 03:10:203535 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen6004a362017-02-04 00:11:403536}
3537
[email protected]cb805452013-05-22 15:16:213538void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:483539 if (!color_chooser_info_.get())
3540 return;
3541 RenderFrameHost* rfh = RenderFrameHost::FromID(
3542 color_chooser_info_->render_process_id,
3543 color_chooser_info_->render_frame_id);
3544 if (!rfh)
3545 return;
3546
3547 rfh->Send(new FrameMsg_DidChooseColorResponse(
3548 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:203549}
3550
[email protected]cb805452013-05-22 15:16:213551void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:483552 if (!color_chooser_info_.get())
3553 return;
3554 RenderFrameHost* rfh = RenderFrameHost::FromID(
3555 color_chooser_info_->render_process_id,
3556 color_chooser_info_->render_frame_id);
3557 if (!rfh)
3558 return;
3559
3560 rfh->Send(new FrameMsg_DidEndColorChooser(
3561 rfh->GetRoutingID(), color_chooser_info_->identifier));
3562 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:203563}
3564
halton.huoca2eabd2015-07-06 08:17:403565int WebContentsImpl::DownloadImage(
3566 const GURL& url,
3567 bool is_favicon,
3568 uint32_t max_bitmap_size,
3569 bool bypass_cache,
3570 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:553571 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:403572 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:063573 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:403574 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:553575 const int download_id = ++next_image_download_id;
3576 if (!mojo_image_downloader) {
3577 // If the renderer process is dead (i.e. crash, or memory pressure on
3578 // Android), the downloader service will be invalid. Pre-Mojo, this would
3579 // hang the callback indefinetly since the IPC would be dropped. Now,
3580 // respond with a 400 HTTP error code to indicate that something went wrong.
3581 BrowserThread::PostTask(
3582 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:193583 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:523584 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
leon.hanc2228532016-08-16 05:59:183585 std::vector<SkBitmap>(), std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:553586 return download_id;
3587 }
3588
halton.huoca2eabd2015-07-06 08:17:403589 mojo_image_downloader->DownloadImage(
sammcf6f4fcf2016-06-21 05:39:393590 url, is_favicon, max_bitmap_size, bypass_cache,
leon.hancbc4bc3c2016-02-26 07:08:523591 base::Bind(&WebContentsImpl::OnDidDownloadImage,
3592 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:553593 return download_id;
[email protected]795c28972012-12-06 06:13:393594}
3595
[email protected]5dcaf8e2013-12-28 01:31:423596bool WebContentsImpl::IsSubframe() const {
3597 return is_subframe_;
3598}
3599
[email protected]36ec24f2014-01-09 00:32:083600void WebContentsImpl::Find(int request_id,
3601 const base::string16& search_text,
3602 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:333603 // Cowardly refuse to search for no text.
3604 if (search_text.empty()) {
3605 NOTREACHED();
3606 return;
3607 }
3608
paulmeyerc0b762b2016-04-13 11:55:173609 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:083610}
3611
3612void WebContentsImpl::StopFinding(StopFindAction action) {
paulmeyerfeafc2d2017-04-25 21:46:403613 if (FindRequestManager* manager = GetFindRequestManager())
3614 manager->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:083615}
3616
dalecurtisbc6572e12014-09-12 19:22:303617bool WebContentsImpl::WasRecentlyAudible() {
wjmaclean1dabf3e32016-05-13 23:34:443618 return audio_stream_monitor_.WasRecentlyAudible() ||
3619 (browser_plugin_embedder_ &&
3620 browser_plugin_embedder_->WereAnyGuestsRecentlyAudible());
dalecurtisbc6572e12014-09-12 19:22:303621}
3622
mlamouriefdca9d2014-09-16 16:55:403623void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
Sam McNally2299ba02017-06-13 00:58:303624 manifest_manager_host_->GetManifest(callback);
mlamouriefdca9d2014-09-16 16:55:403625}
3626
bokanece34a82016-01-28 19:49:463627void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:533628 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:433629 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:463630 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:533631}
3632
mariakhomenko44bdc4732015-04-29 01:55:383633void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:373634 if (delayed_open_url_params_.get()) {
3635 OpenURL(*delayed_open_url_params_.get());
3636 delayed_open_url_params_.reset(nullptr);
3637 return;
3638 }
3639
mariakhomenko44bdc4732015-04-29 01:55:383640 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
3641 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163642 if (is_resume_pending_) {
3643 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133644 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163645 GetMainFrame()->Init();
3646 }
mariakhomenko44bdc4732015-04-29 01:55:383647}
3648
[email protected]b172aee2012-04-10 17:05:263649bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263650 // When the browser is started with about:blank as the startup URL, focus
3651 // the location bar (which will also select its contents) so people can
3652 // simply begin typing to navigate elsewhere.
3653 //
3654 // We need to be careful not to trigger this for anything other than the
3655 // startup navigation. In particular, if we allow an attacker to open a
3656 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3657 // end of the new URL to be scrolled into view instead of the start,
3658 // allowing the attacker to spoof other URLs. The conditions checked here
3659 // are all aimed at ensuring no such attacker-controlled navigation can
3660 // trigger this.
3661 //
3662 // Note that we check the pending entry instead of the visible one; for the
3663 // startup URL case these are the same, but for the attacker-controlled
3664 // navigation case the visible entry is the committed "about:blank" URL and
3665 // the pending entry is the problematic navigation elsewhere.
3666 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3667 if (controller_.IsInitialNavigation() && entry &&
3668 !entry->is_renderer_initiated() &&
csharrisona3bd0b32016-10-19 18:40:483669 entry->GetURL() == url::kAboutBlankURL) {
[email protected]0c9406632013-02-08 01:13:333670 return true;
palmerc70cb1f2016-03-04 23:41:263671 }
[email protected]0c9406632013-02-08 01:13:333672 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273673}
3674
[email protected]b172aee2012-04-10 17:05:263675void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273676 if (delegate_)
3677 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213678}
3679
clamy0e119882015-07-31 16:12:333680void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093681 for (auto& observer : observers_)
3682 observer.DidStartNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:333683}
3684
3685void WebContentsImpl::DidRedirectNavigation(
3686 NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093687 for (auto& observer : observers_)
3688 observer.DidRedirectNavigation(navigation_handle);
jam5f358e52017-02-13 16:37:033689
3690 // Notify accessibility if this is a reload. This has to called on the
3691 // BrowserAccessibilityManager associated with the old RFHI.
3692 if (navigation_handle->GetReloadType() != ReloadType::NONE) {
3693 NavigationHandleImpl* nhi =
3694 static_cast<NavigationHandleImpl*>(navigation_handle);
3695 BrowserAccessibilityManager* manager =
3696 nhi->frame_tree_node()
3697 ->current_frame_host()
3698 ->browser_accessibility_manager();
3699 if (manager)
3700 manager->UserIsReloading();
3701 }
clamy0e119882015-07-31 16:12:333702}
3703
clamyefca29e2015-09-17 00:22:113704void WebContentsImpl::ReadyToCommitNavigation(
3705 NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093706 for (auto& observer : observers_)
3707 observer.ReadyToCommitNavigation(navigation_handle);
clamyefca29e2015-09-17 00:22:113708}
3709
clamy0e119882015-07-31 16:12:333710void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093711 for (auto& observer : observers_)
3712 observer.DidFinishNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:333713
jam5f358e52017-02-13 16:37:033714 if (navigation_handle->HasCommitted()) {
dmazzonibf8cec42015-02-08 08:28:083715 BrowserAccessibilityManager* manager =
jam5f358e52017-02-13 16:37:033716 static_cast<RenderFrameHostImpl*>(
3717 navigation_handle->GetRenderFrameHost())
3718 ->browser_accessibility_manager();
3719 if (manager) {
3720 if (navigation_handle->IsErrorPage()) {
3721 manager->NavigationFailed();
3722 } else {
3723 manager->NavigationSucceeded();
3724 }
3725 }
dmazzonibf8cec42015-02-08 08:28:083726 }
[email protected]400992b2012-06-14 00:03:543727}
3728
[email protected]b80624c2014-02-09 02:46:553729void WebContentsImpl::DidFailLoadWithError(
3730 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553731 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553732 int error_code,
Yutaka Hirano16d3c5d2017-07-31 06:17:303733 const base::string16& error_description) {
ericwilligersde386342016-10-19 02:35:093734 for (auto& observer : observers_) {
Yutaka Hirano16d3c5d2017-07-31 06:17:303735 observer.DidFailLoad(render_frame_host, url, error_code, error_description);
ericwilligersde386342016-10-19 02:35:093736 }
[email protected]b80624c2014-02-09 02:46:553737}
3738
[email protected]52913802013-12-10 05:52:183739void WebContentsImpl::NotifyChangedNavigationState(
3740 InvalidateTypes changed_flags) {
3741 NotifyNavigationStateChanged(changed_flags);
3742}
3743
toyoshim0df1d3a2016-09-09 09:52:483744void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
3745 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:203746 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:093747 for (auto& observer : observers_)
3748 observer.DidStartNavigationToPendingEntry(url, reload_type);
[email protected]3691e5cf2014-01-22 10:16:203749}
3750
lukasza1d025732016-09-28 21:36:083751bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:223752 if (!delegate_)
3753 return true;
lukasza1d025732016-09-28 21:36:083754 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:223755}
3756
[email protected]aa62afd2014-04-22 19:22:463757bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3758 if (!delegate_)
3759 return false;
3760 return delegate_->ShouldPreserveAbortedURLs(this);
3761}
3762
[email protected]0d0f4c492014-04-02 06:42:573763void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233764 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573765 // Ensure fullscreen mode is exited before committing the navigation to a
3766 // different page. The next page will not start out assuming it is in
3767 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233768 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193769 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573770 return;
3771 }
alexmos5dd617d2016-06-07 04:21:153772 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:463773 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:153774 DCHECK(!IsFullscreenForCurrentTab());
[email protected]0d0f4c492014-04-02 06:42:573775}
3776
[email protected]37567b432014-02-12 01:12:223777void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283778 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223779 const LoadCommittedDetails& details,
3780 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3781 if (details.is_navigation_to_different_page()) {
3782 // Clear the status bubble. This is a workaround for a bug where WebKit
3783 // doesn't let us know that the cursor left an element during a
3784 // transition (this is also why the mouse cursor remains as a hand after
3785 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3786 // clear the bubble when a user navigates to a named anchor in the same
3787 // page.
sky8b00392d2015-01-10 00:30:283788 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003789
3790 RenderWidgetHostViewBase* rwhvb =
3791 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3792 if (rwhvb)
3793 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283794
peter90afaba2015-06-01 12:05:293795 did_first_visually_non_empty_paint_ = false;
3796
yusufod41c5f92015-03-06 00:14:283797 // Reset theme color on navigation to new page.
3798 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223799 }
3800
[email protected]e85165c642014-06-10 14:34:313801 if (delegate_)
[email protected]37567b432014-02-12 01:12:223802 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313803 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223804}
3805
3806void WebContentsImpl::DidNavigateAnyFramePostCommit(
3807 RenderFrameHostImpl* render_frame_host,
3808 const LoadCommittedDetails& details,
3809 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103810 // Now that something has committed, we don't need to track whether the
3811 // initial page has been accessed.
3812 has_accessed_initial_document_ = false;
3813
[email protected]37567b432014-02-12 01:12:223814 // If we navigate off the page, close all JavaScript dialogs.
eugenebutee08663a2017-04-27 17:43:123815 if (!details.is_same_document)
creis89a0f782015-05-27 16:13:173816 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223817
avid53461d2016-02-25 17:15:043818 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3819 // again.
avi5d3b8692016-10-12 22:00:463820 if (params.gesture == NavigationGestureUser && dialog_manager_) {
avi6879fcf2017-01-21 05:27:533821 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:463822 }
[email protected]37567b432014-02-12 01:12:223823}
3824
3825void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3826 contents_mime_type_ = mime_type;
3827}
3828
[email protected]277857a2014-06-03 10:38:013829bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313830 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053831 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313832 return false;
3833
[email protected]37567b432014-02-12 01:12:223834 if (delegate_)
3835 return delegate_->CanOverscrollContent();
3836
3837 return false;
3838}
3839
nicka0ac8382016-12-15 23:59:233840void WebContentsImpl::OnThemeColorChanged(RenderFrameHostImpl* source,
3841 SkColor theme_color) {
3842 if (source != GetMainFrame()) {
3843 // Only the main frame may control the theme.
3844 return;
3845 }
3846
peter90afaba2015-06-01 12:05:293847 // Update the theme color. This is to be published to observers after the
3848 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283849 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293850
3851 if (did_first_visually_non_empty_paint_ &&
3852 last_sent_theme_color_ != theme_color_) {
ericwilligersde386342016-10-19 02:35:093853 for (auto& observer : observers_)
3854 observer.DidChangeThemeColor(theme_color_);
peter90afaba2015-06-01 12:05:293855 last_sent_theme_color_ = theme_color_;
3856 }
[email protected]e7104762014-06-20 19:17:253857}
3858
[email protected]b172aee2012-04-10 17:05:263859void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
nicka0ac8382016-12-15 23:59:233860 RenderFrameHostImpl* source,
[email protected]724159a2010-12-30 01:11:183861 const GURL& url,
[email protected]70435962011-08-02 20:13:283862 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183863 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403864 ResourceType resource_type) {
ericwilligersde386342016-10-19 02:35:093865 for (auto& observer : observers_)
3866 observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type);
[email protected]b0f724c2013-09-05 04:21:133867
[email protected]8bfc8272013-09-09 20:10:533868 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
nicka0ac8382016-12-15 23:59:233869 StoragePartition* partition = source->GetProcess()->GetStoragePartition();
[email protected]8bfc8272013-09-09 20:10:533870 scoped_refptr<net::URLRequestContextGetter> request_context(
nicka0ac8382016-12-15 23:59:233871 resource_type == RESOURCE_TYPE_MEDIA
3872 ? partition->GetMediaURLRequestContext()
3873 : partition->GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533874 BrowserThread::PostTask(
nicka0ac8382016-12-15 23:59:233875 BrowserThread::IO, FROM_HERE,
[email protected]8bfc8272013-09-09 20:10:533876 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3877 }
[email protected]724159a2010-12-30 01:11:183878}
3879
nicka0ac8382016-12-15 23:59:233880void WebContentsImpl::OnDidDisplayInsecureContent(RenderFrameHostImpl* source) {
3881 // Any frame can trigger display of insecure content, so we don't check
3882 // |source| here.
carloskd9d97942017-02-16 08:58:093883 DidDisplayInsecureContent();
3884}
3885
3886void WebContentsImpl::DidDisplayInsecureContent() {
estarkc2273502016-10-12 22:03:023887 controller_.ssl_manager()->DidDisplayMixedContent();
[email protected]724159a2010-12-30 01:11:183888}
3889
elawrenceb2ac2a232017-03-27 21:46:253890void WebContentsImpl::OnDidContainInsecureFormAction(
3891 RenderFrameHostImpl* source) {
3892 controller_.ssl_manager()->DidContainInsecureFormAction();
3893}
3894
nicka0ac8382016-12-15 23:59:233895void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source,
3896 const GURL& security_origin,
estark910b4572015-12-09 20:55:413897 const GURL& target_url) {
nicka0ac8382016-12-15 23:59:233898 // TODO(nick, estark): Should we call FilterURL using |source|'s process on
3899 // these parameters? |target_url| seems unused, except for a log message. And
3900 // |security_origin| might be replaceable with the origin of the main frame.
carloskd9d97942017-02-16 08:58:093901 DidRunInsecureContent(security_origin, target_url);
3902}
3903
3904void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin,
3905 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583906 LOG(WARNING) << security_origin << " ran insecure content from "
3907 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393908 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413909 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293910 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393911 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
estarkc2273502016-10-12 22:03:023912 controller_.ssl_manager()->DidRunMixedContent(security_origin);
[email protected]724159a2010-12-30 01:11:183913}
3914
carloskd9d97942017-02-16 08:58:093915void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) {
3916 GetDelegate()->PassiveInsecureContentFound(resource_url);
3917}
3918
3919bool WebContentsImpl::ShouldAllowRunningInsecureContent(
3920 WebContents* web_contents,
3921 bool allowed_per_prefs,
3922 const url::Origin& origin,
3923 const GURL& resource_url) {
3924 return GetDelegate()->ShouldAllowRunningInsecureContent(
3925 web_contents, allowed_per_prefs, origin, resource_url);
3926}
3927
rob.buis300b0872017-03-10 20:43:583928#if defined(OS_ANDROID)
3929base::android::ScopedJavaLocalRef<jobject>
3930WebContentsImpl::GetJavaRenderFrameHostDelegate() {
3931 return GetJavaWebContents();
3932}
3933#endif
3934
estark910b4572015-12-09 20:55:413935void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
nicka0ac8382016-12-15 23:59:233936 RenderFrameHostImpl* source,
jama385e112016-07-22 00:07:583937 const GURL& url) {
nicka0ac8382016-12-15 23:59:233938 // TODO(nick): |url| is unused; get rid of it.
estarkc2273502016-10-12 22:03:023939 controller_.ssl_manager()->DidDisplayContentWithCertErrors();
estark910b4572015-12-09 20:55:413940}
3941
3942void WebContentsImpl::OnDidRunContentWithCertificateErrors(
nicka0ac8382016-12-15 23:59:233943 RenderFrameHostImpl* source,
jama385e112016-07-22 00:07:583944 const GURL& url) {
nicka0ac8382016-12-15 23:59:233945 // TODO(nick, estark): Do we need to consider |source| here somehow?
estarkcd2e30c2016-08-12 06:51:153946 NavigationEntry* entry = controller_.GetVisibleEntry();
3947 if (!entry)
estarkaeda1422016-05-10 02:31:123948 return;
3949
estarkaeda1422016-05-10 02:31:123950 // TODO(estark): check that this does something reasonable for
3951 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:153952 controller_.ssl_manager()->DidRunContentWithCertErrors(
3953 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:413954}
3955
nicka0ac8382016-12-15 23:59:233956void WebContentsImpl::OnDocumentLoadedInFrame(RenderFrameHostImpl* source) {
ericwilligersde386342016-10-19 02:35:093957 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:233958 observer.DocumentLoadedInFrame(source);
[email protected]724159a2010-12-30 01:11:183959}
3960
nicka0ac8382016-12-15 23:59:233961void WebContentsImpl::OnDidFinishLoad(RenderFrameHostImpl* source,
3962 const GURL& url) {
[email protected]8b3af1e2014-01-24 13:29:123963 GURL validated_url(url);
nicka0ac8382016-12-15 23:59:233964 source->GetProcess()->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373965
ericwilligersde386342016-10-19 02:35:093966 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:233967 observer.DidFinishLoad(source, validated_url);
[email protected]1a55c5be2011-11-29 11:36:313968}
3969
nicka0ac8382016-12-15 23:59:233970void WebContentsImpl::OnGoToEntryAtOffset(RenderViewHostImpl* source,
3971 int offset) {
3972 // All frames are allowed to navigate the global history.
avi6ddfcae2015-06-30 15:50:573973 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3974 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263975}
3976
nicka0ac8382016-12-15 23:59:233977void WebContentsImpl::OnUpdateZoomLimits(RenderViewHostImpl* source,
3978 int minimum_percent,
[email protected]fce823222014-05-30 16:24:303979 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263980 minimum_zoom_percent_ = minimum_percent;
3981 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263982}
3983
nicka0ac8382016-12-15 23:59:233984void WebContentsImpl::OnPageScaleFactorChanged(RenderViewHostImpl* source,
3985 float page_scale_factor) {
mcnee336ea2c2017-05-23 22:50:593986#if !defined(OS_ANDROID)
3987 // While page scale factor is used on mobile, this PageScaleFactorIsOne logic
3988 // is only needed on desktop.
mcnee432e47d2015-11-09 19:37:463989 bool is_one = page_scale_factor == 1.f;
3990 if (is_one != page_scale_factor_is_one_) {
3991 page_scale_factor_is_one_ = is_one;
3992
3993 HostZoomMapImpl* host_zoom_map =
3994 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3995
nicka0ac8382016-12-15 23:59:233996 if (host_zoom_map) {
mcnee432e47d2015-11-09 19:37:463997 host_zoom_map->SetPageScaleFactorIsOneForView(
nicka0ac8382016-12-15 23:59:233998 source->GetProcess()->GetID(), source->GetRoutingID(),
mcnee432e47d2015-11-09 19:37:463999 page_scale_factor_is_one_);
4000 }
4001 }
mcnee336ea2c2017-05-23 22:50:594002#endif // !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:464003
ericwilligersde386342016-10-19 02:35:094004 for (auto& observer : observers_)
4005 observer.OnPageScaleFactorChanged(page_scale_factor);
mcnee432e47d2015-11-09 19:37:464006}
4007
nicka0ac8382016-12-15 23:59:234008void WebContentsImpl::OnEnumerateDirectory(RenderViewHostImpl* source,
4009 int request_id,
[email protected]2dec8ec2013-02-07 19:20:344010 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:434011 if (!delegate_)
4012 return;
4013
[email protected]b9535422012-02-09 01:47:594014 ChildProcessSecurityPolicyImpl* policy =
4015 ChildProcessSecurityPolicyImpl::GetInstance();
nicka0ac8382016-12-15 23:59:234016 if (policy->CanReadFile(source->GetProcess()->GetID(), path)) {
4017 // TODO(nick): |this| param in the call below ought to be a RenderFrameHost.
[email protected]b9535422012-02-09 01:47:594018 delegate_->EnumerateDirectory(this, request_id, path);
nicka0ac8382016-12-15 23:59:234019 }
[email protected]3a29a6e2011-08-24 18:26:214020}
4021
nicka0ac8382016-12-15 23:59:234022void WebContentsImpl::OnRegisterProtocolHandler(RenderFrameHostImpl* source,
4023 const std::string& protocol,
[email protected]b172aee2012-04-10 17:05:264024 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:264025 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:364026 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234027 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4028 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]e5f2de02012-07-20 22:15:434029 if (!delegate_)
4030 return;
4031
[email protected]b9535422012-02-09 01:47:594032 ChildProcessSecurityPolicyImpl* policy =
4033 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:324034 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:594035 return;
[email protected]8f810632013-06-06 22:33:324036
[email protected]c125e532014-05-10 20:39:064037 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:204038}
4039
nicka0ac8382016-12-15 23:59:234040void WebContentsImpl::OnUnregisterProtocolHandler(RenderFrameHostImpl* source,
4041 const std::string& protocol,
[email protected]f5273e52014-07-14 16:30:204042 const GURL& url,
4043 bool user_gesture) {
nicka0ac8382016-12-15 23:59:234044 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4045 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]f5273e52014-07-14 16:30:204046 if (!delegate_)
4047 return;
4048
4049 ChildProcessSecurityPolicyImpl* policy =
4050 ChildProcessSecurityPolicyImpl::GetInstance();
4051 if (policy->IsPseudoScheme(protocol))
4052 return;
4053
4054 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
4055}
4056
kouhei40f03cb2015-09-24 07:47:014057void WebContentsImpl::OnUpdatePageImportanceSignals(
nicka0ac8382016-12-15 23:59:234058 RenderFrameHostImpl* source,
kouhei40f03cb2015-09-24 07:47:014059 const PageImportanceSignals& signals) {
nicka0ac8382016-12-15 23:59:234060 // TODO(nick, kouhei): Fix this for oopifs; currently all frames' state gets
4061 // written to this one field.
kouhei40f03cb2015-09-24 07:47:014062 page_importance_signals_ = signals;
4063}
4064
nicka0ac8382016-12-15 23:59:234065void WebContentsImpl::OnFindReply(RenderFrameHostImpl* source,
4066 int request_id,
[email protected]b172aee2012-04-10 17:05:264067 int number_of_matches,
4068 const gfx::Rect& selection_rect,
4069 int active_match_ordinal,
4070 bool final_update) {
paulmeyerfeafc2d2017-04-25 21:46:404071 if (active_match_ordinal > 0)
4072 SetFocusedFrame(source->frame_tree_node(), source->GetSiteInstance());
4073
paulmeyerc0b762b2016-04-13 11:55:174074 // Forward the find reply to the FindRequestManager, along with the
4075 // RenderFrameHost associated with the frame that the reply came from.
nicka0ac8382016-12-15 23:59:234076 GetOrCreateFindRequestManager()->OnFindReply(
4077 source, request_id, number_of_matches, selection_rect,
4078 active_match_ordinal, final_update);
[email protected]b888919c2011-09-02 00:32:164079}
4080
mfomitchev2b8b066a2016-01-28 19:23:154081#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:314082void WebContentsImpl::OnFindMatchRectsReply(
nicka0ac8382016-12-15 23:59:234083 RenderFrameHostImpl* source,
[email protected]59363fc92012-09-05 03:46:314084 int version,
4085 const std::vector<gfx::RectF>& rects,
4086 const gfx::RectF& active_rect) {
nicka0ac8382016-12-15 23:59:234087 GetOrCreateFindRequestManager()->OnFindMatchRectsReply(source, version, rects,
4088 active_rect);
[email protected]59363fc92012-09-05 03:46:314089}
[email protected]583418cc2013-01-17 14:01:104090
nicka0ac8382016-12-15 23:59:234091void WebContentsImpl::OnGetNearestFindResultReply(RenderFrameHostImpl* source,
4092 int request_id,
paulmeyerc8cb7cb2016-06-07 01:14:194093 float distance) {
4094 GetOrCreateFindRequestManager()->OnGetNearestFindResultReply(
nicka0ac8382016-12-15 23:59:234095 source, request_id, distance);
paulmeyerc8cb7cb2016-06-07 01:14:194096}
4097
[email protected]1ff427972013-02-07 21:14:074098void WebContentsImpl::OnOpenDateTimeDialog(
nicka0ac8382016-12-15 23:59:234099 RenderViewHostImpl* source,
[email protected]1ff427972013-02-07 21:14:074100 const ViewHostMsg_DateTimeDialogValue_Params& value) {
nicka0ac8382016-12-15 23:59:234101 date_time_chooser_->ShowDialog(
4102 GetTopLevelNativeWindow(), source, value.dialog_type, value.dialog_value,
4103 value.minimum, value.maximum, value.step, value.suggestions);
[email protected]583418cc2013-01-17 14:01:104104}
[email protected]59363fc92012-09-05 03:46:314105#endif
4106
nicka0ac8382016-12-15 23:59:234107void WebContentsImpl::OnDomOperationResponse(RenderFrameHostImpl* source,
4108 const std::string& json_string) {
4109 // TODO(nick, lukasza): The notification below should probably be updated to
4110 // include |source|.
avi60bd4902015-09-23 20:39:244111 std::string json = json_string;
4112 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
4113 Source<WebContents>(this),
4114 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:404115}
4116
nicka0ac8382016-12-15 23:59:234117void WebContentsImpl::OnAppCacheAccessed(RenderViewHostImpl* source,
4118 const GURL& manifest_url,
[email protected]b172aee2012-04-10 17:05:264119 bool blocked_by_policy) {
nicka0ac8382016-12-15 23:59:234120 // TODO(nick): Should we consider |source| here? Should we call FilterURL on
4121 // |manifest_url|?
4122
[email protected]7fc4bbb2011-09-08 21:23:104123 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094124 for (auto& observer : observers_)
4125 observer.AppCacheAccessed(manifest_url, blocked_by_policy);
[email protected]7fc4bbb2011-09-08 21:23:104126}
4127
[email protected]8bc5ff02013-11-29 06:34:034128void WebContentsImpl::OnOpenColorChooser(
nicka0ac8382016-12-15 23:59:234129 RenderFrameHostImpl* source,
[email protected]8ed16472014-04-11 19:02:484130 int color_chooser_id,
4131 SkColor color,
4132 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:464133 ColorChooser* new_color_chooser = delegate_ ?
4134 delegate_->OpenColorChooser(this, color, suggestions) :
4135 NULL;
[email protected]820957a2014-01-14 14:56:304136 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:214137 return;
[email protected]8ed16472014-04-11 19:02:484138 if (color_chooser_info_.get())
4139 color_chooser_info_->chooser->End();
4140
4141 color_chooser_info_.reset(new ColorChooserInfo(
nicka0ac8382016-12-15 23:59:234142 source->GetProcess()->GetID(), source->GetRoutingID(), new_color_chooser,
[email protected]8ed16472014-04-11 19:02:484143 color_chooser_id));
[email protected]da8543762012-03-20 08:52:204144}
4145
nicka0ac8382016-12-15 23:59:234146void WebContentsImpl::OnEndColorChooser(RenderFrameHostImpl* source,
4147 int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:484148 if (color_chooser_info_ &&
nicka0ac8382016-12-15 23:59:234149 color_chooser_info_->Matches(source, color_chooser_id))
[email protected]8ed16472014-04-11 19:02:484150 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:204151}
4152
nicka0ac8382016-12-15 23:59:234153void WebContentsImpl::OnSetSelectedColorInColorChooser(
4154 RenderFrameHostImpl* source,
4155 int color_chooser_id,
4156 SkColor color) {
[email protected]8ed16472014-04-11 19:02:484157 if (color_chooser_info_ &&
nicka0ac8382016-12-15 23:59:234158 color_chooser_info_->Matches(source, color_chooser_id))
[email protected]8ed16472014-04-11 19:02:484159 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:204160}
4161
[email protected]d0759f492012-04-19 22:50:504162// This exists for render views that don't have a WebUI, but do have WebUI
4163// bindings enabled.
nicka0ac8382016-12-15 23:59:234164void WebContentsImpl::OnWebUISend(RenderViewHostImpl* source,
4165 const GURL& source_url,
[email protected]d0759f492012-04-19 22:50:504166 const std::string& name,
4167 const base::ListValue& args) {
nicka0ac8382016-12-15 23:59:234168 // TODO(nick): Should we consider |source| here or pass it to the delegate?
4169 // TODO(nick): Should FilterURL be applied to |source_url|?
4170 // TODO(nick): This IPC should be ported to FrameHostMsg_, and |source_url|
4171 // should be eliminated (use last_committed_url() on the RFH instead).
[email protected]d0759f492012-04-19 22:50:504172 if (delegate_)
4173 delegate_->WebUISend(this, source_url, name, args);
4174}
4175
brettw4b461082016-11-19 18:55:164176#if BUILDFLAG(ENABLE_PLUGINS)
nicka0ac8382016-12-15 23:59:234177void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source,
4178 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094179 for (auto& observer : observers_)
4180 observer.PepperInstanceCreated();
nicka0ac8382016-12-15 23:59:234181 pepper_playback_observer_->PepperInstanceCreated(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004182}
4183
nicka0ac8382016-12-15 23:59:234184void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source,
4185 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:094186 for (auto& observer : observers_)
4187 observer.PepperInstanceDeleted();
nicka0ac8382016-12-15 23:59:234188 pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:004189}
4190
nicka0ac8382016-12-15 23:59:234191void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source,
4192 int plugin_child_id,
tommyclie6633ca72014-10-31 00:40:424193 const base::FilePath& path,
4194 bool is_hung) {
4195 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
4196
ericwilligersde386342016-10-19 02:35:094197 for (auto& observer : observers_)
4198 observer.PluginHungStatusChanged(plugin_child_id, path, is_hung);
tommyclie6633ca72014-10-31 00:40:424199}
4200
nicka0ac8382016-12-15 23:59:234201void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source,
4202 int32_t pp_instance) {
4203 pepper_playback_observer_->PepperStartsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174204}
4205
nicka0ac8382016-12-15 23:59:234206void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source,
4207 int32_t pp_instance) {
4208 pepper_playback_observer_->PepperStopsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:174209}
4210
nicka0ac8382016-12-15 23:59:234211void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source,
4212 const base::FilePath& plugin_path,
tommyclie6633ca72014-10-31 00:40:424213 base::ProcessId plugin_pid) {
nicka0ac8382016-12-15 23:59:234214 // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted,
4215 // and is only used by BlinkTestController.
ericwilligersde386342016-10-19 02:35:094216 for (auto& observer : observers_)
4217 observer.PluginCrashed(plugin_path, plugin_pid);
tommyclie6633ca72014-10-31 00:40:424218}
4219
[email protected]d8415ad92012-08-23 14:40:504220void WebContentsImpl::OnRequestPpapiBrokerPermission(
nicka0ac8382016-12-15 23:59:234221 RenderViewHostImpl* source,
4222 int ppb_broker_route_id,
[email protected]d8415ad92012-08-23 14:40:504223 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:344224 const base::FilePath& plugin_path) {
nicka0ac8382016-12-15 23:59:234225 base::Callback<void(bool)> permission_result_callback = base::Bind(
4226 &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this),
4227 source->GetProcess()->GetID(), ppb_broker_route_id);
[email protected]8c8fc292012-11-23 18:57:164228 if (!delegate_) {
nicka0ac8382016-12-15 23:59:234229 permission_result_callback.Run(false);
[email protected]8c8fc292012-11-23 18:57:164230 return;
[email protected]d8415ad92012-08-23 14:40:504231 }
4232
nicka0ac8382016-12-15 23:59:234233 if (!delegate_->RequestPpapiBrokerPermission(this, url, plugin_path,
4234 permission_result_callback)) {
[email protected]8c8fc292012-11-23 18:57:164235 NOTIMPLEMENTED();
nicka0ac8382016-12-15 23:59:234236 permission_result_callback.Run(false);
[email protected]8c8fc292012-11-23 18:57:164237 }
[email protected]d8415ad92012-08-23 14:40:504238}
4239
nicka0ac8382016-12-15 23:59:234240void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id,
4241 int ppb_broker_route_id,
4242 bool result) {
4243 RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
4244 if (rph) {
4245 // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it
4246 // is not routed to a RenderView.
4247 rph->Send(
4248 new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result));
4249 }
[email protected]d8415ad92012-08-23 14:40:504250}
4251
fsamuel833ee7c2015-02-13 23:40:404252void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
4253 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:394254 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:144255 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:404256 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:374257}
brettw4b461082016-11-19 18:55:164258#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:374259
[email protected]795c28972012-12-06 06:13:394260void WebContentsImpl::OnUpdateFaviconURL(
lukasza178ff092017-06-07 23:39:504261 RenderFrameHostImpl* source,
[email protected]795c28972012-12-06 06:13:394262 const std::vector<FaviconURL>& candidates) {
lukasza178ff092017-06-07 23:39:504263 // Ignore favicons for non-main frame.
4264 if (source->GetParent()) {
4265 NOTREACHED();
4266 return;
4267 }
4268
pkotwiczf9bc20592015-04-21 18:57:064269 // We get updated favicon URLs after the page stops loading. If a cross-site
4270 // navigation occurs while a page is still loading, the initial page
4271 // may stop loading and send us updated favicon URLs after the navigation
4272 // for the new page has committed.
lukasza178ff092017-06-07 23:39:504273 if (!source->IsCurrent())
pkotwiczf9bc20592015-04-21 18:57:064274 return;
4275
ericwilligersde386342016-10-19 02:35:094276 for (auto& observer : observers_)
4277 observer.DidUpdateFaviconURL(candidates);
[email protected]795c28972012-12-06 06:13:394278}
4279
estark703f1b42016-10-10 21:37:154280void WebContentsImpl::OnPasswordInputShownOnHttp() {
estarkc2273502016-10-12 22:03:024281 controller_.ssl_manager()->DidShowPasswordInputOnHttp();
estark703f1b42016-10-10 21:37:154282}
4283
estarkfae6b5872016-11-04 05:20:314284void WebContentsImpl::OnAllPasswordInputsHiddenOnHttp() {
4285 controller_.ssl_manager()->DidHideAllPasswordInputsOnHttp();
4286}
4287
estark703f1b42016-10-10 21:37:154288void WebContentsImpl::OnCreditCardInputShownOnHttp() {
estarkc2273502016-10-12 22:03:024289 controller_.ssl_manager()->DidShowCreditCardInputOnHttp();
estark703f1b42016-10-10 21:37:154290}
4291
qinmin72e8bd02016-10-21 19:35:374292void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) {
4293 is_overlay_content_ = is_overlay_content;
4294}
4295
nicka0ac8382016-12-15 23:59:234296void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(RenderViewHostImpl* source) {
4297 // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if
4298 // |source| is the main frame.
ericwilligersde386342016-10-19 02:35:094299 for (auto& observer : observers_)
4300 observer.DidFirstVisuallyNonEmptyPaint();
yusufod41c5f92015-03-06 00:14:284301
peter90afaba2015-06-01 12:05:294302 did_first_visually_non_empty_paint_ = true;
4303
yusufod41c5f92015-03-06 00:14:284304 if (theme_color_ != last_sent_theme_color_) {
4305 // Theme color should have updated by now if there was one.
ericwilligersde386342016-10-19 02:35:094306 for (auto& observer : observers_)
4307 observer.DidChangeThemeColor(theme_color_);
yusufod41c5f92015-03-06 00:14:284308 last_sent_theme_color_ = theme_color_;
4309 }
[email protected]9f268072013-11-07 00:02:154310}
[email protected]d9030b82013-07-19 08:26:064311
[email protected]17e286e2013-03-01 23:29:394312void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
ericwilligersde386342016-10-19 02:35:094313 for (auto& observer : observers_)
4314 observer.BeforeFormRepostWarningShow();
[email protected]17e286e2013-03-01 23:29:394315}
4316
[email protected]ec6c05f2013-10-23 18:41:574317void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
4318 Activate();
4319 if (delegate_)
4320 delegate_->ShowRepostFormWarningDialog(this);
4321}
4322
[email protected]b4c84012014-04-28 19:51:104323bool WebContentsImpl::HasAccessedInitialDocument() {
4324 return has_accessed_initial_document_;
4325}
4326
afakhry6f0c1ec22016-07-14 13:55:134327void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:264328 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:324329 // For file URLs without a title, use the pathname instead. In the case of a
4330 // synthesized title, we don't want the update to count toward the "one set
4331 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:264332 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:324333 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:514334 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:244335 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:324336 explicit_set = false; // Don't count synthetic titles toward the set limit.
4337 } else {
[email protected]8af69c6c2014-03-03 19:05:314338 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:324339 explicit_set = true;
4340 }
4341
[email protected]987fc3a2011-05-26 14:18:094342 // If a page is created via window.open and never navigated,
4343 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:554344 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:094345 if (entry) {
[email protected]36fc0392011-12-25 03:59:514346 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:134347 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:324348
[email protected]36fc0392011-12-25 03:59:514349 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:094350 } else {
4351 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:134352 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:094353
4354 page_title_when_no_navigation_entry_ = final_title;
4355 }
[email protected]420ae012009-04-24 05:16:324356
[email protected]420ae012009-04-24 05:16:324357 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:234358 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:324359
ericwilligersde386342016-10-19 02:35:094360 for (auto& observer : observers_)
4361 observer.TitleWasSet(entry, explicit_set);
[email protected]66798902013-10-01 18:40:164362
afakhry6f0c1ec22016-07-14 13:55:134363 // Broadcast notifications when the UI should be updated.
4364 if (entry == controller_.GetEntryAtOffset(0))
4365 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:324366}
4367
fdegansa696e5112015-04-17 01:57:594368void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:004369 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:004370 if (delegate_)
fdegansa696e5112015-04-17 01:57:594371 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:004372}
4373
4374void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:344375 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:004376 loading_weak_factory_.InvalidateWeakPtrs();
4377 loading_last_progress_update_ = base::TimeTicks();
4378}
4379
clamy44e84ce2016-02-22 15:38:254380// Notifies the RenderWidgetHost instance about the fact that the page is
4381// loading, or done loading.
4382void WebContentsImpl::LoadingStateChanged(bool to_different_document,
4383 bool due_to_interstitial,
4384 LoadNotificationDetails* details) {
4385 // Do not send notifications about loading changes in the FrameTree while the
4386 // interstitial page is pausing the throbber.
creisadca9862017-06-16 19:12:114387 if (ShowingInterstitialPage() && interstitial_page_->pause_throbber() &&
clamy44e84ce2016-02-22 15:38:254388 !due_to_interstitial) {
4389 return;
4390 }
4391
4392 bool is_loading = IsLoading();
4393
4394 if (!is_loading) {
4395 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
4396 base::string16());
4397 load_state_host_.clear();
4398 upload_size_ = 0;
4399 upload_position_ = 0;
4400 }
4401
4402 GetRenderManager()->SetIsLoading(is_loading);
4403
4404 waiting_for_response_ = is_loading;
4405 is_load_to_different_document_ = to_different_document;
4406
4407 if (delegate_)
4408 delegate_->LoadingStateChanged(this, to_different_document);
4409 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
4410
4411 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
4412 if (is_loading) {
4413 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
4414 this, "URL", url, "Main FrameTreeNode id",
4415 GetFrameTree()->root()->frame_tree_node_id());
ericwilligersde386342016-10-19 02:35:094416 for (auto& observer : observers_)
4417 observer.DidStartLoading();
clamy44e84ce2016-02-22 15:38:254418 } else {
4419 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
4420 this, "URL", url);
ericwilligersde386342016-10-19 02:35:094421 for (auto& observer : observers_)
4422 observer.DidStopLoading();
clamy44e84ce2016-02-22 15:38:254423 }
4424
4425 // TODO(avi): Remove. http://crbug.com/170921
4426 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
4427 NotificationDetails det = NotificationService::NoDetails();
4428 if (details)
4429 det = Details<LoadNotificationDetails>(details);
4430 NotificationService::current()->Notify(
4431 type, Source<NavigationController>(&controller_), det);
4432}
4433
[email protected]02d7b6e2014-06-24 21:01:504434void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
4435 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:324436 // After sending out a swap notification, we need to send a disconnect
4437 // notification so that clients that pick up a pointer to |this| can NULL the
4438 // pointer. See Bug 1230284.
4439 notify_disconnection_ = true;
ericwilligersde386342016-10-19 02:35:094440 for (auto& observer : observers_)
4441 observer.RenderViewHostChanged(old_host, new_host);
[email protected]da7a7182013-09-06 08:11:114442
[email protected]7a846df2012-09-20 19:17:394443 // Ensure that the associated embedder gets cleared after a RenderViewHost
4444 // gets swapped, so we don't reuse the same embedder next time a
4445 // RenderViewHost is attached to this WebContents.
4446 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:324447}
4448
[email protected]02d7b6e2014-06-24 21:01:504449void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
4450 RenderFrameHost* new_host) {
ericwilligersde386342016-10-19 02:35:094451 for (auto& observer : observers_)
4452 observer.RenderFrameHostChanged(old_host, new_host);
[email protected]02d7b6e2014-06-24 21:01:504453}
4454
[email protected]da7a7182013-09-06 08:11:114455// TODO(avi): Remove this entire function because this notification is already
4456// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:264457void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:324458 if (!notify_disconnection_)
4459 return;
4460
4461 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:214462 NotificationService::current()->Notify(
4463 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
4464 Source<WebContents>(this),
4465 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:324466}
4467
[email protected]cbb1ef592013-06-05 19:49:464468void WebContentsImpl::NotifyNavigationEntryCommitted(
4469 const LoadCommittedDetails& load_details) {
ericwilligersde386342016-10-19 02:35:094470 for (auto& observer : observers_)
4471 observer.NavigationEntryCommitted(load_details);
[email protected]cbb1ef592013-06-05 19:49:464472}
4473
rockotf62002a2016-09-15 00:08:594474void WebContentsImpl::OnAssociatedInterfaceRequest(
4475 RenderFrameHost* render_frame_host,
4476 const std::string& interface_name,
4477 mojo::ScopedInterfaceEndpointHandle handle) {
4478 auto it = binding_sets_.find(interface_name);
4479 if (it != binding_sets_.end())
4480 it->second->OnRequestForFrame(render_frame_host, std::move(handle));
4481}
4482
Ben Goodger9e24929e2017-07-21 03:13:404483void WebContentsImpl::OnInterfaceRequest(
4484 RenderFrameHost* render_frame_host,
4485 const std::string& interface_name,
4486 mojo::ScopedMessagePipeHandle* interface_pipe) {
4487 for (auto& observer : observers_) {
4488 observer.OnInterfaceRequestFromFrame(render_frame_host, interface_name,
4489 interface_pipe);
4490 if (!interface_pipe->is_valid())
4491 break;
4492 }
4493}
4494
[email protected]c31a84802014-04-03 15:55:494495const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
4496 return GetLastCommittedURL();
4497}
4498
[email protected]b849847b2013-12-10 21:57:584499void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:094500 for (auto& observer : observers_)
4501 observer.RenderFrameCreated(render_frame_host);
dmazzonif8a31042016-12-03 00:52:134502 UpdateAccessibilityModeOnFrame(render_frame_host);
clamy91b7abf2016-03-24 15:17:454503
4504 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
4505 return;
4506
4507 NavigationEntry* entry = controller_.GetPendingEntry();
4508 if (entry && entry->IsViewSourceMode()) {
4509 // Put the renderer in view source mode.
4510 render_frame_host->Send(
4511 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
4512 }
[email protected]b849847b2013-12-10 21:57:584513}
4514
4515void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
creis3638897452017-05-09 22:07:504516 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:094517 for (auto& observer : observers_)
4518 observer.RenderFrameDeleted(render_frame_host);
creis3638897452017-05-09 22:07:504519 is_notifying_observers_ = false;
zqzhang7b6f4f02016-12-07 22:10:224520#if BUILDFLAG(ENABLE_PLUGINS)
4521 pepper_playback_observer_->RenderFrameDeleted(render_frame_host);
4522#endif
[email protected]b849847b2013-12-10 21:57:584523}
4524
[email protected]a09d53ce2014-01-31 00:46:424525void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
4526 const ContextMenuParams& params) {
avie9fd8722017-04-10 16:17:584527 // If a renderer fires off a second command to show a context menu before the
4528 // first context menu is closed, just ignore it. https://crbug.com/707534
ekaramadf6750aa2017-06-06 18:29:424529 if (showing_context_menu_)
avie9fd8722017-04-10 16:17:584530 return;
4531
[email protected]077e704b2014-05-23 19:24:104532 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:424533 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:104534 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:424535 return;
4536
[email protected]077e704b2014-05-23 19:24:104537 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
4538 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:424539}
4540
avi777ff452017-02-09 19:04:484541void WebContentsImpl::RunJavaScriptDialog(RenderFrameHost* render_frame_host,
4542 const base::string16& message,
4543 const base::string16& default_prompt,
4544 const GURL& frame_url,
4545 JavaScriptDialogType dialog_type,
4546 IPC::Message* reply_msg) {
avi0720b02e2017-06-13 03:22:134547 // Running a dialog causes an exit to webpage-initiated fullscreen.
4548 // http://crbug.com/728276
4549 if (IsFullscreenForCurrentTab())
4550 ExitFullscreen(true);
4551
Pavel Feldman3c1842b2017-08-02 05:00:164552 base::Callback<void(bool, bool, const base::string16&)> callback =
4553 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
4554 render_frame_host->GetProcess()->GetID(),
4555 render_frame_host->GetRoutingID(), reply_msg);
4556
[email protected]87de04b02014-04-08 22:14:494557 // Suppress JavaScript dialogs when requested. Also suppress messages when
4558 // showing an interstitial as it's shown over the previous page and we don't
4559 // want the hidden page's dialogs to interfere with the interstitial.
Pavel Feldman3c1842b2017-08-02 05:00:164560 bool suppress_this_message = ShowingInterstitialPage() || !delegate_ ||
4561 delegate_->ShouldSuppressDialogs(this);
4562 if (delegate_)
mathiash72a5e462014-11-19 08:18:504563 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
Pavel Feldman3c1842b2017-08-02 05:00:164564
4565 std::vector<protocol::PageHandler*> page_handlers =
4566 protocol::PageHandler::EnabledForWebContents(this);
4567
4568 if (suppress_this_message || (!dialog_manager_ && !page_handlers.size())) {
4569 callback.Run(true, false, base::string16());
4570 return;
4571 }
4572
4573 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
4574 new CloseDialogCallbackWrapper(callback);
4575 callback = base::Bind(&CloseDialogCallbackWrapper::Run, wrapper);
4576
4577 is_showing_javascript_dialog_ = true;
4578
4579 for (auto* handler : page_handlers) {
4580 handler->DidRunJavaScriptDialog(frame_url, message, default_prompt,
4581 dialog_type, base::Bind(callback, false));
4582 }
4583
4584 if (dialog_manager_) {
[email protected]87de04b02014-04-08 22:14:494585 dialog_manager_->RunJavaScriptDialog(
avi777ff452017-02-09 19:04:484586 this, frame_url, dialog_type, message, default_prompt,
Pavel Feldman3c1842b2017-08-02 05:00:164587 base::Bind(callback, false), &suppress_this_message);
[email protected]87de04b02014-04-08 22:14:494588 }
4589
4590 if (suppress_this_message) {
4591 // If we are suppressing messages, just reply as if the user immediately
4592 // pressed "Cancel", passing true to |dialog_was_suppressed|.
Pavel Feldman3c1842b2017-08-02 05:00:164593 callback.Run(true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:494594 }
[email protected]87de04b02014-04-08 22:14:494595}
4596
4597void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:014598 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494599 bool is_reload,
4600 IPC::Message* reply_msg) {
avi0720b02e2017-06-13 03:22:134601 // Running a dialog causes an exit to webpage-initiated fullscreen.
4602 // http://crbug.com/728276
4603 if (IsFullscreenForCurrentTab())
4604 ExitFullscreen(true);
4605
[email protected]39f2f9252014-05-03 00:54:014606 RenderFrameHostImpl* rfhi =
4607 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:494608 if (delegate_)
4609 delegate_->WillRunBeforeUnloadConfirm();
4610
Pavel Feldman3c1842b2017-08-02 05:00:164611 base::Callback<void(bool, bool, const base::string16&)> callback =
4612 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
4613 render_frame_host->GetProcess()->GetID(),
4614 render_frame_host->GetRoutingID(), reply_msg);
4615
4616 bool suppress_this_message = !rfhi->is_active() ||
4617 ShowingInterstitialPage() || !delegate_ ||
4618 delegate_->ShouldSuppressDialogs(this);
4619 if (delegate_)
4620 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
4621
4622 std::vector<protocol::PageHandler*> page_handlers =
4623 protocol::PageHandler::EnabledForWebContents(this);
4624
4625 if (suppress_this_message || (!dialog_manager_ && !page_handlers.size())) {
4626 callback.Run(false, true, base::string16());
[email protected]87de04b02014-04-08 22:14:494627 return;
4628 }
4629
4630 is_showing_before_unload_dialog_ = true;
Pavel Feldman3c1842b2017-08-02 05:00:164631
4632 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
4633 new CloseDialogCallbackWrapper(callback);
4634 callback = base::Bind(&CloseDialogCallbackWrapper::Run, wrapper);
4635
4636 GURL frame_url = rfhi->GetLastCommittedURL();
4637 for (auto* handler : page_handlers) {
4638 handler->DidRunBeforeUnloadConfirm(frame_url, base::Bind(callback, false));
4639 }
4640
4641 if (dialog_manager_) {
4642 dialog_manager_->RunBeforeUnloadDialog(this, is_reload,
4643 base::Bind(callback, false));
4644 }
[email protected]87de04b02014-04-08 22:14:494645}
4646
naskoada75b22016-06-11 16:09:464647void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host,
4648 const FileChooserParams& params) {
4649 if (delegate_)
4650 delegate_->RunFileChooser(render_frame_host, params);
4651}
4652
[email protected]a86c0e962013-12-17 17:10:394653WebContents* WebContentsImpl::GetAsWebContents() {
4654 return this;
4655}
4656
mcnee336ea2c2017-05-23 22:50:594657#if !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:124658double WebContentsImpl::GetPendingPageZoomLevel() {
4659 NavigationEntry* pending_entry = GetController().GetPendingEntry();
4660 if (!pending_entry)
4661 return HostZoomMap::GetZoomLevel(this);
4662
4663 GURL url = pending_entry->GetURL();
4664 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
4665 url.scheme(), net::GetHostOrSpecFromURL(url));
4666}
mcnee336ea2c2017-05-23 22:50:594667#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:124668
qinmin72e8bd02016-10-21 19:35:374669bool WebContentsImpl::HideDownloadUI() const {
4670 return is_overlay_content_;
4671}
4672
mlamouri5cd9ae82017-02-18 11:05:094673bool WebContentsImpl::HasPersistentVideo() const {
4674 return has_persistent_video_;
4675}
4676
mlamourie52c1b542017-02-23 14:57:504677bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const {
4678 return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo();
4679}
4680
ekaramada110f642016-12-21 19:47:284681bool WebContentsImpl::IsFocusedElementEditable() {
4682 RenderFrameHostImpl* frame = GetFocusedFrame();
4683 return frame && frame->has_focused_editable_element();
4684}
4685
ekaramadf6750aa2017-06-06 18:29:424686bool WebContentsImpl::IsShowingContextMenu() const {
4687 return showing_context_menu_;
4688}
4689
4690void WebContentsImpl::SetShowingContextMenu(bool showing) {
4691 DCHECK_NE(showing_context_menu_, showing);
4692 showing_context_menu_ = showing;
4693
4694 if (auto* view = GetRenderWidgetHostView()) {
4695 // Notify the main frame's RWHV to run the platform-specific code, if any.
4696 static_cast<RenderWidgetHostViewBase*>(view)->SetShowingContextMenu(
4697 showing);
4698 }
4699}
4700
ekaramada110f642016-12-21 19:47:284701void WebContentsImpl::ClearFocusedElement() {
4702 if (auto* frame = GetFocusedFrame())
4703 frame->ClearFocusedElement();
4704}
4705
[email protected]7912e822014-04-16 02:37:034706bool WebContentsImpl::IsNeverVisible() {
4707 if (!delegate_)
4708 return false;
4709 return delegate_->IsNeverVisible(this);
4710}
4711
[email protected]5a3bdf52012-05-24 15:12:574712RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
4713 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:324714}
4715
[email protected]8ff00d72012-10-23 19:12:214716RendererPreferences WebContentsImpl::GetRendererPrefs(
4717 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:464718 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:514719}
4720
[email protected]7a846df2012-09-20 19:17:394721void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:274722 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394723 browser_plugin_embedder_.reset();
4724}
4725
avallee0206f782016-07-28 18:55:334726WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
lfg601233692017-03-06 22:45:444727 if (GuestMode::IsCrossProcessFrameGuest(this))
4728 return node_.outer_web_contents();
ekaramad1beabecc2016-09-23 20:18:174729
4730 if (browser_plugin_guest_)
4731 return browser_plugin_guest_->embedder_web_contents();
4732
avallee0206f782016-07-28 18:55:334733 return nullptr;
4734}
4735
4736WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
lfg601233692017-03-06 22:45:444737 return GetOutermostWebContents()->node_.focused_web_contents();
avallee0206f782016-07-28 18:55:334738}
4739
avallee9993fca2016-11-17 06:16:504740bool WebContentsImpl::ContainsOrIsFocusedWebContents() {
4741 for (WebContentsImpl* focused_contents = GetFocusedWebContents();
4742 focused_contents;
4743 focused_contents = focused_contents->GetOuterWebContents()) {
4744 if (focused_contents == this)
4745 return true;
4746 }
4747
4748 return false;
4749}
4750
avallee0206f782016-07-28 18:55:334751WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
4752 WebContentsImpl* root = this;
4753 while (root->GetOuterWebContents())
4754 root = root->GetOuterWebContents();
4755 return root;
4756}
4757
avalleed68cdd12017-06-21 22:07:274758void WebContentsImpl::FocusOuterAttachmentFrameChain() {
4759 WebContentsImpl* outer_contents = GetOuterWebContents();
4760 if (!outer_contents)
4761 return;
4762
4763 FrameTreeNode* outer_node =
4764 FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId());
4765 outer_contents->frame_tree_.SetFocusedFrame(outer_node, nullptr);
4766
4767 // For a browser initiated focus change, let embedding renderer know of the
4768 // change. Otherwise, if the currently focused element is just across a
4769 // process boundary in focus order, it will not be possible to move across
4770 // that boundary. This is because the target element will already be focused
4771 // (that renderer was not notified) and drop the event.
4772 if (GetRenderManager()->GetProxyToOuterDelegate())
4773 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame();
4774
4775 outer_contents->FocusOuterAttachmentFrameChain();
4776}
4777
[email protected]b172aee2012-04-10 17:05:264778void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444779 // Don't send notifications if we are just creating a swapped-out RVH for
4780 // the opener chain. These won't be used for view-source or WebUI, so it's
4781 // ok to return early.
creiscce56cd2014-09-29 22:45:224782 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444783 return;
4784
[email protected]86f98a22013-03-20 14:35:004785 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314786 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084787
[email protected]8ff00d72012-10-23 19:12:214788 NotificationService::current()->Notify(
4789 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4790 Source<WebContents>(this),
4791 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324792
[email protected]60780f412013-02-25 16:34:104793 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264794
ericwilligersde386342016-10-19 02:35:094795 for (auto& observer : observers_)
4796 observer.RenderViewCreated(render_view_host);
dgozmanf00c4f72016-10-19 17:45:154797 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]420ae012009-04-24 05:16:324798}
4799
[email protected]b172aee2012-04-10 17:05:264800void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524801 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324802 // Don't notify the world, since this came from a renderer in the
4803 // background.
4804 return;
4805 }
4806
dmazzoni62111452017-04-28 23:46:554807 RenderWidgetHostViewBase* rwhv =
4808 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
4809 if (rwhv)
4810 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
4811
[email protected]da7a7182013-09-06 08:11:114812 notify_disconnection_ = true;
4813 // TODO(avi): Remove. http://crbug.com/170921
4814 NotificationService::current()->Notify(
4815 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4816 Source<WebContents>(this),
4817 NotificationService::NoDetails());
4818
[email protected]be1f56ab2011-12-22 06:55:314819 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234820 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304821
4822 // Restore the focus to the tab (otherwise the focus will be on the top
4823 // window).
[email protected]484ae5912010-09-29 19:16:144824 if (was_crashed && !FocusLocationBarByDefault() &&
4825 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064826 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144827 }
[email protected]32ded2212011-11-10 18:51:434828
ericwilligersde386342016-10-19 02:35:094829 for (auto& observer : observers_)
4830 observer.RenderViewReady();
[email protected]420ae012009-04-24 05:16:324831}
4832
[email protected]ec6a7eb2013-04-22 17:34:224833void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4834 base::TerminationStatus status,
4835 int error_code) {
[email protected]151a63d2011-12-20 22:32:524836 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324837 // The pending page's RenderViewHost is gone.
4838 return;
4839 }
4840
[email protected]2fcdcc32014-03-05 02:14:074841 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4842 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:154843 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464844 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074845
[email protected]698191dc2014-02-25 01:06:134846 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174847 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134848
dalecurtis3d1e1302017-02-20 22:33:254849 audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID());
4850
[email protected]960b0372014-05-19 18:01:004851 // Reset the loading progress. TODO(avi): What does it mean to have a
4852 // "renderer crash" when there is more than one renderer process serving a
4853 // webpage? Once this function is called at a more granular frame level, we
4854 // probably will need to more granularly reset the state here.
4855 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254856 NotifyDisconnected();
4857 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004858
ericwilligersde386342016-10-19 02:35:094859 for (auto& observer : observers_)
4860 observer.RenderProcessGone(GetCrashedStatus());
[email protected]420ae012009-04-24 05:16:324861}
4862
[email protected]b172aee2012-04-10 17:05:264863void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
ericwilligersde386342016-10-19 02:35:094864 for (auto& observer : observers_)
4865 observer.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:064866}
4867
sky8b00392d2015-01-10 00:30:284868void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4869 const GURL& url) {
4870 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4871 // If we're fullscreen only update the url if it's from the fullscreen
4872 // renderer.
4873 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444874 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284875 return;
4876 }
[email protected]6934a702011-12-20 00:04:514877 if (delegate_)
avi450ce00e2014-09-24 01:58:524878 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324879}
4880
[email protected]b172aee2012-04-10 17:05:264881void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104882#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294883 // The UI may be in an event-tracking loop, such as between the
4884 // mouse-down and mouse-up in text selection or a button click.
4885 // Defer the close until after tracking is complete, so that we
4886 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294887 // TODO(shess): This could get more fine-grained. For instance,
4888 // closing a tab in another window while selecting text in the
4889 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104890 if (view_->IsEventTracking()) {
4891 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294892 return;
4893 }
[email protected]60780f412013-02-25 16:34:104894#endif
[email protected]07707302009-11-06 00:50:294895
[email protected]420ae012009-04-24 05:16:324896 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524897 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514898 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324899}
4900
[email protected]b172aee2012-04-10 17:05:264901void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514902 if (delegate_ && delegate_->IsPopupOrPanel(this))
4903 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324904}
4905
fdegansa696e5112015-04-17 01:57:594906void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094907 bool to_different_document) {
Evan Stadec3b26022017-07-14 19:50:244908 LoadingStateChanged(frame_tree_node->IsMainFrame() && to_different_document,
4909 false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084910
4911 // Notify accessibility that the user is navigating away from the
4912 // current document.
4913 //
4914 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084915 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594916 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084917 if (manager)
4918 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324919}
4920
fdegansc73eec22015-03-19 14:47:544921void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084922 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324923
[email protected]9595fd82013-04-19 21:28:494924 // Use the last committed entry rather than the active one, in case a
4925 // pending entry has been created.
4926 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204927 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494928
[email protected]420ae012009-04-24 05:16:324929 // An entry may not exist for a stop when loading an initial blank page or
4930 // if an iframe injected by script into a blank page finishes loading.
4931 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204932 base::TimeDelta elapsed =
4933 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324934
4935 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514936 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:324937 elapsed,
4938 &controller_,
4939 controller_.GetCurrentEntryIndex()));
4940 }
4941
clamy44e84ce2016-02-22 15:38:254942 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324943}
4944
fdegansa696e5112015-04-17 01:57:594945void WebContentsImpl::DidChangeLoadProgress() {
4946 double load_progress = frame_tree_.load_progress();
4947
4948 // The delegate is notified immediately for the first and last updates. Also,
4949 // since the message loop may be pretty busy when a page is loaded, it might
4950 // not execute a posted task in a timely manner so the progress report is sent
4951 // immediately if enough time has passed.
4952 base::TimeDelta min_delay =
4953 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4954 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4955 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4956
4957 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4958 // If there is a pending task to send progress, it is now obsolete.
4959 loading_weak_factory_.InvalidateWeakPtrs();
4960
4961 // Notify the load progress change.
4962 SendChangeLoadProgress();
4963
4964 // Clean-up the states if needed.
4965 if (load_progress == 1.0)
4966 ResetLoadProgressState();
4967 return;
4968 }
4969
4970 if (loading_weak_factory_.HasWeakPtrs())
4971 return;
4972
skyostil95082a62015-06-05 19:53:074973 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4974 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4975 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594976 min_delay);
4977}
4978
avid6d88b912017-01-13 00:16:004979std::vector<std::unique_ptr<NavigationThrottle>>
4980WebContentsImpl::CreateThrottlesForNavigation(
clamycbf524d42016-09-27 12:48:354981 NavigationHandle* navigation_handle) {
4982 return GetContentClient()->browser()->CreateThrottlesForNavigation(
4983 navigation_handle);
4984}
4985
clamy1e5574e2016-09-29 16:48:444986std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
4987 NavigationHandle* navigation_handle) {
4988 DCHECK(IsBrowserSideNavigationEnabled());
4989 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
4990}
4991
pdr15f5b5b2017-06-20 00:58:004992void WebContentsImpl::DidCancelLoading() {
4993 controller_.DiscardNonCommittedEntries();
4994
4995 // Update the URL display.
4996 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
4997}
4998
[email protected]59167c22013-06-03 18:07:324999void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:105000 has_accessed_initial_document_ = true;
5001
[email protected]d1371bf8e2014-04-19 03:26:245002 // We may have left a failed browser-initiated navigation in the address bar
5003 // to let the user edit it and try again. Clear it now that content might
5004 // show up underneath it.
5005 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:455006 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:245007
[email protected]59167c22013-06-03 18:07:325008 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:505009 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:325010}
5011
alexmosbe2f4c32015-03-10 02:30:235012void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
5013 const std::string& name) {
ericwilligersde386342016-10-19 02:35:095014 for (auto& observer : observers_)
5015 observer.FrameNameChanged(render_frame_host, name);
alexmosbe2f4c32015-03-10 02:30:235016}
5017
[email protected]39f2f9252014-05-03 00:54:015018void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:295019 RenderFrameHost* render_frame_host) {
falken52a56e32016-12-08 05:02:405020 ShowInsecureLocalhostWarningIfNeeded();
5021
creis97867aa2017-02-17 18:39:455022 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095023 for (auto& observer : observers_)
5024 observer.DocumentOnLoadCompletedInMainFrame();
creis97867aa2017-02-17 18:39:455025 is_notifying_observers_ = false;
[email protected]6578fef2013-10-14 02:35:095026
5027 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:215028 NotificationService::current()->Notify(
5029 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
5030 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:295031 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:085032}
5033
creis8eb8ef22015-11-04 22:51:385034void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
5035 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:385036 // The state update affects the last NavigationEntry associated with the given
5037 // |render_frame_host|. This may not be the last committed NavigationEntry (as
5038 // in the case of an UpdateState from a frame being swapped out). We track
5039 // which entry this is in the RenderFrameHost's nav_entry_id.
5040 RenderFrameHostImpl* rfhi =
5041 static_cast<RenderFrameHostImpl*>(render_frame_host);
5042 NavigationEntryImpl* entry =
5043 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
5044 if (!entry)
5045 return;
5046
5047 FrameNavigationEntry* frame_entry =
5048 entry->GetFrameEntry(rfhi->frame_tree_node());
5049 if (!frame_entry)
5050 return;
5051
creisd06a9422015-11-11 03:08:455052 // The SiteInstance might not match if we do a cross-process navigation with
5053 // replacement (e.g., auto-subframe), in which case the swap out of the old
5054 // RenderFrameHost runs in the background after the old FrameNavigationEntry
5055 // has already been replaced and destroyed.
5056 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
5057 return;
5058
creis8eb8ef22015-11-04 22:51:385059 if (page_state == frame_entry->page_state())
5060 return; // Nothing to update.
5061
creis0cade2e2017-02-28 06:37:475062 DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState.";
nasko34634672016-07-29 18:46:065063
5064 // The document_sequence_number and item_sequence_number recorded in the
5065 // FrameNavigationEntry should not differ from the one coming with the update,
5066 // since it must come from the same document. Do not update it if a difference
5067 // is detected, as this indicates that |frame_entry| is not the correct one.
5068 ExplodedPageState exploded_state;
5069 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
5070 return;
5071
5072 if (exploded_state.top.document_sequence_number !=
5073 frame_entry->document_sequence_number() ||
5074 exploded_state.top.item_sequence_number !=
5075 frame_entry->item_sequence_number()) {
5076 return;
5077 }
5078
nasko04a322f25a2016-09-01 00:00:345079 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:385080 controller_.NotifyEntryChanged(entry);
5081}
5082
[email protected]ef3adfc2014-05-11 00:04:545083void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
[email protected]ef3adfc2014-05-11 00:04:545084 const base::string16& title,
5085 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:545086 // If we have a title, that's a pretty good indication that we've started
5087 // getting useful data.
5088 SetNotWaitingForResponse();
5089
5090 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:585091 // For example, it might be from a recently swapped out RFH.
avi1edc8552016-10-13 21:37:165092 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
creisad8c31a2016-05-24 17:07:045093 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
[email protected]ef3adfc2014-05-11 00:04:545094
5095 // We can handle title updates when we don't have an entry in
5096 // UpdateTitleForEntry, but only if the update is from the current RVH.
5097 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:585098 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:545099 return;
5100
5101 // TODO(evan): make use of title_direction.
5102 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:135103 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:545104}
5105
5106void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
5107 const std::string& encoding) {
5108 SetEncoding(encoding);
5109}
5110
[email protected]39f2f9252014-05-03 00:54:015111void WebContentsImpl::DocumentAvailableInMainFrame(
5112 RenderViewHost* render_view_host) {
ericwilligersde386342016-10-19 02:35:095113 for (auto& observer : observers_)
5114 observer.DocumentAvailableInMainFrame();
[email protected]39f2f9252014-05-03 00:54:015115}
naskoc0fceff2015-04-30 15:53:525116
[email protected]e1c3a552012-05-04 20:51:325117void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
5118 // Tell the active RenderViewHost to run unload handlers and close, as long
5119 // as the request came from a RenderViewHost in the same BrowsingInstance.
5120 // In most cases, we receive this from a swapped out RenderViewHost.
5121 // It is possible to receive it from one that has just been swapped in,
5122 // in which case we might as well deliver the message anyway.
5123 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:525124 ClosePage();
[email protected]e1c3a552012-05-04 20:51:325125}
5126
alexmose7da5a12015-04-09 02:22:165127bool WebContentsImpl::ShouldRouteMessageEvent(
5128 RenderFrameHost* target_rfh,
5129 SiteInstance* source_site_instance) const {
5130 // Allow the message if this WebContents is dedicated to a browser plugin
5131 // guest.
[email protected]0eba810b2012-10-18 03:19:365132 // Note: This check means that an embedder could theoretically receive a
5133 // postMessage from anyone (not just its own guests). However, this is
5134 // probably not a risk for apps since other pages won't have references
5135 // to App windows.
alexmose7da5a12015-04-09 02:22:165136 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
5137}
[email protected]f546640b2012-05-15 00:03:495138
alexmos58729042015-06-18 23:20:005139void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:165140 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
5141 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:495142
alexmose7da5a12015-04-09 02:22:165143 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:145144 // If this message is going to outer WebContents from inner WebContents,
5145 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
5146 // already created a RenderFrameProxyHost for that purpose.
5147 if (GetBrowserPluginEmbedder() &&
ekaramad1beabecc2016-09-23 20:18:175148 GuestMode::IsCrossProcessFrameGuest(source_web_contents)) {
lazyboy6ec48b2a2015-06-29 15:18:145149 return;
5150 }
5151
lfg812874d2016-02-09 22:26:135152 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:065153 // We create a RenderFrameProxyHost for the embedder in the guest's render
5154 // process but we intentionally do not expose the embedder's opener chain
5155 // to it.
5156 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
5157 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:495158 } else {
alexmos58729042015-06-18 23:20:005159 RenderFrameHostImpl* source_rfhi =
5160 static_cast<RenderFrameHostImpl*>(source_rfh);
5161 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:395162 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:495163 }
5164 }
[email protected]f546640b2012-05-15 00:03:495165}
5166
avallee9993fca2016-11-17 06:16:505167void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
5168 // Only change focus if we are not currently focused.
5169 WebContentsImpl* old_contents = GetFocusedWebContents();
5170 if (old_contents == this)
5171 return;
5172
paulmeyerfeafc2d2017-04-25 21:46:405173 GetOutermostWebContents()->node_.SetFocusedWebContents(this);
5174
5175 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
5176 return;
5177
avallee9993fca2016-11-17 06:16:505178 // Send a page level blur to the old contents so that it displays inactive UI
5179 // and focus this contents to activate it.
5180 if (old_contents)
5181 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
avalleec2ff1ef2017-01-21 00:12:305182
5183 // Make sure the outer web contents knows our frame is focused. Otherwise, the
5184 // outer renderer could have the element before or after the frame element
5185 // focused which would return early without actually advancing focus.
avalleed68cdd12017-06-21 22:07:275186 FocusOuterAttachmentFrameChain();
avalleec2ff1ef2017-01-21 00:12:305187
lfg1453e412017-04-11 00:48:505188 if (ShowingInterstitialPage()) {
creisadca9862017-06-16 19:12:115189 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:505190 ->GetRenderWidgetHost()
5191 ->SetPageFocus(true);
5192 } else {
5193 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
5194 }
avallee9993fca2016-11-17 06:16:505195}
5196
avallee0206f782016-07-28 18:55:335197void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
5198 SiteInstance* source) {
avallee9993fca2016-11-17 06:16:505199 SetAsFocusedWebContentsIfNecessary();
avalleed68cdd12017-06-21 22:07:275200
avallee0206f782016-07-28 18:55:335201 frame_tree_.SetFocusedFrame(node, source);
avalleed68cdd12017-06-21 22:07:275202
5203 WebContentsImpl* inner_contents = node_.GetInnerWebContentsInFrame(node);
5204
5205 WebContentsImpl* contents_to_focus = inner_contents ? inner_contents : this;
5206 contents_to_focus->SetAsFocusedWebContentsIfNecessary();
5207}
5208
5209RenderFrameHost* WebContentsImpl::GetFocusedFrameIncludingInnerWebContents() {
5210 WebContentsImpl* contents = this;
5211 FrameTreeNode* focused_node = contents->frame_tree_.GetFocusedFrame();
5212
5213 // If there is no focused frame in the outer WebContents, we need to return
5214 // null.
5215 if (!focused_node)
5216 return nullptr;
5217
5218 // If the focused frame is embedding an inner WebContents, we must descend
5219 // into that contents. If the current WebContents does not have a focused
5220 // frame, return the main frame of this contents instead of the focused empty
5221 // frame embedding this contents.
5222 while (true) {
5223 contents = contents->node_.GetInnerWebContentsInFrame(focused_node);
5224 if (!contents)
5225 return focused_node->current_frame_host();
5226
5227 focused_node = contents->frame_tree_.GetFocusedFrame();
5228 if (!focused_node)
5229 return contents->GetMainFrame();
5230 }
avallee0206f782016-07-28 18:55:335231}
5232
ekaramada110f642016-12-21 19:47:285233void WebContentsImpl::OnFocusedElementChangedInFrame(
5234 RenderFrameHostImpl* frame,
5235 const gfx::Rect& bounds_in_root_view) {
5236 RenderWidgetHostViewBase* root_view =
5237 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5238 if (!root_view || !frame->GetView())
5239 return;
5240
5241 // Converting to screen coordinates.
5242 gfx::Point origin = bounds_in_root_view.origin();
5243 origin += root_view->GetViewBounds().OffsetFromOrigin();
5244 gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size());
5245
5246 root_view->FocusedNodeChanged(frame->has_focused_editable_element(),
5247 bounds_in_screen);
5248
5249 FocusedNodeDetails details = {frame->has_focused_editable_element(),
5250 bounds_in_screen};
5251
5252 // TODO(ekaramad): We should replace this with an observer notification
5253 // (https://crbug.com/675975).
5254 NotificationService::current()->Notify(
5255 NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
5256 Source<RenderViewHost>(GetRenderViewHost()),
5257 Details<FocusedNodeDetails>(&details));
5258}
5259
avia90ae4e2016-11-11 20:49:335260bool WebContentsImpl::DidAddMessageToConsole(int32_t level,
5261 const base::string16& message,
5262 int32_t line_no,
5263 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:255264 if (!delegate_)
5265 return false;
avia90ae4e2016-11-11 20:49:335266 return delegate_->DidAddMessageToConsole(this, level, message, line_no,
5267 source_id);
[email protected]a796f202012-05-30 14:14:255268}
5269
dominickn9c7ceaa32016-02-27 01:52:535270void WebContentsImpl::OnUserInteraction(
5271 RenderWidgetHostImpl* render_widget_host,
5272 const blink::WebInputEvent::Type type) {
kenrb19221852016-04-29 17:21:405273 // Ignore unless the widget is currently in the frame tree.
5274 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:225275 return;
5276
ericwilligersde386342016-10-19 02:35:095277 for (auto& observer : observers_)
5278 observer.DidGetUserInteraction(type);
dominickn9c7ceaa32016-02-27 01:52:535279
5280 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
5281 // Exclude scroll events as user gestures for resource load dispatches.
5282 // rdh is NULL in unittests.
Blink Reformat1c4d759e2017-04-09 16:34:545283 if (rdh && type != blink::WebInputEvent::kMouseWheel)
scottmge22a5e52016-06-30 00:36:515284 rdh->OnUserGesture();
dominickn2dd142dd2015-10-29 05:30:505285}
5286
avallee9993fca2016-11-17 06:16:505287void WebContentsImpl::FocusOwningWebContents(
5288 RenderWidgetHostImpl* render_widget_host) {
5289 // The PDF plugin still runs as a BrowserPlugin and must go through the
5290 // input redirection mechanism. It must not become focused direcly.
5291 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
5292 return;
5293
5294 RenderWidgetHostImpl* focused_widget =
5295 GetFocusedRenderWidgetHost(render_widget_host);
5296
5297 if (focused_widget != render_widget_host &&
avallee8e881592016-11-19 00:39:305298 (!focused_widget ||
5299 focused_widget->delegate() != render_widget_host->delegate())) {
avallee9993fca2016-11-17 06:16:505300 SetAsFocusedWebContentsIfNecessary();
5301 }
5302}
5303
[email protected]b172aee2012-04-10 17:05:265304void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:445305 // Notify observers.
ericwilligersde386342016-10-19 02:35:095306 for (auto& observer : observers_)
5307 observer.DidGetIgnoredUIEvent();
[email protected]fa1cf0b82010-01-15 21:49:445308}
5309
avic3aa8422015-11-09 20:57:225310void WebContentsImpl::RendererUnresponsive(
avice799302017-03-09 16:34:595311 RenderWidgetHostImpl* render_widget_host) {
ericwilligersde386342016-10-19 02:35:095312 for (auto& observer : observers_)
5313 observer.OnRendererUnresponsive(render_widget_host);
afakhry98241832016-03-11 19:27:475314
[email protected]992db4c2011-05-12 15:37:155315 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:225316 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:155317 return;
5318
avic031d392017-03-03 03:09:425319 if (ShouldIgnoreUnresponsiveRenderer())
[email protected]e5fc1632011-08-08 07:51:535320 return;
5321
creisc014b402015-04-23 16:41:455322 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:475323 return;
5324
dtapuskae99ec6e52016-10-18 00:15:425325 if (delegate_) {
5326 WebContentsUnresponsiveState unresponsive_state;
dtapuskae99ec6e52016-10-18 00:15:425327 unresponsive_state.outstanding_ack_count =
5328 render_widget_host->in_flight_event_count();
5329 unresponsive_state.outstanding_event_type =
5330 render_widget_host->hang_monitor_event_type();
5331 unresponsive_state.last_event_type = render_widget_host->last_event_type();
5332 delegate_->RendererUnresponsive(this, unresponsive_state);
5333 }
[email protected]420ae012009-04-24 05:16:325334}
5335
avic3aa8422015-11-09 20:57:225336void WebContentsImpl::RendererResponsive(
5337 RenderWidgetHostImpl* render_widget_host) {
5338 if (render_widget_host != GetRenderViewHost()->GetWidget())
5339 return;
5340
[email protected]6934a702011-12-20 00:04:515341 if (delegate_)
5342 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:325343}
5344
[email protected]b172aee2012-04-10 17:05:265345void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:555346 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:325347 bool* proceed_to_fire_unload) {
ericwilligersde386342016-10-19 02:35:095348 for (auto& observer : observers_)
5349 observer.BeforeUnloadFired(proceed_time);
[email protected]6934a702011-12-20 00:04:515350 if (delegate_)
5351 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:095352 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:325353}
5354
[email protected]58d5cfe2013-07-10 02:40:525355void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:545356 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:235357 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:225358 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:545359}
5360
[email protected]b172aee2012-04-10 17:05:265361void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:105362 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:215363 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:265364 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
5365 // here during container initialization and normal window size will be set
5366 // later. In case of tab duplication this resizing to 0x0 prevents setting
5367 // normal size later so just ignore it.
5368 if (!size.IsEmpty())
5369 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:325370}
5371
[email protected]af905902013-10-01 21:38:515372void WebContentsImpl::CancelModalDialogsForRenderManager() {
5373 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:545374 // deferrer would prevent us from swapping out. We also clear the state
5375 // because this is a cross-process navigation, which means that it's a new
5376 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:175377 //
5378 // Note that we don't bother telling browser_plugin_embedder_ because the
5379 // cross-process navigation will either destroy the browser plugins or not
5380 // require their dialogs to close.
avi5d3b8692016-10-12 22:00:465381 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:535382 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:465383 }
[email protected]af905902013-10-01 21:38:515384}
5385
[email protected]02d7b6e2014-06-24 21:01:505386void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
5387 RenderFrameHost* new_host,
5388 bool is_main_frame) {
5389 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:055390 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:505391 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:085392
[email protected]02d7b6e2014-06-24 21:01:505393 // Make sure the visible RVH reflects the new delegate's preferences.
5394 if (delegate_)
5395 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:395396
[email protected]02d7b6e2014-06-24 21:01:505397 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
dmazzoni62111452017-04-28 23:46:555398
5399 RenderWidgetHostViewBase* rwhv =
5400 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5401 if (rwhv)
5402 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
[email protected]02d7b6e2014-06-24 21:01:505403 }
5404
5405 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:545406}
5407
naskof5940b9f2015-03-02 23:04:055408void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
5409 RenderViewHost* old_host,
5410 RenderViewHost* new_host) {
5411 NotifyViewSwapped(old_host, new_host);
5412}
5413
[email protected]b172aee2012-04-10 17:05:265414NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:195415 return GetController();
[email protected]3a3d47472010-07-15 21:03:545416}
5417
dcheng59716272016-04-09 05:19:085418std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:295419 const GURL& url) {
avie865b1d2016-10-24 19:42:595420 return CreateWebUI(url, std::string());
[email protected]420ae012009-04-24 05:16:325421}
5422
[email protected]10f417c52011-12-28 21:04:235423NavigationEntry*
[email protected]b172aee2012-04-10 17:05:265424 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:325425 return controller_.GetLastCommittedEntry();
5426}
5427
creisadca9862017-06-16 19:12:115428InterstitialPageImpl* WebContentsImpl::GetInterstitialForRenderManager() {
5429 return interstitial_page_;
5430}
5431
lfgbede6392015-09-11 21:54:065432void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
5433 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:335434 RenderWidgetHostViewBase* rwh_view =
5435 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:525436
[email protected]420ae012009-04-24 05:16:325437 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:445438 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:215439 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:065440}
5441
5442bool WebContentsImpl::CreateRenderViewForRenderManager(
5443 RenderViewHost* render_view_host,
5444 int opener_frame_routing_id,
5445 int proxy_routing_id,
5446 const FrameReplicationState& replicated_frame_state) {
5447 TRACE_EVENT0("browser,navigation",
5448 "WebContentsImpl::CreateRenderViewForRenderManager");
5449
piman00cf9402017-04-03 17:09:205450 if (proxy_routing_id == MSG_ROUTING_NONE)
lfg9431efd2016-12-14 14:45:265451 CreateRenderWidgetHostViewForRenderManager(render_view_host);
lfg9431efd2016-12-14 14:45:265452
piman00cf9402017-04-03 17:09:205453 if (!static_cast<RenderViewHostImpl*>(render_view_host)
5454 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
lfg9431efd2016-12-14 14:45:265455 replicated_frame_state, created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:525456 return false;
[email protected]14392a52012-05-02 20:28:445457 }
[email protected]a4127722011-04-27 23:13:525458
avi2b177592014-12-10 02:08:025459 SetHistoryOffsetAndLengthForView(render_view_host,
5460 controller_.GetLastCommittedEntryIndex(),
5461 controller_.GetEntryCount());
5462
[email protected]a220b5932013-09-21 03:47:445463#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:505464 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
5465 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:445466 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:445467 if (rwh_view) {
5468 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
5469 render_widget_host->WasResized();
5470 }
[email protected]f8233cc2011-05-31 20:24:505471#endif
5472
[email protected]420ae012009-04-24 05:16:325473 return true;
5474}
5475
[email protected]82307f6b2014-08-07 03:30:125476bool WebContentsImpl::CreateRenderFrameForRenderManager(
5477 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:045478 int proxy_routing_id,
5479 int opener_routing_id,
japhete6adf142014-10-31 00:01:495480 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:045481 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:435482 TRACE_EVENT0("browser,navigation",
5483 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:125484
5485 RenderFrameHostImpl* rfh =
5486 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:045487 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
5488 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:125489 return false;
5490
5491 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
5492 // RenderFrameHost will have to be associated with the appropriate
5493 // RenderWidgetHostView or a new one should be created here.
5494
5495 return true;
5496}
5497
mfomitchev2b8b066a2016-01-28 19:23:155498#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:455499
[email protected]155c7f22013-12-09 17:07:185500base::android::ScopedJavaLocalRef<jobject>
5501WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:405502 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:565503 return GetWebContentsAndroid()->GetJavaObject();
5504}
[email protected]155c7f22013-12-09 17:07:185505
[email protected]0e813a52014-08-13 10:34:565506WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:185507 WebContentsAndroid* web_contents_android =
5508 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
5509 if (!web_contents_android) {
5510 web_contents_android = new WebContentsAndroid(this);
avicb129c02017-05-03 06:49:295511 SetUserData(kWebContentsAndroidKey, base::WrapUnique(web_contents_android));
[email protected]155c7f22013-12-09 17:07:185512 }
[email protected]0e813a52014-08-13 10:34:565513 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:185514}
5515
paulmeyerc0b762b2016-04-13 11:55:175516void WebContentsImpl::ActivateNearestFindResult(float x,
5517 float y) {
5518 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
5519}
5520
5521void WebContentsImpl::RequestFindMatchRects(int current_version) {
5522 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
5523}
5524
[email protected]7d244f12013-08-22 21:41:515525bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:065526 return CreateRenderViewForRenderManager(
5527 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:065528 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:515529}
[email protected]fc2b46b2014-05-03 16:33:455530
rockot400ea35b2016-10-15 19:15:325531service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
sammcf5f1b0f2016-09-20 23:05:115532 if (!java_interfaces_) {
rockot400ea35b2016-10-15 19:15:325533 service_manager::mojom::InterfaceProviderPtr provider;
blundelle0a9f1582016-12-20 11:23:325534 BindInterfaceRegistryForWebContents(mojo::MakeRequest(&provider), this);
rockot400ea35b2016-10-15 19:15:325535 java_interfaces_.reset(new service_manager::InterfaceProvider);
sammcf5f1b0f2016-09-20 23:05:115536 java_interfaces_->Bind(std::move(provider));
5537 }
5538 return java_interfaces_.get();
5539}
5540
[email protected]fc2b46b2014-05-03 16:33:455541#elif defined(OS_MACOSX)
5542
[email protected]75f4df72014-07-16 22:39:425543void WebContentsImpl::SetAllowOtherViews(bool allow) {
5544 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:455545}
5546
[email protected]75f4df72014-07-16 22:39:425547bool WebContentsImpl::GetAllowOtherViews() {
5548 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:455549}
5550
spqchane72c3cb2017-06-30 23:02:105551bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() const {
5552 return did_first_visually_non_empty_paint_;
5553}
5554
[email protected]7d244f12013-08-22 21:41:515555#endif
5556
pkotwicz75ca8ffd2016-02-16 23:10:195557void WebContentsImpl::OnDidDownloadImage(
5558 const ImageDownloadCallback& callback,
5559 int id,
5560 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:525561 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:185562 const std::vector<SkBitmap>& images,
5563 const std::vector<gfx::Size>& original_image_sizes) {
5564 callback.Run(id, http_status_code, image_url, images, original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:195565}
5566
[email protected]6fba26d2014-04-29 09:38:285567void WebContentsImpl::OnDialogClosed(int render_process_id,
5568 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:265569 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:495570 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:265571 bool success,
[email protected]fcf75d42013-12-03 20:11:265572 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:285573 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
5574 render_frame_id);
[email protected]87de04b02014-04-08 22:14:495575 last_dialog_suppressed_ = dialog_was_suppressed;
5576
[email protected]beb440c2009-11-06 04:08:545577 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:235578 // It is possible for the current RenderFrameHost to have changed in the
5579 // meantime. Do not reset the navigation state in that case.
5580 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:255581 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:235582 controller_.DiscardNonCommittedEntries();
5583 }
[email protected]ec8e8b02013-06-19 04:57:105584
ericwilligersde386342016-10-19 02:35:095585 for (auto& observer : observers_)
5586 observer.BeforeUnloadDialogCancelled();
[email protected]beb440c2009-11-06 04:08:545587 }
[email protected]87de04b02014-04-08 22:14:495588
[email protected]6fba26d2014-04-29 09:38:285589 if (rfh) {
avi44acfaa82017-05-03 22:55:355590 rfh->JavaScriptDialogClosed(reply_msg, success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:165591
5592 std::vector<protocol::PageHandler*> page_handlers =
5593 protocol::PageHandler::EnabledForWebContents(this);
5594 for (auto* handler : page_handlers)
5595 handler->DidCloseJavaScriptDialog(success, user_input);
5596
[email protected]6fba26d2014-04-29 09:38:285597 } else {
5598 // Don't leak the sync IPC reply if the RFH or process is gone.
5599 delete reply_msg;
5600 }
avi1c51fb62017-02-27 20:43:035601
5602 is_showing_javascript_dialog_ = false;
5603 is_showing_before_unload_dialog_ = false;
[email protected]beb440c2009-11-06 04:08:545604}
5605
[email protected]b172aee2012-04-10 17:05:265606void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:545607 if (encoding == last_reported_encoding_)
5608 return;
5609 last_reported_encoding_ = encoding;
5610
jinsukkim79df88a2017-01-04 06:26:155611 canonical_encoding_ = base::GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:105612}
[email protected]f45d2a72010-03-08 23:28:355613
[email protected]1ac10dca2013-08-20 20:47:045614bool WebContentsImpl::IsHidden() {
5615 return capturer_count_ == 0 && !should_normally_be_visible_;
5616}
5617
rob97250742015-12-10 17:45:155618int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lfg601233692017-03-06 22:45:445619 return node_.outer_contents_frame_tree_node_id();
lazyboy6ec48b2a2015-06-29 15:18:145620}
5621
ekaramadaeb3c5c2016-11-09 03:22:355622RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const {
5623 return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
5624 fullscreen_widget_routing_id_);
5625}
5626
[email protected]b0936d22013-11-28 06:47:365627RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:215628 return frame_tree_.root()->render_manager();
5629}
5630
[email protected]f8497342013-02-05 22:15:025631BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:395632 return browser_plugin_guest_.get();
5633}
5634
[email protected]738f57a2013-06-29 21:06:545635void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
5636 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:145637 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:545638 browser_plugin_guest_.reset(guest);
5639}
5640
[email protected]f8497342013-02-05 22:15:025641BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:395642 return browser_plugin_embedder_.get();
5643}
[email protected]8ff00d72012-10-23 19:12:215644
fsamuel60b42282015-03-10 03:29:145645void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
5646 if (browser_plugin_embedder_)
5647 return;
5648 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
5649}
5650
[email protected]fc2b46b2014-05-03 16:33:455651gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:215652 gfx::Size size;
5653 if (delegate_)
5654 size = delegate_->GetSizeForNewRenderView(this);
5655 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:455656 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:215657 return size;
5658}
5659
[email protected]ae7eeda2014-07-04 01:53:265660void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:095661 for (auto& observer : observers_)
5662 observer.FrameDeleted(render_frame_host);
[email protected]9b159a52013-10-03 17:24:555663}
5664
[email protected]222f5822014-02-05 23:40:495665void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
5666 if (!delegate_)
5667 return;
5668 const gfx::Size new_size = GetPreferredSize();
5669 if (new_size != old_size)
5670 delegate_->UpdatePreferredSize(this, new_size);
5671}
5672
avie865b1d2016-10-24 19:42:595673std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI(
5674 const GURL& url,
5675 const std::string& frame_name) {
5676 std::unique_ptr<WebUIImpl> web_ui =
5677 base::MakeUnique<WebUIImpl>(this, frame_name);
5678 WebUIController* controller =
5679 WebUIControllerFactoryRegistry::GetInstance()
5680 ->CreateWebUIControllerForURL(web_ui.get(), url);
dbeama1b926a2015-08-31 23:17:515681 if (controller) {
weisert3dab3b92017-01-10 10:31:175682 web_ui->AddMessageHandler(base::MakeUnique<GenericHandler>());
dbeama1b926a2015-08-31 23:17:515683 web_ui->SetController(controller);
5684 return web_ui;
5685 }
5686
avie865b1d2016-10-24 19:42:595687 return nullptr;
dbeama1b926a2015-08-31 23:17:515688}
5689
paulmeyerfeafc2d2017-04-25 21:46:405690FindRequestManager* WebContentsImpl::GetFindRequestManager() {
5691 for (WebContentsImpl* contents = this; contents;
5692 contents = contents->GetOuterWebContents()) {
5693 if (contents->find_request_manager_)
5694 return contents->find_request_manager_.get();
5695 }
5696
5697 return nullptr;
5698}
5699
paulmeyerc0b762b2016-04-13 11:55:175700FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
paulmeyerfeafc2d2017-04-25 21:46:405701 if (FindRequestManager* manager = GetFindRequestManager())
5702 return manager;
5703
5704 // No existing FindRequestManager found, so one must be created.
5705 find_request_manager_.reset(new FindRequestManager(this));
5706
5707 // Concurrent find sessions must not overlap, so destroy any existing
5708 // FindRequestManagers in any inner WebContentses.
5709 for (WebContentsImpl* contents : GetWebContentsAndAllInner()) {
5710 if (contents == this)
5711 continue;
5712 if (contents->find_request_manager_) {
5713 contents->find_request_manager_->StopFinding(
5714 content::STOP_FIND_ACTION_CLEAR_SELECTION);
5715 contents->find_request_manager_.release();
5716 }
5717 }
paulmeyerc0b762b2016-04-13 11:55:175718
5719 return find_request_manager_.get();
5720}
5721
5722void WebContentsImpl::NotifyFindReply(int request_id,
5723 int number_of_matches,
5724 const gfx::Rect& selection_rect,
5725 int active_match_ordinal,
5726 bool final_update) {
Sebastien Marchandcf97ed52017-07-24 23:50:345727 if (delegate_ && !is_being_destroyed_ &&
5728 !GetRenderProcessHost()->FastShutdownStarted()) {
paulmeyerc0b762b2016-04-13 11:55:175729 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
5730 active_match_ordinal, final_update);
5731 }
5732}
5733
ortuno467e5792016-06-10 04:32:395734void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
5735 // Trying to invalidate the tab state while being destroyed could result in a
5736 // use after free.
5737 if (IsBeingDestroyed()) {
5738 return;
5739 }
5740 // Notify for UI updates if the state changes.
5741 bluetooth_connected_device_count_++;
5742 if (bluetooth_connected_device_count_ == 1) {
5743 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
5744 }
5745}
5746
5747void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
5748 // Trying to invalidate the tab state while being destroyed could result in a
5749 // use after free.
5750 if (IsBeingDestroyed()) {
5751 return;
5752 }
5753 // Notify for UI updates if the state changes.
5754 DCHECK(bluetooth_connected_device_count_ != 0);
5755 bluetooth_connected_device_count_--;
5756 if (bluetooth_connected_device_count_ == 0) {
5757 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
5758 }
5759}
5760
zqzhang8ac49002017-03-16 21:51:355761void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) {
5762 if (has_persistent_video_ == has_persistent_video)
mlamouri5cd9ae82017-02-18 11:05:095763 return;
5764
zqzhang8ac49002017-03-16 21:51:355765 has_persistent_video_ = has_persistent_video;
mlamouri5cd9ae82017-02-18 11:05:095766 NotifyPreferencesChanged();
zqzhang8ac49002017-03-16 21:51:355767 media_web_contents_observer()->RequestPersistentVideo(has_persistent_video);
mlamouri5cd9ae82017-02-18 11:05:095768}
5769
paulmeyerfeafc2d2017-04-25 21:46:405770void WebContentsImpl::BrowserPluginGuestWillDetach() {
5771 WebContentsImpl* outermost = GetOutermostWebContents();
5772 if (this != outermost && ContainsOrIsFocusedWebContents())
5773 outermost->SetAsFocusedWebContentsIfNecessary();
5774}
5775
paulmeyerc0b762b2016-04-13 11:55:175776#if defined(OS_ANDROID)
5777void WebContentsImpl::NotifyFindMatchRectsReply(
5778 int version,
5779 const std::vector<gfx::RectF>& rects,
5780 const gfx::RectF& active_rect) {
5781 if (delegate_)
5782 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
5783}
5784#endif
5785
[email protected]34ff1cfc2014-08-20 06:16:055786void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
5787 force_disable_overscroll_content_ = force_disable;
5788 if (view_)
5789 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
5790}
5791
dalecurtis88c240072015-12-09 02:11:185792void WebContentsImpl::MediaStartedPlaying(
billorr21c005d2016-11-17 03:57:045793 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:185794 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:045795 if (media_info.has_video)
5796 currently_playing_video_count_++;
5797
ericwilligersde386342016-10-19 02:35:095798 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:045799 observer.MediaStartedPlaying(media_info, id);
dalecurtis88c240072015-12-09 02:11:185800}
5801
5802void WebContentsImpl::MediaStoppedPlaying(
billorr21c005d2016-11-17 03:57:045803 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:185804 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:045805 if (media_info.has_video)
5806 currently_playing_video_count_--;
5807
ericwilligersde386342016-10-19 02:35:095808 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:045809 observer.MediaStoppedPlaying(media_info, id);
5810}
5811
peconn257951522017-06-09 18:24:595812void WebContentsImpl::MediaResized(
5813 const gfx::Size& size,
5814 const WebContentsObserver::MediaPlayerId& id) {
5815 cached_video_sizes_[id] = size;
5816
5817 for (auto& observer : observers_)
5818 observer.MediaResized(size, id);
5819}
5820
Peter Connaa7f0732017-07-12 12:01:535821const WebContents::VideoSizeMap&
5822WebContentsImpl::GetCurrentlyPlayingVideoSizes() {
5823 return cached_video_sizes_;
peconn257951522017-06-09 18:24:595824}
5825
billorr21c005d2016-11-17 03:57:045826int WebContentsImpl::GetCurrentlyPlayingVideoCount() {
5827 return currently_playing_video_count_;
dalecurtis88c240072015-12-09 02:11:185828}
5829
tapted65ff2ea72016-03-01 23:39:005830void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
5831 if (!did_first_set_visible_) {
5832 // If this WebContents has not yet been set to be visible for the first
5833 // time, ignore any requests to make it hidden, since resources would
5834 // immediately be destroyed and only re-created after content loaded. In
5835 // this state the window content is undefined and can show garbage.
5836 // However, the page load mechanism requires an activation call through a
5837 // visibility call to (re)load.
5838 if (visible) {
5839 did_first_set_visible_ = true;
5840 WasShown();
5841 }
5842 return;
5843 }
5844 if (visible == should_normally_be_visible_)
5845 return;
5846
5847 if (visible)
5848 WasShown();
5849 else
5850 WasHidden();
5851}
5852
aelias5252baa2016-04-10 01:18:025853void WebContentsImpl::UpdateOverridingUserAgent() {
mlamouri5cd9ae82017-02-18 11:05:095854 NotifyPreferencesChanged();
aelias5252baa2016-04-10 01:18:025855}
5856
avid53461d2016-02-25 17:15:045857void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
5858 JavaScriptDialogManager* dialog_manager) {
5859 dialog_manager_ = dialog_manager;
5860}
5861
rockotf62002a2016-09-15 00:08:595862void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) {
5863 auto it = binding_sets_.find(interface_name);
5864 if (it != binding_sets_.end())
5865 binding_sets_.erase(it);
5866}
5867
nzolghadrd87a308d2016-12-07 15:45:565868bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) {
nzolghadrbbffc6c2017-05-25 17:56:395869 // Here we associate this metric to the main frame URL regardless of what
5870 // caused it.
nzolghadrd87a308d2016-12-07 15:45:565871 sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL(
5872 GetLastCommittedURL()));
nzolghadrd87a308d2016-12-07 15:45:565873 return true;
5874}
5875
nzolghadrbbffc6c2017-05-25 17:56:395876void WebContentsImpl::UpdateUrlForUkmSource(ukm::UkmRecorder* service,
5877 ukm::SourceId ukm_source_id) {
5878 // Here we associate this metric to the main frame URL regardless of what
5879 // caused it.
5880 service->UpdateSourceURL(ukm_source_id, GetLastCommittedURL());
5881}
5882
ekaramada110f642016-12-21 19:47:285883void WebContentsImpl::FocusedNodeTouched(bool editable) {
5884#if defined(OS_WIN)
5885 // We use the cursor position to determine where the touch occurred.
5886 RenderWidgetHostView* view = GetRenderWidgetHostView();
5887 if (!view)
5888 return;
5889 POINT cursor_pos = {};
5890 ::GetCursorPos(&cursor_pos);
5891 float scale = GetScaleFactorForView(view);
5892 gfx::Point location_dips_screen =
5893 gfx::ConvertPointToDIP(scale, gfx::Point(cursor_pos));
5894 view->FocusedNodeTouched(location_dips_screen, editable);
5895#endif
5896}
5897
samans90fb8162017-04-04 22:30:455898void WebContentsImpl::DidReceiveCompositorFrame() {
5899 for (auto& observer : observers_)
5900 observer.DidReceiveCompositorFrame();
5901}
5902
falken52a56e32016-12-08 05:02:405903void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() {
5904 bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch(
5905 switches::kAllowInsecureLocalhost);
5906 if (!allow_localhost)
5907 return;
5908
5909 content::NavigationEntry* entry = GetController().GetLastCommittedEntry();
5910 if (!entry || !net::IsLocalhost(entry->GetURL().host()))
5911 return;
5912
5913 content::SSLStatus ssl_status = entry->GetSSL();
5914 bool is_cert_error = net::IsCertStatusError(ssl_status.cert_status) &&
5915 !net::IsCertStatusMinorError(ssl_status.cert_status);
5916 if (!is_cert_error)
5917 return;
5918
5919 GetMainFrame()->AddMessageToConsole(
5920 content::CONSOLE_MESSAGE_LEVEL_WARNING,
5921 base::StringPrintf("This site does not have a valid SSL "
5922 "certificate! Without SSL, your site's and "
5923 "visitors' data is vulnerable to theft and "
5924 "tampering. Get a valid SSL certificate before"
5925 " releasing your website to the public."));
5926}
5927
ekaramadf6750aa2017-06-06 18:29:425928bool WebContentsImpl::IsShowingContextMenuOnPage() const {
5929 return showing_context_menu_;
5930}
5931
mlamouri5cd9ae82017-02-18 11:05:095932void WebContentsImpl::NotifyPreferencesChanged() {
5933 std::set<RenderViewHost*> render_view_host_set;
5934 for (FrameTreeNode* node : frame_tree_.Nodes()) {
5935 RenderWidgetHost* render_widget_host =
5936 node->current_frame_host()->GetRenderWidgetHost();
5937 if (!render_widget_host)
5938 continue;
5939 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
5940 if (!render_view_host)
5941 continue;
5942 render_view_host_set.insert(render_view_host);
5943 }
5944 for (RenderViewHost* render_view_host : render_view_host_set)
5945 render_view_host->OnWebkitPreferencesChanged();
5946}
5947
Megan Jablonski2f6a4c52017-07-10 23:01:255948DownloadUrlParameters::RequestHeadersType WebContentsImpl::ParseDownloadHeaders(
5949 const std::string& headers) {
5950 DownloadUrlParameters::RequestHeadersType request_headers;
5951 for (const base::StringPiece& key_value : base::SplitStringPiece(
5952 headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
5953 std::vector<std::string> pair = base::SplitString(
5954 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
5955 if (2ul == pair.size())
5956 request_headers.push_back(make_pair(pair[0], pair[1]));
5957 }
5958 return request_headers;
5959}
5960
lukasza6f8ac622017-06-06 03:10:205961void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener,
5962 bool opener_suppressed) {
5963 if (opener) {
5964 FrameTreeNode* new_root = GetFrameTree()->root();
5965
5966 // For the "original opener", track the opener's main frame instead, because
5967 // if the opener is a subframe, the opener tracking could be easily bypassed
5968 // by spawning from a subframe and deleting the subframe.
5969 // https://crbug.com/705316
5970 new_root->SetOriginalOpener(opener->frame_tree()->root());
5971
5972 if (!opener_suppressed) {
5973 new_root->SetOpener(opener);
5974 created_with_opener_ = true;
5975 }
5976 }
5977}
5978
Becca Hughes9f6fd4b82017-06-15 10:01:405979void WebContentsImpl::MediaMutedStatusChanged(
5980 const WebContentsObserver::MediaPlayerId& id,
5981 bool muted) {
5982 for (auto& observer : observers_)
5983 observer.MediaMutedStatusChanged(id, muted);
5984}
5985
[email protected]8ff00d72012-10-23 19:12:215986} // namespace content