blob: 6ceef4289ec0a5aafb1a3450fd076b051b6569c9 [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>
[email protected]b75b8292010-10-01 07:28:2511
[email protected]36fb2c7c2011-04-04 15:49:0812#include "base/command_line.h"
creisfafed882016-07-29 00:03:0913#include "base/debug/dump_without_crashing.h"
zqzhang181047e62016-07-01 13:37:1714#include "base/feature_list.h"
[email protected]cbb1ef592013-06-05 19:49:4615#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0716#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5617#include "base/logging.h"
avib7348942015-12-25 20:57:1018#include "base/macros.h"
dmazzonid95ae842016-04-12 21:17:3919#include "base/memory/ref_counted.h"
asvitkine8d51e9d2016-09-02 23:55:4320#include "base/metrics/histogram_macros.h"
[email protected]04cbd3d2013-12-04 04:58:2021#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2222#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0723#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5124#include "base/strings/string16.h"
25#include "base/strings/string_number_conversions.h"
26#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0027#include "base/strings/utf_string_conversions.h"
gab30f26df2016-05-11 19:37:5528#include "base/threading/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3729#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4230#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1031#include "build/build_config.h"
rsleevic327b48f82015-04-30 02:03:2532#include "components/mime_util/mime_util.h"
rsleevi24f64dc22015-08-07 21:39:2133#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3034#include "content/browser/accessibility/accessibility_mode_helper.h"
35#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1836#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3937#include "content/browser/browser_plugin/browser_plugin_embedder.h"
38#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5939#include "content/browser/child_process_security_policy_impl.h"
[email protected]5f2aa722013-08-07 16:59:4140#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0441#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4642#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1243#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1644#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1745#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1646#include "content/browser/frame_host/cross_process_frame_connector.h"
ananta4b7467a52016-09-23 01:42:3847#include "content/browser/frame_host/frame_tree_node.h"
[email protected]d4a8ca482013-10-30 21:06:4048#include "content/browser/frame_host/interstitial_page_impl.h"
49#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3350#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0151#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1852#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0753#include "content/browser/frame_host/render_frame_proxy_host.h"
[email protected]bffc8302014-01-23 20:52:1654#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]5c9250872012-01-30 17:24:0555#include "content/browser/host_zoom_map_impl.h"
csharrison2e8c98e2016-08-01 23:56:2556#include "content/browser/loader/loader_io_thread_notifier.h"
[email protected]678c0362012-12-05 08:02:4457#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4058#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3059#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5260#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1861#include "content/browser/media/media_web_contents_observer.h"
mlamouri918734092016-03-12 04:47:5262#include "content/browser/media/session/media_session.h"
[email protected]0bc7f3542013-10-21 15:05:5363#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0964#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3065#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5066#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3267#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5068#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5969#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4870#include "content/browser/renderer_host/render_widget_host_view_base.h"
ekaramadadd882292016-06-08 15:22:5671#include "content/browser/renderer_host/text_input_manager.h"
jonross74971522014-09-15 14:16:0972#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3373#include "content/browser/site_instance_impl.h"
lfgc740d4b22016-04-15 16:45:3374#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1175#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5876#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0377#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5678#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1479#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4280#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4481#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1782#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0783#include "content/common/page_messages.h"
nasko34634672016-07-29 18:46:0684#include "content/common/page_state_serialization.h"
rockot5c478a72016-09-28 23:14:1885#include "content/common/render_message_filter.mojom.h"
avi286019ce2015-07-29 01:26:5886#include "content/common/site_isolation_policy.h"
[email protected]2c5569662011-03-22 20:45:0287#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3688#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1189#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2890#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4491#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3692#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1793#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1494#include "content/public/browser/download_url_parameters.h"
ekaramad1beabecc2016-09-23 20:18:1795#include "content/public/browser/guest_mode.h"
[email protected]d9083482012-01-06 00:38:4696#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1597#include "content/public/browser/javascript_dialog_manager.h"
[email protected]09d31d52012-03-11 22:30:2798#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0099#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:37100#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:14101#include "content/public/browser/notification_service.h"
scottmg011d96e32016-06-29 19:15:08102#include "content/public/browser/notification_types.h"
[email protected]95640212014-07-26 18:14:30103#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:32104#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:09105#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:12106#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:34107#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:38108#include "content/public/browser/user_metrics.h"
rockotf62002a2016-09-15 00:08:59109#include "content/public/browser/web_contents_binding_set.h"
[email protected]674bc592011-12-20 23:00:42110#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:21111#include "content/public/common/bindings_policy.h"
carloskd80262f52015-12-16 14:40:35112#include "content/public/common/browser_side_navigation_policy.h"
alexmosc9e76ec2016-05-16 22:59:37113#include "content/public/common/child_process_host.h"
[email protected]54087fe2011-10-28 22:02:48114#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54115#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49116#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20117#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:03118#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57119#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05120#include "content/public/common/web_preferences.h"
mcasas4e216e72016-07-28 21:28:38121#include "device/geolocation/geolocation_service_context.h"
sammc5a139ba2016-09-29 01:49:14122#include "device/nfc/nfc.mojom.h"
blundelld46e8832016-10-07 10:34:27123#include "device/wake_lock/wake_lock_service_context.h"
wjmaclean64951902016-04-29 20:59:12124#include "net/base/url_util.h"
[email protected]8bfc8272013-09-09 20:10:53125#include "net/http/http_cache.h"
126#include "net/http/http_transaction_factory.h"
127#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34128#include "net/url_request/url_request_context_getter.h"
sammcf5f1b0f2016-09-20 23:05:11129#include "services/shell/public/cpp/interface_provider.h"
estark47ba9c7d2016-10-11 15:40:11130#include "third_party/WebKit/public/platform/WebSecurityStyle.h"
alexmosaedfc6f2016-01-21 23:57:38131#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40132#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39133#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56134#include "ui/base/layout.h"
chongz4a9751942016-08-17 17:49:39135#include "ui/events/blink/web_input_event_traits.h"
[email protected]66bd5512012-08-01 02:02:52136#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31137
[email protected]583418cc2013-01-17 14:01:10138#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40139#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15140#include "content/browser/android/date_time_chooser_android.h"
sammcf5f1b0f2016-09-20 23:05:11141#include "content/browser/android/java_interfaces_impl.h"
dalecurtisc85ed632016-01-13 00:22:46142#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18143#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15144#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10145
[email protected]f66df822012-05-18 16:52:17146#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50147#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57148#endif
[email protected]3e45ba92009-02-20 21:09:00149
sadrul943e3b32016-08-04 18:22:59150#if defined(USE_AURA)
fsamuel9cf7bdf2015-11-20 02:19:32151#include "content/browser/web_contents/web_contents_view_mus.h"
bend32292b2016-10-07 00:21:58152#include "content/public/common/service_manager_connection.h"
fsamuel6c6da0232015-11-26 05:13:46153#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32154#endif
155
zqzhang181047e62016-07-01 13:37:17156#if defined(ENABLE_PLUGINS)
157#include "content/browser/media/session/pepper_playback_observer.h"
158#endif // ENABLE_PLUGINS
159
[email protected]8ff00d72012-10-23 19:12:21160namespace content {
[email protected]420ae012009-04-24 05:16:32161namespace {
162
[email protected]960b0372014-05-19 18:01:00163const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41164const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05165
[email protected]155c7f22013-12-09 17:07:18166#if defined(OS_ANDROID)
167const char kWebContentsAndroidKey[] = "web_contents_android";
168#endif // OS_ANDROID
169
[email protected]e4abd3b42013-11-12 18:28:47170base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46171g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
172
[email protected]8bfc8272013-09-09 20:10:53173void NotifyCacheOnIO(
174 scoped_refptr<net::URLRequestContextGetter> request_context,
175 const GURL& url,
176 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58177 net::HttpCache* cache = request_context->GetURLRequestContext()->
178 http_transaction_factory()->GetCache();
179 if (cache)
180 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53181}
182
dcheng57e39e22016-01-21 00:25:38183bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
184 for (FrameTreeNode* node : tree->Nodes()) {
185 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
186 return true;
alexmos4cf2aa32015-07-15 23:40:43187 }
dcheng57e39e22016-01-21 00:25:38188 return false;
[email protected]95640212014-07-26 18:14:30189}
190
kenrb19221852016-04-29 17:21:40191bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) {
192 // This method scans the frame tree rather than checking whether
193 // host->delegate() == this, which allows it to return false when the host
194 // for a frame that is pending or pending deletion.
195 if (!host)
196 return false;
197
198 for (FrameTreeNode* node : tree->Nodes()) {
199 if (node->current_frame_host()->GetRenderWidgetHost() == host)
200 return true;
201 }
202 return false;
203}
204
[email protected]95640212014-07-26 18:14:30205void SetAccessibilityModeOnFrame(AccessibilityMode mode,
206 RenderFrameHost* frame_host) {
207 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
208}
209
dtseng0dd3fa12015-07-22 19:00:52210void ResetAccessibility(RenderFrameHost* rfh) {
211 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
212}
213
dmazzonid95ae842016-04-12 21:17:39214using AXTreeSnapshotCallback =
215 base::Callback<void(const ui::AXTreeUpdate&)>;
216
217// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
218// Handles the callbacks from parallel snapshot requests to each frame,
219// and feeds the results to an AXTreeCombiner, which converts them into a
220// single combined accessibility tree.
221class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
222 public:
223 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
224 : callback_(callback) {
225 }
226
227 AXTreeSnapshotCallback AddFrame(bool is_root) {
228 // Adds a reference to |this|.
229 return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot,
230 this,
231 is_root);
232 }
233
234 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
235 combiner_.AddTree(snapshot, is_root);
236 }
237
238 private:
239 friend class base::RefCounted<AXTreeSnapshotCombiner>;
240
241 // This is called automatically after the last call to ReceiveSnapshot
242 // when there are no more references to this object.
243 ~AXTreeSnapshotCombiner() {
244 combiner_.Combine();
245 callback_.Run(combiner_.combined());
246 }
247
248 ui::AXTreeCombiner combiner_;
249 AXTreeSnapshotCallback callback_;
250};
251
[email protected]420ae012009-04-24 05:16:32252} // namespace
253
[email protected]54944cde2012-12-09 09:24:59254WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21255 FrameTreeNode* opener_node = nullptr;
256 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
257 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
258 params.opener_render_process_id, params.opener_render_frame_id);
259 if (opener_rfh)
260 opener_node = opener_rfh->frame_tree_node();
261 }
262 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19263}
264
265WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59266 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30267 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21268 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30269
270 for (SessionStorageNamespaceMap::const_iterator it =
271 session_storage_namespace_map.begin();
272 it != session_storage_namespace_map.end();
273 ++it) {
274 new_contents->GetController()
275 .SetSessionStorageNamespace(it->first, it->second.get());
276 }
277
[email protected]54944cde2012-12-09 09:24:59278 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19279 return new_contents;
[email protected]a81343d232011-12-27 07:39:20280}
[email protected]746d3052012-05-22 15:15:47281
nickf9acfbe2014-12-23 19:12:37282void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
283 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46284 g_created_callbacks.Get().push_back(callback);
285}
286
nickf9acfbe2014-12-23 19:12:37287void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
288 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46289 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
290 if (g_created_callbacks.Get().at(i).Equals(callback)) {
291 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
292 return;
293 }
294 }
295}
296
avidf38c952015-10-27 13:45:13297WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
298 if (!rvh)
299 return nullptr;
[email protected]746d3052012-05-22 15:15:47300 return rvh->GetDelegate()->GetAsWebContents();
301}
302
[email protected]a86c0e962013-12-17 17:10:39303WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13304 if (!rfh)
305 return nullptr;
306 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39307}
308
ananta4b7467a52016-09-23 01:42:38309WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) {
310 FrameTreeNode* frame_tree_node =
311 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
312 return FromRenderFrameHost(frame_tree_node->current_frame_host());
313}
314
[email protected]7fff43e2013-05-21 20:21:10315// WebContentsImpl::DestructionObserver ----------------------------------------
316
317class WebContentsImpl::DestructionObserver : public WebContentsObserver {
318 public:
319 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
320 : WebContentsObserver(watched_contents),
321 owner_(owner) {
322 }
323
324 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58325 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58326 owner_->OnWebContentsDestroyed(
327 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10328 }
329
330 private:
331 WebContentsImpl* owner_;
332
333 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
334};
335
[email protected]8ed16472014-04-11 19:02:48336WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
337 int render_frame_id,
338 ColorChooser* chooser,
339 int identifier)
340 : render_process_id(render_process_id),
341 render_frame_id(render_frame_id),
342 chooser(chooser),
343 identifier(identifier) {
344}
345
346WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
347}
348
lazyboy6ec48b2a2015-06-29 15:18:14349// WebContentsImpl::WebContentsTreeNode ----------------------------------------
350WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
351 : outer_web_contents_(nullptr),
352 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33353 FrameTreeNode::kFrameTreeNodeInvalidId),
354 focused_web_contents_(nullptr) {}
lazyboy6ec48b2a2015-06-29 15:18:14355
356WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
357 // Remove child pointer from our parent.
358 if (outer_web_contents_) {
359 ChildrenSet& child_ptrs_in_parent =
360 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
361 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
362 DCHECK(iter != child_ptrs_in_parent.end());
avallee0206f782016-07-28 18:55:33363 child_ptrs_in_parent.erase(iter);
lazyboy6ec48b2a2015-06-29 15:18:14364 }
365
366 // Remove parent pointers from our children.
367 // TODO(lazyboy): We should destroy the children WebContentses too. If the
368 // children do not manage their own lifetime, then we would leak their
369 // WebContentses.
370 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
371 child->outer_web_contents_ = nullptr;
372}
373
374void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
375 WebContentsImpl* outer_web_contents,
376 RenderFrameHostImpl* outer_contents_frame) {
avallee0206f782016-07-28 18:55:33377 DCHECK(!focused_web_contents_) << "Should not attach a root node.";
lazyboy6ec48b2a2015-06-29 15:18:14378 outer_web_contents_ = outer_web_contents;
379 outer_contents_frame_tree_node_id_ =
380 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
381
avallee0206f782016-07-28 18:55:33382 if (!outer_web_contents_->node_) {
383 // This will only be reached when creating a new WebContents tree.
384 // Initialize the root of this tree and set it as focused.
lazyboy6ec48b2a2015-06-29 15:18:14385 outer_web_contents_->node_.reset(new WebContentsTreeNode());
avallee0206f782016-07-28 18:55:33386 outer_web_contents_->node_->SetFocusedWebContents(outer_web_contents_);
387 }
lazyboy6ec48b2a2015-06-29 15:18:14388
389 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
390}
391
avallee0206f782016-07-28 18:55:33392void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
393 WebContentsImpl* web_contents) {
394 DCHECK(!outer_web_contents())
395 << "Only the outermost WebContents tracks focus.";
396 focused_web_contents_ = web_contents;
397}
398
[email protected]b172aee2012-04-10 17:05:26399// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32400
alexmose201c7cd2015-06-10 17:14:21401WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42402 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22403 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57404 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21405 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01406 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57407 this,
408 this,
409 this,
410 this),
[email protected]6dfed692014-05-22 04:18:03411 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23412 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
413 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34414 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26415 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56416 upload_size_(0),
417 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16418 is_resume_pending_(false),
[email protected]b4c84012014-04-28 19:51:10419 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28420 theme_color_(SK_ColorTRANSPARENT),
421 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29422 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55423 capturer_count_(0),
424 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00425 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57426 is_being_destroyed_(false),
427 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15428 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01429 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39430 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38431 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21432 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
433 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22434 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44435 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55436 render_frame_message_source_(NULL),
alexmosc9e76ec2016-05-16 22:59:37437 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42438 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03439 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49440 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05441 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30442 last_dialog_suppressed_(false),
mcasas4e216e72016-07-28 21:28:38443 geolocation_service_context_(new device::GeolocationServiceContext()),
waffles1c12bf402016-02-10 17:45:48444 accessibility_mode_(
445 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15446 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35447 bluetooth_connected_device_count_(0),
mohan.reddyaae039a2014-11-21 17:39:50448 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46449 page_scale_factor_is_one_(true),
lfgbee1e0a2016-06-08 21:24:21450 mouse_lock_widget_(nullptr),
pkotwicz75ca8ffd2016-02-16 23:10:19451 loading_weak_factory_(this),
452 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55453 frame_tree_.SetFrameRemoveListener(
454 base::Bind(&WebContentsImpl::OnFrameRemoved,
455 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46456#if defined(OS_ANDROID)
457 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
458#else
qinmin58567c82015-01-07 21:00:20459 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46460#endif
zqzhang181047e62016-07-01 13:37:17461#if defined (ENABLE_PLUGINS)
462 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
463#endif
csharrisona2280cd2016-02-03 23:21:15464 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
blundelld46e8832016-10-07 10:34:27465 wake_lock_service_context_.reset(new device::WakeLockServiceContext(
blundellebd75172016-10-03 10:41:43466 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
467 base::Bind(&WebContentsImpl::GetNativeView, base::Unretained(this))));
[email protected]332af7732009-03-11 13:21:35468}
initial.commit09911bf2008-07-26 23:55:29469
[email protected]b172aee2012-04-10 17:05:26470WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32471 is_being_destroyed_ = true;
472
kenrb2a565f82015-09-02 20:24:59473 rwh_input_event_router_.reset();
474
rockotf62002a2016-09-15 00:08:59475 for (auto& entry : binding_sets_)
476 entry.second->CloseAllBindings();
477
avallee0206f782016-07-28 18:55:33478 WebContentsImpl* outermost = GetOutermostWebContents();
479 if (GetFocusedWebContents() == this && this != outermost) {
480 // If the current WebContents is in focus, unset it.
481 outermost->node_->SetFocusedWebContents(outermost);
482 }
483
dcheng72be33c2016-01-21 04:11:31484 for (FrameTreeNode* node : frame_tree_.Nodes()) {
485 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
486 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38487 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38488 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31489 }
carlosk35f35af2015-12-01 10:55:40490
dcheng57e39e22016-01-21 00:25:38491 for (RenderWidgetHostImpl* widget : created_widgets_)
492 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26493 created_widgets_.clear();
494
[email protected]3ab9cb82011-06-03 18:02:07495 // Clear out any JavaScript state.
avi5d3b8692016-10-12 22:00:46496 if (dialog_manager_) {
497 // This object is being destructed, so make sure that no callbacks happen.
498 dialog_manager_->CancelDialogs(this,
499 true, // suppress_callbacks,
500 true); // reset_state
501 }
[email protected]3ab9cb82011-06-03 18:02:07502
[email protected]8ed16472014-04-11 19:02:48503 if (color_chooser_info_.get())
504 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20505
[email protected]420ae012009-04-24 05:16:32506 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32507
[email protected]ca13a442012-04-17 14:00:12508 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21509 NotificationService::current()->Notify(
510 NOTIFICATION_WEB_CONTENTS_DESTROYED,
511 Source<WebContents>(this),
512 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32513
[email protected]df0c843f2014-05-23 20:37:23514 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14515 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23516 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59517
clamy0e119882015-07-31 16:12:33518 // Manually call the observer methods for the root frame tree node. It is
519 // necessary to manually delete all objects tracking navigations
520 // (NavigationHandle, NavigationRequest) for observers to be properly
521 // notified of these navigations stopping before the WebContents is
522 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23523 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56524
clamy0e119882015-07-31 16:12:33525 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56526 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33527 root->pending_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08528 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33529 }
naskob21fe4872015-02-24 14:15:56530 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33531 root->current_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08532 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33533
534 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35535 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41536 // Do not update state as the WebContents is being destroyed.
537 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33538 if (root->speculative_frame_host()) {
539 root->speculative_frame_host()->SetRenderFrameCreated(false);
540 root->speculative_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08541 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33542 }
543 }
[email protected]f273ee52013-10-18 16:05:27544
zqzhang181047e62016-07-01 13:37:17545#if defined(ENABLE_PLUGINS)
546 // Call this before WebContentsDestroyed() is broadcasted since
547 // AudioFocusManager will be destroyed after that.
548 pepper_playback_observer_.reset();
549#endif // defined(ENABLED_PLUGINS)
550
naskoa83483fb2015-02-27 16:57:10551 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
552 FrameDeleted(root->current_frame_host()));
553
[email protected]df0c843f2014-05-23 20:37:23554 if (root->pending_render_view_host()) {
555 FOR_EACH_OBSERVER(WebContentsObserver,
556 observers_,
557 RenderViewDeleted(root->pending_render_view_host()));
558 }
[email protected]c06c58c2014-03-12 20:31:59559
[email protected]f273ee52013-10-18 16:05:27560 FOR_EACH_OBSERVER(WebContentsObserver,
561 observers_,
[email protected]df0c843f2014-05-23 20:37:23562 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27563
[email protected]2db9bd72012-04-13 20:20:56564 FOR_EACH_OBSERVER(WebContentsObserver,
565 observers_,
[email protected]12a46832014-05-09 13:35:58566 WebContentsDestroyed());
567
568 FOR_EACH_OBSERVER(WebContentsObserver,
569 observers_,
570 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08571
[email protected]6934a702011-12-20 00:04:51572 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42573}
574
[email protected]d1198fd2012-08-13 22:50:19575WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59576 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21577 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03578 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21579 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19580
alexmosaedfc6f2016-01-21 23:57:38581 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
582
alexmose201c7cd2015-06-10 17:14:21583 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38584 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21585 new_contents->created_with_opener_ = true;
586 }
587
alexmosaedfc6f2016-01-21 23:57:38588 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
589 // flags, and these flags take effect immediately. An exception is if the
590 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
591 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
592 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
593 if (opener) {
594 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
595 const blink::WebSandboxFlags inherit_flag =
596 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
597 if ((opener_flags & inherit_flag) == inherit_flag) {
598 new_root->SetPendingSandboxFlags(opener_flags);
599 new_root->CommitPendingSandboxFlags();
600 }
601 }
602
alexmose201c7cd2015-06-10 17:14:21603 // This may be true even when opener is null, such as when opening blocked
604 // popups.
alexmos090fae8e2015-05-28 17:09:28605 if (params.created_with_opener)
606 new_contents->created_with_opener_ = true;
607
[email protected]4858e432014-06-23 18:14:17608 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06609 // This makes |new_contents| act as a guest.
610 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16611 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06612 // We are instantiating a WebContents for browser plugin. Set its subframe
613 // bit to true.
614 new_contents->is_subframe_ = true;
615 }
[email protected]54944cde2012-12-09 09:24:59616 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19617 return new_contents;
618}
619
[email protected]95640212014-07-26 18:14:30620// static
621std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
622 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08623 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30624 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30625 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30626 RenderViewHost* rvh = RenderViewHost::From(rwh);
627 if (!rvh)
628 continue;
629 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
630 if (!web_contents)
631 continue;
avidf38c952015-10-27 13:45:13632 if (web_contents->GetRenderViewHost() != rvh)
633 continue;
634 // Because a WebContents can only have one current RVH at a time, there will
635 // be no duplicate WebContents here.
636 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30637 }
638 return result;
639}
640
clamya16aa8172015-05-26 13:07:25641// static
642WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
643 FrameTreeNode* frame_tree_node) {
644 return static_cast<WebContentsImpl*>(
645 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
646}
647
clamy0d32d6d2015-11-24 11:16:26648// static
649WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
650 int render_frame_host_id) {
651 DCHECK_CURRENTLY_ON(BrowserThread::UI);
652 RenderFrameHost* render_frame_host =
653 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
654 if (!render_frame_host)
655 return nullptr;
656
657 return WebContents::FromRenderFrameHost(render_frame_host);
658}
659
[email protected]b0936d22013-11-28 06:47:36660RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21661 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28662}
663
[email protected]7bb761892012-07-20 09:32:47664bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
665 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44666 return OnMessageReceived(render_view_host, NULL, message);
667}
668
669bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
670 RenderFrameHost* render_frame_host,
671 const IPC::Message& message) {
672 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56673 if (GetWebUI() &&
674 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17675 return true;
[email protected]d2353452012-01-19 19:53:56676 }
[email protected]f82d57b52011-04-27 19:13:17677
brettw5a1613dc2015-06-02 05:34:43678 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25679 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33680 if (render_frame_host) {
681 while ((observer = it.GetNext()) != NULL)
682 if (observer->OnMessageReceived(message, render_frame_host))
683 return true;
684 } else {
685 while ((observer = it.GetNext()) != NULL)
686 if (observer->OnMessageReceived(message))
687 return true;
688 }
[email protected]403415a2011-01-10 18:57:53689
[email protected]1d62cf72014-02-07 21:31:57690 // Message handlers should be aware of which
691 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
692 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02693 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57694 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02695 else
[email protected]1d62cf72014-02-07 21:31:57696 render_view_message_source_ = render_view_host;
697
[email protected]724159a2010-12-30 01:11:18698 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33699 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40700 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
701 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05702 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
703 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48704 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
705 OnDocumentLoadedInFrame)
706 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
707 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
708 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
709 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
710 OnSetSelectedColorInColorChooser)
dglazkov79c426102015-08-31 21:22:43711 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11712 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25713 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18714 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54715 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18716 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54717 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18718 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41719 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
720 OnDidDisplayContentWithCertificateErrors)
721 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
722 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25723 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26724 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46725 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
726 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21727 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48728 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
729 OnRegisterProtocolHandler)
730 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
731 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01732 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
733 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52734 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10735 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50736 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50737#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00738 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
739 OnPepperInstanceCreated)
740 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
741 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42742 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:17743 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
744 OnPepperStartsPlayback)
745 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
746 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:42747 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50748 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
749 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55750 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40751 OnBrowserPluginMessage(render_frame_host,
752 message))
thestigc4cac8f2014-09-04 21:17:50753#endif
[email protected]41225fe2013-03-29 05:32:02754 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07755 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
756 OnShowValidationMessage)
757 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
758 OnHideValidationMessage)
759 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
760 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15761#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52762 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48763 OnFindMatchRectsReply)
paulmeyerc8cb7cb2016-06-07 01:14:19764 IPC_MESSAGE_HANDLER(FrameHostMsg_GetNearestFindResult_Reply,
765 OnGetNearestFindResultReply)
[email protected]8ed16472014-04-11 19:02:48766 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
767 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48768#endif
[email protected]724159a2010-12-30 01:11:18769 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33770 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44771 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57772 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18773
[email protected]724159a2010-12-30 01:11:18774 return handled;
775}
776
nasko907fcb62015-01-28 04:24:11777bool WebContentsImpl::HasValidFrameSource() {
778 if (!render_frame_message_source_) {
779 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18780 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
781 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11782 return false;
783 }
784
785 return true;
786}
787
[email protected]d1198fd2012-08-13 22:50:19788NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56789 return controller_;
790}
791
[email protected]d1198fd2012-08-13 22:50:19792const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56793 return controller_;
794}
795
[email protected]8ff00d72012-10-23 19:12:21796BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55797 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30798}
799
[email protected]b172aee2012-04-10 17:05:26800const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24801 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32802 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51803 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31804}
805
[email protected]a093ce02013-07-22 20:53:14806const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24807 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32808 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24809 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
810}
811
812const GURL& WebContentsImpl::GetLastCommittedURL() const {
813 // We may not have a navigation entry yet.
814 NavigationEntry* entry = controller_.GetLastCommittedEntry();
815 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
816}
817
[email protected]8ff00d72012-10-23 19:12:21818WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31819 return delegate_;
820}
821
[email protected]8ff00d72012-10-23 19:12:21822void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31823 // TODO(cbentzel): remove this debugging code?
824 if (delegate == delegate_)
825 return;
826 if (delegate_)
827 delegate_->Detach(this);
828 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08829 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31830 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08831 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00832 if (view_)
[email protected]e85165c642014-06-10 14:34:31833 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08834 }
[email protected]be1f56ab2011-12-22 06:55:31835}
836
[email protected]8ff00d72012-10-23 19:12:21837RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21838 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41839 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16840}
841
clamydf1975e2015-02-05 19:12:24842RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41843 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16844}
845
nick53d5cbf2015-04-23 22:50:14846RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
847 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
848 if (!focused_node)
849 return nullptr;
850 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07851}
852
rob3e2a0732016-01-06 21:22:09853RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
854 int frame_tree_node_id) {
855 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
856 return frame ? frame->current_frame_host() : nullptr;
857}
858
[email protected]a86c0e962013-12-17 17:10:39859void WebContentsImpl::ForEachFrame(
860 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38861 for (FrameTreeNode* node : frame_tree_.Nodes()) {
862 on_frame.Run(node->current_frame_host());
863 }
[email protected]a86c0e962013-12-17 17:10:39864}
865
dchengafb53e22016-02-04 08:11:08866std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
867 std::vector<RenderFrameHost*> frame_hosts;
868 for (FrameTreeNode* node : frame_tree_.Nodes())
869 frame_hosts.push_back(node->current_frame_host());
870 return frame_hosts;
871}
872
lukaszacbdf52e2016-01-15 21:19:51873int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
874 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08875 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25876 if (!rfh->IsRenderFrameLive())
877 continue;
878
dchengafb53e22016-02-04 08:11:08879 ++number_of_messages;
880 IPC::Message* message_copy = new IPC::Message(*message);
881 message_copy->set_routing_id(rfh->GetRoutingID());
882 rfh->Send(message_copy);
883 }
[email protected]a86c0e962013-12-17 17:10:39884 delete message;
lukaszacbdf52e2016-01-15 21:19:51885 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39886}
887
lfgdb5c4ed2016-03-04 23:09:07888void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:41889 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:07890}
891
creisc014b402015-04-23 16:41:45892RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21893 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31894}
895
[email protected]6b618e62012-08-16 12:59:18896int WebContentsImpl::GetRoutingID() const {
897 if (!GetRenderViewHost())
898 return MSG_ROUTING_NONE;
899
900 return GetRenderViewHost()->GetRoutingID();
901}
902
creis89a0f782015-05-27 16:13:17903void WebContentsImpl::CancelActiveAndPendingDialogs() {
avi5d3b8692016-10-12 22:00:46904 if (dialog_manager_) {
905 dialog_manager_->CancelDialogs(this,
906 false, // suppress_callbacks,
907 false); // reset_state
908 }
creis89a0f782015-05-27 16:13:17909 if (browser_plugin_embedder_)
910 browser_plugin_embedder_->CancelGuestDialogs();
911}
912
naskoc0fceff2015-04-30 15:53:52913void WebContentsImpl::ClosePage() {
914 GetRenderViewHost()->ClosePage();
915}
916
[email protected]b172aee2012-04-10 17:05:26917RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21918 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31919}
920
lfg265a2672016-04-23 03:11:02921RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
922 if (GetOuterWebContents())
923 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
924 return GetRenderManager()->GetRenderWidgetHostView();
925}
926
[email protected]4aebbca2013-09-17 22:26:49927RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
928 const {
929 RenderWidgetHost* const widget_host =
alexmosc9e76ec2016-05-16 22:59:37930 RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
931 fullscreen_widget_routing_id_);
[email protected]4aebbca2013-09-17 22:26:49932 return widget_host ? widget_host->GetView() : NULL;
933}
934
[email protected]8ff00d72012-10-23 19:12:21935WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31936 return view_.get();
937}
938
yusufod41c5f92015-03-06 00:14:28939SkColor WebContentsImpl::GetThemeColor() const {
940 return theme_color_;
941}
942
[email protected]95640212014-07-26 18:14:30943void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
944 if (mode == accessibility_mode_)
945 return;
946
947 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38948
949 for (FrameTreeNode* node : frame_tree_.Nodes()) {
950 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
951 RenderFrameHost* pending_frame_host =
952 node->render_manager()->pending_frame_host();
953 if (pending_frame_host)
954 SetAccessibilityModeOnFrame(mode, pending_frame_host);
955 }
[email protected]95640212014-07-26 18:14:30956}
957
958void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50959 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30960}
961
962void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50963 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30964}
965
dmazzoni83ba5c82015-04-14 07:11:51966void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
dmazzonid95ae842016-04-12 21:17:39967 // Send a request to each of the frames in parallel. Each one will return
968 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
969 // them into a single tree and call |callback| with that result, then
970 // delete |combiner|.
971 AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback);
972 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
973 bool is_root = frame_tree_node->parent() == nullptr;
974 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
975 combiner->AddFrame(is_root));
976 }
dmazzoni83ba5c82015-04-14 07:11:51977}
978
wjmaclean64951902016-04-29 20:59:12979void WebContentsImpl::SetTemporaryZoomLevel(double level,
980 bool temporary_zoom_enabled) {
981 SendPageMessage(new PageMsg_SetZoomLevel(
982 MSG_ROUTING_NONE,
983 temporary_zoom_enabled ? PageMsg_SetZoomLevel_Command::SET_TEMPORARY
984 : PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY,
985 level));
986}
987
988void WebContentsImpl::UpdateZoom(double level) {
989 // Individual frames may still ignore the new zoom level if their RenderView
990 // contains a plugin document or if it uses a temporary zoom level.
991 SendPageMessage(new PageMsg_SetZoomLevel(
992 MSG_ROUTING_NONE,
993 PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level));
994}
995
996void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
997 const std::string& host,
998 double level) {
999 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1000 if (!entry)
1001 return;
1002
1003 GURL url = HostZoomMap::GetURLFromEntry(entry);
1004 if (host != net::GetHostOrSpecFromURL(url) ||
1005 (!scheme.empty() && !url.SchemeIs(scheme))) {
1006 return;
1007 }
1008
1009 UpdateZoom(level);
1010}
1011
rockotf62002a2016-09-15 00:08:591012base::Closure WebContentsImpl::AddBindingSet(
1013 const std::string& interface_name,
1014 WebContentsBindingSet* binding_set) {
1015 auto result =
1016 binding_sets_.insert(std::make_pair(interface_name, binding_set));
1017 DCHECK(result.second);
1018 return base::Bind(&WebContentsImpl::RemoveBindingSet,
1019 weak_factory_.GetWeakPtr(), interface_name);
1020}
1021
wjmaclean8a795f32016-08-11 23:49:581022void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) {
1023 SendPageMessage(
1024 new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor));
1025}
1026
ccameron2f451532016-09-07 21:49:271027void WebContentsImpl::GetScreenInfo(ScreenInfo* screen_info) {
wjmaclean8a795f32016-08-11 23:49:581028 if (GetView())
ccameron2f451532016-09-07 21:49:271029 GetView()->GetScreenInfo(screen_info);
wjmaclean8a795f32016-08-11 23:49:581030}
1031
dbeama1b926a2015-08-31 23:17:511032WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
1033 const std::string& frame_name) {
1034 DCHECK(!frame_name.empty());
1035 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:221036}
1037
[email protected]8ff00d72012-10-23 19:12:211038WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:401039 WebUI* commited_web_ui = GetCommittedWebUI();
1040 return commited_web_ui ? commited_web_ui
1041 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:311042}
1043
[email protected]8ff00d72012-10-23 19:12:211044WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:401045 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341046}
1047
[email protected]86ef6a392012-05-11 22:03:111048void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:221049 if (GetUserAgentOverride() == override)
1050 return;
1051
1052 renderer_preferences_.user_agent_override = override;
1053
1054 // Send the new override string to the renderer.
1055 RenderViewHost* host = GetRenderViewHost();
1056 if (host)
1057 host->SyncRendererPrefs();
1058
1059 // Reload the page if a load is currently in progress to avoid having
1060 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271061 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:251062 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim7dad4b1182016-04-01 14:28:051063 controller_.ReloadBypassingCache(true);
[email protected]8d0f3312012-08-18 01:47:531064
1065 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1066 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:111067}
1068
1069const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:221070 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111071}
1072
[email protected]95640212014-07-26 18:14:301073void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:081074 if (GetAccessibilityMode() != AccessibilityModeOff) {
1075 for (RenderFrameHost* rfh : GetAllFrames())
1076 ResetAccessibility(rfh);
1077 } else {
dtseng0dd3fa12015-07-22 19:00:521078 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:081079 }
[email protected]95640212014-07-26 18:14:301080}
1081
1082bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
1083 return accessibility_mode_ == AccessibilityModeTreeOnly;
1084}
1085
1086bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
1087 return accessibility_mode_ == AccessibilityModeComplete;
1088}
1089
kouhei40f03cb2015-09-24 07:47:011090const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
1091 return page_importance_signals_;
1092}
1093
[email protected]fcf75d42013-12-03 20:11:261094const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:551095 // Transient entries take precedence. They are used for interstitial pages
1096 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231097 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231098 if (entry) {
jshin1fb76462016-04-05 22:13:031099 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231100 }
carlosk35f35af2015-12-01 10:55:401101
1102 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
1103 WebUI* our_web_ui = navigating_web_ui
1104 ? navigating_web_ui
1105 : GetRenderManager()->current_frame_host()->web_ui();
1106
[email protected]7ade2732011-02-10 00:13:581107 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541108 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321109 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541110 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351111 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261112 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541113 if (!title.empty())
1114 return title;
1115 }
1116 }
1117
1118 // We use the title for the last committed entry rather than a pending
1119 // navigation entry. For example, when the user types in a URL, we want to
1120 // keep the old page's title until the new load has committed and we get a new
1121 // title.
[email protected]96d185d2009-04-24 03:28:541122 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321123
creis072b61f2015-09-28 20:52:241124 // We make an exception for initial navigations. We only want to use the title
1125 // from the visible entry if:
1126 // 1. The pending entry has been explicitly assigned a title to display.
1127 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1128 // which case there is a pending entry index other than -1.
1129 //
1130 // Otherwise, we want to stick with the last committed entry's title during
1131 // new navigations, which have pending entries at index -1 with no title.
1132 if (controller_.IsInitialNavigation() &&
1133 ((controller_.GetVisibleEntry() &&
1134 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1135 controller_.GetPendingEntryIndex() != -1)) {
1136 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471137 }
[email protected]59167c22013-06-03 18:07:321138
[email protected]45d0ef7f2011-01-05 13:46:231139 if (entry) {
jshin1fb76462016-04-05 22:13:031140 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231141 }
[email protected]987fc3a2011-05-26 14:18:091142
1143 // |page_title_when_no_navigation_entry_| is finally used
1144 // if no title cannot be retrieved.
1145 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541146}
1147
avib7348942015-12-25 20:57:101148int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:461149 return GetMaxPageIDForSiteInstance(GetSiteInstance());
1150}
1151
avib7348942015-12-25 20:57:101152int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:261153 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:331154 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
1155 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:461156
[email protected]b6583592012-01-25 19:52:331157 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:341158}
1159
avib7348942015-12-25 20:57:101160void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461161 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
1162}
1163
[email protected]b172aee2012-04-10 17:05:261164void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:101165 SiteInstance* site_instance,
1166 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461167 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331168 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341169}
1170
[email protected]ec6c05f2013-10-23 18:41:571171void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1172 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1173 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571174}
1175
creiscce56cd2014-09-29 22:45:221176SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211177 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541178}
1179
creiscce56cd2014-09-29 22:45:221180SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1181 RenderViewHostImpl* dest_rvh =
1182 GetRenderManager()->pending_render_view_host() ?
1183 GetRenderManager()->pending_render_view_host() :
1184 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581185 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381186}
1187
[email protected]b172aee2012-04-10 17:05:261188bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251189 return frame_tree_.IsLoading() &&
1190 !(ShowingInterstitialPage() &&
1191 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491192}
1193
[email protected]6dfed692014-05-22 04:18:031194bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251195 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031196}
1197
[email protected]b172aee2012-04-10 17:05:261198bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031199 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311200}
1201
[email protected]b172aee2012-04-10 17:05:261202const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311203 return load_state_;
1204}
1205
[email protected]fcf75d42013-12-03 20:11:261206const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311207 return load_state_host_;
1208}
1209
avib7348942015-12-25 20:57:101210uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311211 return upload_size_;
1212}
1213
avib7348942015-12-25 20:57:101214uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311215 return upload_position_;
1216}
1217
[email protected]b172aee2012-04-10 17:05:261218const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541219 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311220}
1221
[email protected]222f5822014-02-05 23:40:491222void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251223 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551224 ++capturer_count_;
1225 DVLOG(1) << "There are now " << capturer_count_
1226 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491227
1228 // Note: This provides a hint to upstream code to size the views optimally
1229 // for quality (e.g., to avoid scaling).
1230 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1231 preferred_size_for_capture_ = capture_size;
1232 OnPreferredSizeChanged(preferred_size_);
1233 }
ccameron8807c38f2015-01-17 00:29:191234
1235 // Ensure that all views are un-occluded before capture begins.
1236 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551237}
1238
1239void WebContentsImpl::DecrementCapturerCount() {
1240 --capturer_count_;
1241 DVLOG(1) << "There are now " << capturer_count_
1242 << " capturing(s) of WebContentsImpl@" << this;
1243 DCHECK_LE(0, capturer_count_);
1244
[email protected]5a652232013-02-12 06:15:251245 if (is_being_destroyed_)
1246 return;
1247
[email protected]222f5822014-02-05 23:40:491248 if (capturer_count_ == 0) {
1249 const gfx::Size old_size = preferred_size_for_capture_;
1250 preferred_size_for_capture_ = gfx::Size();
1251 OnPreferredSizeChanged(old_size);
1252 }
1253
[email protected]1ac10dca2013-08-20 20:47:041254 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551255 DVLOG(1) << "Executing delayed WasHidden().";
1256 WasHidden();
1257 }
[email protected]be1f56ab2011-12-22 06:55:311258}
1259
[email protected]f2bd40812013-07-20 04:30:441260int WebContentsImpl::GetCapturerCount() const {
1261 return capturer_count_;
1262}
1263
miu50f97892014-09-22 22:49:521264bool WebContentsImpl::IsAudioMuted() const {
1265 return audio_muter_.get() && audio_muter_->is_muting();
1266}
1267
1268void WebContentsImpl::SetAudioMuted(bool mute) {
1269 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1270 << " for WebContentsImpl@" << this;
1271
1272 if (mute == IsAudioMuted())
1273 return;
1274
1275 if (mute) {
1276 if (!audio_muter_)
1277 audio_muter_.reset(new WebContentsAudioMuter(this));
1278 audio_muter_->StartMuting();
1279 } else {
1280 DCHECK(audio_muter_);
1281 audio_muter_->StopMuting();
1282 }
1283
wjmaclean2f797c782016-01-07 14:52:031284 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1285 DidUpdateAudioMutingState(mute));
1286
erikchenab94f972016-10-11 01:34:581287 // Notification for UI updates in response to the changed muting state.
1288 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
miu50f97892014-09-22 22:49:521289}
1290
ortunodf4d7982016-04-08 02:33:351291bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1292 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201293}
1294
[email protected]b172aee2012-04-10 17:05:261295bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311296 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1297 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581298 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271299#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581300 crashed_status_ ==
1301 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271302#endif
wfh0d9532a2015-09-02 23:18:581303 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271304 );
[email protected]3c9e1872010-11-18 16:17:491305}
1306
[email protected]b172aee2012-04-10 17:05:261307void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1308 int error_code) {
[email protected]443b80e2010-12-14 00:42:231309 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341310 return;
1311
[email protected]443b80e2010-12-14 00:42:231312 crashed_status_ = status;
1313 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211314 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341315}
1316
[email protected]b172aee2012-04-10 17:05:261317base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311318 return crashed_status_;
1319}
1320
afakhry98241832016-03-11 19:27:471321int WebContentsImpl::GetCrashedErrorCode() const {
1322 return crashed_error_code_;
1323}
1324
[email protected]b172aee2012-04-10 17:05:261325bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311326 return is_being_destroyed_;
1327}
1328
[email protected]7f924832014-08-09 05:57:221329void WebContentsImpl::NotifyNavigationStateChanged(
1330 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541331 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1332 // is fixed.
1333 tracked_objects::ScopedTracker tracking_profile(
1334 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1335 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181336 // Notify the media observer of potential audibility changes.
1337 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271338 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301339 }
1340
[email protected]d5f942ba2008-09-26 19:30:341341 if (delegate_)
1342 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441343
1344 if (GetOuterWebContents())
1345 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341346}
1347
gab0dccfef2015-05-20 18:43:391348base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021349 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331350}
1351
georgesak5582cbe2015-05-22 22:08:071352void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1353 last_active_time_ = last_active_time;
1354}
1355
[email protected]9e2e4632012-07-27 16:38:411356void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541357 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591358
ccameron8807c38f2015-01-17 00:29:191359 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1360 if (view) {
1361 view->Show();
[email protected]789e9152009-08-04 21:59:431362#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191363 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431364#endif
[email protected]de3c5d82014-05-28 22:12:591365 }
[email protected]789e9152009-08-04 21:59:431366 }
[email protected]96d185d2009-04-24 03:28:541367
lfg717154072016-06-30 15:04:161368 SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE));
1369
gab0dccfef2015-05-20 18:43:391370 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381371
[email protected]c0d9d5672013-10-09 07:38:031372 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1373
[email protected]54597982013-02-06 01:59:551374 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311375}
1376
[email protected]b172aee2012-04-10 17:05:261377void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551378 // If there are entities capturing screenshots or video (e.g., mirroring),
1379 // don't activate the "disable rendering" optimization.
1380 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521381 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551382 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261383 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521384 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331385 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521386 // calls us).
ccameron8807c38f2015-01-17 00:29:191387 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1388 if (view)
1389 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591390 }
lfg717154072016-06-30 15:04:161391
1392 SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
[email protected]96d185d2009-04-24 03:28:541393 }
1394
[email protected]c0d9d5672013-10-09 07:38:031395 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1396
[email protected]54597982013-02-06 01:59:551397 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371398}
1399
ccameron8807c38f2015-01-17 00:29:191400void WebContentsImpl::WasOccluded() {
1401 if (capturer_count_ > 0)
1402 return;
1403
1404 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1405 if (view)
1406 view->WasOccluded();
1407 }
1408}
1409
1410void WebContentsImpl::WasUnOccluded() {
1411 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1412 if (view)
1413 view->WasUnOccluded();
1414 }
1415}
1416
[email protected]b172aee2012-04-10 17:05:261417bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311418 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451419 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1420 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311421}
1422
nasko148bb0b92016-05-10 21:03:191423void WebContentsImpl::DispatchBeforeUnload() {
1424 bool for_cross_site_transition = false;
clamybfd6a812016-05-30 16:25:171425 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false);
[email protected]1c3f80bd2014-04-08 23:02:061426}
1427
lazyboy6ec48b2a2015-06-29 15:18:141428void WebContentsImpl::AttachToOuterWebContentsFrame(
1429 WebContents* outer_web_contents,
1430 RenderFrameHost* outer_contents_frame) {
ekaramad1beabecc2016-09-23 20:18:171431 CHECK(GuestMode::IsCrossProcessFrameGuest(this));
lfg91a79e12016-04-01 23:52:191432 RenderFrameHostManager* render_manager = GetRenderManager();
1433
1434 // When the WebContents being initialized has an opener, the browser side
1435 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1436 // created. This is needed because the usual initialization happens during
1437 // the first navigation, but when attaching a new window we don't navigate
1438 // before attaching. If the browser side is already initialized, the calls
1439 // below will just early return.
1440 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1441 GetMainFrame()->Init();
1442 if (!render_manager->GetRenderWidgetHostView())
1443 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1444
lazyboy6ec48b2a2015-06-29 15:18:141445 // Create a link to our outer WebContents.
1446 node_.reset(new WebContentsTreeNode());
1447 node_->ConnectToOuterWebContents(
1448 static_cast<WebContentsImpl*>(outer_web_contents),
1449 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1450
1451 DCHECK(outer_contents_frame);
1452
1453 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1454 // SiteInstance of the outer WebContents. The proxy will be used to send
1455 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191456 render_manager->CreateOuterDelegateProxy(
lazyboy6ec48b2a2015-06-29 15:18:141457 outer_contents_frame->GetSiteInstance(),
1458 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1459
lfg91a79e12016-04-01 23:52:191460 render_manager->SetRWHViewForInnerContents(
1461 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391462
1463 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191464 render_manager->GetRenderWidgetHostView())
fsamuelb6acafa2016-10-04 03:21:521465 ->RegisterFrameSinkId();
ekaramadadd882292016-06-08 15:22:561466
1467 // At this point, we should destroy the TextInputManager which will notify all
1468 // the RWHV in this WebContents. The RWHV in this WebContents should use the
1469 // TextInputManager owned by the outer WebContents.
1470 // TODO(ekaramad): Is it possible to have TextInputState before attaching to
1471 // outer WebContents? In such a case, is this still the right way to hand off
1472 // state tracking from inner WebContents's TextInputManager to that of the
1473 // outer WebContent (crbug.com/609846)?
1474 text_input_manager_.reset(nullptr);
lazyboy6ec48b2a2015-06-29 15:18:141475}
1476
[email protected]b172aee2012-04-10 17:05:261477void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381478 for (FrameTreeNode* node : frame_tree_.Nodes())
1479 node->StopLoading();
[email protected]d16609c2013-08-23 06:01:401480 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271481}
1482
[email protected]b172aee2012-04-10 17:05:261483WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441484 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211485 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451486 // before.
[email protected]54944cde2012-12-09 09:24:591487 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451488 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211489 WebContentsImpl* tc =
1490 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191491 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221492 FOR_EACH_OBSERVER(WebContentsObserver,
1493 observers_,
1494 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271495 return tc;
1496}
1497
[email protected]14392a52012-05-02 20:28:441498void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211499 const NotificationSource& source,
1500 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441501 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211502 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1503 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031504 RenderWidgetHostView* view = host->GetView();
1505 if (view == GetFullscreenRenderWidgetHostView()) {
1506 // We cannot just call view_->RestoreFocus() here. On some platforms,
1507 // attempting to focus the currently-invisible WebContentsView will be
1508 // flat-out ignored. Therefore, this boolean is used to track whether
1509 // we will request focus after the fullscreen widget has been
1510 // destroyed.
1511 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1512 } else {
alexmosc2a8cec2016-05-23 22:19:531513 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:031514 i != pending_widget_views_.end(); ++i) {
1515 if (host->GetView() == i->second) {
1516 pending_widget_views_.erase(i);
1517 break;
1518 }
[email protected]bafe6cd2012-05-23 23:09:501519 }
1520 }
1521 break;
1522 }
[email protected]14392a52012-05-02 20:28:441523 default:
1524 NOTREACHED();
1525 }
1526}
1527
[email protected]ec6c05f2013-10-23 18:41:571528WebContents* WebContentsImpl::GetWebContents() {
1529 return this;
1530}
1531
[email protected]54944cde2012-12-09 09:24:591532void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211533 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361534 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211535 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431536 should_normally_be_visible_ = !params.initially_hidden;
1537
dcheng3ce04b62015-10-26 23:30:551538 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541539 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551540 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1541 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541542 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551543 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1544 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1545
1546 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1547 if (!site_instance)
1548 site_instance = SiteInstance::Create(params.browser_context);
1549
1550 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1551 // local root by definition.
1552 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1553 // longer be necessary to eagerly grab a routing ID for the view.
1554 // https://crbug.com/545684
1555 int32_t view_routing_id = params.routing_id;
1556 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1557 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1558 view_routing_id = main_frame_widget_routing_id =
1559 site_instance->GetProcess()->GetNextRoutingID();
1560 }
1561
1562 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1563 params.main_frame_routing_id,
1564 main_frame_widget_routing_id);
lukasza464d8692016-02-22 19:26:321565
lukasza5140a412016-09-15 21:12:301566 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
1567 // main frame - let's do the same thing here.
1568 std::string unique_name;
lukasza464d8692016-02-22 19:26:321569 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191570
[email protected]fc2b46b2014-05-03 16:33:451571 WebContentsViewDelegate* delegate =
1572 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1573
sadrul943e3b32016-08-04 18:22:591574#if defined(USE_AURA)
bend32292b2016-10-07 00:21:581575 if (ServiceManagerConnection::GetForProcess() &&
fsamueladb0033602015-12-09 19:20:411576 base::CommandLine::ForCurrentProcess()->HasSwitch(
1577 switches::kUseMusInRenderer)) {
ben3a06a272016-07-04 05:00:101578 ui::Window* mus_window = aura::GetMusWindow(params.context);
fsamueladb0033602015-12-09 19:20:411579 if (mus_window) {
1580 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1581 &render_view_host_delegate_view_));
1582 }
1583 }
1584#endif
1585
1586 if (!view_) {
ekaramad1beabecc2016-09-23 20:18:171587 if (GuestMode::IsCrossProcessFrameGuest(this)) {
lfgc740d4b22016-04-15 16:45:331588 view_.reset(new WebContentsViewChildFrame(
1589 this, delegate, &render_view_host_delegate_view_));
1590 } else {
1591 view_.reset(CreateWebContentsView(this, delegate,
1592 &render_view_host_delegate_view_));
1593 }
fsamueladb0033602015-12-09 19:20:411594 }
fsamuel9cf7bdf2015-11-20 02:19:321595
ekaramad1beabecc2016-09-23 20:18:171596 if (browser_plugin_guest_ && !GuestMode::IsCrossProcessFrameGuest(this)) {
fsamuel9cf7bdf2015-11-20 02:19:321597 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361598 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321599 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191600 }
[email protected]fc2b46b2014-05-03 16:33:451601 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191602 CHECK(view_.get());
1603
[email protected]ed245db2012-12-18 08:00:451604 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591605 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191606
tommyclieb25b2a2014-11-03 19:45:091607#if defined(ENABLE_PLUGINS)
1608 plugin_content_origin_whitelist_.reset(
1609 new PluginContentOriginWhitelist(this));
1610#endif
1611
[email protected]d1198fd2012-08-13 22:50:191612 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211613 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1614 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101615
[email protected]01f83f92014-06-17 14:41:541616 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091617 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541618
mlamouriefdca9d2014-09-16 16:55:401619 manifest_manager_host_.reset(new ManifestManagerHost(this));
1620
mfomitchev2b8b066a2016-01-28 19:23:151621#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101622 date_time_chooser_.reset(new DateTimeChooserAndroid());
1623#endif
fsamuel7310a4262014-12-05 05:06:441624
1625 // BrowserPluginGuest::Init needs to be called after this WebContents has
1626 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1627 if (browser_plugin_guest_)
1628 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371629
1630 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1631 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561632
1633 // If the WebContents creation was renderer-initiated, it means that the
1634 // corresponding RenderView and main RenderFrame have already been created.
1635 // Ensure observers are notified about this.
1636 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431637 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561638 RenderViewCreated(GetRenderViewHost());
1639 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1640 }
naskof5940b9f2015-03-02 23:04:051641
lof84501da082016-05-23 21:22:541642 // Create the renderer process in advance if requested.
1643 if (params.initialize_renderer) {
1644 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
1645 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
1646 }
1647 }
1648
naskof5940b9f2015-03-02 23:04:051649 // Ensure that observers are notified of the creation of this WebContents's
1650 // main RenderFrameHost. It must be done here for main frames, since the
1651 // NotifySwappedFromRenderManager expects view_ to already be created and that
1652 // happens after RenderFrameHostManager::Init.
1653 NotifySwappedFromRenderManager(
1654 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191655}
1656
[email protected]7fff43e2013-05-21 20:21:101657void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1658 RemoveDestructionObserver(web_contents);
1659
[email protected]ceee8cd2013-03-08 04:59:511660 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:531661 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:511662 ++iter) {
1663 if (iter->second != web_contents)
1664 continue;
1665 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511666 return;
1667 }
1668 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441669}
1670
[email protected]7fff43e2013-05-21 20:21:101671void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1672 if (!ContainsKey(destruction_observers_, web_contents)) {
1673 destruction_observers_[web_contents] =
avia8cf81982016-08-12 20:28:461674 base::MakeUnique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:101675 }
1676}
1677
1678void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:461679 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:101680}
1681
[email protected]b172aee2012-04-10 17:05:261682void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311683 observers_.AddObserver(observer);
1684}
1685
[email protected]b172aee2012-04-10 17:05:261686void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311687 observers_.RemoveObserver(observer);
1688}
1689
[email protected]948481d2014-06-11 18:32:221690std::set<RenderWidgetHostView*>
1691WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1692 std::set<RenderWidgetHostView*> set;
1693 if (ShowingInterstitialPage()) {
1694 set.insert(GetRenderWidgetHostView());
1695 } else {
dchengafb53e22016-02-04 08:11:081696 for (RenderFrameHost* rfh : GetAllFrames()) {
1697 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1698 ->frame_tree_node()
1699 ->render_manager()
1700 ->GetRenderWidgetHostView();
1701 set.insert(rwhv);
1702 }
[email protected]948481d2014-06-11 18:32:221703 }
[email protected]de3c5d82014-05-28 22:12:591704 return set;
1705}
1706
[email protected]b172aee2012-04-10 17:05:261707void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341708 if (delegate_)
1709 delegate_->ActivateContents(this);
1710}
1711
avi3e4b8512015-11-11 01:55:491712void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1713 if (!RenderViewHostImpl::From(render_widget_host))
1714 return;
1715
[email protected]63954792011-07-11 04:17:481716 if (delegate_)
1717 delegate_->LostCapture();
1718}
1719
lazyboy63f5b312015-11-23 20:19:521720void WebContentsImpl::RenderWidgetCreated(
1721 RenderWidgetHostImpl* render_widget_host) {
1722 created_widgets_.insert(render_widget_host);
1723}
1724
[email protected]b24b68a2012-09-24 21:57:261725void WebContentsImpl::RenderWidgetDeleted(
1726 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521727 // Note that |is_being_destroyed_| can be true at this point as
1728 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1729 // us here.
1730 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261731
lazyboy63f5b312015-11-23 20:19:521732 if (is_being_destroyed_)
1733 return;
[email protected]44470a22013-01-24 01:21:541734
1735 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:371736 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
1737 render_widget_host->GetProcess()->GetID() ==
1738 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:491739 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531740 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541741 FOR_EACH_OBSERVER(WebContentsObserver,
1742 observers_,
alexmos899e06f2016-05-13 23:08:091743 DidDestroyFullscreenWidget());
alexmosc9e76ec2016-05-16 22:59:371744 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:541745 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031746 if (fullscreen_widget_had_focus_at_shutdown_)
1747 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541748 }
lfgbee1e0a2016-06-08 21:24:211749
lfgad8244352016-07-13 16:55:511750 CHECK(mouse_lock_widget_ != render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261751}
1752
miu9e14e492014-10-25 02:39:041753void WebContentsImpl::RenderWidgetGotFocus(
1754 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371755 // Notify the observers if an embedded fullscreen widget was focused.
1756 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1757 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1758 NotifyWebContentsFocused();
1759 }
miu9e14e492014-10-25 02:39:041760}
1761
estaded0a0c992015-01-21 14:12:061762void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311763 RenderWidgetHostImpl* render_widget_host,
1764 bool width_changed) {
creisc014b402015-04-23 16:41:451765 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291766 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061767 return;
estaded0a0c992015-01-21 14:12:061768
rouslan2f5993f2015-01-29 00:18:311769 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1770 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061771}
1772
paulmeyer9ef6e4462015-02-24 19:15:101773void WebContentsImpl::ScreenInfoChanged() {
1774 if (browser_plugin_embedder_)
1775 browser_plugin_embedder_->ScreenInfoChanged();
1776}
1777
[email protected]b172aee2012-04-10 17:05:261778bool WebContentsImpl::PreHandleKeyboardEvent(
1779 const NativeWebKeyboardEvent& event,
1780 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481781 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131782 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481783}
1784
[email protected]b172aee2012-04-10 17:05:261785void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101786 if (browser_plugin_embedder_ &&
1787 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1788 return;
1789 }
[email protected]63954792011-07-11 04:17:481790 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131791 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481792}
1793
[email protected]d92026ef2014-03-03 21:04:131794bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461795 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191796#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331797 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1798 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191799 // -the OS already has a gesture to do this through pinch-zoom
1800 // -if a user starts an inertial scroll, let's go, and presses control
1801 // (i.e. control+tab) then the OS's buffered scroll events will come in
1802 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331803 if (delegate_ && event.wheelTicksY &&
chongz4a9751942016-08-17 17:49:391804 !ui::WebInputEventTraits::CanCauseScroll(event)) {
w.shackleton49bcd392016-01-06 17:38:221805 // Count only integer cumulative scrolls as zoom events; this handles
1806 // smooth scroll and regular scroll device behavior.
1807 zoom_scroll_remainder_ += event.wheelTicksY;
1808 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1809 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1810 if (whole_zoom_scroll_remainder_ != 0) {
1811 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1812 }
[email protected]fb3f066e2013-02-12 19:12:521813 return true;
1814 }
[email protected]bccc4472013-04-18 16:37:191815#endif
[email protected]fb3f066e2013-02-12 19:12:521816 return false;
1817}
1818
[email protected]04bce562014-01-30 05:34:541819bool WebContentsImpl::PreHandleGestureEvent(
1820 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031821 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541822}
1823
kenrb2a565f82015-09-02 20:24:591824RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451825 if (!is_being_destroyed_ && GetOuterWebContents())
1826 return GetOuterWebContents()->GetInputEventRouter();
1827
1828 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591829 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1830 return rwh_input_event_router_.get();
1831}
1832
alexmos3fcd0ca2015-10-23 18:18:331833void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1834 // Focus loss may occur while this WebContents is being destroyed. Don't
1835 // send the message in this case, as the main frame's RenderFrameHost and
1836 // other state has already been cleared.
1837 if (is_being_destroyed_)
1838 return;
1839
1840 frame_tree_.ReplicatePageFocus(is_focused);
1841}
1842
alexmosc4cbacb2015-11-21 01:29:221843RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1844 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521845 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221846 return receiving_widget;
1847
1848 // Events for widgets other than the main frame (e.g., popup menus) should be
1849 // forwarded directly to the widget they arrived on.
1850 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1851 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521852
avallee0206f782016-07-28 18:55:331853 FrameTreeNode* focused_frame =
1854 GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
alexmosc4d183e2015-11-06 00:46:521855 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221856 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521857
alexmos732ca3a2015-12-08 02:01:021858 // The view may be null if a subframe's renderer process has crashed while
1859 // the subframe has focus. Drop the event in that case. Do not give
1860 // it to the main frame, so that the user doesn't unexpectedly type into the
1861 // wrong frame if a focused subframe renderer crashes while they type.
1862 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1863 if (!view)
1864 return nullptr;
1865
1866 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521867}
1868
mlamouri7a78d6fd2015-01-17 13:23:531869void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1870 // This method is being called to enter renderer-initiated fullscreen mode.
1871 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491872 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371873 if (widget_view) {
1874 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1875 ->ShutdownAndDestroyWidget(true);
1876 }
[email protected]4aebbca2013-09-17 22:26:491877
[email protected]8a5e0ca2011-08-25 06:30:471878 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531879 delegate_->EnterFullscreenModeForTab(this, origin);
1880
alexmos5dd617d2016-06-07 04:21:151881 FOR_EACH_OBSERVER(
1882 WebContentsObserver, observers_,
1883 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false));
mlamouri7a78d6fd2015-01-17 13:23:531884}
1885
bokanece34a82016-01-28 19:49:461886void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531887 // This method is being called to leave renderer-initiated fullscreen mode.
1888 // Make sure any existing fullscreen widget is shut down first.
1889 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371890 if (widget_view) {
1891 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1892 ->ShutdownAndDestroyWidget(true);
1893 }
mlamouri7a78d6fd2015-01-17 13:23:531894
hugo.holgersson61288e6c2015-01-28 17:04:401895#if defined(OS_ANDROID)
1896 ContentVideoView* video_view = ContentVideoView::GetInstance();
1897 if (video_view != NULL)
watk98292292016-01-19 22:24:081898 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401899#endif
1900
mlamouri7a78d6fd2015-01-17 13:23:531901 if (delegate_)
1902 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371903
bokanece34a82016-01-28 19:49:461904 // The fullscreen state is communicated to the renderer through a resize
1905 // message. If the change in fullscreen state doesn't cause a view resize
1906 // then we must ensure web contents exit the fullscreen state by explicitly
1907 // sending a resize message. This is required for the situation of the browser
1908 // moving the view into a "browser fullscreen" state and then the contents
1909 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1910 // have the side effect of the view resizing, hence the explicit call here is
1911 // required.
1912 if (!will_cause_resize) {
1913 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1914 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1915 render_widget_host->WasResized();
1916 }
scheib3dcb6c932015-02-23 10:55:581917 }
1918
avibf58fa0c2015-11-11 01:45:521919 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
alexmos5dd617d2016-06-07 04:21:151920 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
1921 will_cause_resize));
[email protected]8a5e0ca2011-08-25 06:30:471922}
1923
alexmos5dd617d2016-06-07 04:21:151924bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381925 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121926}
1927
avibf58fa0c2015-11-11 01:45:521928blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1929 RenderWidgetHostImpl* render_widget_host) const {
1930 if (!RenderViewHostImpl::From(render_widget_host))
1931 return blink::WebDisplayModeBrowser;
1932
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121933 return delegate_ ? delegate_->GetDisplayMode(this)
1934 : blink::WebDisplayModeBrowser;
1935}
1936
avic3aa8422015-11-09 20:57:221937void WebContentsImpl::RequestToLockMouse(
1938 RenderWidgetHostImpl* render_widget_host,
1939 bool user_gesture,
lfgad8244352016-07-13 16:55:511940 bool last_unlocked_by_target,
1941 bool privileged) {
lfgbee1e0a2016-06-08 21:24:211942 if (mouse_lock_widget_) {
avic3aa8422015-11-09 20:57:221943 render_widget_host->GotResponseToLockMouseRequest(false);
1944 return;
[email protected]e9621112011-10-17 05:38:371945 }
avic3aa8422015-11-09 20:57:221946
lfgad8244352016-07-13 16:55:511947 if (privileged) {
1948 mouse_lock_widget_ = render_widget_host;
1949 render_widget_host->GotResponseToLockMouseRequest(true);
1950 return;
1951 }
1952
lfgbee1e0a2016-06-08 21:24:211953 bool widget_in_frame_tree = false;
1954 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1955 if (node->current_frame_host()->GetRenderWidgetHost() ==
1956 render_widget_host) {
1957 widget_in_frame_tree = true;
1958 break;
1959 }
1960 }
1961
1962 if (widget_in_frame_tree && delegate_) {
1963 mouse_lock_widget_ = render_widget_host;
avic3aa8422015-11-09 20:57:221964 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:211965 } else {
1966 render_widget_host->GotResponseToLockMouseRequest(false);
1967 }
[email protected]e9621112011-10-17 05:38:371968}
1969
avi3e4b8512015-11-11 01:55:491970void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:211971 CHECK(mouse_lock_widget_);
1972 mouse_lock_widget_->SendMouseLockLost();
1973 mouse_lock_widget_ = nullptr;
avi3e4b8512015-11-11 01:55:491974
[email protected]e9621112011-10-17 05:38:371975 if (delegate_)
1976 delegate_->LostMouseLock();
1977}
1978
lfgad8244352016-07-13 16:55:511979bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
1980 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
1981 // assigned to the widget that requested the mouse lock, and the top-level
1982 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
1983 return mouse_lock_widget_ == render_widget_host &&
1984 GetTopLevelRenderWidgetHostView()->IsMouseLocked();
1985}
1986
dtrainor5ef644e2015-11-19 00:12:471987void WebContentsImpl::ForwardCompositorProto(
1988 RenderWidgetHostImpl* render_widget_host,
1989 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:471990 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:291991 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:471992}
1993
ekaramada4f42692016-02-11 19:48:371994void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
lfg9462cef2016-07-18 23:51:061995 if (visible && !GetOuterWebContents()->IsHidden())
ekaramada4f42692016-02-11 19:48:371996 WasShown();
lfg9462cef2016-07-18 23:51:061997 else if (!visible)
ekaramada4f42692016-02-11 19:48:371998 WasHidden();
1999}
2000
[email protected]bafe6cd2012-05-23 23:09:502001void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:432002 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:552003 int32_t route_id,
2004 int32_t main_frame_route_id,
2005 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:182006 const mojom::CreateNewWindowParams& params,
[email protected]97714c82012-06-06 10:15:132007 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:502008 // We usually create the new window in the same BrowsingInstance (group of
2009 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:552010 // if the opener is being suppressed (in a non-guest), we create a new
2011 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:252012 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:552013
[email protected]04cbd3d2013-12-04 04:58:202014 // If the opener is to be suppressed, the new window can be in any process.
2015 // Since routing ids are process specific, we must not have one passed in
2016 // as argument here.
2017 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
2018
[email protected]bafe6cd2012-05-23 23:09:502019 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:432020 params.opener_suppressed && !is_guest
2021 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
2022 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:502023
alexmos4cf2aa32015-07-15 23:40:432024 // A message to create a new window can only come from a process for a frame
2025 // in this WebContents' FrameTree. If any other process sends the request, it
2026 // is invalid and the process must be terminated.
2027 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:382028 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:432029 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:352030 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:202031 if (process_handle != base::kNullProcessHandle) {
2032 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392033 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:352034 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:202035 }
2036 return;
2037 }
2038
[email protected]d1198fd2012-08-13 22:50:192039 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:342040 //
2041 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:302042 const std::string& partition_id =
2043 GetContentClient()->browser()->
2044 GetStoragePartitionIdForSite(GetBrowserContext(),
2045 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:462046 StoragePartition* partition = BrowserContext::GetStoragePartition(
2047 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:412048 DOMStorageContextWrapper* dom_storage_context =
2049 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:192050 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2051 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2052 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:372053
2054 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:552055 !delegate_->ShouldCreateWebContents(
2056 this, route_id, main_frame_route_id, main_frame_widget_route_id,
2057 params.window_container_type, params.frame_name, params.target_url,
2058 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:012059 if (route_id != MSG_ROUTING_NONE &&
2060 !RenderViewHost::FromID(render_process_id, route_id)) {
2061 // If the embedder didn't create a WebContents for this route, we need to
2062 // delete the RenderView that had already been created.
2063 Send(new ViewMsg_Close(route_id));
2064 }
csharrisona2280cd2016-02-03 23:21:152065 // It's safe to only target the frame because the render process will not
2066 // have a chance to create more frames at this point.
2067 ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
2068 GlobalFrameRoutingId(render_process_id, main_frame_route_id));
[email protected]dd6730412013-08-14 15:03:372069 return;
2070 }
2071
2072 // Create the new web contents. This will automatically create the new
2073 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462074 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:592075 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:042076 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:552077 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:122078 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432079 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:212080 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:062081 create_params.opener_suppressed = params.opener_suppressed;
nick3b04f322016-08-31 19:29:192082 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
[email protected]50d326e2014-05-20 17:59:062083 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:192084 create_params.renderer_initiated_creation =
2085 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:062086
[email protected]4858e432014-06-23 18:14:172087 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:552088 if (!is_guest) {
2089 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:452090 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:172091 new_contents = static_cast<WebContentsImpl*>(
2092 WebContents::Create(create_params));
2093 } else {
2094 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:552095 }
[email protected]50d326e2014-05-20 17:59:062096 new_contents->GetController().SetSessionStorageNamespace(
2097 partition_id,
2098 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192099
alexmos646fec02015-07-25 00:11:492100 // If the new frame has a name, make sure any SiteInstances that can find
2101 // this named frame have proxies for it. Must be called after
2102 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2103 // GetSessionStorageNamespace.
2104 if (!params.frame_name.empty())
2105 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
2106
[email protected]c4538072013-03-18 02:17:552107 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342108 // will be shown immediately).
2109 if (!params.opener_suppressed) {
2110 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:452111 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502112
[email protected]d70bea92013-04-05 04:23:342113 // TODO(brettw): It seems bogus that we have to call this function on the
2114 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:432115 new_view->CreateViewForWidget(
2116 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:342117 }
[email protected]bafe6cd2012-05-23 23:09:502118 // Save the created window associated with the route so we can show it
2119 // later.
2120 DCHECK_NE(MSG_ROUTING_NONE, route_id);
alexmosc2a8cec2016-05-23 22:19:532121 pending_contents_[std::make_pair(render_process_id, route_id)] =
2122 new_contents;
[email protected]7fff43e2013-05-21 20:21:102123 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502124 }
2125
2126 if (delegate_) {
2127 delegate_->WebContentsCreated(
naskoe2df1d72016-10-04 00:20:172128 this, render_process_id, params.opener_render_frame_id,
2129 params.frame_name, params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:502130 }
2131
2132 if (params.opener_suppressed) {
2133 // When the opener is suppressed, the original renderer cannot access the
2134 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002135 bool was_blocked = false;
2136 if (delegate_) {
bokan107a47f2015-02-03 23:23:392137 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:002138 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:392139 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:002140 params.user_gesture, &was_blocked);
2141 }
2142 if (!was_blocked) {
nick3b04f322016-08-31 19:29:192143 OpenURLParams open_params(params.target_url, params.referrer,
2144 WindowOpenDisposition::CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352145 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212146 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:302147 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372148
2149 if (delegate_ && !is_guest &&
2150 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
2151 // We are in asynchronous add new contents path, delay opening url
2152 new_contents->delayed_open_url_params_.reset(
2153 new OpenURLParams(open_params));
2154 } else {
2155 new_contents->OpenURL(open_params);
2156 }
[email protected]eda238a12012-09-07 23:44:002157 }
[email protected]bafe6cd2012-05-23 23:09:502158 }
2159}
2160
avib7348942015-12-25 20:57:102161void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2162 int32_t route_id,
[email protected]180ef242013-11-07 06:50:462163 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:052164 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:502165}
2166
avib7348942015-12-25 20:57:102167void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
2168 int32_t route_id) {
piman5d36dae2015-09-24 22:47:052169 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502170}
2171
avib7348942015-12-25 20:57:102172void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2173 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502174 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:462175 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252176 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232177 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512178 // this WebContentsImpl instance. If any other process sends the request,
2179 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382180 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:252181 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:512182 if (process_handle != base::kNullProcessHandle) {
2183 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392184 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252185 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512186 }
2187 return;
2188 }
2189
[email protected]bafe6cd2012-05-23 23:09:502190 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:052191 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:262192
[email protected]cfd80b02014-05-01 17:46:482193 RenderWidgetHostViewBase* widget_view =
2194 static_cast<RenderWidgetHostViewBase*>(
2195 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192196 if (!widget_view)
2197 return;
[email protected]bafe6cd2012-05-23 23:09:502198 if (!is_fullscreen) {
2199 // Popups should not get activated.
2200 widget_view->SetPopupType(popup_type);
2201 }
2202 // Save the created widget associated with the route so we can show it later.
alexmosc2a8cec2016-05-23 22:19:532203 pending_widget_views_[std::make_pair(render_process_id, route_id)] =
2204 widget_view;
[email protected]bafe6cd2012-05-23 23:09:502205
2206#if defined(OS_MACOSX)
2207 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2208 // to allow it to survive the trip without being hosted.
2209 base::mac::NSObjectRetain(widget_view->GetNativeView());
2210#endif
2211}
2212
alexmosc2a8cec2016-05-23 22:19:532213void WebContentsImpl::ShowCreatedWindow(int process_id,
2214 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502215 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392216 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502217 bool user_gesture) {
alexmosc2a8cec2016-05-23 22:19:532218 WebContentsImpl* contents = GetCreatedWindow(process_id, route_id);
[email protected]eda238a12012-09-07 23:44:002219 if (contents) {
2220 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162221 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382222 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2223 contents->ResumeLoadingCreatedWebContents();
2224
[email protected]eda238a12012-09-07 23:44:002225 if (delegate) {
2226 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392227 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002228 }
2229 }
[email protected]bafe6cd2012-05-23 23:09:502230}
2231
alexmosc2a8cec2016-05-23 22:19:532232void WebContentsImpl::ShowCreatedWidget(int process_id,
2233 int route_id,
bokan107a47f2015-02-03 23:23:392234 const gfx::Rect& initial_rect) {
alexmosc2a8cec2016-05-23 22:19:532235 ShowCreatedWidget(process_id, route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502236}
2237
alexmosc2a8cec2016-05-23 22:19:532238void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
2239 int route_id) {
2240 ShowCreatedWidget(process_id, route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:502241}
2242
alexmosc2a8cec2016-05-23 22:19:532243void WebContentsImpl::ShowCreatedWidget(int process_id,
2244 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502245 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392246 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482247 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:532248 static_cast<RenderWidgetHostViewBase*>(
2249 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502250 if (!widget_host_view)
2251 return;
[email protected]cfd80b02014-05-01 17:46:482252
2253 RenderWidgetHostView* view = NULL;
lfgc740d4b22016-04-15 16:45:332254 if (GetOuterWebContents()) {
2255 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482256 } else {
2257 view = GetRenderWidgetHostView();
2258 }
2259
[email protected]4aebbca2013-09-17 22:26:492260 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312261 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032262 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:372263 fullscreen_widget_process_id_ =
2264 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:312265 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492266 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2267 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532268 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492269 } else {
[email protected]cfd80b02014-05-01 17:46:482270 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492271 }
[email protected]4aebbca2013-09-17 22:26:492272 FOR_EACH_OBSERVER(WebContentsObserver,
2273 observers_,
alexmos899e06f2016-05-13 23:08:092274 DidShowFullscreenWidget());
[email protected]4aebbca2013-09-17 22:26:492275 if (!widget_host_view->HasFocus())
2276 widget_host_view->Focus();
2277 } else {
bokan107a47f2015-02-03 23:23:392278 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492279 }
[email protected]89054502012-06-03 10:29:242280
2281 RenderWidgetHostImpl* render_widget_host_impl =
2282 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2283 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312284 // Only allow privileged mouse lock for fullscreen render widget, which is
2285 // used to implement Pepper Flash fullscreen.
2286 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502287
2288#if defined(OS_MACOSX)
2289 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2290 // properly embedded (or purposefully ignored) we can release the retain we
2291 // took in CreateNewWidget().
2292 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2293#endif
2294}
2295
alexmosc2a8cec2016-05-23 22:19:532296WebContentsImpl* WebContentsImpl::GetCreatedWindow(int process_id,
2297 int route_id) {
2298 auto iter = pending_contents_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502299
2300 // Certain systems can block the creation of new windows. If we didn't succeed
2301 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:532302 if (iter == pending_contents_.end())
2303 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502304
2305 WebContentsImpl* new_contents = iter->second;
alexmosc2a8cec2016-05-23 22:19:532306 pending_contents_.erase(std::make_pair(process_id, route_id));
[email protected]7fff43e2013-05-21 20:21:102307 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502308
[email protected]d70bea92013-04-05 04:23:342309 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252310 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342311 return new_contents;
2312
[email protected]bafe6cd2012-05-23 23:09:502313 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432314 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
alexmosc2a8cec2016-05-23 22:19:532315 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502316
[email protected]bafe6cd2012-05-23 23:09:502317 return new_contents;
2318}
2319
alexmosc2a8cec2016-05-23 22:19:532320RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
2321 int route_id) {
2322 auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502323 if (iter == pending_widget_views_.end()) {
2324 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:532325 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502326 }
2327
2328 RenderWidgetHostView* widget_host_view = iter->second;
alexmosc2a8cec2016-05-23 22:19:532329 pending_widget_views_.erase(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502330
2331 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2332 if (!widget_host->GetProcess()->HasConnection()) {
2333 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:532334 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502335 }
2336
2337 return widget_host_view;
2338}
2339
[email protected]f13b4202012-06-12 23:53:232340void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092341 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212342 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372343 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232344 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372345 } else {
dcheng59716272016-04-09 05:19:082346 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2347 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372348 }
[email protected]f13b4202012-06-12 23:53:232349}
2350
grunell657d4d82014-09-18 00:09:432351bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2352 MediaStreamType type) {
2353 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2354 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2355 return delegate_ &&
2356 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2357}
2358
[email protected]cc9200432013-07-23 23:02:402359SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2360 SiteInstance* instance) {
2361 return controller_.GetSessionStorageNamespace(instance);
2362}
2363
[email protected]6de7fc482014-06-06 10:46:442364SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2365 return controller_.GetSessionStorageNamespaceMap();
2366}
2367
[email protected]9b159a52013-10-03 17:24:552368FrameTree* WebContentsImpl::GetFrameTree() {
2369 return &frame_tree_;
2370}
2371
lukendc35e7f2014-11-10 19:06:142372void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2373 virtual_keyboard_requested_ = requested;
2374}
2375
2376bool WebContentsImpl::IsVirtualKeyboardRequested() {
2377 return virtual_keyboard_requested_;
2378}
2379
aelias5252baa2016-04-10 01:18:022380bool WebContentsImpl::IsOverridingUserAgent() {
2381 return GetController().GetVisibleEntry() &&
2382 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2383}
2384
avi85ee8362016-10-08 02:09:082385bool WebContentsImpl::IsJavaScriptDialogShowing() const {
2386 return is_showing_javascript_dialog_;
2387}
2388
[email protected]95640212014-07-26 18:14:302389AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2390 return accessibility_mode_;
2391}
2392
[email protected]31a71eaf2014-03-13 01:47:362393void WebContentsImpl::AccessibilityEventReceived(
2394 const std::vector<AXEventNotificationDetails>& details) {
2395 FOR_EACH_OBSERVER(
2396 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2397}
2398
dmazzoni2400c462016-08-23 15:07:132399void WebContentsImpl::AccessibilityLocationChangesReceived(
2400 const std::vector<AXLocationChangeNotificationDetails>& details) {
2401 FOR_EACH_OBSERVER(WebContentsObserver,
2402 observers_,
2403 AccessibilityLocationChangesReceived(details));
2404}
2405
dmazzonia656928e2014-09-15 20:28:542406RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402407 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542408 int browser_plugin_instance_id) {
2409 BrowserPluginGuestManager* guest_manager =
2410 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202411 if (!guest_manager)
2412 return nullptr;
2413
dmazzonia656928e2014-09-15 20:28:542414 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442415 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542416 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202417 return nullptr;
2418
dmazzonia656928e2014-09-15 20:28:542419 return guest->GetMainFrame();
2420}
2421
mcasas4e216e72016-07-28 21:28:382422device::GeolocationServiceContext*
2423WebContentsImpl::GetGeolocationServiceContext() {
blundellc57b93f2014-10-29 13:19:572424 return geolocation_service_context_.get();
2425}
2426
blundelld46e8832016-10-07 10:34:272427device::WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
alogvinovf50445a2015-10-30 13:00:122428 return wake_lock_service_context_.get();
2429}
2430
[email protected]edc3af82013-12-12 21:24:072431void WebContentsImpl::OnShowValidationMessage(
2432 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292433 const base::string16& main_text,
2434 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072435 if (delegate_)
2436 delegate_->ShowValidationMessage(
2437 this, anchor_in_root_view, main_text, sub_text);
2438}
2439
2440void WebContentsImpl::OnHideValidationMessage() {
2441 if (delegate_)
2442 delegate_->HideValidationMessage(this);
2443}
2444
2445void WebContentsImpl::OnMoveValidationMessage(
2446 const gfx::Rect& anchor_in_root_view) {
2447 if (delegate_)
2448 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2449}
2450
lfgbb9c28a2016-03-01 03:19:492451void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372452 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:402453 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:372454 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2455 }
lfgbb9c28a2016-03-01 03:19:492456
lfgdb5c4ed2016-03-04 23:09:072457 RenderWidgetHostViewBase* rwhv =
2458 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2459 if (rwhv) {
2460 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2461 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2462 }
2463
[email protected]32deec62013-05-15 23:55:042464 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442465 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042466}
2467
khushalsagarf3b62b62016-05-26 21:54:232468void WebContentsImpl::OnFirstPaintAfterLoad(
2469 RenderWidgetHostImpl* render_widget_host) {
2470 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2471 DidFirstPaintAfterLoad(render_widget_host));
2472}
2473
ekaramadadd882292016-06-08 15:22:562474TextInputManager* WebContentsImpl::GetTextInputManager() {
2475 if (GetOuterWebContents())
2476 return GetOuterWebContents()->GetTextInputManager();
2477
2478 if (!text_input_manager_)
2479 text_input_manager_.reset(new TextInputManager());
2480
2481 return text_input_manager_.get();
2482}
2483
[email protected]95640212014-07-26 18:14:302484BrowserAccessibilityManager*
2485 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452486 RenderFrameHostImpl* rfh = GetMainFrame();
2487 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302488}
2489
2490BrowserAccessibilityManager*
2491 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452492 RenderFrameHostImpl* rfh = GetMainFrame();
2493 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302494}
2495
mohsen7ab1ec16ec2015-07-02 18:26:232496void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2497 RenderFrameHost* focused_frame = GetFocusedFrame();
2498 if (!focused_frame)
2499 return;
2500
2501 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2502 focused_frame->GetRoutingID(), extent));
2503}
2504
2505void WebContentsImpl::SelectRange(const gfx::Point& base,
2506 const gfx::Point& extent) {
2507 RenderFrameHost* focused_frame = GetFocusedFrame();
2508 if (!focused_frame)
2509 return;
2510
2511 focused_frame->Send(
2512 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2513}
2514
aurimasab0319022015-07-10 21:57:382515void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2516 int end_adjust) {
2517 RenderFrameHost* focused_frame = GetFocusedFrame();
2518 if (!focused_frame)
2519 return;
2520
2521 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2522 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2523}
2524
[email protected]b172aee2012-04-10 17:05:262525void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492526 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232527 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492528 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332529}
2530
avic3aa8422015-11-09 20:57:222531void WebContentsImpl::ResizeDueToAutoResize(
2532 RenderWidgetHostImpl* render_widget_host,
2533 const gfx::Size& new_size) {
2534 if (render_widget_host != GetRenderViewHost()->GetWidget())
2535 return;
2536
[email protected]61e2b3cc2012-03-02 16:13:342537 if (delegate_)
2538 delegate_->ResizeDueToAutoResize(this, new_size);
2539}
2540
[email protected]b172aee2012-04-10 17:05:262541WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202542 if (!delegate_)
2543 return NULL;
[email protected]00c37fc2011-08-02 00:22:502544
[email protected]e5d549d2011-12-28 01:29:202545 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202546 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342547}
2548
[email protected]6b618e62012-08-16 12:59:182549bool WebContentsImpl::Send(IPC::Message* message) {
2550 if (!GetRenderViewHost()) {
2551 delete message;
2552 return false;
2553 }
2554
2555 return GetRenderViewHost()->Send(message);
2556}
2557
[email protected]a86c0e962013-12-17 17:10:392558void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2559 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442560 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392561 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442562}
2563
[email protected]20ca0382013-02-28 19:50:072564void WebContentsImpl::AttachInterstitialPage(
2565 InterstitialPageImpl* interstitial_page) {
2566 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212567 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292568
2569 // Cancel any visible dialogs so that they don't interfere with the
2570 // interstitial.
creis89a0f782015-05-27 16:13:172571 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292572
[email protected]20ca0382013-02-28 19:50:072573 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2574 DidAttachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252575
2576 // Stop the throbber if needed while the interstitial page is shown.
2577 if (frame_tree_.IsLoading())
2578 LoadingStateChanged(true, true, nullptr);
2579}
2580
2581void WebContentsImpl::DidProceedOnInterstitial() {
2582 // The interstitial page should no longer be pausing the throbber.
2583 DCHECK(!(ShowingInterstitialPage() &&
2584 GetRenderManager()->interstitial_page()->pause_throbber()));
2585
2586 // Restart the throbber now that the interstitial page no longer pauses it.
2587 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2588 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072589}
2590
2591void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252592 bool interstitial_pausing_throbber =
2593 ShowingInterstitialPage() &&
2594 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572595 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212596 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072597 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2598 DidDetachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252599
2600 // Restart the throbber if needed now that the interstitial page is going
2601 // away.
2602 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2603 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072604}
2605
avi2b177592014-12-10 02:08:022606void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2607 int history_length) {
alexmos136fd6e62016-08-15 20:58:412608 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
2609 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:022610}
2611
2612void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2613 RenderViewHost* render_view_host,
2614 int history_offset,
2615 int history_length) {
alexmos136fd6e62016-08-15 20:58:412616 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:022617 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142618}
2619
toyoshim24a4c7ab2016-04-05 09:24:142620void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172621 RenderFrameHost* focused_frame = GetFocusedFrame();
2622 if (!focused_frame)
2623 return;
2624
[email protected]959be4c2014-04-08 15:01:332625 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:142626 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:332627}
2628
megjablon3f5941072016-02-04 23:27:522629void WebContentsImpl::ReloadLoFiImages() {
2630 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2631}
2632
[email protected]959be4c2014-04-08 15:01:332633void WebContentsImpl::Undo() {
2634 RenderFrameHost* focused_frame = GetFocusedFrame();
2635 if (!focused_frame)
2636 return;
2637
2638 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2639 RecordAction(base::UserMetricsAction("Undo"));
2640}
2641
2642void WebContentsImpl::Redo() {
2643 RenderFrameHost* focused_frame = GetFocusedFrame();
2644 if (!focused_frame)
2645 return;
2646 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2647 RecordAction(base::UserMetricsAction("Redo"));
2648}
2649
2650void WebContentsImpl::Cut() {
2651 RenderFrameHost* focused_frame = GetFocusedFrame();
2652 if (!focused_frame)
2653 return;
2654
2655 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2656 RecordAction(base::UserMetricsAction("Cut"));
2657}
2658
2659void WebContentsImpl::Copy() {
2660 RenderFrameHost* focused_frame = GetFocusedFrame();
2661 if (!focused_frame)
2662 return;
2663
2664 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2665 RecordAction(base::UserMetricsAction("Copy"));
2666}
2667
2668void WebContentsImpl::CopyToFindPboard() {
2669#if defined(OS_MACOSX)
2670 RenderFrameHost* focused_frame = GetFocusedFrame();
2671 if (!focused_frame)
2672 return;
2673
2674 // Windows/Linux don't have the concept of a find pasteboard.
2675 focused_frame->Send(
2676 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2677 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2678#endif
2679}
2680
2681void WebContentsImpl::Paste() {
2682 RenderFrameHost* focused_frame = GetFocusedFrame();
2683 if (!focused_frame)
2684 return;
2685
2686 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2687 RecordAction(base::UserMetricsAction("Paste"));
2688}
2689
2690void WebContentsImpl::PasteAndMatchStyle() {
2691 RenderFrameHost* focused_frame = GetFocusedFrame();
2692 if (!focused_frame)
2693 return;
2694
2695 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2696 focused_frame->GetRoutingID()));
2697 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2698}
2699
2700void WebContentsImpl::Delete() {
2701 RenderFrameHost* focused_frame = GetFocusedFrame();
2702 if (!focused_frame)
2703 return;
2704
2705 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2706 RecordAction(base::UserMetricsAction("DeleteSelection"));
2707}
2708
2709void WebContentsImpl::SelectAll() {
2710 RenderFrameHost* focused_frame = GetFocusedFrame();
2711 if (!focused_frame)
2712 return;
2713
2714 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2715 RecordAction(base::UserMetricsAction("SelectAll"));
2716}
2717
2718void WebContentsImpl::Unselect() {
2719 RenderFrameHost* focused_frame = GetFocusedFrame();
2720 if (!focused_frame)
2721 return;
2722
2723 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2724 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172725}
2726
2727void WebContentsImpl::Replace(const base::string16& word) {
2728 RenderFrameHost* focused_frame = GetFocusedFrame();
2729 if (!focused_frame)
2730 return;
2731
[email protected]959be4c2014-04-08 15:01:332732 focused_frame->Send(new InputMsg_Replace(
2733 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172734}
2735
2736void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2737 RenderFrameHost* focused_frame = GetFocusedFrame();
2738 if (!focused_frame)
2739 return;
2740
[email protected]959be4c2014-04-08 15:01:332741 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2742 focused_frame->GetRoutingID(), word));
2743}
2744
2745void WebContentsImpl::NotifyContextMenuClosed(
2746 const CustomContextMenuContext& context) {
2747 RenderFrameHost* focused_frame = GetFocusedFrame();
2748 if (!focused_frame)
2749 return;
2750
2751 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2752 focused_frame->GetRoutingID(), context));
2753}
2754
2755void WebContentsImpl::ExecuteCustomContextMenuCommand(
2756 int action, const CustomContextMenuContext& context) {
2757 RenderFrameHost* focused_frame = GetFocusedFrame();
2758 if (!focused_frame)
2759 return;
2760
2761 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2762 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002763}
2764
[email protected]fc2b46b2014-05-03 16:33:452765gfx::NativeView WebContentsImpl::GetNativeView() {
2766 return view_->GetNativeView();
2767}
2768
2769gfx::NativeView WebContentsImpl::GetContentNativeView() {
2770 return view_->GetContentNativeView();
2771}
2772
2773gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2774 return view_->GetTopLevelNativeWindow();
2775}
2776
2777gfx::Rect WebContentsImpl::GetViewBounds() {
2778 return view_->GetViewBounds();
2779}
2780
2781gfx::Rect WebContentsImpl::GetContainerBounds() {
2782 gfx::Rect rv;
2783 view_->GetContainerBounds(&rv);
2784 return rv;
2785}
2786
2787DropData* WebContentsImpl::GetDropData() {
2788 return view_->GetDropData();
2789}
2790
2791void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042792 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452793}
2794
2795void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042796 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452797}
2798
2799void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042800 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452801}
2802
2803void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042804 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452805}
2806
[email protected]b172aee2012-04-10 17:05:262807void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272808 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212809 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542810 return;
2811 }
[email protected]0b431992014-06-24 00:08:032812 RenderWidgetHostView* const fullscreen_view =
2813 GetFullscreenRenderWidgetHostView();
2814 if (fullscreen_view) {
2815 fullscreen_view->Focus();
2816 return;
2817 }
creisc014b402015-04-23 16:41:452818 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542819}
2820
[email protected]b172aee2012-04-10 17:05:262821bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212822 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542823}
2824
[email protected]b172aee2012-04-10 17:05:262825InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212826 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222827}
2828
[email protected]b172aee2012-04-10 17:05:262829bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162830 // WebKit creates Document object when MIME type is application/xhtml+xml,
2831 // so we also support this MIME type.
2832 return contents_mime_type_ == "text/html" ||
2833 contents_mime_type_ == "text/xml" ||
2834 contents_mime_type_ == "application/xhtml+xml" ||
2835 contents_mime_type_ == "text/plain" ||
2836 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252837 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162838}
2839
[email protected]b172aee2012-04-10 17:05:262840void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592841 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162842 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552843 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192844 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142845 return;
[email protected]c7dd2f62011-07-18 15:57:592846 }
2847
2848 Stop();
2849
2850 // Create the save package and possibly prompt the user for the name to save
2851 // the page as. The user prompt is an asynchronous operation that runs on
2852 // another thread.
2853 save_package_ = new SavePackage(this);
2854 save_package_->GetSaveInfo();
2855}
2856
2857// Used in automated testing to bypass prompting the user for file names.
2858// Instead, the names and paths are hard coded rather than running them through
2859// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342860bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2861 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212862 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592863 // Stop the page from navigating.
2864 Stop();
2865
2866 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212867 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592868}
2869
[email protected]3c71576ce2013-07-23 02:00:012870void WebContentsImpl::SaveFrame(const GURL& url,
2871 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372872 SaveFrameWithHeaders(url, referrer, std::string());
2873}
2874
2875void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2876 const Referrer& referrer,
2877 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192878 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012879 return;
sammc92af61552014-11-19 23:27:402880 if (delegate_ && delegate_->SaveFrame(url, referrer))
2881 return;
2882
nasko89ad7742015-03-05 22:14:192883 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:222884 // by explicitly passing in which frame this method should target. This would
2885 // indicate whether it's the main frame, and also tell us the frame pointer
2886 // to use for routing.
nasko89ad7742015-03-05 22:14:192887 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:222888 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:012889
brettw760f7442016-05-23 21:19:222890 StoragePartition* storage_partition = BrowserContext::GetStoragePartition(
2891 GetBrowserContext(), frame_host->GetSiteInstance());
[email protected]3c71576ce2013-07-23 02:00:012892 DownloadManager* dlm =
2893 BrowserContext::GetDownloadManager(GetBrowserContext());
2894 if (!dlm)
2895 return;
avib7348942015-12-25 20:57:102896 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012897 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272898 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012899 if (entry)
2900 post_id = entry->GetPostID();
2901 }
brettw760f7442016-05-23 21:19:222902 std::unique_ptr<DownloadUrlParameters> params(new DownloadUrlParameters(
2903 url, frame_host->GetProcess()->GetID(),
2904 frame_host->GetRenderViewHost()->GetRoutingID(),
2905 frame_host->GetRoutingID(), storage_partition->GetURLRequestContext()));
[email protected]3c71576ce2013-07-23 02:00:012906 params->set_referrer(referrer);
2907 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012908 if (post_id >= 0)
2909 params->set_method("POST");
2910 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372911
2912 if (headers.empty()) {
2913 params->set_prefer_cache(true);
2914 } else {
brettw26dab8f02015-08-08 00:28:472915 for (const base::StringPiece& key_value :
2916 base::SplitStringPiece(
2917 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2918 std::vector<std::string> pair = base::SplitString(
2919 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372920 DCHECK_EQ(2ul, pair.size());
2921 params->add_request_header(pair[0], pair[1]);
2922 }
2923 }
dcheng36b6aec92015-12-26 06:16:362924 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012925}
2926
[email protected]b172aee2012-04-10 17:05:262927void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:472928 const MHTMLGenerationParams& params,
avib7348942015-12-25 20:57:102929 const base::Callback<void(int64_t)>& callback) {
dewittj6dc5747a2016-05-17 01:48:472930 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, callback);
[email protected]aa4f3972012-03-01 18:12:122931}
2932
[email protected]b172aee2012-04-10 17:05:262933const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272934 return contents_mime_type_;
2935}
2936
[email protected]b172aee2012-04-10 17:05:262937bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272938 return notify_disconnection_;
2939}
2940
[email protected]8ff00d72012-10-23 19:12:212941RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272942 return &renderer_preferences_;
2943}
2944
[email protected]e35ccd52012-05-23 16:22:472945void WebContentsImpl::Close() {
2946 Close(GetRenderViewHost());
2947}
2948
[email protected]cf200a562013-05-03 16:24:292949void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462950 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292951 if (browser_plugin_embedder_.get())
2952 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2953 screen_x, screen_y, operation);
2954 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452955 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2956 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292957}
2958
jam73f892642016-09-11 06:04:062959void WebContentsImpl::LoadStateChanged(
2960 const GURL& url,
2961 const net::LoadStateWithParam& load_state,
2962 uint64_t upload_position,
2963 uint64_t upload_size) {
2964 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
2965 // is fixed.
2966 tracked_objects::ScopedTracker tracking_profile1(
2967 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2968 "466285 WebContentsImpl::LoadStateChanged::Start"));
2969 load_state_ = load_state;
2970 upload_position_ = upload_position;
2971 upload_size_ = upload_size;
2972 load_state_host_ = url_formatter::IDNToUnicode(url.host());
2973 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
2974 SetNotWaitingForResponse();
2975 if (IsLoading()) {
2976 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
2977 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
2978 }
2979}
2980
[email protected]d60f3702013-12-26 16:30:242981void WebContentsImpl::DidGetResourceResponseStart(
2982 const ResourceRequestDetails& details) {
estarkf83ac122016-10-05 19:06:062983 controller_.ssl_manager()->DidStartResourceResponse(
2984 details.url, details.has_certificate, details.ssl_cert_status);
[email protected]d60f3702013-12-26 16:30:242985
2986 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2987 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242988}
2989
2990void WebContentsImpl::DidGetRedirectForResourceRequest(
[email protected]d60f3702013-12-26 16:30:242991 const ResourceRedirectDetails& details) {
[email protected]d60f3702013-12-26 16:30:242992 FOR_EACH_OBSERVER(
2993 WebContentsObserver,
2994 observers_,
jam73f892642016-09-11 06:04:062995 DidGetRedirectForResourceRequest(details));
[email protected]d60f3702013-12-26 16:30:242996
2997 // TODO(avi): Remove. http://crbug.com/170921
2998 NotificationService::current()->Notify(
2999 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
3000 Source<WebContents>(this),
3001 Details<const ResourceRedirectDetails>(&details));
3002}
3003
calamity7fe55ce2015-04-10 03:59:373004void WebContentsImpl::NotifyWebContentsFocused() {
3005 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
3006}
3007
[email protected]b172aee2012-04-10 17:05:263008void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:523009 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:453010 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:293011 if (browser_plugin_embedder_.get())
3012 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:343013}
3014
[email protected]e35ccd52012-05-23 16:22:473015void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:533016 OnUserInteraction(GetRenderViewHost()->GetWidget(),
3017 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:473018}
3019
[email protected]b172aee2012-04-10 17:05:263020void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:273021 closed_by_user_gesture_ = value;
3022}
3023
[email protected]b172aee2012-04-10 17:05:263024bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:273025 return closed_by_user_gesture_;
3026}
3027
[email protected]b172aee2012-04-10 17:05:263028void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:503029 if (!delegate_)
3030 return;
3031
[email protected]6286a372013-10-09 04:03:273032 NavigationEntry* entry = GetController().GetLastCommittedEntry();
3033 if (!entry)
[email protected]1788e772010-12-15 16:40:503034 return;
3035
[email protected]6286a372013-10-09 04:03:273036 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:123037}
3038
[email protected]b172aee2012-04-10 17:05:263039void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:043040 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:273041 if (!delegate_)
3042 return;
3043
[email protected]691aa2f2013-05-28 22:52:043044 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:273045}
3046
[email protected]b172aee2012-04-10 17:05:263047int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273048 return minimum_zoom_percent_;
3049}
3050
[email protected]b172aee2012-04-10 17:05:263051int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273052 return maximum_zoom_percent_;
3053}
3054
mcnee432e47d2015-11-09 19:37:463055void WebContentsImpl::SetPageScale(float page_scale_factor) {
3056 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:243057}
3058
[email protected]b172aee2012-04-10 17:05:263059gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:493060 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:233061}
3062
[email protected]b172aee2012-04-10 17:05:263063bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:053064 if (GetBrowserPluginGuest())
3065 return GetBrowserPluginGuest()->LockMouse(allowed);
3066
lfgad8244352016-07-13 16:55:513067 if (mouse_lock_widget_ &&
3068 mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3069 return true;
3070
3071 mouse_lock_widget_ = nullptr;
lfgbee1e0a2016-06-08 21:24:213072 return false;
[email protected]0bfbf882011-12-22 18:19:273073}
3074
[email protected]b172aee2012-04-10 17:05:263075bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:213076 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:503077}
3078
alexmose201c7cd2015-06-10 17:14:213079WebContentsImpl* WebContentsImpl::GetOpener() const {
3080 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
3081 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:573082}
3083
[email protected]cb805452013-05-22 15:16:213084void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:483085 if (!color_chooser_info_.get())
3086 return;
3087 RenderFrameHost* rfh = RenderFrameHost::FromID(
3088 color_chooser_info_->render_process_id,
3089 color_chooser_info_->render_frame_id);
3090 if (!rfh)
3091 return;
3092
3093 rfh->Send(new FrameMsg_DidChooseColorResponse(
3094 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:203095}
3096
[email protected]cb805452013-05-22 15:16:213097void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:483098 if (!color_chooser_info_.get())
3099 return;
3100 RenderFrameHost* rfh = RenderFrameHost::FromID(
3101 color_chooser_info_->render_process_id,
3102 color_chooser_info_->render_frame_id);
3103 if (!rfh)
3104 return;
3105
3106 rfh->Send(new FrameMsg_DidEndColorChooser(
3107 rfh->GetRoutingID(), color_chooser_info_->identifier));
3108 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:203109}
3110
halton.huoca2eabd2015-07-06 08:17:403111int WebContentsImpl::DownloadImage(
3112 const GURL& url,
3113 bool is_favicon,
3114 uint32_t max_bitmap_size,
3115 bool bypass_cache,
3116 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:553117 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:403118 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:063119 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:403120 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:553121 const int download_id = ++next_image_download_id;
3122 if (!mojo_image_downloader) {
3123 // If the renderer process is dead (i.e. crash, or memory pressure on
3124 // Android), the downloader service will be invalid. Pre-Mojo, this would
3125 // hang the callback indefinetly since the IPC would be dropped. Now,
3126 // respond with a 400 HTTP error code to indicate that something went wrong.
3127 BrowserThread::PostTask(
3128 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:193129 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:523130 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
leon.hanc2228532016-08-16 05:59:183131 std::vector<SkBitmap>(), std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:553132 return download_id;
3133 }
3134
halton.huoca2eabd2015-07-06 08:17:403135 mojo_image_downloader->DownloadImage(
sammcf6f4fcf2016-06-21 05:39:393136 url, is_favicon, max_bitmap_size, bypass_cache,
leon.hancbc4bc3c2016-02-26 07:08:523137 base::Bind(&WebContentsImpl::OnDidDownloadImage,
3138 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:553139 return download_id;
[email protected]795c28972012-12-06 06:13:393140}
3141
[email protected]5dcaf8e2013-12-28 01:31:423142bool WebContentsImpl::IsSubframe() const {
3143 return is_subframe_;
3144}
3145
[email protected]36ec24f2014-01-09 00:32:083146void WebContentsImpl::Find(int request_id,
3147 const base::string16& search_text,
3148 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:333149 // Cowardly refuse to search for no text.
3150 if (search_text.empty()) {
3151 NOTREACHED();
3152 return;
3153 }
3154
raymes0fa0be52014-10-13 20:38:093155 // See if a top level browser plugin handles the find request first.
paulmeyerc0b762b2016-04-13 11:55:173156 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473157 if (browser_plugin_embedder_ &&
3158 browser_plugin_embedder_->Find(request_id, search_text, options)) {
3159 return;
raymes0fa0be52014-10-13 20:38:093160 }
paulmeyerc0b762b2016-04-13 11:55:173161
3162 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:083163}
3164
3165void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:013166 // See if a top level browser plugin handles the stop finding request first.
paulmeyerc0b762b2016-04-13 11:55:173167 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473168 if (browser_plugin_embedder_ &&
3169 browser_plugin_embedder_->StopFinding(action)) {
3170 return;
raymes2bc64182015-02-06 01:23:013171 }
paulmeyerc0b762b2016-04-13 11:55:173172
3173 GetOrCreateFindRequestManager()->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:083174}
3175
dalecurtisbc6572e12014-09-12 19:22:303176bool WebContentsImpl::WasRecentlyAudible() {
wjmaclean1dabf3e32016-05-13 23:34:443177 return audio_stream_monitor_.WasRecentlyAudible() ||
3178 (browser_plugin_embedder_ &&
3179 browser_plugin_embedder_->WereAnyGuestsRecentlyAudible());
dalecurtisbc6572e12014-09-12 19:22:303180}
3181
mlamouriefdca9d2014-09-16 16:55:403182void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
3183 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
3184}
3185
bokanece34a82016-01-28 19:49:463186void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:533187 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:433188 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:463189 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:533190}
3191
mariakhomenko44bdc4732015-04-29 01:55:383192void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:373193 if (delayed_open_url_params_.get()) {
3194 OpenURL(*delayed_open_url_params_.get());
3195 delayed_open_url_params_.reset(nullptr);
3196 return;
3197 }
3198
mariakhomenko44bdc4732015-04-29 01:55:383199 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
3200 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163201 if (is_resume_pending_) {
3202 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133203 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163204 GetMainFrame()->Init();
3205 }
mariakhomenko44bdc4732015-04-29 01:55:383206}
3207
[email protected]b172aee2012-04-10 17:05:263208bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263209 // When the browser is started with about:blank as the startup URL, focus
3210 // the location bar (which will also select its contents) so people can
3211 // simply begin typing to navigate elsewhere.
3212 //
3213 // We need to be careful not to trigger this for anything other than the
3214 // startup navigation. In particular, if we allow an attacker to open a
3215 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3216 // end of the new URL to be scrolled into view instead of the start,
3217 // allowing the attacker to spoof other URLs. The conditions checked here
3218 // are all aimed at ensuring no such attacker-controlled navigation can
3219 // trigger this.
3220 //
3221 // Note that we check the pending entry instead of the visible one; for the
3222 // startup URL case these are the same, but for the attacker-controlled
3223 // navigation case the visible entry is the committed "about:blank" URL and
3224 // the pending entry is the problematic navigation elsewhere.
3225 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3226 if (controller_.IsInitialNavigation() && entry &&
3227 !entry->is_renderer_initiated() &&
3228 entry->GetURL() == GURL(url::kAboutBlankURL)) {
[email protected]0c9406632013-02-08 01:13:333229 return true;
palmerc70cb1f2016-03-04 23:41:263230 }
[email protected]0c9406632013-02-08 01:13:333231 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273232}
3233
[email protected]b172aee2012-04-10 17:05:263234void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273235 if (delegate_)
3236 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213237}
3238
clamy0e119882015-07-31 16:12:333239void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
3240 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3241 DidStartNavigation(navigation_handle));
3242}
3243
3244void WebContentsImpl::DidRedirectNavigation(
3245 NavigationHandle* navigation_handle) {
3246 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3247 DidRedirectNavigation(navigation_handle));
3248}
3249
clamyefca29e2015-09-17 00:22:113250void WebContentsImpl::ReadyToCommitNavigation(
3251 NavigationHandle* navigation_handle) {
3252 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3253 ReadyToCommitNavigation(navigation_handle));
3254}
3255
clamy0e119882015-07-31 16:12:333256void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
3257 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3258 DidFinishNavigation(navigation_handle));
3259}
3260
[email protected]52913802013-12-10 05:52:183261void WebContentsImpl::DidStartProvisionalLoad(
3262 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183263 const GURL& validated_url,
3264 bool is_error_page,
3265 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:103266 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483267 FOR_EACH_OBSERVER(
3268 WebContentsObserver,
3269 observers_,
3270 DidStartProvisionalLoadForFrame(
3271 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:083272
3273 // Notify accessibility if this is a reload.
3274 NavigationEntry* entry = controller_.GetVisibleEntry();
3275 if (entry && ui::PageTransitionCoreTypeIs(
3276 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
3277 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3278 BrowserAccessibilityManager* manager =
3279 ftn->current_frame_host()->browser_accessibility_manager();
3280 if (manager)
3281 manager->UserIsReloading();
3282 }
[email protected]400992b2012-06-14 00:03:543283}
3284
[email protected]3109fbb72014-01-06 23:57:153285void WebContentsImpl::DidFailProvisionalLoadWithError(
3286 RenderFrameHostImpl* render_frame_host,
lazyboy552a9382016-07-14 20:38:373287 const GURL& validated_url,
3288 int error_code,
3289 const base::string16& error_description,
3290 bool was_ignored_by_handler) {
3291 FOR_EACH_OBSERVER(
3292 WebContentsObserver, observers_,
3293 DidFailProvisionalLoad(render_frame_host, validated_url, error_code,
3294 error_description, was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:083295
3296 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3297 BrowserAccessibilityManager* manager =
3298 ftn->current_frame_host()->browser_accessibility_manager();
3299 if (manager)
3300 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153301}
3302
[email protected]b80624c2014-02-09 02:46:553303void WebContentsImpl::DidFailLoadWithError(
3304 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553305 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553306 int error_code,
gsennton6fbb38692015-06-24 19:23:553307 const base::string16& error_description,
3308 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:143309 FOR_EACH_OBSERVER(
3310 WebContentsObserver,
3311 observers_,
gsennton6fbb38692015-06-24 19:23:553312 DidFailLoad(render_frame_host, url, error_code, error_description,
3313 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553314}
3315
[email protected]52913802013-12-10 05:52:183316void WebContentsImpl::NotifyChangedNavigationState(
3317 InvalidateTypes changed_flags) {
3318 NotifyNavigationStateChanged(changed_flags);
3319}
3320
toyoshim0df1d3a2016-09-09 09:52:483321void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
3322 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:203323 // Notify observers about navigation.
3324 FOR_EACH_OBSERVER(
3325 WebContentsObserver,
3326 observers_,
3327 DidStartNavigationToPendingEntry(url, reload_type));
3328}
3329
[email protected]8cb834e2014-03-06 14:23:233330void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3331 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503332 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3333 // weak pointer of sorts.
3334 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3335 const int32_t frame_id = render_frame_host->GetRoutingID();
3336
[email protected]65920f332014-03-04 21:14:183337 WebContents* new_contents = OpenURL(params);
3338
dchengb907f7332015-01-07 20:35:503339 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183340 // Notify observers.
3341 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3342 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463343 render_frame_host,
[email protected]65920f332014-03-04 21:14:183344 params.url,
3345 params.referrer,
3346 params.disposition,
creis114ca1b2014-11-13 23:51:463347 params.transition));
[email protected]65920f332014-03-04 21:14:183348 }
3349}
3350
lukasza1d025732016-09-28 21:36:083351bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:223352 if (!delegate_)
3353 return true;
lukasza1d025732016-09-28 21:36:083354 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:223355}
3356
[email protected]aa62afd2014-04-22 19:22:463357bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3358 if (!delegate_)
3359 return false;
3360 return delegate_->ShouldPreserveAbortedURLs(this);
3361}
3362
[email protected]37567b432014-02-12 01:12:223363void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433364 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223365 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353366 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223367 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483368 FOR_EACH_OBSERVER(WebContentsObserver,
3369 observers_,
3370 DidCommitProvisionalLoadForFrame(
3371 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083372
3373 BrowserAccessibilityManager* manager =
3374 render_frame_host->browser_accessibility_manager();
3375 if (manager)
3376 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223377}
3378
[email protected]0d0f4c492014-04-02 06:42:573379void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233380 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573381 // Ensure fullscreen mode is exited before committing the navigation to a
3382 // different page. The next page will not start out assuming it is in
3383 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233384 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193385 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573386 return;
3387 }
alexmos5dd617d2016-06-07 04:21:153388 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:463389 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:153390 DCHECK(!IsFullscreenForCurrentTab());
[email protected]0d0f4c492014-04-02 06:42:573391}
3392
[email protected]37567b432014-02-12 01:12:223393void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283394 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223395 const LoadCommittedDetails& details,
3396 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3397 if (details.is_navigation_to_different_page()) {
3398 // Clear the status bubble. This is a workaround for a bug where WebKit
3399 // doesn't let us know that the cursor left an element during a
3400 // transition (this is also why the mouse cursor remains as a hand after
3401 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3402 // clear the bubble when a user navigates to a named anchor in the same
3403 // page.
sky8b00392d2015-01-10 00:30:283404 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003405
3406 RenderWidgetHostViewBase* rwhvb =
3407 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3408 if (rwhvb)
3409 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283410
peter90afaba2015-06-01 12:05:293411 did_first_visually_non_empty_paint_ = false;
3412
yusufod41c5f92015-03-06 00:14:283413 // Reset theme color on navigation to new page.
3414 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223415 }
3416
[email protected]37567b432014-02-12 01:12:223417 // Notify observers about navigation.
3418 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3419 DidNavigateMainFrame(details, params));
3420
[email protected]e85165c642014-06-10 14:34:313421 if (delegate_)
[email protected]37567b432014-02-12 01:12:223422 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313423 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223424}
3425
3426void WebContentsImpl::DidNavigateAnyFramePostCommit(
3427 RenderFrameHostImpl* render_frame_host,
3428 const LoadCommittedDetails& details,
3429 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103430 // Now that something has committed, we don't need to track whether the
3431 // initial page has been accessed.
3432 has_accessed_initial_document_ = false;
3433
[email protected]37567b432014-02-12 01:12:223434 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173435 if (!details.is_in_page)
3436 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223437
avid53461d2016-02-25 17:15:043438 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3439 // again.
avi5d3b8692016-10-12 22:00:463440 if (params.gesture == NavigationGestureUser && dialog_manager_) {
3441 dialog_manager_->CancelDialogs(this,
3442 false, // suppress_callbacks,
3443 true); // reset_state
3444 }
avid53461d2016-02-25 17:15:043445
[email protected]37567b432014-02-12 01:12:223446 // Notify observers about navigation.
3447 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093448 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223449}
3450
3451void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3452 contents_mime_type_ = mime_type;
3453}
3454
[email protected]277857a2014-06-03 10:38:013455bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313456 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053457 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313458 return false;
3459
[email protected]37567b432014-02-12 01:12:223460 if (delegate_)
3461 return delegate_->CanOverscrollContent();
3462
3463 return false;
3464}
3465
[email protected]37b64c52014-07-11 21:14:053466void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293467 // Update the theme color. This is to be published to observers after the
3468 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283469 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293470
3471 if (did_first_visually_non_empty_paint_ &&
3472 last_sent_theme_color_ != theme_color_) {
3473 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3474 DidChangeThemeColor(theme_color_));
3475 last_sent_theme_color_ = theme_color_;
3476 }
[email protected]e7104762014-06-20 19:17:253477}
3478
[email protected]b172aee2012-04-10 17:05:263479void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183480 const GURL& url,
[email protected]70435962011-08-02 20:13:283481 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183482 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403483 ResourceType resource_type) {
[email protected]b0f724c2013-09-05 04:21:133484 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
jam91dd24e2016-08-12 17:16:423485 DidLoadResourceFromMemoryCache(url, mime_type,
3486 resource_type));
[email protected]b0f724c2013-09-05 04:21:133487
[email protected]8bfc8272013-09-09 20:10:533488 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3489 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403490 resource_type == RESOURCE_TYPE_MEDIA ?
jam2503f932016-04-15 20:08:303491 GetRenderProcessHost()->GetStoragePartition()->
3492 GetMediaURLRequestContext() :
jam608f2992016-03-31 16:35:343493 GetRenderProcessHost()->GetStoragePartition()->
3494 GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533495 BrowserThread::PostTask(
3496 BrowserThread::IO,
3497 FROM_HERE,
3498 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3499 }
[email protected]724159a2010-12-30 01:11:183500}
3501
[email protected]b172aee2012-04-10 17:05:263502void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393503 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
estarkc2273502016-10-12 22:03:023504 controller_.ssl_manager()->DidDisplayMixedContent();
[email protected]724159a2010-12-30 01:11:183505}
3506
estark910b4572015-12-09 20:55:413507void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3508 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583509 LOG(WARNING) << security_origin << " ran insecure content from "
3510 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393511 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413512 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293513 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393514 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
estarkc2273502016-10-12 22:03:023515 controller_.ssl_manager()->DidRunMixedContent(security_origin);
[email protected]724159a2010-12-30 01:11:183516}
3517
estark910b4572015-12-09 20:55:413518void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
jama385e112016-07-22 00:07:583519 const GURL& url) {
estarkc2273502016-10-12 22:03:023520 controller_.ssl_manager()->DidDisplayContentWithCertErrors();
estark910b4572015-12-09 20:55:413521}
3522
3523void WebContentsImpl::OnDidRunContentWithCertificateErrors(
jama385e112016-07-22 00:07:583524 const GURL& url) {
estarkcd2e30c2016-08-12 06:51:153525 NavigationEntry* entry = controller_.GetVisibleEntry();
3526 if (!entry)
estarkaeda1422016-05-10 02:31:123527 return;
3528
estarkaeda1422016-05-10 02:31:123529 // TODO(estark): check that this does something reasonable for
3530 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:153531 controller_.ssl_manager()->DidRunContentWithCertErrors(
3532 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:413533}
3534
[email protected]501052ff2014-02-21 22:19:073535void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113536 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473537 return;
naskofbd033392015-01-27 02:34:473538
[email protected]1d62cf72014-02-07 21:31:573539 RenderFrameHostImpl* rfh =
3540 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143541 FOR_EACH_OBSERVER(
3542 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183543}
3544
naskofbd033392015-01-27 02:34:473545void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113546 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123547 return;
[email protected]a1b99262013-12-27 21:56:223548
[email protected]8b3af1e2014-01-24 13:29:123549 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443550 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373551 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423552 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373553
[email protected]61ac9e242014-03-21 20:55:263554 RenderFrameHostImpl* rfh =
3555 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143556 FOR_EACH_OBSERVER(
3557 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313558}
3559
[email protected]b172aee2012-04-10 17:05:263560void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573561 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3562 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263563}
3564
[email protected]b172aee2012-04-10 17:05:263565void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303566 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263567 minimum_zoom_percent_ = minimum_percent;
3568 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263569}
3570
mcnee432e47d2015-11-09 19:37:463571void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3572 bool is_one = page_scale_factor == 1.f;
3573 if (is_one != page_scale_factor_is_one_) {
3574 page_scale_factor_is_one_ = is_one;
3575
3576 HostZoomMapImpl* host_zoom_map =
3577 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3578
3579 if (host_zoom_map && GetRenderProcessHost()) {
3580 host_zoom_map->SetPageScaleFactorIsOneForView(
3581 GetRenderProcessHost()->GetID(), GetRoutingID(),
3582 page_scale_factor_is_one_);
3583 }
3584 }
3585
3586 FOR_EACH_OBSERVER(WebContentsObserver,
3587 observers_,
3588 OnPageScaleFactorChanged(page_scale_factor));
3589}
3590
[email protected]b172aee2012-04-10 17:05:263591void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343592 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433593 if (!delegate_)
3594 return;
3595
[email protected]b9535422012-02-09 01:47:593596 ChildProcessSecurityPolicyImpl* policy =
3597 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223598 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593599 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213600}
3601
[email protected]b172aee2012-04-10 17:05:263602void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3603 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263604 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363605 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433606 if (!delegate_)
3607 return;
3608
[email protected]b9535422012-02-09 01:47:593609 ChildProcessSecurityPolicyImpl* policy =
3610 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323611 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593612 return;
[email protected]8f810632013-06-06 22:33:323613
[email protected]c125e532014-05-10 20:39:063614 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203615}
3616
[email protected]f5273e52014-07-14 16:30:203617void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3618 const GURL& url,
3619 bool user_gesture) {
3620 if (!delegate_)
3621 return;
3622
3623 ChildProcessSecurityPolicyImpl* policy =
3624 ChildProcessSecurityPolicyImpl::GetInstance();
3625 if (policy->IsPseudoScheme(protocol))
3626 return;
3627
3628 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3629}
3630
kouhei40f03cb2015-09-24 07:47:013631void WebContentsImpl::OnUpdatePageImportanceSignals(
3632 const PageImportanceSignals& signals) {
3633 page_importance_signals_ = signals;
3634}
3635
[email protected]b172aee2012-04-10 17:05:263636void WebContentsImpl::OnFindReply(int request_id,
3637 int number_of_matches,
3638 const gfx::Rect& selection_rect,
3639 int active_match_ordinal,
3640 bool final_update) {
paulmeyerc0b762b2016-04-13 11:55:173641 // Forward the find reply to the FindRequestManager, along with the
3642 // RenderFrameHost associated with the frame that the reply came from.
3643 GetOrCreateFindRequestManager()->OnFindReply(render_frame_message_source_,
3644 request_id,
3645 number_of_matches,
3646 selection_rect,
3647 active_match_ordinal,
3648 final_update);
[email protected]b888919c2011-09-02 00:32:163649}
3650
mfomitchev2b8b066a2016-01-28 19:23:153651#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313652void WebContentsImpl::OnFindMatchRectsReply(
3653 int version,
3654 const std::vector<gfx::RectF>& rects,
3655 const gfx::RectF& active_rect) {
paulmeyerc0b762b2016-04-13 11:55:173656 GetOrCreateFindRequestManager()->OnFindMatchRectsReply(
3657 render_frame_message_source_, version, rects, active_rect);
[email protected]59363fc92012-09-05 03:46:313658}
[email protected]583418cc2013-01-17 14:01:103659
paulmeyerc8cb7cb2016-06-07 01:14:193660void WebContentsImpl::OnGetNearestFindResultReply(int request_id,
3661 float distance) {
3662 GetOrCreateFindRequestManager()->OnGetNearestFindResultReply(
3663 render_frame_message_source_, request_id, distance);
3664}
3665
[email protected]1ff427972013-02-07 21:14:073666void WebContentsImpl::OnOpenDateTimeDialog(
3667 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173668 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093669 GetRenderViewHost(),
3670 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133671 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093672 value.minimum,
3673 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173674 value.step,
3675 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103676}
[email protected]59363fc92012-09-05 03:46:313677#endif
3678
avi60bd4902015-09-23 20:39:243679void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3680 std::string json = json_string;
3681 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3682 Source<WebContents>(this),
3683 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403684}
3685
[email protected]b172aee2012-04-10 17:05:263686void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3687 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103688 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253689 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103690 AppCacheAccessed(manifest_url, blocked_by_policy));
3691}
3692
[email protected]8bc5ff02013-11-29 06:34:033693void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483694 int color_chooser_id,
3695 SkColor color,
3696 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113697 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003698 return;
nasko907fcb62015-01-28 04:24:113699
[email protected]aa62afd2014-04-22 19:22:463700 ColorChooser* new_color_chooser = delegate_ ?
3701 delegate_->OpenColorChooser(this, color, suggestions) :
3702 NULL;
[email protected]820957a2014-01-14 14:56:303703 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213704 return;
[email protected]8ed16472014-04-11 19:02:483705 if (color_chooser_info_.get())
3706 color_chooser_info_->chooser->End();
3707
3708 color_chooser_info_.reset(new ColorChooserInfo(
3709 render_frame_message_source_->GetProcess()->GetID(),
3710 render_frame_message_source_->GetRoutingID(),
3711 new_color_chooser,
3712 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203713}
3714
[email protected]b172aee2012-04-10 17:05:263715void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483716 if (color_chooser_info_ &&
3717 color_chooser_id == color_chooser_info_->identifier)
3718 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203719}
3720
[email protected]b172aee2012-04-10 17:05:263721void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323722 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483723 if (color_chooser_info_ &&
3724 color_chooser_id == color_chooser_info_->identifier)
3725 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203726}
3727
[email protected]d0759f492012-04-19 22:50:503728// This exists for render views that don't have a WebUI, but do have WebUI
3729// bindings enabled.
3730void WebContentsImpl::OnWebUISend(const GURL& source_url,
3731 const std::string& name,
3732 const base::ListValue& args) {
3733 if (delegate_)
3734 delegate_->WebUISend(this, source_url, name, args);
3735}
3736
thestigc4cac8f2014-09-04 21:17:503737#if defined(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:173738void WebContentsImpl::OnPepperInstanceCreated(int32_t pp_instance) {
3739 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3740 PepperInstanceCreated());
3741 pepper_playback_observer_->PepperInstanceCreated(pp_instance);
emaxxe70f5e12015-05-29 11:26:003742}
3743
zqzhang181047e62016-07-01 13:37:173744void WebContentsImpl::OnPepperInstanceDeleted(int32_t pp_instance) {
3745 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3746 PepperInstanceDeleted());
3747 pepper_playback_observer_->PepperInstanceDeleted(pp_instance);
emaxxe70f5e12015-05-29 11:26:003748}
3749
tommyclie6633ca72014-10-31 00:40:423750void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3751 const base::FilePath& path,
3752 bool is_hung) {
3753 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3754
3755 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3756 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3757}
3758
zqzhang181047e62016-07-01 13:37:173759void WebContentsImpl::OnPepperStartsPlayback(int32_t pp_instance) {
3760 pepper_playback_observer_->PepperStartsPlayback(pp_instance);
3761}
3762
3763void WebContentsImpl::OnPepperStopsPlayback(int32_t pp_instance) {
3764 pepper_playback_observer_->PepperStopsPlayback(pp_instance);
3765}
3766
tommyclie6633ca72014-10-31 00:40:423767void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3768 base::ProcessId plugin_pid) {
3769 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3770 PluginCrashed(plugin_path, plugin_pid));
3771}
3772
[email protected]d8415ad92012-08-23 14:40:503773void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443774 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503775 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343776 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163777 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443778 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163779 return;
[email protected]d8415ad92012-08-23 14:40:503780 }
3781
[email protected]8c8fc292012-11-23 18:57:163782 if (!delegate_->RequestPpapiBrokerPermission(
3783 this, url, plugin_path,
3784 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443785 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163786 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443787 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163788 }
[email protected]d8415ad92012-08-23 14:40:503789}
3790
[email protected]ea0309c2013-08-06 19:35:443791void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503792 bool result) {
[email protected]ea0309c2013-08-06 19:35:443793 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503794}
3795
fsamuel833ee7c2015-02-13 23:40:403796void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3797 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393798 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143799 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403800 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373801}
tommyclie6633ca72014-10-31 00:40:423802#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373803
[email protected]795c28972012-12-06 06:13:393804void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393805 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063806 // We get updated favicon URLs after the page stops loading. If a cross-site
3807 // navigation occurs while a page is still loading, the initial page
3808 // may stop loading and send us updated favicon URLs after the navigation
3809 // for the new page has committed.
3810 RenderViewHostImpl* rvhi =
3811 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3812 if (!rvhi->is_active())
3813 return;
3814
[email protected]795c28972012-12-06 06:13:393815 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293816 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393817}
3818
avayvod41634b12015-07-08 17:07:053819void WebContentsImpl::OnMediaSessionStateChanged() {
3820 MediaSession* session = MediaSession::Get(this);
3821 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3822 MediaSessionStateChanged(session->IsControllable(),
mlamouri2d1bfbd2016-03-17 13:14:543823 session->IsSuspended(),
3824 session->metadata()));
avayvod41634b12015-07-08 17:07:053825}
3826
3827void WebContentsImpl::ResumeMediaSession() {
mlamouri918734092016-03-12 04:47:523828 MediaSession::Get(this)->Resume(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053829}
3830
3831void WebContentsImpl::SuspendMediaSession() {
mlamouri918734092016-03-12 04:47:523832 MediaSession::Get(this)->Suspend(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053833}
3834
mlamouri4c4fbed2015-08-17 15:51:013835void WebContentsImpl::StopMediaSession() {
mlamouri918734092016-03-12 04:47:523836 MediaSession::Get(this)->Stop(MediaSession::SuspendType::UI);
mlamouri4c4fbed2015-08-17 15:51:013837}
3838
estark703f1b42016-10-10 21:37:153839void WebContentsImpl::OnPasswordInputShownOnHttp() {
estarkc2273502016-10-12 22:03:023840 controller_.ssl_manager()->DidShowPasswordInputOnHttp();
estark703f1b42016-10-10 21:37:153841}
3842
3843void WebContentsImpl::OnCreditCardInputShownOnHttp() {
estarkc2273502016-10-12 22:03:023844 controller_.ssl_manager()->DidShowCreditCardInputOnHttp();
estark703f1b42016-10-10 21:37:153845}
3846
[email protected]50279492014-05-05 23:24:293847void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153848 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293849 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283850
peter90afaba2015-06-01 12:05:293851 did_first_visually_non_empty_paint_ = true;
3852
yusufod41c5f92015-03-06 00:14:283853 if (theme_color_ != last_sent_theme_color_) {
3854 // Theme color should have updated by now if there was one.
3855 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3856 DidChangeThemeColor(theme_color_));
3857 last_sent_theme_color_ = theme_color_;
3858 }
[email protected]9f268072013-11-07 00:02:153859}
[email protected]d9030b82013-07-19 08:26:063860
[email protected]e67ebf32013-02-13 11:07:193861void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013862 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073863 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013864
estark5ea80e52015-06-19 18:43:123865 SecurityStyleExplanations security_style_explanations;
estark47ba9c7d2016-10-11 15:40:113866 blink::WebSecurityStyle security_style =
estark5ea80e52015-06-19 18:43:123867 delegate_->GetSecurityStyle(this, &security_style_explanations);
3868 FOR_EACH_OBSERVER(
3869 WebContentsObserver, observers_,
3870 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013871 }
[email protected]e67ebf32013-02-13 11:07:193872}
3873
[email protected]17e286e2013-03-01 23:29:393874void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3875 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3876 BeforeFormRepostWarningShow());
3877}
3878
[email protected]ec6c05f2013-10-23 18:41:573879void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3880 Activate();
3881 if (delegate_)
3882 delegate_->ShowRepostFormWarningDialog(this);
3883}
3884
[email protected]b4c84012014-04-28 19:51:103885bool WebContentsImpl::HasAccessedInitialDocument() {
3886 return has_accessed_initial_document_;
3887}
3888
[email protected]b172aee2012-04-10 17:05:263889void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463890 // If we are creating a RVH for a restored controller, then we need to make
3891 // sure the RenderView starts with a next_page_id_ larger than the number
3892 // of restored entries. This must be called before the RenderView starts
3893 // navigating (to avoid a race between the browser updating max_page_id and
3894 // the renderer updating next_page_id_). Because of this, we only call this
3895 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563896 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583897 if (max_restored_page_id >
3898 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3899 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3900 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323901}
3902
afakhry6f0c1ec22016-07-14 13:55:133903void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:263904 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323905 // For file URLs without a title, use the pathname instead. In the case of a
3906 // synthesized title, we don't want the update to count toward the "one set
3907 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263908 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323909 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513910 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243911 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323912 explicit_set = false; // Don't count synthetic titles toward the set limit.
3913 } else {
[email protected]8af69c6c2014-03-03 19:05:313914 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323915 explicit_set = true;
3916 }
3917
[email protected]987fc3a2011-05-26 14:18:093918 // If a page is created via window.open and never navigated,
3919 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553920 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093921 if (entry) {
[email protected]36fc0392011-12-25 03:59:513922 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:133923 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323924
[email protected]36fc0392011-12-25 03:59:513925 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093926 } else {
3927 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:133928 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:093929
3930 page_title_when_no_navigation_entry_ = final_title;
3931 }
[email protected]420ae012009-04-24 05:16:323932
[email protected]420ae012009-04-24 05:16:323933 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233934 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323935
[email protected]66798902013-10-01 18:40:163936 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533937 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163938
afakhry6f0c1ec22016-07-14 13:55:133939 // Broadcast notifications when the UI should be updated.
3940 if (entry == controller_.GetEntryAtOffset(0))
3941 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323942}
3943
fdegansa696e5112015-04-17 01:57:593944void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003945 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003946 if (delegate_)
fdegansa696e5112015-04-17 01:57:593947 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003948}
3949
3950void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343951 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003952 loading_weak_factory_.InvalidateWeakPtrs();
3953 loading_last_progress_update_ = base::TimeTicks();
3954}
3955
clamy44e84ce2016-02-22 15:38:253956// Notifies the RenderWidgetHost instance about the fact that the page is
3957// loading, or done loading.
3958void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3959 bool due_to_interstitial,
3960 LoadNotificationDetails* details) {
3961 // Do not send notifications about loading changes in the FrameTree while the
3962 // interstitial page is pausing the throbber.
3963 if (ShowingInterstitialPage() &&
3964 GetRenderManager()->interstitial_page()->pause_throbber() &&
3965 !due_to_interstitial) {
3966 return;
3967 }
3968
3969 bool is_loading = IsLoading();
3970
3971 if (!is_loading) {
3972 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3973 base::string16());
3974 load_state_host_.clear();
3975 upload_size_ = 0;
3976 upload_position_ = 0;
3977 }
3978
3979 GetRenderManager()->SetIsLoading(is_loading);
3980
3981 waiting_for_response_ = is_loading;
3982 is_load_to_different_document_ = to_different_document;
3983
3984 if (delegate_)
3985 delegate_->LoadingStateChanged(this, to_different_document);
3986 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3987
3988 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3989 if (is_loading) {
3990 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3991 this, "URL", url, "Main FrameTreeNode id",
3992 GetFrameTree()->root()->frame_tree_node_id());
3993 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
3994 } else {
3995 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3996 this, "URL", url);
3997 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
3998 }
3999
4000 // TODO(avi): Remove. http://crbug.com/170921
4001 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
4002 NotificationDetails det = NotificationService::NoDetails();
4003 if (details)
4004 det = Details<LoadNotificationDetails>(details);
4005 NotificationService::current()->Notify(
4006 type, Source<NavigationController>(&controller_), det);
4007}
4008
[email protected]02d7b6e2014-06-24 21:01:504009void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
4010 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:324011 // After sending out a swap notification, we need to send a disconnect
4012 // notification so that clients that pick up a pointer to |this| can NULL the
4013 // pointer. See Bug 1230284.
4014 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:114015 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:284016 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:114017
[email protected]7a846df2012-09-20 19:17:394018 // Ensure that the associated embedder gets cleared after a RenderViewHost
4019 // gets swapped, so we don't reuse the same embedder next time a
4020 // RenderViewHost is attached to this WebContents.
4021 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:324022}
4023
[email protected]02d7b6e2014-06-24 21:01:504024void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
4025 RenderFrameHost* new_host) {
4026 FOR_EACH_OBSERVER(WebContentsObserver,
4027 observers_,
4028 RenderFrameHostChanged(old_host, new_host));
4029}
4030
[email protected]da7a7182013-09-06 08:11:114031// TODO(avi): Remove this entire function because this notification is already
4032// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:264033void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:324034 if (!notify_disconnection_)
4035 return;
4036
4037 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:214038 NotificationService::current()->Notify(
4039 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
4040 Source<WebContents>(this),
4041 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:324042}
4043
[email protected]cbb1ef592013-06-05 19:49:464044void WebContentsImpl::NotifyNavigationEntryCommitted(
4045 const LoadCommittedDetails& load_details) {
4046 FOR_EACH_OBSERVER(
4047 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
4048}
4049
[email protected]f114fa42013-12-06 17:06:444050bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
4051 const IPC::Message& message) {
4052 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:314053}
4054
rockotf62002a2016-09-15 00:08:594055void WebContentsImpl::OnAssociatedInterfaceRequest(
4056 RenderFrameHost* render_frame_host,
4057 const std::string& interface_name,
4058 mojo::ScopedInterfaceEndpointHandle handle) {
4059 auto it = binding_sets_.find(interface_name);
4060 if (it != binding_sets_.end())
4061 it->second->OnRequestForFrame(render_frame_host, std::move(handle));
4062}
4063
[email protected]c31a84802014-04-03 15:55:494064const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
4065 return GetLastCommittedURL();
4066}
4067
[email protected]b849847b2013-12-10 21:57:584068void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:584069 FOR_EACH_OBSERVER(WebContentsObserver,
4070 observers_,
4071 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:304072 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
clamy91b7abf2016-03-24 15:17:454073
4074 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
4075 return;
4076
4077 NavigationEntry* entry = controller_.GetPendingEntry();
4078 if (entry && entry->IsViewSourceMode()) {
4079 // Put the renderer in view source mode.
4080 render_frame_host->Send(
4081 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
4082 }
sammc5a139ba2016-09-29 01:49:144083#if defined(OS_ANDROID)
4084 render_frame_host->GetInterfaceRegistry()->AddInterface(
4085 GetJavaInterfaces()->CreateInterfaceFactory<device::nfc::mojom::NFC>());
4086#endif
[email protected]b849847b2013-12-10 21:57:584087}
4088
4089void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
4090 FOR_EACH_OBSERVER(WebContentsObserver,
4091 observers_,
4092 RenderFrameDeleted(render_frame_host));
4093}
4094
[email protected]a09d53ce2014-01-31 00:46:424095void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
4096 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:104097 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:424098 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:104099 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:424100 return;
4101
[email protected]077e704b2014-05-23 19:24:104102 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
4103 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:424104}
4105
[email protected]87de04b02014-04-08 22:14:494106void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:014107 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494108 const base::string16& message,
4109 const base::string16& default_prompt,
4110 const GURL& frame_url,
4111 JavaScriptMessageType javascript_message_type,
4112 IPC::Message* reply_msg) {
4113 // Suppress JavaScript dialogs when requested. Also suppress messages when
4114 // showing an interstitial as it's shown over the previous page and we don't
4115 // want the hidden page's dialogs to interfere with the interstitial.
4116 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:504117 ShowingInterstitialPage() || !delegate_ ||
4118 delegate_->ShouldSuppressDialogs(this) ||
4119 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494120
4121 if (!suppress_this_message) {
avi85ee8362016-10-08 02:09:084122 is_showing_javascript_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504123 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494124 dialog_manager_->RunJavaScriptDialog(
jshin1fb76462016-04-05 22:13:034125 this, frame_url, javascript_message_type, message, default_prompt,
palmer4e0ae10d2015-09-03 23:38:414126 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014127 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:414128 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:494129 &suppress_this_message);
4130 }
4131
4132 if (suppress_this_message) {
4133 // If we are suppressing messages, just reply as if the user immediately
4134 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:014135 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
4136 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284137 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:494138 }
4139
4140 // OnDialogClosed (two lines up) may have caused deletion of this object (see
4141 // http://crbug.com/288961 ). The only safe thing to do here is return.
4142}
4143
4144void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:014145 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494146 bool is_reload,
4147 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:014148 RenderFrameHostImpl* rfhi =
4149 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:494150 if (delegate_)
4151 delegate_->WillRunBeforeUnloadConfirm();
4152
4153 bool suppress_this_message =
nasko19736cc9f2016-04-08 22:38:454154 !rfhi->is_active() ||
creis36e228b2015-06-08 18:48:024155 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:504156 delegate_->ShouldSuppressDialogs(this) ||
4157 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494158 if (suppress_this_message) {
4159 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
4160 return;
4161 }
4162
4163 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504164 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494165 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:424166 this, is_reload,
[email protected]87de04b02014-04-08 22:14:494167 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014168 render_frame_host->GetProcess()->GetID(),
4169 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284170 false));
[email protected]87de04b02014-04-08 22:14:494171}
4172
naskoada75b22016-06-11 16:09:464173void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host,
4174 const FileChooserParams& params) {
4175 if (delegate_)
4176 delegate_->RunFileChooser(render_frame_host, params);
4177}
4178
[email protected]a86c0e962013-12-17 17:10:394179WebContents* WebContentsImpl::GetAsWebContents() {
4180 return this;
4181}
4182
wjmaclean64951902016-04-29 20:59:124183double WebContentsImpl::GetPendingPageZoomLevel() {
4184 NavigationEntry* pending_entry = GetController().GetPendingEntry();
4185 if (!pending_entry)
4186 return HostZoomMap::GetZoomLevel(this);
4187
4188 GURL url = pending_entry->GetURL();
4189 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
4190 url.scheme(), net::GetHostOrSpecFromURL(url));
4191}
4192
[email protected]7912e822014-04-16 02:37:034193bool WebContentsImpl::IsNeverVisible() {
4194 if (!delegate_)
4195 return false;
4196 return delegate_->IsNeverVisible(this);
4197}
4198
[email protected]5a3bdf52012-05-24 15:12:574199RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
4200 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:324201}
4202
[email protected]8ff00d72012-10-23 19:12:214203RendererPreferences WebContentsImpl::GetRendererPrefs(
4204 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:464205 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:514206}
4207
[email protected]7a846df2012-09-20 19:17:394208void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:274209 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394210 browser_plugin_embedder_.reset();
4211}
4212
avallee0206f782016-07-28 18:55:334213WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
ekaramad1beabecc2016-09-23 20:18:174214 if (GuestMode::IsCrossProcessFrameGuest(this) && node_)
4215 return node_->outer_web_contents();
4216
4217 if (browser_plugin_guest_)
4218 return browser_plugin_guest_->embedder_web_contents();
4219
avallee0206f782016-07-28 18:55:334220 return nullptr;
4221}
4222
4223WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
4224 // There is no inner or outer web contents.
4225 if (!node_ && !GetBrowserPluginGuest())
4226 return this;
4227
4228 // We may need to create a node_ on the outermost contents in the
4229 // BrowserPlugin case.
4230 WebContentsImpl* outermost = GetOutermostWebContents();
4231 if (!outermost->node_) {
4232 outermost->node_.reset(new WebContentsTreeNode());
4233 outermost->node_->SetFocusedWebContents(outermost);
4234 }
4235 return outermost->node_->focused_web_contents();
4236}
4237
4238WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
4239 WebContentsImpl* root = this;
4240 while (root->GetOuterWebContents())
4241 root = root->GetOuterWebContents();
4242 return root;
4243}
4244
[email protected]b172aee2012-04-10 17:05:264245void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444246 // Don't send notifications if we are just creating a swapped-out RVH for
4247 // the opener chain. These won't be used for view-source or WebUI, so it's
4248 // ok to return early.
creiscce56cd2014-09-29 22:45:224249 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444250 return;
4251
[email protected]86f98a22013-03-20 14:35:004252 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314253 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084254
[email protected]8ff00d72012-10-23 19:12:214255 NotificationService::current()->Notify(
4256 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4257 Source<WebContents>(this),
4258 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324259
[email protected]60780f412013-02-25 16:34:104260 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264261
4262 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:254263 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:324264}
4265
[email protected]b172aee2012-04-10 17:05:264266void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524267 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324268 // Don't notify the world, since this came from a renderer in the
4269 // background.
4270 return;
4271 }
4272
[email protected]da7a7182013-09-06 08:11:114273 notify_disconnection_ = true;
4274 // TODO(avi): Remove. http://crbug.com/170921
4275 NotificationService::current()->Notify(
4276 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4277 Source<WebContents>(this),
4278 NotificationService::NoDetails());
4279
[email protected]be1f56ab2011-12-22 06:55:314280 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234281 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304282
4283 // Restore the focus to the tab (otherwise the focus will be on the top
4284 // window).
[email protected]484ae5912010-09-29 19:16:144285 if (was_crashed && !FocusLocationBarByDefault() &&
4286 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064287 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144288 }
[email protected]32ded2212011-11-10 18:51:434289
[email protected]d8c660432011-12-22 20:51:254290 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:324291}
4292
[email protected]ec6a7eb2013-04-22 17:34:224293void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4294 base::TerminationStatus status,
4295 int error_code) {
[email protected]151a63d2011-12-20 22:32:524296 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324297 // The pending page's RenderViewHost is gone.
4298 return;
4299 }
4300
[email protected]2fcdcc32014-03-05 02:14:074301 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4302 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:154303 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464304 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074305
[email protected]698191dc2014-02-25 01:06:134306 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174307 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134308
[email protected]f738bdcb2014-07-11 20:40:444309 if (delegate_)
4310 delegate_->HideValidationMessage(this);
4311
[email protected]960b0372014-05-19 18:01:004312 // Reset the loading progress. TODO(avi): What does it mean to have a
4313 // "renderer crash" when there is more than one renderer process serving a
4314 // webpage? Once this function is called at a more granular frame level, we
4315 // probably will need to more granularly reset the state here.
4316 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254317 NotifyDisconnected();
4318 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004319
[email protected]d8c660432011-12-22 20:51:254320 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:274321 observers_,
[email protected]58d5cfe2013-07-10 02:40:524322 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:324323}
4324
[email protected]b172aee2012-04-10 17:05:264325void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:254326 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:064327}
4328
[email protected]b172aee2012-04-10 17:05:264329void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:104330 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:044331 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384332 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4333
creise1d3e5b2014-12-01 18:21:574334 // Ensure that this state update comes from a RenderViewHost that belongs to
4335 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414336 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574337 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414338 return;
[email protected]420ae012009-04-24 05:16:324339
avi286019ce2015-07-29 01:26:584340 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:324341 // when the user is scrolling and entering form data, as well as when we're
4342 // leaving a page, in which case our state may have already been moved to
4343 // the next page. The navigation controller will look up the appropriate
4344 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:584345 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:114346 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584347 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:114348 if (!entry)
[email protected]420ae012009-04-24 05:16:324349 return;
[email protected]420ae012009-04-24 05:16:324350
nasko346969912015-12-16 22:36:474351 // Sanity check that ensures nav_entry_id and page_id point to the same
4352 // navigation entry.
4353 if (rvhi->GetMainFrame()) {
4354 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4355 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4356 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534357
nasko346969912015-12-16 22:36:474358 DCHECK_EQ(entry, new_entry);
4359 }
creisd63f6c4a2015-11-06 19:05:534360
[email protected]691aa2f2013-05-28 22:52:044361 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324362 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044363 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114364 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324365}
4366
sky8b00392d2015-01-10 00:30:284367void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4368 const GURL& url) {
4369 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4370 // If we're fullscreen only update the url if it's from the fullscreen
4371 // renderer.
4372 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444373 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284374 return;
4375 }
[email protected]6934a702011-12-20 00:04:514376 if (delegate_)
avi450ce00e2014-09-24 01:58:524377 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324378}
4379
[email protected]b172aee2012-04-10 17:05:264380void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104381#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294382 // The UI may be in an event-tracking loop, such as between the
4383 // mouse-down and mouse-up in text selection or a button click.
4384 // Defer the close until after tracking is complete, so that we
4385 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294386 // TODO(shess): This could get more fine-grained. For instance,
4387 // closing a tab in another window while selecting text in the
4388 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104389 if (view_->IsEventTracking()) {
4390 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294391 return;
4392 }
[email protected]60780f412013-02-25 16:34:104393#endif
[email protected]07707302009-11-06 00:50:294394
[email protected]420ae012009-04-24 05:16:324395 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524396 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514397 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324398}
4399
[email protected]b172aee2012-04-10 17:05:264400void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514401 if (delegate_ && delegate_->IsPopupOrPanel(this))
4402 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324403}
4404
fdegansa696e5112015-04-17 01:57:594405void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094406 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254407 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084408
4409 // Notify accessibility that the user is navigating away from the
4410 // current document.
4411 //
4412 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084413 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594414 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084415 if (manager)
4416 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324417}
4418
fdegansc73eec22015-03-19 14:47:544419void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084420 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324421
[email protected]9595fd82013-04-19 21:28:494422 // Use the last committed entry rather than the active one, in case a
4423 // pending entry has been created.
4424 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204425 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494426
[email protected]420ae012009-04-24 05:16:324427 // An entry may not exist for a stop when loading an initial blank page or
4428 // if an iframe injected by script into a blank page finishes loading.
4429 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204430 base::TimeDelta elapsed =
4431 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324432
4433 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514434 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:324435 elapsed,
4436 &controller_,
4437 controller_.GetCurrentEntryIndex()));
4438 }
4439
clamy44e84ce2016-02-22 15:38:254440 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324441}
4442
fdegansa696e5112015-04-17 01:57:594443void WebContentsImpl::DidChangeLoadProgress() {
4444 double load_progress = frame_tree_.load_progress();
4445
4446 // The delegate is notified immediately for the first and last updates. Also,
4447 // since the message loop may be pretty busy when a page is loaded, it might
4448 // not execute a posted task in a timely manner so the progress report is sent
4449 // immediately if enough time has passed.
4450 base::TimeDelta min_delay =
4451 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4452 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4453 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4454
4455 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4456 // If there is a pending task to send progress, it is now obsolete.
4457 loading_weak_factory_.InvalidateWeakPtrs();
4458
4459 // Notify the load progress change.
4460 SendChangeLoadProgress();
4461
4462 // Clean-up the states if needed.
4463 if (load_progress == 1.0)
4464 ResetLoadProgressState();
4465 return;
4466 }
4467
4468 if (loading_weak_factory_.HasWeakPtrs())
4469 return;
4470
skyostil95082a62015-06-05 19:53:074471 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4472 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4473 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594474 min_delay);
4475}
4476
clamycbf524d42016-09-27 12:48:354477ScopedVector<NavigationThrottle> WebContentsImpl::CreateThrottlesForNavigation(
4478 NavigationHandle* navigation_handle) {
4479 return GetContentClient()->browser()->CreateThrottlesForNavigation(
4480 navigation_handle);
4481}
4482
clamy1e5574e2016-09-29 16:48:444483std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
4484 NavigationHandle* navigation_handle) {
4485 DCHECK(IsBrowserSideNavigationEnabled());
4486 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
4487}
4488
[email protected]b172aee2012-04-10 17:05:264489void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164490 controller_.DiscardNonCommittedEntries();
4491
4492 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214493 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164494}
4495
[email protected]59167c22013-06-03 18:07:324496void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104497 has_accessed_initial_document_ = true;
4498
[email protected]d1371bf8e2014-04-19 03:26:244499 // We may have left a failed browser-initiated navigation in the address bar
4500 // to let the user edit it and try again. Clear it now that content might
4501 // show up underneath it.
4502 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454503 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244504
[email protected]59167c22013-06-03 18:07:324505 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504506 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324507}
4508
alexmosbe2f4c32015-03-10 02:30:234509void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4510 const std::string& name) {
4511 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4512 FrameNameChanged(render_frame_host, name));
4513}
4514
[email protected]39f2f9252014-05-03 00:54:014515void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294516 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094517 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294518 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094519
4520 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214521 NotificationService::current()->Notify(
4522 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4523 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294524 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084525}
4526
creis8eb8ef22015-11-04 22:51:384527void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4528 const PageState& page_state) {
4529 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4530
4531 // The state update affects the last NavigationEntry associated with the given
4532 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4533 // in the case of an UpdateState from a frame being swapped out). We track
4534 // which entry this is in the RenderFrameHost's nav_entry_id.
4535 RenderFrameHostImpl* rfhi =
4536 static_cast<RenderFrameHostImpl*>(render_frame_host);
4537 NavigationEntryImpl* entry =
4538 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4539 if (!entry)
4540 return;
4541
4542 FrameNavigationEntry* frame_entry =
4543 entry->GetFrameEntry(rfhi->frame_tree_node());
4544 if (!frame_entry)
4545 return;
4546
creisd06a9422015-11-11 03:08:454547 // The SiteInstance might not match if we do a cross-process navigation with
4548 // replacement (e.g., auto-subframe), in which case the swap out of the old
4549 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4550 // has already been replaced and destroyed.
4551 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4552 return;
4553
creis8eb8ef22015-11-04 22:51:384554 if (page_state == frame_entry->page_state())
4555 return; // Nothing to update.
4556
creisfafed882016-07-29 00:03:094557 if (!page_state.IsValid()) {
4558 // Temporarily generate a minidump to diagnose https://crbug.com/568703.
4559 base::debug::DumpWithoutCrashing();
4560 NOTREACHED() << "Shouldn't set an empty PageState.";
4561 }
nasko34634672016-07-29 18:46:064562
4563 // The document_sequence_number and item_sequence_number recorded in the
4564 // FrameNavigationEntry should not differ from the one coming with the update,
4565 // since it must come from the same document. Do not update it if a difference
4566 // is detected, as this indicates that |frame_entry| is not the correct one.
4567 ExplodedPageState exploded_state;
4568 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
4569 return;
4570
4571 if (exploded_state.top.document_sequence_number !=
4572 frame_entry->document_sequence_number() ||
4573 exploded_state.top.item_sequence_number !=
4574 frame_entry->item_sequence_number()) {
4575 return;
4576 }
4577
nasko04a322f25a2016-09-01 00:00:344578 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:384579 controller_.NotifyEntryChanged(entry);
4580}
4581
[email protected]ef3adfc2014-05-11 00:04:544582void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104583 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544584 const base::string16& title,
4585 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544586 // If we have a title, that's a pretty good indication that we've started
4587 // getting useful data.
4588 SetNotWaitingForResponse();
4589
4590 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584591 // For example, it might be from a recently swapped out RFH.
creisad8c31a2016-05-24 17:07:044592 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
creise64343ae2016-05-23 20:02:404593 render_frame_host->GetSiteInstance(), page_id);
creisad8c31a2016-05-24 17:07:044594
creisad8c31a2016-05-24 17:07:044595 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4596 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
creis0bfe5282016-06-02 06:46:204597 if (SiteIsolationPolicy::AreCrossProcessFramesPossible()) {
4598 // In out-of-process iframe enabled modes, page_id can't keep track of
4599 // navigations in other processes, so we must use nav_entry_id.
4600 // TODO(creis): Switch to use this as the default.
4601 entry = new_entry;
creis0bfe5282016-06-02 06:46:204602 }
creis03e1338d2016-10-04 22:47:284603 // (In modes that have no out-of-process iframes, nav_entry_id and page_id
4604 // will usually agree on which entry to update, but may disagree if commits
4605 // from a previous RFH have been ignored, resetting the RFH's nav_entry_id.)
[email protected]ef3adfc2014-05-11 00:04:544606
4607 // We can handle title updates when we don't have an entry in
4608 // UpdateTitleForEntry, but only if the update is from the current RVH.
4609 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584610 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544611 return;
4612
4613 // TODO(evan): make use of title_direction.
4614 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:134615 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:544616}
4617
4618void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4619 const std::string& encoding) {
4620 SetEncoding(encoding);
4621}
4622
[email protected]39f2f9252014-05-03 00:54:014623void WebContentsImpl::DocumentAvailableInMainFrame(
4624 RenderViewHost* render_view_host) {
4625 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4626 DocumentAvailableInMainFrame());
4627}
naskoc0fceff2015-04-30 15:53:524628
[email protected]e1c3a552012-05-04 20:51:324629void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4630 // Tell the active RenderViewHost to run unload handlers and close, as long
4631 // as the request came from a RenderViewHost in the same BrowsingInstance.
4632 // In most cases, we receive this from a swapped out RenderViewHost.
4633 // It is possible to receive it from one that has just been swapped in,
4634 // in which case we might as well deliver the message anyway.
4635 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524636 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324637}
4638
alexmose7da5a12015-04-09 02:22:164639bool WebContentsImpl::ShouldRouteMessageEvent(
4640 RenderFrameHost* target_rfh,
4641 SiteInstance* source_site_instance) const {
4642 // Allow the message if this WebContents is dedicated to a browser plugin
4643 // guest.
[email protected]0eba810b2012-10-18 03:19:364644 // Note: This check means that an embedder could theoretically receive a
4645 // postMessage from anyone (not just its own guests). However, this is
4646 // probably not a risk for apps since other pages won't have references
4647 // to App windows.
alexmose7da5a12015-04-09 02:22:164648 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4649}
[email protected]f546640b2012-05-15 00:03:494650
alexmos58729042015-06-18 23:20:004651void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164652 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4653 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494654
alexmose7da5a12015-04-09 02:22:164655 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144656 // If this message is going to outer WebContents from inner WebContents,
4657 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4658 // already created a RenderFrameProxyHost for that purpose.
4659 if (GetBrowserPluginEmbedder() &&
ekaramad1beabecc2016-09-23 20:18:174660 GuestMode::IsCrossProcessFrameGuest(source_web_contents)) {
lazyboy6ec48b2a2015-06-29 15:18:144661 return;
4662 }
4663
lfg812874d2016-02-09 22:26:134664 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064665 // We create a RenderFrameProxyHost for the embedder in the guest's render
4666 // process but we intentionally do not expose the embedder's opener chain
4667 // to it.
4668 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4669 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494670 } else {
alexmos58729042015-06-18 23:20:004671 RenderFrameHostImpl* source_rfhi =
4672 static_cast<RenderFrameHostImpl*>(source_rfh);
4673 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394674 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494675 }
4676 }
[email protected]f546640b2012-05-15 00:03:494677}
4678
avallee0206f782016-07-28 18:55:334679void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
4680 SiteInstance* source) {
ekaramad1beabecc2016-09-23 20:18:174681 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) {
avallee0206f782016-07-28 18:55:334682 frame_tree_.SetFocusedFrame(node, source);
4683 return;
4684 }
4685
4686 // 1. Find old focused frame and unfocus it.
4687 // 2. Focus the new frame in the current FrameTree.
4688 // 3. Set current WebContents as focused.
4689 WebContentsImpl* old_focused_contents = GetFocusedWebContents();
4690 if (old_focused_contents != this) {
4691 // Focus is moving between frame trees, unfocus the frame in the old tree.
4692 old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source);
4693 GetOutermostWebContents()->node_->SetFocusedWebContents(this);
4694 }
4695
4696 frame_tree_.SetFocusedFrame(node, source);
4697
4698 // TODO(avallee): Remove this once page focus is fixed.
4699 RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost();
ekaramad1beabecc2016-09-23 20:18:174700 if (rwh && old_focused_contents != this)
avallee0206f782016-07-28 18:55:334701 rwh->Focus();
4702}
4703
avib7348942015-12-25 20:57:104704bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264705 const base::string16& message,
avib7348942015-12-25 20:57:104706 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264707 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254708 if (!delegate_)
4709 return false;
4710 return delegate_->AddMessageToConsole(this, level, message, line_no,
4711 source_id);
4712}
4713
dominickn9c7ceaa32016-02-27 01:52:534714void WebContentsImpl::OnUserInteraction(
4715 RenderWidgetHostImpl* render_widget_host,
4716 const blink::WebInputEvent::Type type) {
kenrb19221852016-04-29 17:21:404717 // Ignore unless the widget is currently in the frame tree.
4718 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:224719 return;
4720
dominickn2dd142dd2015-10-29 05:30:504721 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4722 DidGetUserInteraction(type));
dominickn9c7ceaa32016-02-27 01:52:534723
4724 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4725 // Exclude scroll events as user gestures for resource load dispatches.
4726 // rdh is NULL in unittests.
4727 if (rdh && type != blink::WebInputEvent::MouseWheel)
scottmge22a5e52016-06-30 00:36:514728 rdh->OnUserGesture();
dominickn2dd142dd2015-10-29 05:30:504729}
4730
[email protected]b172aee2012-04-10 17:05:264731void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444732 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254733 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444734}
4735
avic3aa8422015-11-09 20:57:224736void WebContentsImpl::RendererUnresponsive(
clamy639fdffb2016-07-18 18:13:324737 RenderWidgetHostImpl* render_widget_host,
4738 RenderWidgetHostDelegate::RendererUnresponsiveType type) {
afakhry98241832016-03-11 19:27:474739 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4740 OnRendererUnresponsive(render_widget_host));
4741
[email protected]992db4c2011-05-12 15:37:154742 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224743 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154744 return;
4745
creiscce56cd2014-09-29 22:45:224746 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224747 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584748
[email protected]e5fc1632011-08-08 07:51:534749 // Ignore renderer unresponsive event if debugger is attached to the tab
4750 // since the event may be a result of the renderer sitting on a breakpoint.
4751 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364752 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534753 return;
4754
clamy639fdffb2016-07-18 18:13:324755 // Record histograms about the type of renderer hang.
4756 UMA_HISTOGRAM_ENUMERATION(
4757 "ChildProcess.HangRendererType", type,
4758 RenderWidgetHostDelegate::RENDERER_UNRESPONSIVE_MAX);
4759
metaflow73fc9552016-05-23 18:26:484760 // We might have been waiting for both beforeunload and unload ACK.
4761 // Check if tab is to be unloaded first.
4762 if (rfhi->IsWaitingForUnloadACK()) {
4763 // Hang occurred while firing the unload handler.
[email protected]420ae012009-04-24 05:16:324764 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224765 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324766
[email protected]fa944cb82013-11-15 17:51:214767 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324768 return;
4769
metaflow73fc9552016-05-23 18:26:484770 // If the tab hangs in the unload handler there's really nothing we can do
4771 // to recover. Pretend the unload listeners have all fired and close
[email protected]2e9d79f2013-08-16 05:45:564772 // the tab.
metaflow73fc9552016-05-23 18:26:484773 Close();
4774 return;
4775 }
4776
4777 if (rfhi->is_waiting_for_beforeunload_ack()) {
4778 // If the hang is in the beforeunload handler, pretend the beforeunload
4779 // listeners have all fired and allow the delegate to continue closing;
4780 // the user will not have the option of cancelling the close.
4781 rfhi->SimulateBeforeUnloadAck();
[email protected]420ae012009-04-24 05:16:324782 return;
4783 }
4784
creisc014b402015-04-23 16:41:454785 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474786 return;
4787
[email protected]6934a702011-12-20 00:04:514788 if (delegate_)
4789 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324790}
4791
avic3aa8422015-11-09 20:57:224792void WebContentsImpl::RendererResponsive(
4793 RenderWidgetHostImpl* render_widget_host) {
4794 if (render_widget_host != GetRenderViewHost()->GetWidget())
4795 return;
4796
[email protected]6934a702011-12-20 00:04:514797 if (delegate_)
4798 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324799}
4800
[email protected]b172aee2012-04-10 17:05:264801void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554802 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324803 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124804 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4805 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514806 if (delegate_)
4807 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094808 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324809}
4810
[email protected]58d5cfe2013-07-10 02:40:524811void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544812 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234813 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224814 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544815}
4816
[email protected]b172aee2012-04-10 17:05:264817void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104818 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214819 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264820 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4821 // here during container initialization and normal window size will be set
4822 // later. In case of tab duplication this resizing to 0x0 prevents setting
4823 // normal size later so just ignore it.
4824 if (!size.IsEmpty())
4825 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324826}
4827
[email protected]af905902013-10-01 21:38:514828void WebContentsImpl::CancelModalDialogsForRenderManager() {
4829 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544830 // deferrer would prevent us from swapping out. We also clear the state
4831 // because this is a cross-process navigation, which means that it's a new
4832 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174833 //
4834 // Note that we don't bother telling browser_plugin_embedder_ because the
4835 // cross-process navigation will either destroy the browser plugins or not
4836 // require their dialogs to close.
avi5d3b8692016-10-12 22:00:464837 if (dialog_manager_) {
4838 dialog_manager_->CancelDialogs(this,
4839 false, // suppress_callbacks,
4840 true); // reset_state
4841 }
[email protected]af905902013-10-01 21:38:514842}
4843
[email protected]02d7b6e2014-06-24 21:01:504844void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4845 RenderFrameHost* new_host,
4846 bool is_main_frame) {
4847 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054848 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504849 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084850
[email protected]02d7b6e2014-06-24 21:01:504851 // Make sure the visible RVH reflects the new delegate's preferences.
4852 if (delegate_)
4853 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394854
[email protected]02d7b6e2014-06-24 21:01:504855 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4856 }
4857
4858 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544859}
4860
naskof5940b9f2015-03-02 23:04:054861void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4862 RenderViewHost* old_host,
4863 RenderViewHost* new_host) {
4864 NotifyViewSwapped(old_host, new_host);
4865}
4866
[email protected]b172aee2012-04-10 17:05:264867NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194868 return GetController();
[email protected]3a3d47472010-07-15 21:03:544869}
4870
dcheng59716272016-04-09 05:19:084871std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294872 const GURL& url) {
dcheng59716272016-04-09 05:19:084873 return std::unique_ptr<WebUIImpl>(
4874 static_cast<WebUIImpl*>(CreateWebUI(url, std::string())));
[email protected]420ae012009-04-24 05:16:324875}
4876
[email protected]10f417c52011-12-28 21:04:234877NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264878 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324879 return controller_.GetLastCommittedEntry();
4880}
4881
lfgbede6392015-09-11 21:54:064882void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4883 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:334884 RenderWidgetHostViewBase* rwh_view =
4885 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:524886
[email protected]420ae012009-04-24 05:16:324887 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444888 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214889 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064890}
4891
4892bool WebContentsImpl::CreateRenderViewForRenderManager(
4893 RenderViewHost* render_view_host,
4894 int opener_frame_routing_id,
4895 int proxy_routing_id,
4896 const FrameReplicationState& replicated_frame_state) {
4897 TRACE_EVENT0("browser,navigation",
4898 "WebContentsImpl::CreateRenderViewForRenderManager");
4899
4900 if (proxy_routing_id == MSG_ROUTING_NONE)
4901 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324902
[email protected]74ce1ad2011-12-16 21:51:464903 // Make sure we use the correct starting page_id in the new RenderView.
4904 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104905 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584906 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464907
alexmos5ac402d2015-07-09 07:51:104908 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4909 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4910 max_page_id, replicated_frame_state,
4911 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524912 return false;
[email protected]14392a52012-05-02 20:28:444913 }
[email protected]a4127722011-04-27 23:13:524914
avi2b177592014-12-10 02:08:024915 SetHistoryOffsetAndLengthForView(render_view_host,
4916 controller_.GetLastCommittedEntryIndex(),
4917 controller_.GetEntryCount());
4918
[email protected]a220b5932013-09-21 03:47:444919#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504920 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4921 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444922 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444923 if (rwh_view) {
4924 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4925 render_widget_host->WasResized();
4926 }
[email protected]f8233cc2011-05-31 20:24:504927#endif
4928
[email protected]420ae012009-04-24 05:16:324929 return true;
4930}
4931
[email protected]82307f6b2014-08-07 03:30:124932bool WebContentsImpl::CreateRenderFrameForRenderManager(
4933 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044934 int proxy_routing_id,
4935 int opener_routing_id,
japhete6adf142014-10-31 00:01:494936 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044937 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434938 TRACE_EVENT0("browser,navigation",
4939 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124940
4941 RenderFrameHostImpl* rfh =
4942 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044943 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4944 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124945 return false;
4946
4947 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4948 // RenderFrameHost will have to be associated with the appropriate
4949 // RenderWidgetHostView or a new one should be created here.
4950
4951 return true;
4952}
4953
mfomitchev2b8b066a2016-01-28 19:23:154954#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454955
[email protected]155c7f22013-12-09 17:07:184956base::android::ScopedJavaLocalRef<jobject>
4957WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404958 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564959 return GetWebContentsAndroid()->GetJavaObject();
4960}
[email protected]155c7f22013-12-09 17:07:184961
[email protected]0e813a52014-08-13 10:34:564962WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184963 WebContentsAndroid* web_contents_android =
4964 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4965 if (!web_contents_android) {
4966 web_contents_android = new WebContentsAndroid(this);
4967 SetUserData(kWebContentsAndroidKey, web_contents_android);
4968 }
[email protected]0e813a52014-08-13 10:34:564969 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184970}
4971
paulmeyerc0b762b2016-04-13 11:55:174972void WebContentsImpl::ActivateNearestFindResult(float x,
4973 float y) {
4974 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
4975}
4976
4977void WebContentsImpl::RequestFindMatchRects(int current_version) {
4978 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
4979}
4980
[email protected]7d244f12013-08-22 21:41:514981bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064982 return CreateRenderViewForRenderManager(
4983 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064984 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514985}
[email protected]fc2b46b2014-05-03 16:33:454986
sammcf5f1b0f2016-09-20 23:05:114987shell::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
4988 if (!java_interfaces_) {
4989 shell::mojom::InterfaceProviderPtr provider;
4990 BindInterfaceRegistryForWebContents(mojo::GetProxy(&provider), this);
4991 java_interfaces_.reset(new shell::InterfaceProvider);
4992 java_interfaces_->Bind(std::move(provider));
4993 }
4994 return java_interfaces_.get();
4995}
4996
[email protected]fc2b46b2014-05-03 16:33:454997#elif defined(OS_MACOSX)
4998
[email protected]75f4df72014-07-16 22:39:424999void WebContentsImpl::SetAllowOtherViews(bool allow) {
5000 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:455001}
5002
[email protected]75f4df72014-07-16 22:39:425003bool WebContentsImpl::GetAllowOtherViews() {
5004 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:455005}
5006
[email protected]7d244f12013-08-22 21:41:515007#endif
5008
pkotwicz75ca8ffd2016-02-16 23:10:195009void WebContentsImpl::OnDidDownloadImage(
5010 const ImageDownloadCallback& callback,
5011 int id,
5012 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:525013 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:185014 const std::vector<SkBitmap>& images,
5015 const std::vector<gfx::Size>& original_image_sizes) {
5016 callback.Run(id, http_status_code, image_url, images, original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:195017}
5018
[email protected]6fba26d2014-04-29 09:38:285019void WebContentsImpl::OnDialogClosed(int render_process_id,
5020 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:265021 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:495022 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:265023 bool success,
[email protected]fcf75d42013-12-03 20:11:265024 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:285025 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
5026 render_frame_id);
[email protected]87de04b02014-04-08 22:14:495027 last_dialog_suppressed_ = dialog_was_suppressed;
5028
[email protected]beb440c2009-11-06 04:08:545029 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:235030 // It is possible for the current RenderFrameHost to have changed in the
5031 // meantime. Do not reset the navigation state in that case.
5032 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:255033 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:235034 controller_.DiscardNonCommittedEntries();
5035 }
[email protected]ec8e8b02013-06-19 04:57:105036
[email protected]6d65a462013-06-21 21:29:125037 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
5038 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:545039 }
[email protected]87de04b02014-04-08 22:14:495040
avi85ee8362016-10-08 02:09:085041 is_showing_javascript_dialog_ = false;
[email protected]beb440c2009-11-06 04:08:545042 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:285043 if (rfh) {
5044 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
5045 dialog_was_suppressed);
5046 } else {
5047 // Don't leak the sync IPC reply if the RFH or process is gone.
5048 delete reply_msg;
5049 }
[email protected]beb440c2009-11-06 04:08:545050}
5051
[email protected]b172aee2012-04-10 17:05:265052void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:545053 if (encoding == last_reported_encoding_)
5054 return;
5055 last_reported_encoding_ = encoding;
5056
5057 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:125058 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:105059}
[email protected]f45d2a72010-03-08 23:28:355060
[email protected]1ac10dca2013-08-20 20:47:045061bool WebContentsImpl::IsHidden() {
5062 return capturer_count_ == 0 && !should_normally_be_visible_;
5063}
5064
rob97250742015-12-10 17:45:155065int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:145066 if (node_ && node_->outer_web_contents())
5067 return node_->outer_contents_frame_tree_node_id();
5068
nick2482a2d2015-12-18 01:39:375069 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:145070}
5071
[email protected]b0936d22013-11-28 06:47:365072RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:215073 return frame_tree_.root()->render_manager();
5074}
5075
[email protected]f8497342013-02-05 22:15:025076BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:395077 return browser_plugin_guest_.get();
5078}
5079
[email protected]738f57a2013-06-29 21:06:545080void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
5081 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:145082 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:545083 browser_plugin_guest_.reset(guest);
5084}
5085
[email protected]f8497342013-02-05 22:15:025086BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:395087 return browser_plugin_embedder_.get();
5088}
[email protected]8ff00d72012-10-23 19:12:215089
fsamuel60b42282015-03-10 03:29:145090void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
5091 if (browser_plugin_embedder_)
5092 return;
5093 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
5094}
5095
[email protected]fc2b46b2014-05-03 16:33:455096gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:215097 gfx::Size size;
5098 if (delegate_)
5099 size = delegate_->GetSizeForNewRenderView(this);
5100 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:455101 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:215102 return size;
5103}
5104
[email protected]ae7eeda2014-07-04 01:53:265105void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
5106 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:025107 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:555108}
5109
[email protected]222f5822014-02-05 23:40:495110void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
5111 if (!delegate_)
5112 return;
5113 const gfx::Size new_size = GetPreferredSize();
5114 if (new_size != old_size)
5115 delegate_->UpdatePreferredSize(this, new_size);
5116}
5117
dbeama1b926a2015-08-31 23:17:515118WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
5119 const std::string& frame_name) {
5120 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
5121 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
5122 CreateWebUIControllerForURL(web_ui, url);
5123 if (controller) {
5124 web_ui->AddMessageHandler(new GenericHandler());
5125 web_ui->SetController(controller);
5126 return web_ui;
5127 }
5128
5129 delete web_ui;
5130 return NULL;
5131}
5132
paulmeyerc0b762b2016-04-13 11:55:175133FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
5134 // TODO(paulmeyer): This method will need to access (or potentially create)
5135 // the FindRequestManager in the outermost WebContents once find-in-page
5136 // across GuestViews is implemented.
5137 if (!find_request_manager_)
5138 find_request_manager_.reset(new FindRequestManager(this));
5139
5140 return find_request_manager_.get();
5141}
5142
5143void WebContentsImpl::NotifyFindReply(int request_id,
5144 int number_of_matches,
5145 const gfx::Rect& selection_rect,
5146 int active_match_ordinal,
5147 bool final_update) {
paulmeyer60b5d832016-08-31 18:46:345148 if (delegate_ && !is_being_destroyed_) {
paulmeyerc0b762b2016-04-13 11:55:175149 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
5150 active_match_ordinal, final_update);
5151 }
5152}
5153
ortuno467e5792016-06-10 04:32:395154void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
5155 // Trying to invalidate the tab state while being destroyed could result in a
5156 // use after free.
5157 if (IsBeingDestroyed()) {
5158 return;
5159 }
5160 // Notify for UI updates if the state changes.
5161 bluetooth_connected_device_count_++;
5162 if (bluetooth_connected_device_count_ == 1) {
5163 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
5164 }
5165}
5166
5167void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
5168 // Trying to invalidate the tab state while being destroyed could result in a
5169 // use after free.
5170 if (IsBeingDestroyed()) {
5171 return;
5172 }
5173 // Notify for UI updates if the state changes.
5174 DCHECK(bluetooth_connected_device_count_ != 0);
5175 bluetooth_connected_device_count_--;
5176 if (bluetooth_connected_device_count_ == 0) {
5177 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
5178 }
5179}
5180
paulmeyerc0b762b2016-04-13 11:55:175181#if defined(OS_ANDROID)
5182void WebContentsImpl::NotifyFindMatchRectsReply(
5183 int version,
5184 const std::vector<gfx::RectF>& rects,
5185 const gfx::RectF& active_rect) {
5186 if (delegate_)
5187 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
5188}
5189#endif
5190
[email protected]34ff1cfc2014-08-20 06:16:055191void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
5192 force_disable_overscroll_content_ = force_disable;
5193 if (view_)
5194 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
5195}
5196
dalecurtis88c240072015-12-09 02:11:185197void WebContentsImpl::MediaStartedPlaying(
5198 const WebContentsObserver::MediaPlayerId& id) {
5199 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
5200}
5201
5202void WebContentsImpl::MediaStoppedPlaying(
5203 const WebContentsObserver::MediaPlayerId& id) {
5204 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
5205}
5206
tapted65ff2ea72016-03-01 23:39:005207void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
5208 if (!did_first_set_visible_) {
5209 // If this WebContents has not yet been set to be visible for the first
5210 // time, ignore any requests to make it hidden, since resources would
5211 // immediately be destroyed and only re-created after content loaded. In
5212 // this state the window content is undefined and can show garbage.
5213 // However, the page load mechanism requires an activation call through a
5214 // visibility call to (re)load.
5215 if (visible) {
5216 did_first_set_visible_ = true;
5217 WasShown();
5218 }
5219 return;
5220 }
5221 if (visible == should_normally_be_visible_)
5222 return;
5223
5224 if (visible)
5225 WasShown();
5226 else
5227 WasHidden();
5228}
5229
aelias5252baa2016-04-10 01:18:025230void WebContentsImpl::UpdateOverridingUserAgent() {
5231 std::set<RenderViewHost*> render_view_host_set;
5232 for (FrameTreeNode* node : frame_tree_.Nodes()) {
5233 RenderWidgetHost* render_widget_host =
5234 node->current_frame_host()->GetRenderWidgetHost();
5235 if (!render_widget_host)
5236 continue;
5237 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
5238 if (!render_view_host)
5239 continue;
5240 render_view_host_set.insert(render_view_host);
5241 }
5242 for (RenderViewHost* render_view_host : render_view_host_set)
5243 render_view_host->OnWebkitPreferencesChanged();
5244}
5245
avid53461d2016-02-25 17:15:045246void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
5247 JavaScriptDialogManager* dialog_manager) {
5248 dialog_manager_ = dialog_manager;
5249}
5250
rockotf62002a2016-09-15 00:08:595251void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) {
5252 auto it = binding_sets_.find(interface_name);
5253 if (it != binding_sets_.end())
5254 binding_sets_.erase(it);
5255}
5256
[email protected]8ff00d72012-10-23 19:12:215257} // namespace content