blob: 552dfb6fe864364b1037c41c7e7b4b9c90685e37 [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"
[email protected]cbb1ef592013-06-05 19:49:4613#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0714#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5615#include "base/logging.h"
avib7348942015-12-25 20:57:1016#include "base/macros.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2018#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2219#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0720#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5121#include "base/strings/string16.h"
22#include "base/strings/string_number_conversions.h"
23#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0024#include "base/strings/utf_string_conversions.h"
skyostil95082a62015-06-05 19:53:0725#include "base/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3726#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4227#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1028#include "build/build_config.h"
rsleevic327b48f82015-04-30 02:03:2529#include "components/mime_util/mime_util.h"
rsleevi24f64dc22015-08-07 21:39:2130#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3031#include "content/browser/accessibility/accessibility_mode_helper.h"
32#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1833#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3934#include "content/browser/browser_plugin/browser_plugin_embedder.h"
35#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5936#include "content/browser/child_process_security_policy_impl.h"
[email protected]5f2aa722013-08-07 16:59:4137#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0438#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4639#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1240#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1641#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1642#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4043#include "content/browser/frame_host/interstitial_page_impl.h"
44#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3345#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0146#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1847#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0748#include "content/browser/frame_host/render_frame_proxy_host.h"
[email protected]bffc8302014-01-23 20:52:1649#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5750#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0551#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4452#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4053#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3054#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5255#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1856#include "content/browser/media/media_web_contents_observer.h"
mlamouri918734092016-03-12 04:47:5257#include "content/browser/media/session/media_session.h"
[email protected]0bc7f3542013-10-21 15:05:5358#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0959#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3060#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5061#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3262#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5063#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5964#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4865#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0966#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3367#include "content/browser/site_instance_impl.h"
alogvinovf50445a2015-10-30 13:00:1268#include "content/browser/wake_lock/wake_lock_service_context.h"
[email protected]b5a40842012-11-28 15:26:1169#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5870#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0371#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5672#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1473#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4274#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4475#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1776#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0777#include "content/common/page_messages.h"
avi286019ce2015-07-29 01:26:5878#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5179#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0280#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3681#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1182#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2883#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4484#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3685#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1786#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1487#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4688#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1589#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0090#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2791#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0092#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3793#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1494#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3095#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3296#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0997#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:1298#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:3499#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:38100#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:42101#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:21102#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:08103#include "content/public/common/browser_plugin_guest_mode.h"
carloskd80262f52015-12-16 14:40:35104#include "content/public/common/browser_side_navigation_policy.h"
[email protected]54087fe2011-10-28 22:02:48105#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54106#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49107#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20108#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:01109#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:03110#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57111#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05112#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40113#include "mojo/common/url_type_converters.h"
114#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]8bfc8272013-09-09 20:10:53115#include "net/http/http_cache.h"
116#include "net/http/http_transaction_factory.h"
117#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34118#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40119#include "skia/public/type_converters.h"
alexmosaedfc6f2016-01-21 23:57:38120#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40121#include "third_party/skia/include/core/SkBitmap.h"
[email protected]a08412b62012-05-29 21:28:56122#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01123#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41124#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52125#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31126
[email protected]583418cc2013-01-17 14:01:10127#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40128#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15129#include "content/browser/android/date_time_chooser_android.h"
dalecurtisc85ed632016-01-13 00:22:46130#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18131#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15132#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10133
[email protected]f66df822012-05-18 16:52:17134#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50135#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57136#endif
[email protected]3e45ba92009-02-20 21:09:00137
fsamuel9cf7bdf2015-11-20 02:19:32138#if defined(MOJO_SHELL_CLIENT)
139#include "content/browser/web_contents/web_contents_view_mus.h"
140#include "content/public/common/mojo_shell_connection.h"
fsamuel6c6da0232015-11-26 05:13:46141#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32142#endif
143
[email protected]8ff00d72012-10-23 19:12:21144namespace content {
[email protected]420ae012009-04-24 05:16:32145namespace {
146
[email protected]960b0372014-05-19 18:01:00147const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41148const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05149
[email protected]155c7f22013-12-09 17:07:18150#if defined(OS_ANDROID)
151const char kWebContentsAndroidKey[] = "web_contents_android";
152#endif // OS_ANDROID
153
[email protected]e4abd3b42013-11-12 18:28:47154base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46155g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
156
[email protected]8bfc8272013-09-09 20:10:53157void NotifyCacheOnIO(
158 scoped_refptr<net::URLRequestContextGetter> request_context,
159 const GURL& url,
160 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58161 net::HttpCache* cache = request_context->GetURLRequestContext()->
162 http_transaction_factory()->GetCache();
163 if (cache)
164 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53165}
166
dcheng57e39e22016-01-21 00:25:38167bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
168 for (FrameTreeNode* node : tree->Nodes()) {
169 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
170 return true;
alexmos4cf2aa32015-07-15 23:40:43171 }
dcheng57e39e22016-01-21 00:25:38172 return false;
[email protected]95640212014-07-26 18:14:30173}
174
[email protected]95640212014-07-26 18:14:30175void SetAccessibilityModeOnFrame(AccessibilityMode mode,
176 RenderFrameHost* frame_host) {
177 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
178}
179
dtseng0dd3fa12015-07-22 19:00:52180void ResetAccessibility(RenderFrameHost* rfh) {
181 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
182}
183
[email protected]420ae012009-04-24 05:16:32184} // namespace
185
[email protected]54944cde2012-12-09 09:24:59186WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21187 FrameTreeNode* opener_node = nullptr;
188 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
189 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
190 params.opener_render_process_id, params.opener_render_frame_id);
191 if (opener_rfh)
192 opener_node = opener_rfh->frame_tree_node();
193 }
194 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19195}
196
197WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59198 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30199 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21200 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30201
202 for (SessionStorageNamespaceMap::const_iterator it =
203 session_storage_namespace_map.begin();
204 it != session_storage_namespace_map.end();
205 ++it) {
206 new_contents->GetController()
207 .SetSessionStorageNamespace(it->first, it->second.get());
208 }
209
[email protected]54944cde2012-12-09 09:24:59210 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19211 return new_contents;
[email protected]a81343d232011-12-27 07:39:20212}
[email protected]746d3052012-05-22 15:15:47213
nickf9acfbe2014-12-23 19:12:37214void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
215 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46216 g_created_callbacks.Get().push_back(callback);
217}
218
nickf9acfbe2014-12-23 19:12:37219void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
220 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46221 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
222 if (g_created_callbacks.Get().at(i).Equals(callback)) {
223 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
224 return;
225 }
226 }
227}
228
avidf38c952015-10-27 13:45:13229WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
230 if (!rvh)
231 return nullptr;
[email protected]746d3052012-05-22 15:15:47232 return rvh->GetDelegate()->GetAsWebContents();
233}
234
[email protected]a86c0e962013-12-17 17:10:39235WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13236 if (!rfh)
237 return nullptr;
238 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39239}
240
[email protected]7fff43e2013-05-21 20:21:10241// WebContentsImpl::DestructionObserver ----------------------------------------
242
243class WebContentsImpl::DestructionObserver : public WebContentsObserver {
244 public:
245 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
246 : WebContentsObserver(watched_contents),
247 owner_(owner) {
248 }
249
250 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58251 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58252 owner_->OnWebContentsDestroyed(
253 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10254 }
255
256 private:
257 WebContentsImpl* owner_;
258
259 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
260};
261
[email protected]8ed16472014-04-11 19:02:48262WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
263 int render_frame_id,
264 ColorChooser* chooser,
265 int identifier)
266 : render_process_id(render_process_id),
267 render_frame_id(render_frame_id),
268 chooser(chooser),
269 identifier(identifier) {
270}
271
272WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
273}
274
lazyboy6ec48b2a2015-06-29 15:18:14275// WebContentsImpl::WebContentsTreeNode ----------------------------------------
276WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
277 : outer_web_contents_(nullptr),
278 outer_contents_frame_tree_node_id_(
nick2482a2d2015-12-18 01:39:37279 FrameTreeNode::kFrameTreeNodeInvalidId) {
lazyboy6ec48b2a2015-06-29 15:18:14280}
281
282WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
283 // Remove child pointer from our parent.
284 if (outer_web_contents_) {
285 ChildrenSet& child_ptrs_in_parent =
286 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
287 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
288 DCHECK(iter != child_ptrs_in_parent.end());
289 child_ptrs_in_parent.erase(this);
290 }
291
292 // Remove parent pointers from our children.
293 // TODO(lazyboy): We should destroy the children WebContentses too. If the
294 // children do not manage their own lifetime, then we would leak their
295 // WebContentses.
296 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
297 child->outer_web_contents_ = nullptr;
298}
299
300void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
301 WebContentsImpl* outer_web_contents,
302 RenderFrameHostImpl* outer_contents_frame) {
303 outer_web_contents_ = outer_web_contents;
304 outer_contents_frame_tree_node_id_ =
305 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
306
307 if (!outer_web_contents_->node_)
308 outer_web_contents_->node_.reset(new WebContentsTreeNode());
309
310 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
311}
312
[email protected]b172aee2012-04-10 17:05:26313// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32314
alexmose201c7cd2015-06-10 17:14:21315WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42316 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22317 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57318 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21319 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01320 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57321 this,
322 this,
323 this,
324 this),
[email protected]6dfed692014-05-22 04:18:03325 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23326 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
327 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34328 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26329 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56330 upload_size_(0),
331 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16332 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47333 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10334 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28335 theme_color_(SK_ColorTRANSPARENT),
336 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29337 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55338 capturer_count_(0),
339 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00340 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57341 is_being_destroyed_(false),
342 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15343 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01344 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39345 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38346 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21347 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
348 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22349 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44350 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55351 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42352 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03353 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49354 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05355 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30356 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57357 geolocation_service_context_(new GeolocationServiceContext()),
waffles1c12bf402016-02-10 17:45:48358 accessibility_mode_(
359 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15360 audio_stream_monitor_(this),
ortuno32e7db3c2016-03-29 16:14:20361 bluetooth_device_connected_(false),
mohan.reddyaae039a2014-11-21 17:39:50362 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46363 page_scale_factor_is_one_(true),
pkotwicz75ca8ffd2016-02-16 23:10:19364 loading_weak_factory_(this),
365 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55366 frame_tree_.SetFrameRemoveListener(
367 base::Bind(&WebContentsImpl::OnFrameRemoved,
368 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46369#if defined(OS_ANDROID)
370 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
371#else
qinmin58567c82015-01-07 21:00:20372 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46373#endif
csharrisona2280cd2016-02-03 23:21:15374 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
alogvinovf50445a2015-10-30 13:00:12375 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
[email protected]332af7732009-03-11 13:21:35376}
initial.commit09911bf2008-07-26 23:55:29377
[email protected]b172aee2012-04-10 17:05:26378WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32379 is_being_destroyed_ = true;
380
kenrb2a565f82015-09-02 20:24:59381 rwh_input_event_router_.reset();
382
dcheng72be33c2016-01-21 04:11:31383 for (FrameTreeNode* node : frame_tree_.Nodes()) {
384 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
385 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38386 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38387 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31388 }
carlosk35f35af2015-12-01 10:55:40389
dcheng57e39e22016-01-21 00:25:38390 for (RenderWidgetHostImpl* widget : created_widgets_)
391 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26392 created_widgets_.clear();
393
[email protected]3ab9cb82011-06-03 18:02:07394 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15395 if (dialog_manager_)
avi2460c762015-04-17 15:21:54396 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07397
[email protected]8ed16472014-04-11 19:02:48398 if (color_chooser_info_.get())
399 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20400
[email protected]420ae012009-04-24 05:16:32401 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32402
[email protected]ca13a442012-04-17 14:00:12403 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21404 NotificationService::current()->Notify(
405 NOTIFICATION_WEB_CONTENTS_DESTROYED,
406 Source<WebContents>(this),
407 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32408
[email protected]df0c843f2014-05-23 20:37:23409 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14410 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23411 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59412
clamy0e119882015-07-31 16:12:33413 // Manually call the observer methods for the root frame tree node. It is
414 // necessary to manually delete all objects tracking navigations
415 // (NavigationHandle, NavigationRequest) for observers to be properly
416 // notified of these navigations stopping before the WebContents is
417 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23418 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56419
clamy0e119882015-07-31 16:12:33420 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56421 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33422 root->pending_frame_host()->SetNavigationHandle(
423 scoped_ptr<NavigationHandleImpl>());
424 }
naskob21fe4872015-02-24 14:15:56425 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33426 root->current_frame_host()->SetNavigationHandle(
427 scoped_ptr<NavigationHandleImpl>());
428
429 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35430 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41431 // Do not update state as the WebContents is being destroyed.
432 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33433 if (root->speculative_frame_host()) {
434 root->speculative_frame_host()->SetRenderFrameCreated(false);
435 root->speculative_frame_host()->SetNavigationHandle(
436 scoped_ptr<NavigationHandleImpl>());
437 }
438 }
[email protected]f273ee52013-10-18 16:05:27439
naskoa83483fb2015-02-27 16:57:10440 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
441 FrameDeleted(root->current_frame_host()));
442
[email protected]df0c843f2014-05-23 20:37:23443 if (root->pending_render_view_host()) {
444 FOR_EACH_OBSERVER(WebContentsObserver,
445 observers_,
446 RenderViewDeleted(root->pending_render_view_host()));
447 }
[email protected]c06c58c2014-03-12 20:31:59448
[email protected]f273ee52013-10-18 16:05:27449 FOR_EACH_OBSERVER(WebContentsObserver,
450 observers_,
[email protected]df0c843f2014-05-23 20:37:23451 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27452
[email protected]2db9bd72012-04-13 20:20:56453 FOR_EACH_OBSERVER(WebContentsObserver,
454 observers_,
[email protected]12a46832014-05-09 13:35:58455 WebContentsDestroyed());
456
457 FOR_EACH_OBSERVER(WebContentsObserver,
458 observers_,
459 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08460
[email protected]6934a702011-12-20 00:04:51461 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10462
463 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
464 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42465}
466
[email protected]d1198fd2012-08-13 22:50:19467WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59468 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21469 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03470 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21471 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19472
alexmosaedfc6f2016-01-21 23:57:38473 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
474
alexmose201c7cd2015-06-10 17:14:21475 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38476 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21477 new_contents->created_with_opener_ = true;
478 }
479
alexmosaedfc6f2016-01-21 23:57:38480 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
481 // flags, and these flags take effect immediately. An exception is if the
482 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
483 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
484 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
485 if (opener) {
486 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
487 const blink::WebSandboxFlags inherit_flag =
488 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
489 if ((opener_flags & inherit_flag) == inherit_flag) {
490 new_root->SetPendingSandboxFlags(opener_flags);
491 new_root->CommitPendingSandboxFlags();
492 }
493 }
494
alexmose201c7cd2015-06-10 17:14:21495 // This may be true even when opener is null, such as when opening blocked
496 // popups.
alexmos090fae8e2015-05-28 17:09:28497 if (params.created_with_opener)
498 new_contents->created_with_opener_ = true;
499
[email protected]4858e432014-06-23 18:14:17500 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06501 // This makes |new_contents| act as a guest.
502 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16503 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06504 // We are instantiating a WebContents for browser plugin. Set its subframe
505 // bit to true.
506 new_contents->is_subframe_ = true;
507 }
[email protected]54944cde2012-12-09 09:24:59508 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19509 return new_contents;
510}
511
[email protected]95640212014-07-26 18:14:30512// static
513std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
514 std::vector<WebContentsImpl*> result;
515 scoped_ptr<RenderWidgetHostIterator> widgets(
516 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30517 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30518 RenderViewHost* rvh = RenderViewHost::From(rwh);
519 if (!rvh)
520 continue;
521 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
522 if (!web_contents)
523 continue;
avidf38c952015-10-27 13:45:13524 if (web_contents->GetRenderViewHost() != rvh)
525 continue;
526 // Because a WebContents can only have one current RVH at a time, there will
527 // be no duplicate WebContents here.
528 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30529 }
530 return result;
531}
532
clamya16aa8172015-05-26 13:07:25533// static
534WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
535 FrameTreeNode* frame_tree_node) {
536 return static_cast<WebContentsImpl*>(
537 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
538}
539
clamy0d32d6d2015-11-24 11:16:26540// static
541WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
542 int render_frame_host_id) {
543 DCHECK_CURRENTLY_ON(BrowserThread::UI);
544 RenderFrameHost* render_frame_host =
545 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
546 if (!render_frame_host)
547 return nullptr;
548
549 return WebContents::FromRenderFrameHost(render_frame_host);
550}
551
[email protected]b0936d22013-11-28 06:47:36552RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21553 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28554}
555
[email protected]7bb761892012-07-20 09:32:47556bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
557 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44558 return OnMessageReceived(render_view_host, NULL, message);
559}
560
561bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
562 RenderFrameHost* render_frame_host,
563 const IPC::Message& message) {
564 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56565 if (GetWebUI() &&
566 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17567 return true;
[email protected]d2353452012-01-19 19:53:56568 }
[email protected]f82d57b52011-04-27 19:13:17569
brettw5a1613dc2015-06-02 05:34:43570 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25571 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33572 if (render_frame_host) {
573 while ((observer = it.GetNext()) != NULL)
574 if (observer->OnMessageReceived(message, render_frame_host))
575 return true;
576 } else {
577 while ((observer = it.GetNext()) != NULL)
578 if (observer->OnMessageReceived(message))
579 return true;
580 }
[email protected]403415a2011-01-10 18:57:53581
[email protected]1d62cf72014-02-07 21:31:57582 // Message handlers should be aware of which
583 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
584 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02585 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57586 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02587 else
[email protected]1d62cf72014-02-07 21:31:57588 render_view_message_source_ = render_view_host;
589
[email protected]724159a2010-12-30 01:11:18590 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33591 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40592 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
593 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05594 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
595 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48596 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
597 OnDocumentLoadedInFrame)
598 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
599 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
600 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
601 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
602 OnSetSelectedColorInColorChooser)
dalecurtis88c240072015-12-09 02:11:18603
dglazkov79c426102015-08-31 21:22:43604 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11605 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25606 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18607 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54608 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18609 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54610 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18611 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41612 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
613 OnDidDisplayContentWithCertificateErrors)
614 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
615 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25616 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26617 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46618 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
619 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21620 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48621 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
622 OnRegisterProtocolHandler)
623 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
624 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01625 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
626 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52627 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10628 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50629 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50630#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00631 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
632 OnPepperInstanceCreated)
633 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
634 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42635 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
636 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50637 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
638 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55639 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40640 OnBrowserPluginMessage(render_frame_host,
641 message))
thestigc4cac8f2014-09-04 21:17:50642#endif
[email protected]41225fe2013-03-29 05:32:02643 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07644 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
645 OnShowValidationMessage)
646 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
647 OnHideValidationMessage)
648 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
649 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15650#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52651 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48652 OnFindMatchRectsReply)
653 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
654 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48655#endif
[email protected]724159a2010-12-30 01:11:18656 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33657 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44658 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57659 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18660
[email protected]724159a2010-12-30 01:11:18661 return handled;
662}
663
nasko907fcb62015-01-28 04:24:11664bool WebContentsImpl::HasValidFrameSource() {
665 if (!render_frame_message_source_) {
666 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18667 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
668 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11669 return false;
670 }
671
672 return true;
673}
674
[email protected]b172aee2012-04-10 17:05:26675void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18676 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21677 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43678 if (delegate_)
679 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18680}
681
[email protected]d1198fd2012-08-13 22:50:19682NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56683 return controller_;
684}
685
[email protected]d1198fd2012-08-13 22:50:19686const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56687 return controller_;
688}
689
[email protected]8ff00d72012-10-23 19:12:21690BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55691 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30692}
693
[email protected]b172aee2012-04-10 17:05:26694const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24695 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32696 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51697 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31698}
699
[email protected]a093ce02013-07-22 20:53:14700const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24701 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32702 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24703 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
704}
705
706const GURL& WebContentsImpl::GetLastCommittedURL() const {
707 // We may not have a navigation entry yet.
708 NavigationEntry* entry = controller_.GetLastCommittedEntry();
709 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
710}
711
[email protected]8ff00d72012-10-23 19:12:21712WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31713 return delegate_;
714}
715
[email protected]8ff00d72012-10-23 19:12:21716void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31717 // TODO(cbentzel): remove this debugging code?
718 if (delegate == delegate_)
719 return;
720 if (delegate_)
721 delegate_->Detach(this);
722 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08723 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31724 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08725 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00726 if (view_)
[email protected]e85165c642014-06-10 14:34:31727 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08728 }
[email protected]be1f56ab2011-12-22 06:55:31729}
730
[email protected]8ff00d72012-10-23 19:12:21731RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21732 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41733 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16734}
735
clamydf1975e2015-02-05 19:12:24736RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41737 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16738}
739
nick53d5cbf2015-04-23 22:50:14740RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
741 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
742 if (!focused_node)
743 return nullptr;
744 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07745}
746
rob3e2a0732016-01-06 21:22:09747RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
748 int frame_tree_node_id) {
749 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
750 return frame ? frame->current_frame_host() : nullptr;
751}
752
[email protected]a86c0e962013-12-17 17:10:39753void WebContentsImpl::ForEachFrame(
754 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38755 for (FrameTreeNode* node : frame_tree_.Nodes()) {
756 on_frame.Run(node->current_frame_host());
757 }
[email protected]a86c0e962013-12-17 17:10:39758}
759
dchengafb53e22016-02-04 08:11:08760std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
761 std::vector<RenderFrameHost*> frame_hosts;
762 for (FrameTreeNode* node : frame_tree_.Nodes())
763 frame_hosts.push_back(node->current_frame_host());
764 return frame_hosts;
765}
766
lukaszacbdf52e2016-01-15 21:19:51767int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
768 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08769 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25770 if (!rfh->IsRenderFrameLive())
771 continue;
772
dchengafb53e22016-02-04 08:11:08773 ++number_of_messages;
774 IPC::Message* message_copy = new IPC::Message(*message);
775 message_copy->set_routing_id(rfh->GetRoutingID());
776 rfh->Send(message_copy);
777 }
[email protected]a86c0e962013-12-17 17:10:39778 delete message;
lukaszacbdf52e2016-01-15 21:19:51779 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39780}
781
lfgdb5c4ed2016-03-04 23:09:07782void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
783 frame_tree_.root()->render_manager()->SendPageMessage(msg);
784}
785
creisc014b402015-04-23 16:41:45786RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21787 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31788}
789
[email protected]6b618e62012-08-16 12:59:18790int WebContentsImpl::GetRoutingID() const {
791 if (!GetRenderViewHost())
792 return MSG_ROUTING_NONE;
793
794 return GetRenderViewHost()->GetRoutingID();
795}
796
creis89a0f782015-05-27 16:13:17797void WebContentsImpl::CancelActiveAndPendingDialogs() {
798 if (dialog_manager_)
799 dialog_manager_->CancelActiveAndPendingDialogs(this);
800 if (browser_plugin_embedder_)
801 browser_plugin_embedder_->CancelGuestDialogs();
802}
803
[email protected]44470a22013-01-24 01:21:54804int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
805 return fullscreen_widget_routing_id_;
806}
807
naskoc0fceff2015-04-30 15:53:52808void WebContentsImpl::ClosePage() {
809 GetRenderViewHost()->ClosePage();
810}
811
[email protected]b172aee2012-04-10 17:05:26812RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21813 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31814}
815
[email protected]4aebbca2013-09-17 22:26:49816RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
817 const {
818 RenderWidgetHost* const widget_host =
819 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
820 GetFullscreenWidgetRoutingID());
821 return widget_host ? widget_host->GetView() : NULL;
822}
823
[email protected]8ff00d72012-10-23 19:12:21824WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31825 return view_.get();
826}
827
yusufod41c5f92015-03-06 00:14:28828SkColor WebContentsImpl::GetThemeColor() const {
829 return theme_color_;
830}
831
[email protected]95640212014-07-26 18:14:30832void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
833 if (mode == accessibility_mode_)
834 return;
835
836 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38837
838 for (FrameTreeNode* node : frame_tree_.Nodes()) {
839 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
840 RenderFrameHost* pending_frame_host =
841 node->render_manager()->pending_frame_host();
842 if (pending_frame_host)
843 SetAccessibilityModeOnFrame(mode, pending_frame_host);
844 }
[email protected]95640212014-07-26 18:14:30845}
846
847void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50848 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30849}
850
851void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50852 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30853}
854
dmazzoni83ba5c82015-04-14 07:11:51855void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
856 // TODO(dmazzoni): http://crbug.com/475608 This only returns the
857 // accessibility tree from the main frame and everything in the
858 // same site instance.
859 GetMainFrame()->RequestAXTreeSnapshot(callback);
860}
861
dbeama1b926a2015-08-31 23:17:51862WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
863 const std::string& frame_name) {
864 DCHECK(!frame_name.empty());
865 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22866}
867
[email protected]8ff00d72012-10-23 19:12:21868WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:40869 WebUI* commited_web_ui = GetCommittedWebUI();
870 return commited_web_ui ? commited_web_ui
871 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:31872}
873
[email protected]8ff00d72012-10-23 19:12:21874WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:40875 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34876}
877
[email protected]86ef6a392012-05-11 22:03:11878void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22879 if (GetUserAgentOverride() == override)
880 return;
881
882 renderer_preferences_.user_agent_override = override;
883
884 // Send the new override string to the renderer.
885 RenderViewHost* host = GetRenderViewHost();
886 if (host)
887 host->SyncRendererPrefs();
888
889 // Reload the page if a load is currently in progress to avoid having
890 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27891 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:25892 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim7dad4b1182016-04-01 14:28:05893 controller_.ReloadBypassingCache(true);
[email protected]8d0f3312012-08-18 01:47:53894
895 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
896 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11897}
898
899const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22900 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11901}
902
[email protected]95640212014-07-26 18:14:30903void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:08904 if (GetAccessibilityMode() != AccessibilityModeOff) {
905 for (RenderFrameHost* rfh : GetAllFrames())
906 ResetAccessibility(rfh);
907 } else {
dtseng0dd3fa12015-07-22 19:00:52908 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:08909 }
[email protected]95640212014-07-26 18:14:30910}
911
912bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
913 return accessibility_mode_ == AccessibilityModeTreeOnly;
914}
915
916bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
917 return accessibility_mode_ == AccessibilityModeComplete;
918}
919
kouhei40f03cb2015-09-24 07:47:01920const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
921 return page_importance_signals_;
922}
923
[email protected]fcf75d42013-12-03 20:11:26924const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55925 // Transient entries take precedence. They are used for interstitial pages
926 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23927 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08928 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21929 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30930 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23931 if (entry) {
[email protected]b5cca982011-05-26 04:42:08932 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23933 }
carlosk35f35af2015-12-01 10:55:40934
935 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
936 WebUI* our_web_ui = navigating_web_ui
937 ? navigating_web_ui
938 : GetRenderManager()->current_frame_host()->web_ui();
939
[email protected]7ade2732011-02-10 00:13:58940 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54941 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32942 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54943 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35944 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26945 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54946 if (!title.empty())
947 return title;
948 }
949 }
950
951 // We use the title for the last committed entry rather than a pending
952 // navigation entry. For example, when the user types in a URL, we want to
953 // keep the old page's title until the new load has committed and we get a new
954 // title.
[email protected]96d185d2009-04-24 03:28:54955 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32956
creis072b61f2015-09-28 20:52:24957 // We make an exception for initial navigations. We only want to use the title
958 // from the visible entry if:
959 // 1. The pending entry has been explicitly assigned a title to display.
960 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
961 // which case there is a pending entry index other than -1.
962 //
963 // Otherwise, we want to stick with the last committed entry's title during
964 // new navigations, which have pending entries at index -1 with no title.
965 if (controller_.IsInitialNavigation() &&
966 ((controller_.GetVisibleEntry() &&
967 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
968 controller_.GetPendingEntryIndex() != -1)) {
969 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:47970 }
[email protected]59167c22013-06-03 18:07:32971
[email protected]45d0ef7f2011-01-05 13:46:23972 if (entry) {
[email protected]b5cca982011-05-26 04:42:08973 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23974 }
[email protected]987fc3a2011-05-26 14:18:09975
976 // |page_title_when_no_navigation_entry_| is finally used
977 // if no title cannot be retrieved.
978 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54979}
980
avib7348942015-12-25 20:57:10981int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46982 return GetMaxPageIDForSiteInstance(GetSiteInstance());
983}
984
avib7348942015-12-25 20:57:10985int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:26986 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33987 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
988 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46989
[email protected]b6583592012-01-25 19:52:33990 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34991}
992
avib7348942015-12-25 20:57:10993void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:46994 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
995}
996
[email protected]b172aee2012-04-10 17:05:26997void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:10998 SiteInstance* site_instance,
999 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461000 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331001 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341002}
1003
[email protected]ec6c05f2013-10-23 18:41:571004void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1005 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1006 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571007}
1008
creiscce56cd2014-09-29 22:45:221009SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211010 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541011}
1012
creiscce56cd2014-09-29 22:45:221013SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1014 RenderViewHostImpl* dest_rvh =
1015 GetRenderManager()->pending_render_view_host() ?
1016 GetRenderManager()->pending_render_view_host() :
1017 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581018 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381019}
1020
[email protected]b172aee2012-04-10 17:05:261021bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251022 return frame_tree_.IsLoading() &&
1023 !(ShowingInterstitialPage() &&
1024 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491025}
1026
[email protected]6dfed692014-05-22 04:18:031027bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251028 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031029}
1030
[email protected]b172aee2012-04-10 17:05:261031bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031032 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311033}
1034
[email protected]b172aee2012-04-10 17:05:261035const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311036 return load_state_;
1037}
1038
[email protected]fcf75d42013-12-03 20:11:261039const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311040 return load_state_host_;
1041}
1042
avib7348942015-12-25 20:57:101043uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311044 return upload_size_;
1045}
1046
avib7348942015-12-25 20:57:101047uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311048 return upload_position_;
1049}
1050
[email protected]b172aee2012-04-10 17:05:261051const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541052 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311053}
1054
[email protected]b172aee2012-04-10 17:05:261055bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311056 return displayed_insecure_content_;
1057}
1058
[email protected]222f5822014-02-05 23:40:491059void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251060 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551061 ++capturer_count_;
1062 DVLOG(1) << "There are now " << capturer_count_
1063 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491064
1065 // Note: This provides a hint to upstream code to size the views optimally
1066 // for quality (e.g., to avoid scaling).
1067 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1068 preferred_size_for_capture_ = capture_size;
1069 OnPreferredSizeChanged(preferred_size_);
1070 }
ccameron8807c38f2015-01-17 00:29:191071
1072 // Ensure that all views are un-occluded before capture begins.
1073 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551074}
1075
1076void WebContentsImpl::DecrementCapturerCount() {
1077 --capturer_count_;
1078 DVLOG(1) << "There are now " << capturer_count_
1079 << " capturing(s) of WebContentsImpl@" << this;
1080 DCHECK_LE(0, capturer_count_);
1081
[email protected]5a652232013-02-12 06:15:251082 if (is_being_destroyed_)
1083 return;
1084
[email protected]222f5822014-02-05 23:40:491085 if (capturer_count_ == 0) {
1086 const gfx::Size old_size = preferred_size_for_capture_;
1087 preferred_size_for_capture_ = gfx::Size();
1088 OnPreferredSizeChanged(old_size);
1089 }
1090
[email protected]1ac10dca2013-08-20 20:47:041091 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551092 DVLOG(1) << "Executing delayed WasHidden().";
1093 WasHidden();
1094 }
[email protected]be1f56ab2011-12-22 06:55:311095}
1096
[email protected]f2bd40812013-07-20 04:30:441097int WebContentsImpl::GetCapturerCount() const {
1098 return capturer_count_;
1099}
1100
miu50f97892014-09-22 22:49:521101bool WebContentsImpl::IsAudioMuted() const {
1102 return audio_muter_.get() && audio_muter_->is_muting();
1103}
1104
1105void WebContentsImpl::SetAudioMuted(bool mute) {
1106 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1107 << " for WebContentsImpl@" << this;
1108
1109 if (mute == IsAudioMuted())
1110 return;
1111
1112 if (mute) {
1113 if (!audio_muter_)
1114 audio_muter_.reset(new WebContentsAudioMuter(this));
1115 audio_muter_->StartMuting();
1116 } else {
1117 DCHECK(audio_muter_);
1118 audio_muter_->StopMuting();
1119 }
1120
wjmaclean2f797c782016-01-07 14:52:031121 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1122 DidUpdateAudioMutingState(mute));
1123
miu50f97892014-09-22 22:49:521124 // Notification for UI updates in response to the changed muting state.
1125 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1126}
1127
ortuno32e7db3c2016-03-29 16:14:201128bool WebContentsImpl::IsBluetoothDeviceConnected() const {
1129 return bluetooth_device_connected_;
1130}
1131
1132void WebContentsImpl::SetBluetoothDeviceConnected(bool connected) {
1133 bluetooth_device_connected_ = connected;
1134 // Notification for UI updates in response to the connected device.
1135 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1136}
1137
[email protected]b172aee2012-04-10 17:05:261138bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311139 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1140 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581141 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271142#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581143 crashed_status_ ==
1144 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271145#endif
wfh0d9532a2015-09-02 23:18:581146 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271147 );
[email protected]3c9e1872010-11-18 16:17:491148}
1149
[email protected]b172aee2012-04-10 17:05:261150void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1151 int error_code) {
[email protected]443b80e2010-12-14 00:42:231152 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341153 return;
1154
[email protected]443b80e2010-12-14 00:42:231155 crashed_status_ = status;
1156 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211157 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341158}
1159
[email protected]b172aee2012-04-10 17:05:261160base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311161 return crashed_status_;
1162}
1163
afakhry98241832016-03-11 19:27:471164int WebContentsImpl::GetCrashedErrorCode() const {
1165 return crashed_error_code_;
1166}
1167
[email protected]b172aee2012-04-10 17:05:261168bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311169 return is_being_destroyed_;
1170}
1171
[email protected]7f924832014-08-09 05:57:221172void WebContentsImpl::NotifyNavigationStateChanged(
1173 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541174 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1175 // is fixed.
1176 tracked_objects::ScopedTracker tracking_profile(
1177 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1178 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181179 // Notify the media observer of potential audibility changes.
1180 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271181 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301182 }
1183
[email protected]d5f942ba2008-09-26 19:30:341184 if (delegate_)
1185 delegate_->NavigationStateChanged(this, changed_flags);
1186}
1187
gab0dccfef2015-05-20 18:43:391188base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021189 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331190}
1191
georgesak5582cbe2015-05-22 22:08:071192void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1193 last_active_time_ = last_active_time;
1194}
1195
[email protected]9e2e4632012-07-27 16:38:411196void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541197 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591198
ccameron8807c38f2015-01-17 00:29:191199 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1200 if (view) {
1201 view->Show();
[email protected]789e9152009-08-04 21:59:431202#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191203 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431204#endif
[email protected]de3c5d82014-05-28 22:12:591205 }
[email protected]789e9152009-08-04 21:59:431206 }
[email protected]96d185d2009-04-24 03:28:541207
gab0dccfef2015-05-20 18:43:391208 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381209
[email protected]b9769d82012-02-10 00:23:591210 // The resize rect might have changed while this was inactive -- send the new
1211 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451212 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221213 if (rvh) {
1214 rvh->GetWidget()->ResizeRectChanged(
1215 GetRootWindowResizerRect(rvh->GetWidget()));
1216 }
[email protected]96d185d2009-04-24 03:28:541217
[email protected]c0d9d5672013-10-09 07:38:031218 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1219
[email protected]54597982013-02-06 01:59:551220 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311221}
1222
[email protected]b172aee2012-04-10 17:05:261223void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551224 // If there are entities capturing screenshots or video (e.g., mirroring),
1225 // don't activate the "disable rendering" optimization.
1226 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521227 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551228 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261229 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521230 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331231 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521232 // calls us).
ccameron8807c38f2015-01-17 00:29:191233 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1234 if (view)
1235 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591236 }
[email protected]96d185d2009-04-24 03:28:541237 }
1238
[email protected]c0d9d5672013-10-09 07:38:031239 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1240
[email protected]54597982013-02-06 01:59:551241 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371242}
1243
ccameron8807c38f2015-01-17 00:29:191244void WebContentsImpl::WasOccluded() {
1245 if (capturer_count_ > 0)
1246 return;
1247
1248 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1249 if (view)
1250 view->WasOccluded();
1251 }
1252}
1253
1254void WebContentsImpl::WasUnOccluded() {
1255 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1256 if (view)
1257 view->WasUnOccluded();
1258 }
1259}
1260
[email protected]b172aee2012-04-10 17:05:261261bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311262 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451263 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1264 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311265}
1266
[email protected]1c3f80bd2014-04-08 23:02:061267void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451268 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061269}
1270
lazyboy6ec48b2a2015-06-29 15:18:141271void WebContentsImpl::AttachToOuterWebContentsFrame(
1272 WebContents* outer_web_contents,
1273 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081274 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lazyboy6ec48b2a2015-06-29 15:18:141275 // Create a link to our outer WebContents.
1276 node_.reset(new WebContentsTreeNode());
1277 node_->ConnectToOuterWebContents(
1278 static_cast<WebContentsImpl*>(outer_web_contents),
1279 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1280
1281 DCHECK(outer_contents_frame);
1282
1283 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1284 // SiteInstance of the outer WebContents. The proxy will be used to send
1285 // postMessage to the inner WebContents.
1286 GetRenderManager()->CreateOuterDelegateProxy(
1287 outer_contents_frame->GetSiteInstance(),
1288 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1289
1290 GetRenderManager()->SetRWHViewForInnerContents(
1291 GetRenderManager()->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391292
1293 static_cast<RenderWidgetHostViewChildFrame*>(
1294 GetRenderManager()->GetRenderWidgetHostView())
1295 ->RegisterSurfaceNamespaceId();
lazyboy6ec48b2a2015-06-29 15:18:141296}
1297
[email protected]b172aee2012-04-10 17:05:261298void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381299 for (FrameTreeNode* node : frame_tree_.Nodes())
1300 node->StopLoading();
[email protected]d16609c2013-08-23 06:01:401301 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271302}
1303
[email protected]b172aee2012-04-10 17:05:261304WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441305 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211306 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451307 // before.
[email protected]54944cde2012-12-09 09:24:591308 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451309 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211310 WebContentsImpl* tc =
1311 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191312 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221313 FOR_EACH_OBSERVER(WebContentsObserver,
1314 observers_,
1315 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271316 return tc;
1317}
1318
[email protected]14392a52012-05-02 20:28:441319void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211320 const NotificationSource& source,
1321 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441322 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211323 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1324 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031325 RenderWidgetHostView* view = host->GetView();
1326 if (view == GetFullscreenRenderWidgetHostView()) {
1327 // We cannot just call view_->RestoreFocus() here. On some platforms,
1328 // attempting to focus the currently-invisible WebContentsView will be
1329 // flat-out ignored. Therefore, this boolean is used to track whether
1330 // we will request focus after the fullscreen widget has been
1331 // destroyed.
1332 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1333 } else {
1334 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1335 i != pending_widget_views_.end(); ++i) {
1336 if (host->GetView() == i->second) {
1337 pending_widget_views_.erase(i);
1338 break;
1339 }
[email protected]bafe6cd2012-05-23 23:09:501340 }
1341 }
1342 break;
1343 }
[email protected]14392a52012-05-02 20:28:441344 default:
1345 NOTREACHED();
1346 }
1347}
1348
[email protected]ec6c05f2013-10-23 18:41:571349WebContents* WebContentsImpl::GetWebContents() {
1350 return this;
1351}
1352
[email protected]54944cde2012-12-09 09:24:591353void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211354 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361355 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211356 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431357 should_normally_be_visible_ = !params.initially_hidden;
1358
dcheng3ce04b62015-10-26 23:30:551359 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541360 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551361 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1362 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541363 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551364 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1365 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1366
1367 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1368 if (!site_instance)
1369 site_instance = SiteInstance::Create(params.browser_context);
1370
1371 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1372 // local root by definition.
1373 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1374 // longer be necessary to eagerly grab a routing ID for the view.
1375 // https://crbug.com/545684
1376 int32_t view_routing_id = params.routing_id;
1377 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1378 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1379 view_routing_id = main_frame_widget_routing_id =
1380 site_instance->GetProcess()->GetNextRoutingID();
1381 }
1382
1383 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1384 params.main_frame_routing_id,
1385 main_frame_widget_routing_id);
lukasza464d8692016-02-22 19:26:321386
1387 // blink::FrameTree::setName uses |name| as the |unique_name| for the main
1388 // frame - let's do the same thing here.
1389 std::string unique_name = params.main_frame_name;
1390 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191391
[email protected]fc2b46b2014-05-03 16:33:451392 WebContentsViewDelegate* delegate =
1393 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1394
fsamueladb0033602015-12-09 19:20:411395#if defined(MOJO_SHELL_CLIENT)
1396 if (MojoShellConnection::Get() &&
1397 base::CommandLine::ForCurrentProcess()->HasSwitch(
1398 switches::kUseMusInRenderer)) {
1399 mus::Window* mus_window = aura::GetMusWindow(params.context);
1400 if (mus_window) {
1401 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1402 &render_view_host_delegate_view_));
1403 }
1404 }
1405#endif
1406
1407 if (!view_) {
1408 view_.reset(CreateWebContentsView(this, delegate,
1409 &render_view_host_delegate_view_));
1410 }
fsamuel9cf7bdf2015-11-20 02:19:321411
lazyboy6ec48b2a2015-06-29 15:18:141412 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081413 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
fsamuel9cf7bdf2015-11-20 02:19:321414 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361415 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321416 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191417 }
[email protected]fc2b46b2014-05-03 16:33:451418 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191419 CHECK(view_.get());
1420
[email protected]ed245db2012-12-18 08:00:451421 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591422 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191423
tommyclieb25b2a2014-11-03 19:45:091424#if defined(ENABLE_PLUGINS)
1425 plugin_content_origin_whitelist_.reset(
1426 new PluginContentOriginWhitelist(this));
1427#endif
1428
[email protected]d1198fd2012-08-13 22:50:191429 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211430 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1431 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101432
[email protected]01f83f92014-06-17 14:41:541433 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091434 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541435
mlamouriefdca9d2014-09-16 16:55:401436 manifest_manager_host_.reset(new ManifestManagerHost(this));
1437
mfomitchev2b8b066a2016-01-28 19:23:151438#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101439 date_time_chooser_.reset(new DateTimeChooserAndroid());
1440#endif
fsamuel7310a4262014-12-05 05:06:441441
1442 // BrowserPluginGuest::Init needs to be called after this WebContents has
1443 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1444 if (browser_plugin_guest_)
1445 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371446
1447 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1448 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561449
1450 // If the WebContents creation was renderer-initiated, it means that the
1451 // corresponding RenderView and main RenderFrame have already been created.
1452 // Ensure observers are notified about this.
1453 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431454 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561455 RenderViewCreated(GetRenderViewHost());
1456 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1457 }
naskof5940b9f2015-03-02 23:04:051458
1459 // Ensure that observers are notified of the creation of this WebContents's
1460 // main RenderFrameHost. It must be done here for main frames, since the
1461 // NotifySwappedFromRenderManager expects view_ to already be created and that
1462 // happens after RenderFrameHostManager::Init.
1463 NotifySwappedFromRenderManager(
1464 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191465}
1466
[email protected]7fff43e2013-05-21 20:21:101467void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1468 RemoveDestructionObserver(web_contents);
1469
[email protected]ceee8cd2013-03-08 04:59:511470 // Clear a pending contents that has been closed before being shown.
1471 for (PendingContents::iterator iter = pending_contents_.begin();
1472 iter != pending_contents_.end();
1473 ++iter) {
1474 if (iter->second != web_contents)
1475 continue;
1476 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511477 return;
1478 }
1479 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441480}
1481
[email protected]7fff43e2013-05-21 20:21:101482void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1483 if (!ContainsKey(destruction_observers_, web_contents)) {
1484 destruction_observers_[web_contents] =
1485 new DestructionObserver(this, web_contents);
1486 }
1487}
1488
1489void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1490 DestructionObservers::iterator iter =
1491 destruction_observers_.find(web_contents);
1492 if (iter != destruction_observers_.end()) {
1493 delete destruction_observers_[web_contents];
1494 destruction_observers_.erase(iter);
1495 }
1496}
1497
[email protected]b172aee2012-04-10 17:05:261498void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311499 observers_.AddObserver(observer);
1500}
1501
[email protected]b172aee2012-04-10 17:05:261502void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311503 observers_.RemoveObserver(observer);
1504}
1505
[email protected]948481d2014-06-11 18:32:221506std::set<RenderWidgetHostView*>
1507WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1508 std::set<RenderWidgetHostView*> set;
1509 if (ShowingInterstitialPage()) {
1510 set.insert(GetRenderWidgetHostView());
1511 } else {
dchengafb53e22016-02-04 08:11:081512 for (RenderFrameHost* rfh : GetAllFrames()) {
1513 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1514 ->frame_tree_node()
1515 ->render_manager()
1516 ->GetRenderWidgetHostView();
1517 set.insert(rwhv);
1518 }
[email protected]948481d2014-06-11 18:32:221519 }
[email protected]de3c5d82014-05-28 22:12:591520 return set;
1521}
1522
[email protected]b172aee2012-04-10 17:05:261523void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341524 if (delegate_)
1525 delegate_->ActivateContents(this);
1526}
1527
avi3e4b8512015-11-11 01:55:491528void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1529 if (!RenderViewHostImpl::From(render_widget_host))
1530 return;
1531
[email protected]63954792011-07-11 04:17:481532 if (delegate_)
1533 delegate_->LostCapture();
1534}
1535
lazyboy63f5b312015-11-23 20:19:521536void WebContentsImpl::RenderWidgetCreated(
1537 RenderWidgetHostImpl* render_widget_host) {
1538 created_widgets_.insert(render_widget_host);
1539}
1540
[email protected]b24b68a2012-09-24 21:57:261541void WebContentsImpl::RenderWidgetDeleted(
1542 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521543 // Note that |is_being_destroyed_| can be true at this point as
1544 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1545 // us here.
1546 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261547
lazyboy63f5b312015-11-23 20:19:521548 if (is_being_destroyed_)
1549 return;
[email protected]44470a22013-01-24 01:21:541550
1551 if (render_widget_host &&
1552 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491553 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531554 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541555 FOR_EACH_OBSERVER(WebContentsObserver,
1556 observers_,
1557 DidDestroyFullscreenWidget(
1558 fullscreen_widget_routing_id_));
1559 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031560 if (fullscreen_widget_had_focus_at_shutdown_)
1561 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541562 }
[email protected]b24b68a2012-09-24 21:57:261563}
1564
miu9e14e492014-10-25 02:39:041565void WebContentsImpl::RenderWidgetGotFocus(
1566 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371567 // Notify the observers if an embedded fullscreen widget was focused.
1568 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1569 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1570 NotifyWebContentsFocused();
1571 }
miu9e14e492014-10-25 02:39:041572}
1573
estaded0a0c992015-01-21 14:12:061574void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311575 RenderWidgetHostImpl* render_widget_host,
1576 bool width_changed) {
creisc014b402015-04-23 16:41:451577 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291578 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061579 return;
estaded0a0c992015-01-21 14:12:061580
rouslan2f5993f2015-01-29 00:18:311581 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1582 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061583}
1584
paulmeyer9ef6e4462015-02-24 19:15:101585void WebContentsImpl::ScreenInfoChanged() {
1586 if (browser_plugin_embedder_)
1587 browser_plugin_embedder_->ScreenInfoChanged();
1588}
1589
[email protected]b172aee2012-04-10 17:05:261590bool WebContentsImpl::PreHandleKeyboardEvent(
1591 const NativeWebKeyboardEvent& event,
1592 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481593 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131594 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481595}
1596
[email protected]b172aee2012-04-10 17:05:261597void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101598 if (browser_plugin_embedder_ &&
1599 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1600 return;
1601 }
[email protected]63954792011-07-11 04:17:481602 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131603 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481604}
1605
[email protected]d92026ef2014-03-03 21:04:131606bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461607 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191608#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331609 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1610 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191611 // -the OS already has a gesture to do this through pinch-zoom
1612 // -if a user starts an inertial scroll, let's go, and presses control
1613 // (i.e. control+tab) then the OS's buffered scroll events will come in
1614 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331615 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551616 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331617 !event.canScroll) {
w.shackleton49bcd392016-01-06 17:38:221618 // Count only integer cumulative scrolls as zoom events; this handles
1619 // smooth scroll and regular scroll device behavior.
1620 zoom_scroll_remainder_ += event.wheelTicksY;
1621 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1622 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1623 if (whole_zoom_scroll_remainder_ != 0) {
1624 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1625 }
[email protected]fb3f066e2013-02-12 19:12:521626 return true;
1627 }
[email protected]bccc4472013-04-18 16:37:191628#endif
[email protected]fb3f066e2013-02-12 19:12:521629 return false;
1630}
1631
[email protected]04bce562014-01-30 05:34:541632bool WebContentsImpl::PreHandleGestureEvent(
1633 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031634 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541635}
1636
kenrb2a565f82015-09-02 20:24:591637RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451638 if (!is_being_destroyed_ && GetOuterWebContents())
1639 return GetOuterWebContents()->GetInputEventRouter();
1640
1641 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591642 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1643 return rwh_input_event_router_.get();
1644}
1645
alexmos3fcd0ca2015-10-23 18:18:331646void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1647 // Focus loss may occur while this WebContents is being destroyed. Don't
1648 // send the message in this case, as the main frame's RenderFrameHost and
1649 // other state has already been cleared.
1650 if (is_being_destroyed_)
1651 return;
1652
1653 frame_tree_.ReplicatePageFocus(is_focused);
1654}
1655
alexmosc4cbacb2015-11-21 01:29:221656RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1657 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521658 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221659 return receiving_widget;
1660
1661 // Events for widgets other than the main frame (e.g., popup menus) should be
1662 // forwarded directly to the widget they arrived on.
1663 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1664 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521665
1666 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1667 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221668 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521669
alexmos732ca3a2015-12-08 02:01:021670 // The view may be null if a subframe's renderer process has crashed while
1671 // the subframe has focus. Drop the event in that case. Do not give
1672 // it to the main frame, so that the user doesn't unexpectedly type into the
1673 // wrong frame if a focused subframe renderer crashes while they type.
1674 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1675 if (!view)
1676 return nullptr;
1677
1678 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521679}
1680
mlamouri7a78d6fd2015-01-17 13:23:531681void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1682 // This method is being called to enter renderer-initiated fullscreen mode.
1683 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491684 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371685 if (widget_view) {
1686 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1687 ->ShutdownAndDestroyWidget(true);
1688 }
[email protected]4aebbca2013-09-17 22:26:491689
[email protected]8a5e0ca2011-08-25 06:30:471690 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531691 delegate_->EnterFullscreenModeForTab(this, origin);
1692
1693 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461694 DidToggleFullscreenModeForTab(
1695 IsFullscreenForCurrentTab(
1696 GetRenderViewHost()->GetWidget()),
1697 false));
mlamouri7a78d6fd2015-01-17 13:23:531698}
1699
bokanece34a82016-01-28 19:49:461700void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531701 // This method is being called to leave renderer-initiated fullscreen mode.
1702 // Make sure any existing fullscreen widget is shut down first.
1703 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371704 if (widget_view) {
1705 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1706 ->ShutdownAndDestroyWidget(true);
1707 }
mlamouri7a78d6fd2015-01-17 13:23:531708
hugo.holgersson61288e6c2015-01-28 17:04:401709#if defined(OS_ANDROID)
1710 ContentVideoView* video_view = ContentVideoView::GetInstance();
1711 if (video_view != NULL)
watk98292292016-01-19 22:24:081712 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401713#endif
1714
mlamouri7a78d6fd2015-01-17 13:23:531715 if (delegate_)
1716 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371717
bokanece34a82016-01-28 19:49:461718 // The fullscreen state is communicated to the renderer through a resize
1719 // message. If the change in fullscreen state doesn't cause a view resize
1720 // then we must ensure web contents exit the fullscreen state by explicitly
1721 // sending a resize message. This is required for the situation of the browser
1722 // moving the view into a "browser fullscreen" state and then the contents
1723 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1724 // have the side effect of the view resizing, hence the explicit call here is
1725 // required.
1726 if (!will_cause_resize) {
1727 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1728 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1729 render_widget_host->WasResized();
1730 }
scheib3dcb6c932015-02-23 10:55:581731 }
1732
avibf58fa0c2015-11-11 01:45:521733 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461734 DidToggleFullscreenModeForTab(
1735 IsFullscreenForCurrentTab(
1736 GetRenderViewHost()->GetWidget()),
1737 will_cause_resize));
[email protected]8a5e0ca2011-08-25 06:30:471738}
1739
avibf58fa0c2015-11-11 01:45:521740bool WebContentsImpl::IsFullscreenForCurrentTab(
1741 RenderWidgetHostImpl* render_widget_host) const {
1742 if (!RenderViewHostImpl::From(render_widget_host))
1743 return false;
1744
[email protected]199bba6e2012-04-04 16:19:381745 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121746}
1747
avibf58fa0c2015-11-11 01:45:521748blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1749 RenderWidgetHostImpl* render_widget_host) const {
1750 if (!RenderViewHostImpl::From(render_widget_host))
1751 return blink::WebDisplayModeBrowser;
1752
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121753 return delegate_ ? delegate_->GetDisplayMode(this)
1754 : blink::WebDisplayModeBrowser;
1755}
1756
avic3aa8422015-11-09 20:57:221757void WebContentsImpl::RequestToLockMouse(
1758 RenderWidgetHostImpl* render_widget_host,
1759 bool user_gesture,
1760 bool last_unlocked_by_target) {
1761 if (render_widget_host != GetRenderViewHost()->GetWidget()) {
1762 render_widget_host->GotResponseToLockMouseRequest(false);
1763 return;
[email protected]e9621112011-10-17 05:38:371764 }
avic3aa8422015-11-09 20:57:221765
1766 if (delegate_)
1767 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1768 else
1769 GotResponseToLockMouseRequest(false);
[email protected]e9621112011-10-17 05:38:371770}
1771
avi3e4b8512015-11-11 01:55:491772void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1773 if (!RenderViewHostImpl::From(render_widget_host))
1774 return;
1775
[email protected]e9621112011-10-17 05:38:371776 if (delegate_)
1777 delegate_->LostMouseLock();
1778}
1779
dtrainor5ef644e2015-11-19 00:12:471780void WebContentsImpl::ForwardCompositorProto(
1781 RenderWidgetHostImpl* render_widget_host,
1782 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:471783 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:291784 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:471785}
1786
ekaramada4f42692016-02-11 19:48:371787void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
1788 if (visible)
1789 WasShown();
1790 else
1791 WasHidden();
1792}
1793
[email protected]bafe6cd2012-05-23 23:09:501794void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431795 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551796 int32_t route_id,
1797 int32_t main_frame_route_id,
1798 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131799 const ViewHostMsg_CreateWindow_Params& params,
1800 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501801 // We usually create the new window in the same BrowsingInstance (group of
1802 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551803 // if the opener is being suppressed (in a non-guest), we create a new
1804 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251805 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551806
nickd30fd962015-07-27 21:51:081807 if (is_guest && BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:141808 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1809 // yet.
1810 NOTREACHED();
1811 }
1812
[email protected]04cbd3d2013-12-04 04:58:201813 // If the opener is to be suppressed, the new window can be in any process.
1814 // Since routing ids are process specific, we must not have one passed in
1815 // as argument here.
1816 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1817
[email protected]bafe6cd2012-05-23 23:09:501818 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431819 params.opener_suppressed && !is_guest
1820 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1821 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501822
alexmos4cf2aa32015-07-15 23:40:431823 // A message to create a new window can only come from a process for a frame
1824 // in this WebContents' FrameTree. If any other process sends the request, it
1825 // is invalid and the process must be terminated.
1826 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:381827 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:431828 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351829 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201830 if (process_handle != base::kNullProcessHandle) {
1831 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391832 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351833 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201834 }
1835 return;
1836 }
1837
[email protected]d1198fd2012-08-13 22:50:191838 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341839 //
1840 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301841 const std::string& partition_id =
1842 GetContentClient()->browser()->
1843 GetStoragePartitionIdForSite(GetBrowserContext(),
1844 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461845 StoragePartition* partition = BrowserContext::GetStoragePartition(
1846 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411847 DOMStorageContextWrapper* dom_storage_context =
1848 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191849 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1850 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1851 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371852
1853 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551854 !delegate_->ShouldCreateWebContents(
1855 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1856 params.window_container_type, params.frame_name, params.target_url,
1857 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011858 if (route_id != MSG_ROUTING_NONE &&
1859 !RenderViewHost::FromID(render_process_id, route_id)) {
1860 // If the embedder didn't create a WebContents for this route, we need to
1861 // delete the RenderView that had already been created.
1862 Send(new ViewMsg_Close(route_id));
1863 }
csharrisona2280cd2016-02-03 23:21:151864 // It's safe to only target the frame because the render process will not
1865 // have a chance to create more frames at this point.
1866 ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
1867 GlobalFrameRoutingId(render_process_id, main_frame_route_id));
[email protected]dd6730412013-08-14 15:03:371868 return;
1869 }
1870
1871 // Create the new web contents. This will automatically create the new
1872 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461873 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591874 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041875 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551876 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121877 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431878 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211879 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061880 create_params.opener_suppressed = params.opener_suppressed;
1881 if (params.disposition == NEW_BACKGROUND_TAB)
1882 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191883 create_params.renderer_initiated_creation =
1884 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061885
[email protected]4858e432014-06-23 18:14:171886 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551887 if (!is_guest) {
1888 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451889 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171890 new_contents = static_cast<WebContentsImpl*>(
1891 WebContents::Create(create_params));
1892 } else {
1893 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551894 }
[email protected]50d326e2014-05-20 17:59:061895 new_contents->GetController().SetSessionStorageNamespace(
1896 partition_id,
1897 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191898
alexmos646fec02015-07-25 00:11:491899 // If the new frame has a name, make sure any SiteInstances that can find
1900 // this named frame have proxies for it. Must be called after
1901 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1902 // GetSessionStorageNamespace.
1903 if (!params.frame_name.empty())
1904 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1905
[email protected]c4538072013-03-18 02:17:551906 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341907 // will be shown immediately).
1908 if (!params.opener_suppressed) {
1909 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451910 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501911
[email protected]d70bea92013-04-05 04:23:341912 // TODO(brettw): It seems bogus that we have to call this function on the
1913 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431914 new_view->CreateViewForWidget(
1915 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341916 }
[email protected]bafe6cd2012-05-23 23:09:501917 // Save the created window associated with the route so we can show it
1918 // later.
1919 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1920 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101921 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501922 }
1923
1924 if (delegate_) {
1925 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071926 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131927 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501928 }
1929
1930 if (params.opener_suppressed) {
1931 // When the opener is suppressed, the original renderer cannot access the
1932 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001933 bool was_blocked = false;
1934 if (delegate_) {
bokan107a47f2015-02-03 23:23:391935 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001936 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391937 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001938 params.user_gesture, &was_blocked);
1939 }
1940 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211941 OpenURLParams open_params(params.target_url,
1942 Referrer(),
1943 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351944 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211945 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301946 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:371947
1948 if (delegate_ && !is_guest &&
1949 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
1950 // We are in asynchronous add new contents path, delay opening url
1951 new_contents->delayed_open_url_params_.reset(
1952 new OpenURLParams(open_params));
1953 } else {
1954 new_contents->OpenURL(open_params);
1955 }
[email protected]eda238a12012-09-07 23:44:001956 }
[email protected]bafe6cd2012-05-23 23:09:501957 }
1958}
1959
avib7348942015-12-25 20:57:101960void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1961 int32_t route_id,
[email protected]180ef242013-11-07 06:50:461962 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:051963 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501964}
1965
avib7348942015-12-25 20:57:101966void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
1967 int32_t route_id) {
piman5d36dae2015-09-24 22:47:051968 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501969}
1970
avib7348942015-12-25 20:57:101971void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1972 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:501973 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461974 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:251975 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:231976 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:511977 // this WebContentsImpl instance. If any other process sends the request,
1978 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:381979 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:251980 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:511981 if (process_handle != base::kNullProcessHandle) {
1982 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391983 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:251984 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511985 }
1986 return;
1987 }
1988
[email protected]bafe6cd2012-05-23 23:09:501989 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:051990 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261991
[email protected]cfd80b02014-05-01 17:46:481992 RenderWidgetHostViewBase* widget_view =
1993 static_cast<RenderWidgetHostViewBase*>(
1994 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191995 if (!widget_view)
1996 return;
[email protected]bafe6cd2012-05-23 23:09:501997 if (!is_fullscreen) {
1998 // Popups should not get activated.
1999 widget_view->SetPopupType(popup_type);
2000 }
2001 // Save the created widget associated with the route so we can show it later.
2002 pending_widget_views_[route_id] = widget_view;
2003
2004#if defined(OS_MACOSX)
2005 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2006 // to allow it to survive the trip without being hosted.
2007 base::mac::NSObjectRetain(widget_view->GetNativeView());
2008#endif
2009}
2010
2011void WebContentsImpl::ShowCreatedWindow(int route_id,
2012 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392013 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502014 bool user_gesture) {
2015 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:002016 if (contents) {
2017 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162018 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382019 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2020 contents->ResumeLoadingCreatedWebContents();
2021
[email protected]eda238a12012-09-07 23:44:002022 if (delegate) {
2023 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392024 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002025 }
2026 }
[email protected]bafe6cd2012-05-23 23:09:502027}
2028
2029void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:392030 const gfx::Rect& initial_rect) {
2031 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502032}
2033
2034void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
2035 ShowCreatedWidget(route_id, true, gfx::Rect());
2036}
2037
2038void WebContentsImpl::ShowCreatedWidget(int route_id,
2039 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392040 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482041 RenderWidgetHostViewBase* widget_host_view =
2042 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502043 if (!widget_host_view)
2044 return;
[email protected]cfd80b02014-05-01 17:46:482045
2046 RenderWidgetHostView* view = NULL;
2047 BrowserPluginGuest* guest = GetBrowserPluginGuest();
2048 if (guest && guest->embedder_web_contents()) {
2049 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
2050 } else {
2051 view = GetRenderWidgetHostView();
2052 }
2053
[email protected]4aebbca2013-09-17 22:26:492054 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312055 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032056 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312057 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492058 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2059 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532060 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492061 } else {
[email protected]cfd80b02014-05-01 17:46:482062 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492063 }
[email protected]4aebbca2013-09-17 22:26:492064 FOR_EACH_OBSERVER(WebContentsObserver,
2065 observers_,
2066 DidShowFullscreenWidget(route_id));
2067 if (!widget_host_view->HasFocus())
2068 widget_host_view->Focus();
2069 } else {
bokan107a47f2015-02-03 23:23:392070 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492071 }
[email protected]89054502012-06-03 10:29:242072
2073 RenderWidgetHostImpl* render_widget_host_impl =
2074 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2075 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312076 // Only allow privileged mouse lock for fullscreen render widget, which is
2077 // used to implement Pepper Flash fullscreen.
2078 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502079
2080#if defined(OS_MACOSX)
2081 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2082 // properly embedded (or purposefully ignored) we can release the retain we
2083 // took in CreateNewWidget().
2084 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2085#endif
2086}
2087
2088WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2089 PendingContents::iterator iter = pending_contents_.find(route_id);
2090
2091 // Certain systems can block the creation of new windows. If we didn't succeed
2092 // in creating one, just return NULL.
2093 if (iter == pending_contents_.end()) {
2094 return NULL;
2095 }
2096
2097 WebContentsImpl* new_contents = iter->second;
2098 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102099 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502100
[email protected]d70bea92013-04-05 04:23:342101 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252102 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342103 return new_contents;
2104
[email protected]bafe6cd2012-05-23 23:09:502105 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432106 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502107 return NULL;
2108
[email protected]bafe6cd2012-05-23 23:09:502109 return new_contents;
2110}
2111
2112RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2113 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2114 if (iter == pending_widget_views_.end()) {
2115 DCHECK(false);
2116 return NULL;
2117 }
2118
2119 RenderWidgetHostView* widget_host_view = iter->second;
2120 pending_widget_views_.erase(route_id);
2121
2122 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2123 if (!widget_host->GetProcess()->HasConnection()) {
2124 // The view has gone away or the renderer crashed. Nothing to do.
2125 return NULL;
2126 }
2127
2128 return widget_host_view;
2129}
2130
[email protected]f13b4202012-06-12 23:53:232131void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092132 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212133 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372134 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232135 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372136 } else {
2137 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:042138 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:372139 scoped_ptr<MediaStreamUI>());
2140 }
[email protected]f13b4202012-06-12 23:53:232141}
2142
grunell657d4d82014-09-18 00:09:432143bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2144 MediaStreamType type) {
2145 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2146 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2147 return delegate_ &&
2148 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2149}
2150
[email protected]cc9200432013-07-23 23:02:402151SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2152 SiteInstance* instance) {
2153 return controller_.GetSessionStorageNamespace(instance);
2154}
2155
[email protected]6de7fc482014-06-06 10:46:442156SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2157 return controller_.GetSessionStorageNamespaceMap();
2158}
2159
[email protected]9b159a52013-10-03 17:24:552160FrameTree* WebContentsImpl::GetFrameTree() {
2161 return &frame_tree_;
2162}
2163
lukendc35e7f2014-11-10 19:06:142164void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2165 virtual_keyboard_requested_ = requested;
2166}
2167
2168bool WebContentsImpl::IsVirtualKeyboardRequested() {
2169 return virtual_keyboard_requested_;
2170}
2171
[email protected]95640212014-07-26 18:14:302172AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2173 return accessibility_mode_;
2174}
2175
[email protected]31a71eaf2014-03-13 01:47:362176void WebContentsImpl::AccessibilityEventReceived(
2177 const std::vector<AXEventNotificationDetails>& details) {
2178 FOR_EACH_OBSERVER(
2179 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2180}
2181
dmazzonia656928e2014-09-15 20:28:542182RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402183 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542184 int browser_plugin_instance_id) {
2185 BrowserPluginGuestManager* guest_manager =
2186 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202187 if (!guest_manager)
2188 return nullptr;
2189
dmazzonia656928e2014-09-15 20:28:542190 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442191 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542192 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202193 return nullptr;
2194
dmazzonia656928e2014-09-15 20:28:542195 return guest->GetMainFrame();
2196}
2197
blundellc57b93f2014-10-29 13:19:572198GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2199 return geolocation_service_context_.get();
2200}
2201
alogvinovf50445a2015-10-30 13:00:122202WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2203 return wake_lock_service_context_.get();
2204}
2205
[email protected]edc3af82013-12-12 21:24:072206void WebContentsImpl::OnShowValidationMessage(
2207 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292208 const base::string16& main_text,
2209 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072210 if (delegate_)
2211 delegate_->ShowValidationMessage(
2212 this, anchor_in_root_view, main_text, sub_text);
2213}
2214
2215void WebContentsImpl::OnHideValidationMessage() {
2216 if (delegate_)
2217 delegate_->HideValidationMessage(this);
2218}
2219
2220void WebContentsImpl::OnMoveValidationMessage(
2221 const gfx::Rect& anchor_in_root_view) {
2222 if (delegate_)
2223 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2224}
2225
lfgbb9c28a2016-03-01 03:19:492226void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372227 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2228 if (node->current_frame_host()->GetRenderWidgetHost())
2229 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2230 }
lfgbb9c28a2016-03-01 03:19:492231
lfgdb5c4ed2016-03-04 23:09:072232 RenderWidgetHostViewBase* rwhv =
2233 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2234 if (rwhv) {
2235 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2236 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2237 }
2238
[email protected]32deec62013-05-15 23:55:042239 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442240 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042241}
2242
[email protected]95640212014-07-26 18:14:302243BrowserAccessibilityManager*
2244 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452245 RenderFrameHostImpl* rfh = GetMainFrame();
2246 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302247}
2248
2249BrowserAccessibilityManager*
2250 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452251 RenderFrameHostImpl* rfh = GetMainFrame();
2252 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302253}
2254
mohsen7ab1ec16ec2015-07-02 18:26:232255void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2256 RenderFrameHost* focused_frame = GetFocusedFrame();
2257 if (!focused_frame)
2258 return;
2259
2260 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2261 focused_frame->GetRoutingID(), extent));
2262}
2263
2264void WebContentsImpl::SelectRange(const gfx::Point& base,
2265 const gfx::Point& extent) {
2266 RenderFrameHost* focused_frame = GetFocusedFrame();
2267 if (!focused_frame)
2268 return;
2269
2270 focused_frame->Send(
2271 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2272}
2273
aurimasab0319022015-07-10 21:57:382274void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2275 int end_adjust) {
2276 RenderFrameHost* focused_frame = GetFocusedFrame();
2277 if (!focused_frame)
2278 return;
2279
2280 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2281 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2282}
2283
[email protected]b172aee2012-04-10 17:05:262284void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492285 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232286 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492287 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332288}
2289
avic3aa8422015-11-09 20:57:222290void WebContentsImpl::ResizeDueToAutoResize(
2291 RenderWidgetHostImpl* render_widget_host,
2292 const gfx::Size& new_size) {
2293 if (render_widget_host != GetRenderViewHost()->GetWidget())
2294 return;
2295
[email protected]61e2b3cc2012-03-02 16:13:342296 if (delegate_)
2297 delegate_->ResizeDueToAutoResize(this, new_size);
2298}
2299
[email protected]b172aee2012-04-10 17:05:262300WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202301 if (!delegate_)
2302 return NULL;
[email protected]00c37fc2011-08-02 00:22:502303
[email protected]e5d549d2011-12-28 01:29:202304 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202305 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342306}
2307
[email protected]6b618e62012-08-16 12:59:182308bool WebContentsImpl::Send(IPC::Message* message) {
2309 if (!GetRenderViewHost()) {
2310 delete message;
2311 return false;
2312 }
2313
2314 return GetRenderViewHost()->Send(message);
2315}
2316
[email protected]a86c0e962013-12-17 17:10:392317void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2318 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442319 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392320 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442321}
2322
[email protected]20ca0382013-02-28 19:50:072323void WebContentsImpl::AttachInterstitialPage(
2324 InterstitialPageImpl* interstitial_page) {
2325 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212326 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292327
2328 // Cancel any visible dialogs so that they don't interfere with the
2329 // interstitial.
creis89a0f782015-05-27 16:13:172330 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292331
[email protected]20ca0382013-02-28 19:50:072332 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2333 DidAttachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252334
2335 // Stop the throbber if needed while the interstitial page is shown.
2336 if (frame_tree_.IsLoading())
2337 LoadingStateChanged(true, true, nullptr);
2338}
2339
2340void WebContentsImpl::DidProceedOnInterstitial() {
2341 // The interstitial page should no longer be pausing the throbber.
2342 DCHECK(!(ShowingInterstitialPage() &&
2343 GetRenderManager()->interstitial_page()->pause_throbber()));
2344
2345 // Restart the throbber now that the interstitial page no longer pauses it.
2346 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2347 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072348}
2349
2350void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252351 bool interstitial_pausing_throbber =
2352 ShowingInterstitialPage() &&
2353 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572354 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212355 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072356 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2357 DidDetachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252358
2359 // Restart the throbber if needed now that the interstitial page is going
2360 // away.
2361 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2362 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072363}
2364
avi2b177592014-12-10 02:08:022365void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2366 int history_length) {
2367 SetHistoryOffsetAndLengthForView(
2368 GetRenderViewHost(), history_offset, history_length);
2369}
2370
2371void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2372 RenderViewHost* render_view_host,
2373 int history_offset,
2374 int history_length) {
2375 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2376 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142377}
2378
[email protected]4fed3702014-04-01 09:08:002379void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172380 RenderFrameHost* focused_frame = GetFocusedFrame();
2381 if (!focused_frame)
2382 return;
2383
[email protected]959be4c2014-04-08 15:01:332384 focused_frame->Send(new FrameMsg_Reload(
2385 focused_frame->GetRoutingID(), ignore_cache));
2386}
2387
megjablon3f5941072016-02-04 23:27:522388void WebContentsImpl::ReloadLoFiImages() {
2389 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2390}
2391
[email protected]959be4c2014-04-08 15:01:332392void WebContentsImpl::Undo() {
2393 RenderFrameHost* focused_frame = GetFocusedFrame();
2394 if (!focused_frame)
2395 return;
2396
2397 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2398 RecordAction(base::UserMetricsAction("Undo"));
2399}
2400
2401void WebContentsImpl::Redo() {
2402 RenderFrameHost* focused_frame = GetFocusedFrame();
2403 if (!focused_frame)
2404 return;
2405 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2406 RecordAction(base::UserMetricsAction("Redo"));
2407}
2408
2409void WebContentsImpl::Cut() {
2410 RenderFrameHost* focused_frame = GetFocusedFrame();
2411 if (!focused_frame)
2412 return;
2413
2414 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2415 RecordAction(base::UserMetricsAction("Cut"));
2416}
2417
2418void WebContentsImpl::Copy() {
2419 RenderFrameHost* focused_frame = GetFocusedFrame();
2420 if (!focused_frame)
2421 return;
2422
2423 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2424 RecordAction(base::UserMetricsAction("Copy"));
2425}
2426
2427void WebContentsImpl::CopyToFindPboard() {
2428#if defined(OS_MACOSX)
2429 RenderFrameHost* focused_frame = GetFocusedFrame();
2430 if (!focused_frame)
2431 return;
2432
2433 // Windows/Linux don't have the concept of a find pasteboard.
2434 focused_frame->Send(
2435 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2436 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2437#endif
2438}
2439
2440void WebContentsImpl::Paste() {
2441 RenderFrameHost* focused_frame = GetFocusedFrame();
2442 if (!focused_frame)
2443 return;
2444
2445 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2446 RecordAction(base::UserMetricsAction("Paste"));
2447}
2448
2449void WebContentsImpl::PasteAndMatchStyle() {
2450 RenderFrameHost* focused_frame = GetFocusedFrame();
2451 if (!focused_frame)
2452 return;
2453
2454 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2455 focused_frame->GetRoutingID()));
2456 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2457}
2458
2459void WebContentsImpl::Delete() {
2460 RenderFrameHost* focused_frame = GetFocusedFrame();
2461 if (!focused_frame)
2462 return;
2463
2464 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2465 RecordAction(base::UserMetricsAction("DeleteSelection"));
2466}
2467
2468void WebContentsImpl::SelectAll() {
2469 RenderFrameHost* focused_frame = GetFocusedFrame();
2470 if (!focused_frame)
2471 return;
2472
2473 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2474 RecordAction(base::UserMetricsAction("SelectAll"));
2475}
2476
2477void WebContentsImpl::Unselect() {
2478 RenderFrameHost* focused_frame = GetFocusedFrame();
2479 if (!focused_frame)
2480 return;
2481
2482 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2483 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172484}
2485
2486void WebContentsImpl::Replace(const base::string16& word) {
2487 RenderFrameHost* focused_frame = GetFocusedFrame();
2488 if (!focused_frame)
2489 return;
2490
[email protected]959be4c2014-04-08 15:01:332491 focused_frame->Send(new InputMsg_Replace(
2492 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172493}
2494
2495void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2496 RenderFrameHost* focused_frame = GetFocusedFrame();
2497 if (!focused_frame)
2498 return;
2499
[email protected]959be4c2014-04-08 15:01:332500 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2501 focused_frame->GetRoutingID(), word));
2502}
2503
2504void WebContentsImpl::NotifyContextMenuClosed(
2505 const CustomContextMenuContext& context) {
2506 RenderFrameHost* focused_frame = GetFocusedFrame();
2507 if (!focused_frame)
2508 return;
2509
2510 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2511 focused_frame->GetRoutingID(), context));
2512}
2513
2514void WebContentsImpl::ExecuteCustomContextMenuCommand(
2515 int action, const CustomContextMenuContext& context) {
2516 RenderFrameHost* focused_frame = GetFocusedFrame();
2517 if (!focused_frame)
2518 return;
2519
2520 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2521 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002522}
2523
[email protected]fc2b46b2014-05-03 16:33:452524gfx::NativeView WebContentsImpl::GetNativeView() {
2525 return view_->GetNativeView();
2526}
2527
2528gfx::NativeView WebContentsImpl::GetContentNativeView() {
2529 return view_->GetContentNativeView();
2530}
2531
2532gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2533 return view_->GetTopLevelNativeWindow();
2534}
2535
2536gfx::Rect WebContentsImpl::GetViewBounds() {
2537 return view_->GetViewBounds();
2538}
2539
2540gfx::Rect WebContentsImpl::GetContainerBounds() {
2541 gfx::Rect rv;
2542 view_->GetContainerBounds(&rv);
2543 return rv;
2544}
2545
2546DropData* WebContentsImpl::GetDropData() {
2547 return view_->GetDropData();
2548}
2549
2550void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042551 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452552}
2553
2554void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042555 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452556}
2557
2558void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042559 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452560}
2561
2562void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042563 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452564}
2565
[email protected]b172aee2012-04-10 17:05:262566void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272567 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212568 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542569 return;
2570 }
[email protected]0b431992014-06-24 00:08:032571 RenderWidgetHostView* const fullscreen_view =
2572 GetFullscreenRenderWidgetHostView();
2573 if (fullscreen_view) {
2574 fullscreen_view->Focus();
2575 return;
2576 }
creisc014b402015-04-23 16:41:452577 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542578}
2579
[email protected]b172aee2012-04-10 17:05:262580bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212581 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542582}
2583
[email protected]b172aee2012-04-10 17:05:262584InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212585 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222586}
2587
[email protected]b172aee2012-04-10 17:05:262588bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162589 // WebKit creates Document object when MIME type is application/xhtml+xml,
2590 // so we also support this MIME type.
2591 return contents_mime_type_ == "text/html" ||
2592 contents_mime_type_ == "text/xml" ||
2593 contents_mime_type_ == "application/xhtml+xml" ||
2594 contents_mime_type_ == "text/plain" ||
2595 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252596 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162597}
2598
[email protected]b172aee2012-04-10 17:05:262599void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592600 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162601 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552602 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192603 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142604 return;
[email protected]c7dd2f62011-07-18 15:57:592605 }
2606
2607 Stop();
2608
2609 // Create the save package and possibly prompt the user for the name to save
2610 // the page as. The user prompt is an asynchronous operation that runs on
2611 // another thread.
2612 save_package_ = new SavePackage(this);
2613 save_package_->GetSaveInfo();
2614}
2615
2616// Used in automated testing to bypass prompting the user for file names.
2617// Instead, the names and paths are hard coded rather than running them through
2618// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342619bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2620 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212621 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592622 // Stop the page from navigating.
2623 Stop();
2624
2625 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212626 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592627}
2628
[email protected]3c71576ce2013-07-23 02:00:012629void WebContentsImpl::SaveFrame(const GURL& url,
2630 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372631 SaveFrameWithHeaders(url, referrer, std::string());
2632}
2633
2634void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2635 const Referrer& referrer,
2636 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192637 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012638 return;
sammc92af61552014-11-19 23:27:402639 if (delegate_ && delegate_->SaveFrame(url, referrer))
2640 return;
2641
nasko89ad7742015-03-05 22:14:192642 // TODO(nasko): This check for main frame is incorrect and should be fixed
2643 // by explicitly passing in which frame this method should target.
2644 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012645
2646 DownloadManager* dlm =
2647 BrowserContext::GetDownloadManager(GetBrowserContext());
2648 if (!dlm)
2649 return;
avib7348942015-12-25 20:57:102650 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012651 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272652 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012653 if (entry)
2654 post_id = entry->GetPostID();
2655 }
2656 scoped_ptr<DownloadUrlParameters> params(
2657 DownloadUrlParameters::FromWebContents(this, url));
2658 params->set_referrer(referrer);
2659 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012660 if (post_id >= 0)
2661 params->set_method("POST");
2662 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372663
2664 if (headers.empty()) {
2665 params->set_prefer_cache(true);
2666 } else {
brettw26dab8f02015-08-08 00:28:472667 for (const base::StringPiece& key_value :
2668 base::SplitStringPiece(
2669 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2670 std::vector<std::string> pair = base::SplitString(
2671 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372672 DCHECK_EQ(2ul, pair.size());
2673 params->add_request_header(pair[0], pair[1]);
2674 }
2675 }
dcheng36b6aec92015-12-26 06:16:362676 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012677}
2678
[email protected]b172aee2012-04-10 17:05:262679void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342680 const base::FilePath& file,
avib7348942015-12-25 20:57:102681 const base::Callback<void(int64_t)>& callback) {
[email protected]18516cf92013-08-28 18:19:482682 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122683}
2684
[email protected]b172aee2012-04-10 17:05:262685const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272686 return contents_mime_type_;
2687}
2688
[email protected]b172aee2012-04-10 17:05:262689bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272690 return notify_disconnection_;
2691}
2692
[email protected]b172aee2012-04-10 17:05:262693void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312694 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182695 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162696}
2697
[email protected]b172aee2012-04-10 17:05:262698void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542699 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182700 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162701}
2702
[email protected]8ff00d72012-10-23 19:12:212703RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272704 return &renderer_preferences_;
2705}
2706
[email protected]e35ccd52012-05-23 16:22:472707void WebContentsImpl::Close() {
2708 Close(GetRenderViewHost());
2709}
2710
[email protected]cf200a562013-05-03 16:24:292711void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462712 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292713 if (browser_plugin_embedder_.get())
2714 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2715 screen_x, screen_y, operation);
2716 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452717 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2718 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292719}
2720
[email protected]d60f3702013-12-26 16:30:242721void WebContentsImpl::DidGetResourceResponseStart(
2722 const ResourceRequestDetails& details) {
2723 controller_.ssl_manager()->DidStartResourceResponse(details);
2724
2725 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2726 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242727}
2728
2729void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462730 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242731 const ResourceRedirectDetails& details) {
2732 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2733
2734 FOR_EACH_OBSERVER(
2735 WebContentsObserver,
2736 observers_,
creis114ca1b2014-11-13 23:51:462737 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242738
2739 // TODO(avi): Remove. http://crbug.com/170921
2740 NotificationService::current()->Notify(
2741 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2742 Source<WebContents>(this),
2743 Details<const ResourceRedirectDetails>(&details));
2744}
2745
calamity7fe55ce2015-04-10 03:59:372746void WebContentsImpl::NotifyWebContentsFocused() {
2747 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2748}
2749
[email protected]b172aee2012-04-10 17:05:262750void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522751 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452752 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292753 if (browser_plugin_embedder_.get())
2754 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342755}
2756
[email protected]e35ccd52012-05-23 16:22:472757void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:532758 OnUserInteraction(GetRenderViewHost()->GetWidget(),
2759 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:472760}
2761
[email protected]b172aee2012-04-10 17:05:262762void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272763 closed_by_user_gesture_ = value;
2764}
2765
[email protected]b172aee2012-04-10 17:05:262766bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272767 return closed_by_user_gesture_;
2768}
2769
[email protected]b172aee2012-04-10 17:05:262770void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502771 if (!delegate_)
2772 return;
2773
[email protected]6286a372013-10-09 04:03:272774 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2775 if (!entry)
[email protected]1788e772010-12-15 16:40:502776 return;
2777
[email protected]6286a372013-10-09 04:03:272778 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122779}
2780
[email protected]b172aee2012-04-10 17:05:262781void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042782 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272783 if (!delegate_)
2784 return;
2785
[email protected]691aa2f2013-05-28 22:52:042786 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272787}
2788
[email protected]b172aee2012-04-10 17:05:262789int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272790 return minimum_zoom_percent_;
2791}
2792
[email protected]b172aee2012-04-10 17:05:262793int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272794 return maximum_zoom_percent_;
2795}
2796
mcnee432e47d2015-11-09 19:37:462797void WebContentsImpl::SetPageScale(float page_scale_factor) {
2798 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242799}
2800
[email protected]b172aee2012-04-10 17:05:262801gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492802 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232803}
2804
[email protected]b172aee2012-04-10 17:05:262805bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052806 if (GetBrowserPluginGuest())
2807 return GetBrowserPluginGuest()->LockMouse(allowed);
2808
creisc014b402015-04-23 16:41:452809 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432810 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2811 allowed)
creisc014b402015-04-23 16:41:452812 : false;
[email protected]0bfbf882011-12-22 18:19:272813}
2814
[email protected]b172aee2012-04-10 17:05:262815bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212816 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502817}
2818
alexmose201c7cd2015-06-10 17:14:212819WebContentsImpl* WebContentsImpl::GetOpener() const {
2820 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2821 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572822}
2823
[email protected]cb805452013-05-22 15:16:212824void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482825 if (!color_chooser_info_.get())
2826 return;
2827 RenderFrameHost* rfh = RenderFrameHost::FromID(
2828 color_chooser_info_->render_process_id,
2829 color_chooser_info_->render_frame_id);
2830 if (!rfh)
2831 return;
2832
2833 rfh->Send(new FrameMsg_DidChooseColorResponse(
2834 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202835}
2836
[email protected]cb805452013-05-22 15:16:212837void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482838 if (!color_chooser_info_.get())
2839 return;
2840 RenderFrameHost* rfh = RenderFrameHost::FromID(
2841 color_chooser_info_->render_process_id,
2842 color_chooser_info_->render_frame_id);
2843 if (!rfh)
2844 return;
2845
2846 rfh->Send(new FrameMsg_DidEndColorChooser(
2847 rfh->GetRoutingID(), color_chooser_info_->identifier));
2848 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202849}
2850
halton.huoca2eabd2015-07-06 08:17:402851int WebContentsImpl::DownloadImage(
2852 const GURL& url,
2853 bool is_favicon,
2854 uint32_t max_bitmap_size,
2855 bool bypass_cache,
2856 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552857 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402858 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:062859 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:402860 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552861 const int download_id = ++next_image_download_id;
2862 if (!mojo_image_downloader) {
2863 // If the renderer process is dead (i.e. crash, or memory pressure on
2864 // Android), the downloader service will be invalid. Pre-Mojo, this would
2865 // hang the callback indefinetly since the IPC would be dropped. Now,
2866 // respond with a 400 HTTP error code to indicate that something went wrong.
2867 BrowserThread::PostTask(
2868 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:192869 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:522870 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
2871 nullptr, nullptr));
amistry9f01b772015-07-29 01:54:552872 return download_id;
2873 }
2874
halton.huoca2eabd2015-07-06 08:17:402875 mojo_image_downloader->DownloadImage(
leon.hancbc4bc3c2016-02-26 07:08:522876 mojo::String::From(url), is_favicon, max_bitmap_size, bypass_cache,
2877 base::Bind(&WebContentsImpl::OnDidDownloadImage,
2878 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:552879 return download_id;
[email protected]795c28972012-12-06 06:13:392880}
2881
[email protected]5dcaf8e2013-12-28 01:31:422882bool WebContentsImpl::IsSubframe() const {
2883 return is_subframe_;
2884}
2885
[email protected]36ec24f2014-01-09 00:32:082886void WebContentsImpl::Find(int request_id,
2887 const base::string16& search_text,
2888 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:332889 // Cowardly refuse to search for no text.
2890 if (search_text.empty()) {
2891 NOTREACHED();
2892 return;
2893 }
2894
raymes0fa0be52014-10-13 20:38:092895 // See if a top level browser plugin handles the find request first.
paulmeyer95703b92015-08-10 17:38:472896 if (browser_plugin_embedder_ &&
2897 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2898 return;
raymes0fa0be52014-10-13 20:38:092899 }
paulmeyer5d0a5f02016-01-21 20:15:522900 GetMainFrame()->Send(new FrameMsg_Find(GetMainFrame()->GetRoutingID(),
2901 request_id, search_text, options));
[email protected]36ec24f2014-01-09 00:32:082902}
2903
2904void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012905 // See if a top level browser plugin handles the stop finding request first.
paulmeyer95703b92015-08-10 17:38:472906 if (browser_plugin_embedder_ &&
2907 browser_plugin_embedder_->StopFinding(action)) {
2908 return;
raymes2bc64182015-02-06 01:23:012909 }
paulmeyer5d0a5f02016-01-21 20:15:522910 GetMainFrame()->Send(
2911 new FrameMsg_StopFinding(GetMainFrame()->GetRoutingID(), action));
[email protected]36ec24f2014-01-09 00:32:082912}
2913
[email protected]4fe53add2014-04-08 19:53:362914void WebContentsImpl::InsertCSS(const std::string& css) {
2915 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2916 GetMainFrame()->GetRoutingID(), css));
2917}
2918
dalecurtisbc6572e12014-09-12 19:22:302919bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:152920 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302921}
2922
mlamouriefdca9d2014-09-16 16:55:402923void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2924 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2925}
2926
dominickn6919ce32015-10-15 01:52:282927void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
2928 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
2929}
2930
bokanece34a82016-01-28 19:49:462931void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532932 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:432933 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:462934 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:532935}
2936
mariakhomenko44bdc4732015-04-29 01:55:382937void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:372938 if (delayed_open_url_params_.get()) {
2939 OpenURL(*delayed_open_url_params_.get());
2940 delayed_open_url_params_.reset(nullptr);
2941 return;
2942 }
2943
mariakhomenko44bdc4732015-04-29 01:55:382944 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
2945 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:162946 if (is_resume_pending_) {
2947 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:132948 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:162949 GetMainFrame()->Init();
2950 }
mariakhomenko44bdc4732015-04-29 01:55:382951}
2952
[email protected]b172aee2012-04-10 17:05:262953bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:262954 // When the browser is started with about:blank as the startup URL, focus
2955 // the location bar (which will also select its contents) so people can
2956 // simply begin typing to navigate elsewhere.
2957 //
2958 // We need to be careful not to trigger this for anything other than the
2959 // startup navigation. In particular, if we allow an attacker to open a
2960 // popup to about:blank, then navigate, focusing the Omnibox will cause the
2961 // end of the new URL to be scrolled into view instead of the start,
2962 // allowing the attacker to spoof other URLs. The conditions checked here
2963 // are all aimed at ensuring no such attacker-controlled navigation can
2964 // trigger this.
2965 //
2966 // Note that we check the pending entry instead of the visible one; for the
2967 // startup URL case these are the same, but for the attacker-controlled
2968 // navigation case the visible entry is the committed "about:blank" URL and
2969 // the pending entry is the problematic navigation elsewhere.
2970 NavigationEntryImpl* entry = controller_.GetPendingEntry();
2971 if (controller_.IsInitialNavigation() && entry &&
2972 !entry->is_renderer_initiated() &&
2973 entry->GetURL() == GURL(url::kAboutBlankURL)) {
[email protected]0c9406632013-02-08 01:13:332974 return true;
palmerc70cb1f2016-03-04 23:41:262975 }
[email protected]0c9406632013-02-08 01:13:332976 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272977}
2978
[email protected]b172aee2012-04-10 17:05:262979void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272980 if (delegate_)
2981 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212982}
2983
clamy0e119882015-07-31 16:12:332984void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
2985 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2986 DidStartNavigation(navigation_handle));
2987}
2988
2989void WebContentsImpl::DidRedirectNavigation(
2990 NavigationHandle* navigation_handle) {
2991 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2992 DidRedirectNavigation(navigation_handle));
2993}
2994
clamyefca29e2015-09-17 00:22:112995void WebContentsImpl::ReadyToCommitNavigation(
2996 NavigationHandle* navigation_handle) {
2997 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2998 ReadyToCommitNavigation(navigation_handle));
2999}
3000
clamy0e119882015-07-31 16:12:333001void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
3002 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3003 DidFinishNavigation(navigation_handle));
3004}
3005
[email protected]52913802013-12-10 05:52:183006void WebContentsImpl::DidStartProvisionalLoad(
3007 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183008 const GURL& validated_url,
3009 bool is_error_page,
3010 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:103011 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483012 FOR_EACH_OBSERVER(
3013 WebContentsObserver,
3014 observers_,
3015 DidStartProvisionalLoadForFrame(
3016 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:083017
3018 // Notify accessibility if this is a reload.
3019 NavigationEntry* entry = controller_.GetVisibleEntry();
3020 if (entry && ui::PageTransitionCoreTypeIs(
3021 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
3022 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3023 BrowserAccessibilityManager* manager =
3024 ftn->current_frame_host()->browser_accessibility_manager();
3025 if (manager)
3026 manager->UserIsReloading();
3027 }
[email protected]400992b2012-06-14 00:03:543028}
3029
[email protected]3109fbb72014-01-06 23:57:153030void WebContentsImpl::DidFailProvisionalLoadWithError(
3031 RenderFrameHostImpl* render_frame_host,
3032 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
3033 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:313034 FOR_EACH_OBSERVER(WebContentsObserver,
3035 observers_,
3036 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:313037 validated_url,
3038 params.error_code,
gsennton6fbb38692015-06-24 19:23:553039 params.error_description,
3040 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:083041
3042 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3043 BrowserAccessibilityManager* manager =
3044 ftn->current_frame_host()->browser_accessibility_manager();
3045 if (manager)
3046 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153047}
3048
[email protected]b80624c2014-02-09 02:46:553049void WebContentsImpl::DidFailLoadWithError(
3050 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553051 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553052 int error_code,
gsennton6fbb38692015-06-24 19:23:553053 const base::string16& error_description,
3054 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:143055 FOR_EACH_OBSERVER(
3056 WebContentsObserver,
3057 observers_,
gsennton6fbb38692015-06-24 19:23:553058 DidFailLoad(render_frame_host, url, error_code, error_description,
3059 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553060}
3061
[email protected]52913802013-12-10 05:52:183062void WebContentsImpl::NotifyChangedNavigationState(
3063 InvalidateTypes changed_flags) {
3064 NotifyNavigationStateChanged(changed_flags);
3065}
3066
[email protected]3691e5cf2014-01-22 10:16:203067void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:203068 const GURL& url,
3069 NavigationController::ReloadType reload_type) {
3070 // Notify observers about navigation.
3071 FOR_EACH_OBSERVER(
3072 WebContentsObserver,
3073 observers_,
3074 DidStartNavigationToPendingEntry(url, reload_type));
3075}
3076
[email protected]8cb834e2014-03-06 14:23:233077void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3078 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503079 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3080 // weak pointer of sorts.
3081 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3082 const int32_t frame_id = render_frame_host->GetRoutingID();
3083
[email protected]65920f332014-03-04 21:14:183084 WebContents* new_contents = OpenURL(params);
3085
dchengb907f7332015-01-07 20:35:503086 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183087 // Notify observers.
3088 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3089 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463090 render_frame_host,
[email protected]65920f332014-03-04 21:14:183091 params.url,
3092 params.referrer,
3093 params.disposition,
creis114ca1b2014-11-13 23:51:463094 params.transition));
[email protected]65920f332014-03-04 21:14:183095 }
3096}
3097
creis29460272015-12-16 04:38:223098bool WebContentsImpl::ShouldTransferNavigation() {
3099 if (!delegate_)
3100 return true;
3101 return delegate_->ShouldTransferNavigation();
3102}
3103
[email protected]aa62afd2014-04-22 19:22:463104bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3105 if (!delegate_)
3106 return false;
3107 return delegate_->ShouldPreserveAbortedURLs(this);
3108}
3109
[email protected]37567b432014-02-12 01:12:223110void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433111 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223112 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353113 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223114 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483115 FOR_EACH_OBSERVER(WebContentsObserver,
3116 observers_,
3117 DidCommitProvisionalLoadForFrame(
3118 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083119
3120 BrowserAccessibilityManager* manager =
3121 render_frame_host->browser_accessibility_manager();
3122 if (manager)
3123 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223124}
3125
[email protected]0d0f4c492014-04-02 06:42:573126void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233127 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573128 // Ensure fullscreen mode is exited before committing the navigation to a
3129 // different page. The next page will not start out assuming it is in
3130 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233131 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193132 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573133 return;
3134 }
avibf58fa0c2015-11-11 01:45:523135 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463136 ExitFullscreen(false);
avibf58fa0c2015-11-11 01:45:523137 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573138}
3139
[email protected]37567b432014-02-12 01:12:223140void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283141 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223142 const LoadCommittedDetails& details,
3143 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3144 if (details.is_navigation_to_different_page()) {
3145 // Clear the status bubble. This is a workaround for a bug where WebKit
3146 // doesn't let us know that the cursor left an element during a
3147 // transition (this is also why the mouse cursor remains as a hand after
3148 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3149 // clear the bubble when a user navigates to a named anchor in the same
3150 // page.
sky8b00392d2015-01-10 00:30:283151 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003152
3153 RenderWidgetHostViewBase* rwhvb =
3154 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3155 if (rwhvb)
3156 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283157
peter90afaba2015-06-01 12:05:293158 did_first_visually_non_empty_paint_ = false;
3159
yusufod41c5f92015-03-06 00:14:283160 // Reset theme color on navigation to new page.
3161 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223162 }
3163
3164 if (!details.is_in_page) {
3165 // Once the main frame is navigated, we're no longer considered to have
3166 // displayed insecure content.
3167 displayed_insecure_content_ = false;
3168 SSLManager::NotifySSLInternalStateChanged(
3169 GetController().GetBrowserContext());
3170 }
3171
3172 // Notify observers about navigation.
3173 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3174 DidNavigateMainFrame(details, params));
3175
[email protected]e85165c642014-06-10 14:34:313176 if (delegate_)
[email protected]37567b432014-02-12 01:12:223177 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313178 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223179}
3180
3181void WebContentsImpl::DidNavigateAnyFramePostCommit(
3182 RenderFrameHostImpl* render_frame_host,
3183 const LoadCommittedDetails& details,
3184 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103185 // Now that something has committed, we don't need to track whether the
3186 // initial page has been accessed.
3187 has_accessed_initial_document_ = false;
3188
[email protected]37567b432014-02-12 01:12:223189 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173190 if (!details.is_in_page)
3191 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223192
avid53461d2016-02-25 17:15:043193 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3194 // again.
3195 if (params.gesture == NavigationGestureUser && dialog_manager_)
3196 dialog_manager_->ResetDialogState(this);
3197
[email protected]37567b432014-02-12 01:12:223198 // Notify observers about navigation.
3199 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093200 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223201}
3202
3203void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3204 contents_mime_type_ = mime_type;
3205}
3206
[email protected]277857a2014-06-03 10:38:013207bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313208 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053209 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313210 return false;
3211
[email protected]37567b432014-02-12 01:12:223212 if (delegate_)
3213 return delegate_->CanOverscrollContent();
3214
3215 return false;
3216}
3217
[email protected]37b64c52014-07-11 21:14:053218void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293219 // Update the theme color. This is to be published to observers after the
3220 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283221 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293222
3223 if (did_first_visually_non_empty_paint_ &&
3224 last_sent_theme_color_ != theme_color_) {
3225 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3226 DidChangeThemeColor(theme_color_));
3227 last_sent_theme_color_ = theme_color_;
3228 }
[email protected]e7104762014-06-20 19:17:253229}
3230
[email protected]b172aee2012-04-10 17:05:263231void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183232 const GURL& url,
[email protected]70435962011-08-02 20:13:283233 const std::string& security_info,
3234 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183235 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403236 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533237 SSLStatus status;
3238 if (!DeserializeSecurityInfo(security_info, &status)) {
3239 bad_message::ReceivedBadMessage(
3240 GetRenderProcessHost(),
3241 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3242 return;
3243 }
[email protected]724159a2010-12-30 01:11:183244
3245 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593246 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213247 LoadFromMemoryCacheDetails details(
rob1ca070f2016-01-12 01:06:263248 url, status.cert_id, status.cert_status, http_method, mime_type,
3249 resource_type);
[email protected]724159a2010-12-30 01:11:183250
[email protected]b0f724c2013-09-05 04:21:133251 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3252
3253 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3254 DidLoadResourceFromMemoryCache(details));
3255
[email protected]8bfc8272013-09-09 20:10:533256 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3257 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403258 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533259 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3260 GetRenderProcessHost()->GetID()) :
jam608f2992016-03-31 16:35:343261 GetRenderProcessHost()->GetStoragePartition()->
3262 GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533263 BrowserThread::PostTask(
3264 BrowserThread::IO,
3265 FROM_HERE,
3266 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3267 }
[email protected]724159a2010-12-30 01:11:183268}
3269
[email protected]b172aee2012-04-10 17:05:263270void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393271 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183272 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193273 SSLManager::NotifySSLInternalStateChanged(
3274 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183275}
3276
estark910b4572015-12-09 20:55:413277void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3278 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583279 LOG(WARNING) << security_origin << " ran insecure content from "
3280 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393281 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413282 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293283 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393284 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183285 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193286 SSLManager::NotifySSLInternalStateChanged(
3287 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183288}
3289
estark910b4572015-12-09 20:55:413290void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3291 const GURL& url,
3292 const std::string& security_info) {
3293 SSLStatus ssl;
3294 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3295 bad_message::ReceivedBadMessage(
3296 GetRenderProcessHost(),
3297 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3298 return;
3299 }
3300
3301 displayed_insecure_content_ = true;
3302 SSLManager::NotifySSLInternalStateChanged(
3303 GetController().GetBrowserContext());
3304}
3305
3306void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3307 const GURL& security_origin,
3308 const GURL& url,
3309 const std::string& security_info) {
3310 SSLStatus ssl;
3311 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3312 bad_message::ReceivedBadMessage(
3313 GetRenderProcessHost(),
3314 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3315 return;
3316 }
3317
3318 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3319 SSLManager::NotifySSLInternalStateChanged(
3320 GetController().GetBrowserContext());
3321}
3322
[email protected]501052ff2014-02-21 22:19:073323void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113324 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473325 return;
naskofbd033392015-01-27 02:34:473326
[email protected]1d62cf72014-02-07 21:31:573327 RenderFrameHostImpl* rfh =
3328 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143329 FOR_EACH_OBSERVER(
3330 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183331}
3332
naskofbd033392015-01-27 02:34:473333void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113334 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123335 return;
[email protected]a1b99262013-12-27 21:56:223336
[email protected]8b3af1e2014-01-24 13:29:123337 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443338 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373339 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423340 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373341
[email protected]61ac9e242014-03-21 20:55:263342 RenderFrameHostImpl* rfh =
3343 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143344 FOR_EACH_OBSERVER(
3345 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313346}
3347
[email protected]b172aee2012-04-10 17:05:263348void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573349 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3350 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263351}
3352
[email protected]b172aee2012-04-10 17:05:263353void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303354 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263355 minimum_zoom_percent_ = minimum_percent;
3356 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263357}
3358
mcnee432e47d2015-11-09 19:37:463359void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3360 bool is_one = page_scale_factor == 1.f;
3361 if (is_one != page_scale_factor_is_one_) {
3362 page_scale_factor_is_one_ = is_one;
3363
3364 HostZoomMapImpl* host_zoom_map =
3365 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3366
3367 if (host_zoom_map && GetRenderProcessHost()) {
3368 host_zoom_map->SetPageScaleFactorIsOneForView(
3369 GetRenderProcessHost()->GetID(), GetRoutingID(),
3370 page_scale_factor_is_one_);
3371 }
3372 }
3373
3374 FOR_EACH_OBSERVER(WebContentsObserver,
3375 observers_,
3376 OnPageScaleFactorChanged(page_scale_factor));
3377}
3378
[email protected]b172aee2012-04-10 17:05:263379void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343380 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433381 if (!delegate_)
3382 return;
3383
[email protected]b9535422012-02-09 01:47:593384 ChildProcessSecurityPolicyImpl* policy =
3385 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223386 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593387 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213388}
3389
[email protected]b172aee2012-04-10 17:05:263390void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3391 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263392 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363393 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433394 if (!delegate_)
3395 return;
3396
[email protected]b9535422012-02-09 01:47:593397 ChildProcessSecurityPolicyImpl* policy =
3398 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323399 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593400 return;
[email protected]8f810632013-06-06 22:33:323401
[email protected]c125e532014-05-10 20:39:063402 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203403}
3404
[email protected]f5273e52014-07-14 16:30:203405void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3406 const GURL& url,
3407 bool user_gesture) {
3408 if (!delegate_)
3409 return;
3410
3411 ChildProcessSecurityPolicyImpl* policy =
3412 ChildProcessSecurityPolicyImpl::GetInstance();
3413 if (policy->IsPseudoScheme(protocol))
3414 return;
3415
3416 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3417}
3418
kouhei40f03cb2015-09-24 07:47:013419void WebContentsImpl::OnUpdatePageImportanceSignals(
3420 const PageImportanceSignals& signals) {
3421 page_importance_signals_ = signals;
3422}
3423
[email protected]b172aee2012-04-10 17:05:263424void WebContentsImpl::OnFindReply(int request_id,
3425 int number_of_matches,
3426 const gfx::Rect& selection_rect,
3427 int active_match_ordinal,
3428 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433429 if (delegate_) {
3430 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3431 active_match_ordinal, final_update);
3432 }
[email protected]b888919c2011-09-02 00:32:163433}
3434
mfomitchev2b8b066a2016-01-28 19:23:153435#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313436void WebContentsImpl::OnFindMatchRectsReply(
3437 int version,
3438 const std::vector<gfx::RectF>& rects,
3439 const gfx::RectF& active_rect) {
3440 if (delegate_)
3441 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3442}
[email protected]583418cc2013-01-17 14:01:103443
[email protected]1ff427972013-02-07 21:14:073444void WebContentsImpl::OnOpenDateTimeDialog(
3445 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173446 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093447 GetRenderViewHost(),
3448 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133449 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093450 value.minimum,
3451 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173452 value.step,
3453 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103454}
[email protected]59363fc92012-09-05 03:46:313455#endif
3456
avi60bd4902015-09-23 20:39:243457void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3458 std::string json = json_string;
3459 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3460 Source<WebContents>(this),
3461 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403462}
3463
[email protected]b172aee2012-04-10 17:05:263464void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3465 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103466 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253467 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103468 AppCacheAccessed(manifest_url, blocked_by_policy));
3469}
3470
[email protected]8bc5ff02013-11-29 06:34:033471void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483472 int color_chooser_id,
3473 SkColor color,
3474 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113475 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003476 return;
nasko907fcb62015-01-28 04:24:113477
[email protected]aa62afd2014-04-22 19:22:463478 ColorChooser* new_color_chooser = delegate_ ?
3479 delegate_->OpenColorChooser(this, color, suggestions) :
3480 NULL;
[email protected]820957a2014-01-14 14:56:303481 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213482 return;
[email protected]8ed16472014-04-11 19:02:483483 if (color_chooser_info_.get())
3484 color_chooser_info_->chooser->End();
3485
3486 color_chooser_info_.reset(new ColorChooserInfo(
3487 render_frame_message_source_->GetProcess()->GetID(),
3488 render_frame_message_source_->GetRoutingID(),
3489 new_color_chooser,
3490 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203491}
3492
[email protected]b172aee2012-04-10 17:05:263493void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483494 if (color_chooser_info_ &&
3495 color_chooser_id == color_chooser_info_->identifier)
3496 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203497}
3498
[email protected]b172aee2012-04-10 17:05:263499void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323500 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483501 if (color_chooser_info_ &&
3502 color_chooser_id == color_chooser_info_->identifier)
3503 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203504}
3505
[email protected]d0759f492012-04-19 22:50:503506// This exists for render views that don't have a WebUI, but do have WebUI
3507// bindings enabled.
3508void WebContentsImpl::OnWebUISend(const GURL& source_url,
3509 const std::string& name,
3510 const base::ListValue& args) {
3511 if (delegate_)
3512 delegate_->WebUISend(this, source_url, name, args);
3513}
3514
thestigc4cac8f2014-09-04 21:17:503515#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003516void WebContentsImpl::OnPepperInstanceCreated() {
3517 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3518}
3519
3520void WebContentsImpl::OnPepperInstanceDeleted() {
3521 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3522}
3523
tommyclie6633ca72014-10-31 00:40:423524void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3525 const base::FilePath& path,
3526 bool is_hung) {
3527 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3528
3529 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3530 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3531}
3532
3533void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3534 base::ProcessId plugin_pid) {
3535 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3536 PluginCrashed(plugin_path, plugin_pid));
3537}
3538
[email protected]d8415ad92012-08-23 14:40:503539void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443540 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503541 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343542 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163543 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443544 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163545 return;
[email protected]d8415ad92012-08-23 14:40:503546 }
3547
[email protected]8c8fc292012-11-23 18:57:163548 if (!delegate_->RequestPpapiBrokerPermission(
3549 this, url, plugin_path,
3550 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443551 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163552 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443553 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163554 }
[email protected]d8415ad92012-08-23 14:40:503555}
3556
[email protected]ea0309c2013-08-06 19:35:443557void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503558 bool result) {
[email protected]ea0309c2013-08-06 19:35:443559 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503560}
3561
fsamuel833ee7c2015-02-13 23:40:403562void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3563 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393564 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143565 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403566 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373567}
tommyclie6633ca72014-10-31 00:40:423568#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373569
[email protected]795c28972012-12-06 06:13:393570void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393571 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063572 // We get updated favicon URLs after the page stops loading. If a cross-site
3573 // navigation occurs while a page is still loading, the initial page
3574 // may stop loading and send us updated favicon URLs after the navigation
3575 // for the new page has committed.
3576 RenderViewHostImpl* rvhi =
3577 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3578 if (!rvhi->is_active())
3579 return;
3580
[email protected]795c28972012-12-06 06:13:393581 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293582 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393583}
3584
avayvod41634b12015-07-08 17:07:053585void WebContentsImpl::OnMediaSessionStateChanged() {
3586 MediaSession* session = MediaSession::Get(this);
3587 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3588 MediaSessionStateChanged(session->IsControllable(),
mlamouri2d1bfbd2016-03-17 13:14:543589 session->IsSuspended(),
3590 session->metadata()));
avayvod41634b12015-07-08 17:07:053591}
3592
3593void WebContentsImpl::ResumeMediaSession() {
mlamouri918734092016-03-12 04:47:523594 MediaSession::Get(this)->Resume(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053595}
3596
3597void WebContentsImpl::SuspendMediaSession() {
mlamouri918734092016-03-12 04:47:523598 MediaSession::Get(this)->Suspend(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053599}
3600
mlamouri4c4fbed2015-08-17 15:51:013601void WebContentsImpl::StopMediaSession() {
mlamouri918734092016-03-12 04:47:523602 MediaSession::Get(this)->Stop(MediaSession::SuspendType::UI);
mlamouri4c4fbed2015-08-17 15:51:013603}
3604
[email protected]50279492014-05-05 23:24:293605void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153606 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293607 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283608
peter90afaba2015-06-01 12:05:293609 did_first_visually_non_empty_paint_ = true;
3610
yusufod41c5f92015-03-06 00:14:283611 if (theme_color_ != last_sent_theme_color_) {
3612 // Theme color should have updated by now if there was one.
3613 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3614 DidChangeThemeColor(theme_color_));
3615 last_sent_theme_color_ = theme_color_;
3616 }
[email protected]9f268072013-11-07 00:02:153617}
[email protected]d9030b82013-07-19 08:26:063618
[email protected]e67ebf32013-02-13 11:07:193619void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013620 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073621 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013622
estark5ea80e52015-06-19 18:43:123623 SecurityStyleExplanations security_style_explanations;
3624 SecurityStyle security_style =
3625 delegate_->GetSecurityStyle(this, &security_style_explanations);
3626 FOR_EACH_OBSERVER(
3627 WebContentsObserver, observers_,
3628 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013629 }
[email protected]e67ebf32013-02-13 11:07:193630}
3631
[email protected]17e286e2013-03-01 23:29:393632void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3633 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3634 BeforeFormRepostWarningShow());
3635}
3636
[email protected]ec6c05f2013-10-23 18:41:573637void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3638 Activate();
3639 if (delegate_)
3640 delegate_->ShowRepostFormWarningDialog(this);
3641}
3642
[email protected]b4c84012014-04-28 19:51:103643bool WebContentsImpl::HasAccessedInitialDocument() {
3644 return has_accessed_initial_document_;
3645}
3646
[email protected]b172aee2012-04-10 17:05:263647void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463648 // If we are creating a RVH for a restored controller, then we need to make
3649 // sure the RenderView starts with a next_page_id_ larger than the number
3650 // of restored entries. This must be called before the RenderView starts
3651 // navigating (to avoid a race between the browser updating max_page_id and
3652 // the renderer updating next_page_id_). Because of this, we only call this
3653 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563654 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583655 if (max_restored_page_id >
3656 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3657 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3658 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323659}
3660
[email protected]b172aee2012-04-10 17:05:263661bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263662 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323663 // For file URLs without a title, use the pathname instead. In the case of a
3664 // synthesized title, we don't want the update to count toward the "one set
3665 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263666 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323667 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513668 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243669 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323670 explicit_set = false; // Don't count synthetic titles toward the set limit.
3671 } else {
[email protected]8af69c6c2014-03-03 19:05:313672 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323673 explicit_set = true;
3674 }
3675
[email protected]987fc3a2011-05-26 14:18:093676 // If a page is created via window.open and never navigated,
3677 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553678 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093679 if (entry) {
[email protected]36fc0392011-12-25 03:59:513680 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093681 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323682
[email protected]36fc0392011-12-25 03:59:513683 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093684 } else {
3685 if (page_title_when_no_navigation_entry_ == final_title)
3686 return false; // Nothing changed, don't bother.
3687
3688 page_title_when_no_navigation_entry_ = final_title;
3689 }
[email protected]420ae012009-04-24 05:16:323690
[email protected]420ae012009-04-24 05:16:323691 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233692 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323693
[email protected]66798902013-10-01 18:40:163694 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533695 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163696
[email protected]420ae012009-04-24 05:16:323697 return true;
3698}
3699
fdegansa696e5112015-04-17 01:57:593700void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003701 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003702 if (delegate_)
fdegansa696e5112015-04-17 01:57:593703 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003704}
3705
3706void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343707 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003708 loading_weak_factory_.InvalidateWeakPtrs();
3709 loading_last_progress_update_ = base::TimeTicks();
3710}
3711
clamy44e84ce2016-02-22 15:38:253712// Notifies the RenderWidgetHost instance about the fact that the page is
3713// loading, or done loading.
3714void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3715 bool due_to_interstitial,
3716 LoadNotificationDetails* details) {
3717 // Do not send notifications about loading changes in the FrameTree while the
3718 // interstitial page is pausing the throbber.
3719 if (ShowingInterstitialPage() &&
3720 GetRenderManager()->interstitial_page()->pause_throbber() &&
3721 !due_to_interstitial) {
3722 return;
3723 }
3724
3725 bool is_loading = IsLoading();
3726
3727 if (!is_loading) {
3728 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3729 base::string16());
3730 load_state_host_.clear();
3731 upload_size_ = 0;
3732 upload_position_ = 0;
3733 }
3734
3735 GetRenderManager()->SetIsLoading(is_loading);
3736
3737 waiting_for_response_ = is_loading;
3738 is_load_to_different_document_ = to_different_document;
3739
3740 if (delegate_)
3741 delegate_->LoadingStateChanged(this, to_different_document);
3742 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3743
3744 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3745 if (is_loading) {
3746 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3747 this, "URL", url, "Main FrameTreeNode id",
3748 GetFrameTree()->root()->frame_tree_node_id());
3749 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
3750 } else {
3751 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3752 this, "URL", url);
3753 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
3754 }
3755
3756 // TODO(avi): Remove. http://crbug.com/170921
3757 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3758 NotificationDetails det = NotificationService::NoDetails();
3759 if (details)
3760 det = Details<LoadNotificationDetails>(details);
3761 NotificationService::current()->Notify(
3762 type, Source<NavigationController>(&controller_), det);
3763}
3764
[email protected]02d7b6e2014-06-24 21:01:503765void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3766 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323767 // After sending out a swap notification, we need to send a disconnect
3768 // notification so that clients that pick up a pointer to |this| can NULL the
3769 // pointer. See Bug 1230284.
3770 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113771 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283772 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113773
[email protected]7a846df2012-09-20 19:17:393774 // Ensure that the associated embedder gets cleared after a RenderViewHost
3775 // gets swapped, so we don't reuse the same embedder next time a
3776 // RenderViewHost is attached to this WebContents.
3777 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323778}
3779
[email protected]02d7b6e2014-06-24 21:01:503780void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3781 RenderFrameHost* new_host) {
3782 FOR_EACH_OBSERVER(WebContentsObserver,
3783 observers_,
3784 RenderFrameHostChanged(old_host, new_host));
3785}
3786
[email protected]da7a7182013-09-06 08:11:113787// TODO(avi): Remove this entire function because this notification is already
3788// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263789void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323790 if (!notify_disconnection_)
3791 return;
3792
3793 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213794 NotificationService::current()->Notify(
3795 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3796 Source<WebContents>(this),
3797 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323798}
3799
[email protected]cbb1ef592013-06-05 19:49:463800void WebContentsImpl::NotifyNavigationEntryCommitted(
3801 const LoadCommittedDetails& load_details) {
3802 FOR_EACH_OBSERVER(
3803 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3804}
3805
[email protected]f114fa42013-12-06 17:06:443806bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3807 const IPC::Message& message) {
3808 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313809}
3810
[email protected]c31a84802014-04-03 15:55:493811const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3812 return GetLastCommittedURL();
3813}
3814
[email protected]b849847b2013-12-10 21:57:583815void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583816 FOR_EACH_OBSERVER(WebContentsObserver,
3817 observers_,
3818 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303819 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
clamy91b7abf2016-03-24 15:17:453820
3821 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
3822 return;
3823
3824 NavigationEntry* entry = controller_.GetPendingEntry();
3825 if (entry && entry->IsViewSourceMode()) {
3826 // Put the renderer in view source mode.
3827 render_frame_host->Send(
3828 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
3829 }
[email protected]b849847b2013-12-10 21:57:583830}
3831
3832void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3833 FOR_EACH_OBSERVER(WebContentsObserver,
3834 observers_,
3835 RenderFrameDeleted(render_frame_host));
3836}
3837
[email protected]a09d53ce2014-01-31 00:46:423838void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3839 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103840 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423841 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103842 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423843 return;
3844
[email protected]077e704b2014-05-23 19:24:103845 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3846 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423847}
3848
[email protected]87de04b02014-04-08 22:14:493849void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013850 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493851 const base::string16& message,
3852 const base::string16& default_prompt,
3853 const GURL& frame_url,
3854 JavaScriptMessageType javascript_message_type,
3855 IPC::Message* reply_msg) {
3856 // Suppress JavaScript dialogs when requested. Also suppress messages when
3857 // showing an interstitial as it's shown over the previous page and we don't
3858 // want the hidden page's dialogs to interfere with the interstitial.
3859 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503860 ShowingInterstitialPage() || !delegate_ ||
3861 delegate_->ShouldSuppressDialogs(this) ||
3862 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493863
3864 if (!suppress_this_message) {
3865 std::string accept_lang = GetContentClient()->browser()->
3866 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503867 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493868 dialog_manager_->RunJavaScriptDialog(
palmer4e0ae10d2015-09-03 23:38:413869 this, frame_url, accept_lang, javascript_message_type, message,
[email protected]87de04b02014-04-08 22:14:493870 default_prompt,
palmer4e0ae10d2015-09-03 23:38:413871 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013872 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413873 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493874 &suppress_this_message);
3875 }
3876
3877 if (suppress_this_message) {
3878 // If we are suppressing messages, just reply as if the user immediately
3879 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013880 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3881 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283882 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493883 }
3884
3885 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3886 // http://crbug.com/288961 ). The only safe thing to do here is return.
3887}
3888
3889void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013890 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493891 bool is_reload,
3892 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013893 RenderFrameHostImpl* rfhi =
3894 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493895 if (delegate_)
3896 delegate_->WillRunBeforeUnloadConfirm();
3897
3898 bool suppress_this_message =
creis36e228b2015-06-08 18:48:023899 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT ||
3900 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:503901 delegate_->ShouldSuppressDialogs(this) ||
3902 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493903 if (suppress_this_message) {
3904 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3905 return;
3906 }
3907
3908 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503909 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493910 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:423911 this, is_reload,
[email protected]87de04b02014-04-08 22:14:493912 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013913 render_frame_host->GetProcess()->GetID(),
3914 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283915 false));
[email protected]87de04b02014-04-08 22:14:493916}
3917
[email protected]a86c0e962013-12-17 17:10:393918WebContents* WebContentsImpl::GetAsWebContents() {
3919 return this;
3920}
3921
[email protected]7912e822014-04-16 02:37:033922bool WebContentsImpl::IsNeverVisible() {
3923 if (!delegate_)
3924 return false;
3925 return delegate_->IsNeverVisible(this);
3926}
3927
[email protected]5a3bdf52012-05-24 15:12:573928RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3929 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323930}
3931
[email protected]8ff00d72012-10-23 19:12:213932RendererPreferences WebContentsImpl::GetRendererPrefs(
3933 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463934 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513935}
3936
avic3aa8422015-11-09 20:57:223937gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
3938 RenderWidgetHostImpl* render_widget_host) const {
3939 if (!RenderViewHostImpl::From(render_widget_host))
3940 return gfx::Rect();
3941
[email protected]b7a756d42012-01-23 18:08:173942 if (delegate_)
3943 return delegate_->GetRootWindowResizerRect();
3944 return gfx::Rect();
3945}
3946
[email protected]7a846df2012-09-20 19:17:393947void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273948 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393949 browser_plugin_embedder_.reset();
3950}
3951
[email protected]b172aee2012-04-10 17:05:263952void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443953 // Don't send notifications if we are just creating a swapped-out RVH for
3954 // the opener chain. These won't be used for view-source or WebUI, so it's
3955 // ok to return early.
creiscce56cd2014-09-29 22:45:223956 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443957 return;
3958
[email protected]86f98a22013-03-20 14:35:003959 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313960 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083961
[email protected]8ff00d72012-10-23 19:12:213962 NotificationService::current()->Notify(
3963 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3964 Source<WebContents>(this),
3965 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323966
[email protected]60780f412013-02-25 16:34:103967 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263968
3969 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253970 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:323971}
3972
[email protected]b172aee2012-04-10 17:05:263973void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523974 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323975 // Don't notify the world, since this came from a renderer in the
3976 // background.
3977 return;
3978 }
3979
[email protected]da7a7182013-09-06 08:11:113980 notify_disconnection_ = true;
3981 // TODO(avi): Remove. http://crbug.com/170921
3982 NotificationService::current()->Notify(
3983 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3984 Source<WebContents>(this),
3985 NotificationService::NoDetails());
3986
[email protected]be1f56ab2011-12-22 06:55:313987 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233988 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303989
3990 // Restore the focus to the tab (otherwise the focus will be on the top
3991 // window).
[email protected]484ae5912010-09-29 19:16:143992 if (was_crashed && !FocusLocationBarByDefault() &&
3993 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063994 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143995 }
[email protected]32ded2212011-11-10 18:51:433996
[email protected]d8c660432011-12-22 20:51:253997 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323998}
3999
[email protected]ec6a7eb2013-04-22 17:34:224000void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4001 base::TerminationStatus status,
4002 int error_code) {
[email protected]151a63d2011-12-20 22:32:524003 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324004 // The pending page's RenderViewHost is gone.
4005 return;
4006 }
4007
[email protected]2fcdcc32014-03-05 02:14:074008 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4009 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:524010 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:464011 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074012
[email protected]698191dc2014-02-25 01:06:134013 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174014 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134015
[email protected]f738bdcb2014-07-11 20:40:444016 if (delegate_)
4017 delegate_->HideValidationMessage(this);
4018
[email protected]960b0372014-05-19 18:01:004019 // Reset the loading progress. TODO(avi): What does it mean to have a
4020 // "renderer crash" when there is more than one renderer process serving a
4021 // webpage? Once this function is called at a more granular frame level, we
4022 // probably will need to more granularly reset the state here.
4023 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254024 NotifyDisconnected();
4025 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004026
[email protected]d8c660432011-12-22 20:51:254027 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:274028 observers_,
[email protected]58d5cfe2013-07-10 02:40:524029 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:324030}
4031
[email protected]b172aee2012-04-10 17:05:264032void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:254033 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:064034}
4035
[email protected]b172aee2012-04-10 17:05:264036void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:104037 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:044038 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384039 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4040
creise1d3e5b2014-12-01 18:21:574041 // Ensure that this state update comes from a RenderViewHost that belongs to
4042 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414043 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574044 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414045 return;
[email protected]420ae012009-04-24 05:16:324046
avi286019ce2015-07-29 01:26:584047 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:324048 // when the user is scrolling and entering form data, as well as when we're
4049 // leaving a page, in which case our state may have already been moved to
4050 // the next page. The navigation controller will look up the appropriate
4051 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:584052 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:114053 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584054 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:114055 if (!entry)
[email protected]420ae012009-04-24 05:16:324056 return;
[email protected]420ae012009-04-24 05:16:324057
nasko346969912015-12-16 22:36:474058 // Sanity check that ensures nav_entry_id and page_id point to the same
4059 // navigation entry.
4060 if (rvhi->GetMainFrame()) {
4061 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4062 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4063 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534064
nasko346969912015-12-16 22:36:474065 DCHECK_EQ(entry, new_entry);
4066 }
creisd63f6c4a2015-11-06 19:05:534067
[email protected]691aa2f2013-05-28 22:52:044068 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324069 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044070 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114071 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324072}
4073
sky8b00392d2015-01-10 00:30:284074void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4075 const GURL& url) {
4076 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4077 // If we're fullscreen only update the url if it's from the fullscreen
4078 // renderer.
4079 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444080 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284081 return;
4082 }
[email protected]6934a702011-12-20 00:04:514083 if (delegate_)
avi450ce00e2014-09-24 01:58:524084 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324085}
4086
[email protected]b172aee2012-04-10 17:05:264087void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104088#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294089 // The UI may be in an event-tracking loop, such as between the
4090 // mouse-down and mouse-up in text selection or a button click.
4091 // Defer the close until after tracking is complete, so that we
4092 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294093 // TODO(shess): This could get more fine-grained. For instance,
4094 // closing a tab in another window while selecting text in the
4095 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104096 if (view_->IsEventTracking()) {
4097 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294098 return;
4099 }
[email protected]60780f412013-02-25 16:34:104100#endif
[email protected]07707302009-11-06 00:50:294101
[email protected]420ae012009-04-24 05:16:324102 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524103 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514104 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324105}
4106
[email protected]66bbadaf2014-03-28 16:25:544107void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574108 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4109 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574110}
4111
[email protected]b172aee2012-04-10 17:05:264112void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514113 if (delegate_ && delegate_->IsPopupOrPanel(this))
4114 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324115}
4116
fdegansa696e5112015-04-17 01:57:594117void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094118 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254119 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084120
4121 // Notify accessibility that the user is navigating away from the
4122 // current document.
4123 //
4124 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084125 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594126 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084127 if (manager)
4128 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324129}
4130
fdegansc73eec22015-03-19 14:47:544131void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:324132 scoped_ptr<LoadNotificationDetails> details;
4133
[email protected]9595fd82013-04-19 21:28:494134 // Use the last committed entry rather than the active one, in case a
4135 // pending entry has been created.
4136 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204137 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494138
[email protected]420ae012009-04-24 05:16:324139 // An entry may not exist for a stop when loading an initial blank page or
4140 // if an iframe injected by script into a blank page finishes loading.
4141 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204142 base::TimeDelta elapsed =
4143 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324144
4145 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514146 entry->GetVirtualURL(),
4147 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:324148 elapsed,
4149 &controller_,
4150 controller_.GetCurrentEntryIndex()));
4151 }
4152
clamy44e84ce2016-02-22 15:38:254153 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324154}
4155
fdegansa696e5112015-04-17 01:57:594156void WebContentsImpl::DidChangeLoadProgress() {
4157 double load_progress = frame_tree_.load_progress();
4158
4159 // The delegate is notified immediately for the first and last updates. Also,
4160 // since the message loop may be pretty busy when a page is loaded, it might
4161 // not execute a posted task in a timely manner so the progress report is sent
4162 // immediately if enough time has passed.
4163 base::TimeDelta min_delay =
4164 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4165 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4166 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4167
4168 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4169 // If there is a pending task to send progress, it is now obsolete.
4170 loading_weak_factory_.InvalidateWeakPtrs();
4171
4172 // Notify the load progress change.
4173 SendChangeLoadProgress();
4174
4175 // Clean-up the states if needed.
4176 if (load_progress == 1.0)
4177 ResetLoadProgressState();
4178 return;
4179 }
4180
4181 if (loading_weak_factory_.HasWeakPtrs())
4182 return;
4183
skyostil95082a62015-06-05 19:53:074184 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4185 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4186 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594187 min_delay);
4188}
4189
[email protected]b172aee2012-04-10 17:05:264190void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164191 controller_.DiscardNonCommittedEntries();
4192
4193 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214194 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164195}
4196
[email protected]59167c22013-06-03 18:07:324197void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104198 has_accessed_initial_document_ = true;
4199
[email protected]d1371bf8e2014-04-19 03:26:244200 // We may have left a failed browser-initiated navigation in the address bar
4201 // to let the user edit it and try again. Clear it now that content might
4202 // show up underneath it.
4203 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454204 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244205
[email protected]59167c22013-06-03 18:07:324206 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504207 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324208}
4209
alexmosbe2f4c32015-03-10 02:30:234210void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4211 const std::string& name) {
4212 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4213 FrameNameChanged(render_frame_host, name));
4214}
4215
[email protected]39f2f9252014-05-03 00:54:014216void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294217 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094218 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294219 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094220
4221 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214222 NotificationService::current()->Notify(
4223 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4224 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294225 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084226}
4227
creis8eb8ef22015-11-04 22:51:384228void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4229 const PageState& page_state) {
4230 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4231
4232 // The state update affects the last NavigationEntry associated with the given
4233 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4234 // in the case of an UpdateState from a frame being swapped out). We track
4235 // which entry this is in the RenderFrameHost's nav_entry_id.
4236 RenderFrameHostImpl* rfhi =
4237 static_cast<RenderFrameHostImpl*>(render_frame_host);
4238 NavigationEntryImpl* entry =
4239 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4240 if (!entry)
4241 return;
4242
4243 FrameNavigationEntry* frame_entry =
4244 entry->GetFrameEntry(rfhi->frame_tree_node());
4245 if (!frame_entry)
4246 return;
4247
creisd06a9422015-11-11 03:08:454248 // The SiteInstance might not match if we do a cross-process navigation with
4249 // replacement (e.g., auto-subframe), in which case the swap out of the old
4250 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4251 // has already been replaced and destroyed.
4252 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4253 return;
4254
creis8eb8ef22015-11-04 22:51:384255 if (page_state == frame_entry->page_state())
4256 return; // Nothing to update.
4257
4258 frame_entry->set_page_state(page_state);
4259 controller_.NotifyEntryChanged(entry);
4260}
4261
[email protected]ef3adfc2014-05-11 00:04:544262void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104263 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544264 const base::string16& title,
4265 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544266 // If we have a title, that's a pretty good indication that we've started
4267 // getting useful data.
4268 SetNotWaitingForResponse();
4269
4270 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584271 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544272 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584273 render_frame_host->GetSiteInstance(), page_id);
4274
creis081bc102016-02-26 00:56:274275 // TODO(creis): Find a way to use nav entry IDs to locate the entry to update,
4276 // and intentionally skip updates when the most recent commit was ignored.
4277 // See https://crbug.com/577449.
[email protected]ef3adfc2014-05-11 00:04:544278
4279 // We can handle title updates when we don't have an entry in
4280 // UpdateTitleForEntry, but only if the update is from the current RVH.
4281 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584282 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544283 return;
4284
4285 // TODO(evan): make use of title_direction.
4286 // http://code.google.com/p/chromium/issues/detail?id=27094
4287 if (!UpdateTitleForEntry(entry, title))
4288 return;
4289
4290 // Broadcast notifications when the UI should be updated.
4291 if (entry == controller_.GetEntryAtOffset(0))
4292 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4293}
4294
4295void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4296 const std::string& encoding) {
4297 SetEncoding(encoding);
4298}
4299
[email protected]39f2f9252014-05-03 00:54:014300void WebContentsImpl::DocumentAvailableInMainFrame(
4301 RenderViewHost* render_view_host) {
4302 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4303 DocumentAvailableInMainFrame());
4304}
naskoc0fceff2015-04-30 15:53:524305
[email protected]e1c3a552012-05-04 20:51:324306void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4307 // Tell the active RenderViewHost to run unload handlers and close, as long
4308 // as the request came from a RenderViewHost in the same BrowsingInstance.
4309 // In most cases, we receive this from a swapped out RenderViewHost.
4310 // It is possible to receive it from one that has just been swapped in,
4311 // in which case we might as well deliver the message anyway.
4312 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524313 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324314}
4315
alexmose7da5a12015-04-09 02:22:164316bool WebContentsImpl::ShouldRouteMessageEvent(
4317 RenderFrameHost* target_rfh,
4318 SiteInstance* source_site_instance) const {
4319 // Allow the message if this WebContents is dedicated to a browser plugin
4320 // guest.
[email protected]0eba810b2012-10-18 03:19:364321 // Note: This check means that an embedder could theoretically receive a
4322 // postMessage from anyone (not just its own guests). However, this is
4323 // probably not a risk for apps since other pages won't have references
4324 // to App windows.
alexmose7da5a12015-04-09 02:22:164325 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4326}
[email protected]f546640b2012-05-15 00:03:494327
alexmos58729042015-06-18 23:20:004328void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164329 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4330 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494331
alexmose7da5a12015-04-09 02:22:164332 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144333 // If this message is going to outer WebContents from inner WebContents,
4334 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4335 // already created a RenderFrameProxyHost for that purpose.
4336 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084337 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144338 return;
4339 }
4340
lfg812874d2016-02-09 22:26:134341 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064342 // We create a RenderFrameProxyHost for the embedder in the guest's render
4343 // process but we intentionally do not expose the embedder's opener chain
4344 // to it.
4345 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4346 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494347 } else {
alexmos58729042015-06-18 23:20:004348 RenderFrameHostImpl* source_rfhi =
4349 static_cast<RenderFrameHostImpl*>(source_rfh);
4350 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394351 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494352 }
4353 }
[email protected]f546640b2012-05-15 00:03:494354}
4355
avib7348942015-12-25 20:57:104356bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264357 const base::string16& message,
avib7348942015-12-25 20:57:104358 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264359 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254360 if (!delegate_)
4361 return false;
4362 return delegate_->AddMessageToConsole(this, level, message, line_no,
4363 source_id);
4364}
4365
dominickn9c7ceaa32016-02-27 01:52:534366void WebContentsImpl::OnUserInteraction(
4367 RenderWidgetHostImpl* render_widget_host,
4368 const blink::WebInputEvent::Type type) {
4369 // Ignore when the renderer is swapped out.
4370 // TODO(dominickn,creis): support widgets for out-of-process iframes.
avic3aa8422015-11-09 20:57:224371 if (render_widget_host != GetRenderViewHost()->GetWidget())
4372 return;
4373
dominickn2dd142dd2015-10-29 05:30:504374 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4375 DidGetUserInteraction(type));
dominickn9c7ceaa32016-02-27 01:52:534376
4377 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4378 // Exclude scroll events as user gestures for resource load dispatches.
4379 // rdh is NULL in unittests.
4380 if (rdh && type != blink::WebInputEvent::MouseWheel)
4381 rdh->OnUserGesture(this);
dominickn2dd142dd2015-10-29 05:30:504382}
4383
[email protected]b172aee2012-04-10 17:05:264384void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444385 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254386 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444387}
4388
avic3aa8422015-11-09 20:57:224389void WebContentsImpl::RendererUnresponsive(
4390 RenderWidgetHostImpl* render_widget_host) {
afakhry98241832016-03-11 19:27:474391 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4392 OnRendererUnresponsive(render_widget_host));
4393
[email protected]992db4c2011-05-12 15:37:154394 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224395 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154396 return;
4397
creiscce56cd2014-09-29 22:45:224398 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224399 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584400
[email protected]e5fc1632011-08-08 07:51:534401 // Ignore renderer unresponsive event if debugger is attached to the tab
4402 // since the event may be a result of the renderer sitting on a breakpoint.
4403 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364404 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534405 return;
4406
clamy226727e2015-06-29 10:28:474407 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224408 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324409 // Hang occurred while firing the beforeunload/unload handler.
4410 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224411 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324412
[email protected]fa944cb82013-11-15 17:51:214413 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324414 return;
4415
4416 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564417 // nothing we can do to recover. If the hang is in the beforeunload handler,
4418 // pretend the beforeunload listeners have all fired and allow the delegate
4419 // to continue closing; the user will not have the option of cancelling the
4420 // close. Otherwise, pretend the unload listeners have all fired and close
4421 // the tab.
4422 bool close = true;
clamy226727e2015-06-29 10:28:474423 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564424 delegate_->BeforeUnloadFired(this, true, &close);
4425 }
4426 if (close)
avic3aa8422015-11-09 20:57:224427 Close();
[email protected]420ae012009-04-24 05:16:324428 return;
4429 }
4430
creisc014b402015-04-23 16:41:454431 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474432 return;
4433
[email protected]6934a702011-12-20 00:04:514434 if (delegate_)
4435 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324436}
4437
avic3aa8422015-11-09 20:57:224438void WebContentsImpl::RendererResponsive(
4439 RenderWidgetHostImpl* render_widget_host) {
4440 if (render_widget_host != GetRenderViewHost()->GetWidget())
4441 return;
4442
[email protected]6934a702011-12-20 00:04:514443 if (delegate_)
4444 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324445}
4446
[email protected]b172aee2012-04-10 17:05:264447void WebContentsImpl::LoadStateChanged(
4448 const GURL& url,
4449 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104450 uint64_t upload_position,
4451 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544452 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4453 // is fixed.
4454 tracked_objects::ScopedTracker tracking_profile1(
4455 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4456 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324457 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564458 upload_position_ = upload_position;
4459 upload_size_ = upload_size;
rsleevi24f64dc22015-08-07 21:39:214460 load_state_host_ = url_formatter::IDNToUnicode(
4461 url.host(),
4462 GetContentClient()->browser()->GetAcceptLangs(GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214463 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324464 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464465 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224466 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4467 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464468 }
[email protected]420ae012009-04-24 05:16:324469}
4470
[email protected]b172aee2012-04-10 17:05:264471void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554472 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324473 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124474 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4475 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514476 if (delegate_)
4477 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094478 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324479}
4480
[email protected]58d5cfe2013-07-10 02:40:524481void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544482 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234483 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224484 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544485}
4486
[email protected]b172aee2012-04-10 17:05:264487void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104488 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214489 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264490 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4491 // here during container initialization and normal window size will be set
4492 // later. In case of tab duplication this resizing to 0x0 prevents setting
4493 // normal size later so just ignore it.
4494 if (!size.IsEmpty())
4495 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324496}
4497
[email protected]af905902013-10-01 21:38:514498void WebContentsImpl::CancelModalDialogsForRenderManager() {
4499 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544500 // deferrer would prevent us from swapping out. We also clear the state
4501 // because this is a cross-process navigation, which means that it's a new
4502 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174503 //
4504 // Note that we don't bother telling browser_plugin_embedder_ because the
4505 // cross-process navigation will either destroy the browser plugins or not
4506 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514507 if (dialog_manager_)
avi2460c762015-04-17 15:21:544508 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514509}
4510
[email protected]02d7b6e2014-06-24 21:01:504511void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4512 RenderFrameHost* new_host,
4513 bool is_main_frame) {
4514 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054515 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504516 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084517
[email protected]02d7b6e2014-06-24 21:01:504518 // Make sure the visible RVH reflects the new delegate's preferences.
4519 if (delegate_)
4520 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394521
[email protected]02d7b6e2014-06-24 21:01:504522 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4523 }
4524
4525 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544526}
4527
naskof5940b9f2015-03-02 23:04:054528void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4529 RenderViewHost* old_host,
4530 RenderViewHost* new_host) {
4531 NotifyViewSwapped(old_host, new_host);
4532}
4533
[email protected]b172aee2012-04-10 17:05:264534NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194535 return GetController();
[email protected]3a3d47472010-07-15 21:03:544536}
4537
carlosk35f35af2015-12-01 10:55:404538scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294539 const GURL& url) {
dbeama1b926a2015-08-31 23:17:514540 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(
4541 url, std::string())));
[email protected]420ae012009-04-24 05:16:324542}
4543
[email protected]10f417c52011-12-28 21:04:234544NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264545 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324546 return controller_.GetLastCommittedEntry();
4547}
4548
lfgbede6392015-09-11 21:54:064549void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4550 RenderViewHost* render_view_host) {
4551 RenderWidgetHostViewBase* rwh_view = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:144552 bool is_guest_in_site_per_process =
4553 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084554 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lfgbede6392015-09-11 21:54:064555 if (is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164556 RenderWidgetHostViewChildFrame* rwh_view_child =
avif9ab5d942015-10-15 14:05:444557 new RenderWidgetHostViewChildFrame(render_view_host->GetWidget());
[email protected]bffc8302014-01-23 20:52:164558 rwh_view = rwh_view_child;
4559 } else {
avif9ab5d942015-10-15 14:05:444560 rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]bffc8302014-01-23 20:52:164561 }
[email protected]1a98a932009-11-17 00:12:524562
[email protected]420ae012009-04-24 05:16:324563 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444564 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214565 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064566}
4567
4568bool WebContentsImpl::CreateRenderViewForRenderManager(
4569 RenderViewHost* render_view_host,
4570 int opener_frame_routing_id,
4571 int proxy_routing_id,
4572 const FrameReplicationState& replicated_frame_state) {
4573 TRACE_EVENT0("browser,navigation",
4574 "WebContentsImpl::CreateRenderViewForRenderManager");
4575
4576 if (proxy_routing_id == MSG_ROUTING_NONE)
4577 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324578
[email protected]74ce1ad2011-12-16 21:51:464579 // Make sure we use the correct starting page_id in the new RenderView.
4580 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104581 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584582 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464583
alexmos5ac402d2015-07-09 07:51:104584 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4585 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4586 max_page_id, replicated_frame_state,
4587 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524588 return false;
[email protected]14392a52012-05-02 20:28:444589 }
[email protected]a4127722011-04-27 23:13:524590
avi2b177592014-12-10 02:08:024591 SetHistoryOffsetAndLengthForView(render_view_host,
4592 controller_.GetLastCommittedEntryIndex(),
4593 controller_.GetEntryCount());
4594
[email protected]a220b5932013-09-21 03:47:444595#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504596 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4597 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444598 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444599 if (rwh_view) {
4600 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4601 render_widget_host->WasResized();
4602 }
[email protected]f8233cc2011-05-31 20:24:504603#endif
4604
[email protected]420ae012009-04-24 05:16:324605 return true;
4606}
4607
[email protected]82307f6b2014-08-07 03:30:124608bool WebContentsImpl::CreateRenderFrameForRenderManager(
4609 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044610 int proxy_routing_id,
4611 int opener_routing_id,
japhete6adf142014-10-31 00:01:494612 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044613 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434614 TRACE_EVENT0("browser,navigation",
4615 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124616
4617 RenderFrameHostImpl* rfh =
4618 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044619 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4620 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124621 return false;
4622
4623 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4624 // RenderFrameHost will have to be associated with the appropriate
4625 // RenderWidgetHostView or a new one should be created here.
4626
4627 return true;
4628}
4629
mfomitchev2b8b066a2016-01-28 19:23:154630#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454631
[email protected]155c7f22013-12-09 17:07:184632base::android::ScopedJavaLocalRef<jobject>
4633WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404634 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564635 return GetWebContentsAndroid()->GetJavaObject();
4636}
[email protected]155c7f22013-12-09 17:07:184637
[email protected]0e813a52014-08-13 10:34:564638WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184639 WebContentsAndroid* web_contents_android =
4640 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4641 if (!web_contents_android) {
4642 web_contents_android = new WebContentsAndroid(this);
4643 SetUserData(kWebContentsAndroidKey, web_contents_android);
4644 }
[email protected]0e813a52014-08-13 10:34:564645 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184646}
4647
[email protected]7d244f12013-08-22 21:41:514648bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064649 return CreateRenderViewForRenderManager(
4650 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064651 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514652}
[email protected]fc2b46b2014-05-03 16:33:454653
4654#elif defined(OS_MACOSX)
4655
[email protected]75f4df72014-07-16 22:39:424656void WebContentsImpl::SetAllowOtherViews(bool allow) {
4657 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454658}
4659
[email protected]75f4df72014-07-16 22:39:424660bool WebContentsImpl::GetAllowOtherViews() {
4661 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454662}
4663
[email protected]7d244f12013-08-22 21:41:514664#endif
4665
pkotwicz75ca8ffd2016-02-16 23:10:194666void WebContentsImpl::OnDidDownloadImage(
4667 const ImageDownloadCallback& callback,
4668 int id,
4669 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:524670 int32_t http_status_code,
jamescook70246212016-03-25 19:56:044671 mojo::Array<skia::mojom::BitmapPtr> images,
leon.hancbc4bc3c2016-02-26 07:08:524672 mojo::Array<mojo::SizePtr> original_image_sizes) {
4673 const std::vector<SkBitmap> bitmaps = images.To<std::vector<SkBitmap>>();
4674 const std::vector<gfx::Size> sizes =
4675 original_image_sizes.To<std::vector<gfx::Size>>();
pkotwicz75ca8ffd2016-02-16 23:10:194676
leon.hancbc4bc3c2016-02-26 07:08:524677 callback.Run(id, http_status_code, image_url, bitmaps, sizes);
pkotwicz75ca8ffd2016-02-16 23:10:194678}
4679
[email protected]6fba26d2014-04-29 09:38:284680void WebContentsImpl::OnDialogClosed(int render_process_id,
4681 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264682 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494683 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264684 bool success,
[email protected]fcf75d42013-12-03 20:11:264685 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284686 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4687 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494688 last_dialog_suppressed_ = dialog_was_suppressed;
4689
[email protected]beb440c2009-11-06 04:08:544690 if (is_showing_before_unload_dialog_ && !success) {
[email protected]6fba26d2014-04-29 09:38:284691 if (rfh)
clamy44e84ce2016-02-22 15:38:254692 rfh->frame_tree_node()->BeforeUnloadCanceled();
[email protected]15d160c02012-07-04 10:52:354693 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104694
[email protected]6d65a462013-06-21 21:29:124695 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4696 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544697 }
[email protected]87de04b02014-04-08 22:14:494698
[email protected]beb440c2009-11-06 04:08:544699 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284700 if (rfh) {
4701 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4702 dialog_was_suppressed);
4703 } else {
4704 // Don't leak the sync IPC reply if the RFH or process is gone.
4705 delete reply_msg;
4706 }
[email protected]beb440c2009-11-06 04:08:544707}
4708
[email protected]b172aee2012-04-10 17:05:264709void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544710 if (encoding == last_reported_encoding_)
4711 return;
4712 last_reported_encoding_ = encoding;
4713
4714 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124715 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104716}
[email protected]f45d2a72010-03-08 23:28:354717
[email protected]1ac10dca2013-08-20 20:47:044718bool WebContentsImpl::IsHidden() {
4719 return capturer_count_ == 0 && !should_normally_be_visible_;
4720}
4721
rob97250742015-12-10 17:45:154722int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144723 if (node_ && node_->outer_web_contents())
4724 return node_->outer_contents_frame_tree_node_id();
4725
nick2482a2d2015-12-18 01:39:374726 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144727}
4728
[email protected]b0936d22013-11-28 06:47:364729RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214730 return frame_tree_.root()->render_manager();
4731}
4732
lazyboy8e16ddfd2015-09-28 03:41:564733WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4734 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4735 if (node_)
4736 return node_->outer_web_contents();
4737 } else {
4738 if (GetBrowserPluginGuest())
4739 return GetBrowserPluginGuest()->embedder_web_contents();
4740 }
4741 return nullptr;
4742}
4743
[email protected]f8497342013-02-05 22:15:024744BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394745 return browser_plugin_guest_.get();
4746}
4747
[email protected]738f57a2013-06-29 21:06:544748void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4749 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144750 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544751 browser_plugin_guest_.reset(guest);
4752}
4753
[email protected]f8497342013-02-05 22:15:024754BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394755 return browser_plugin_embedder_.get();
4756}
[email protected]8ff00d72012-10-23 19:12:214757
fsamuel60b42282015-03-10 03:29:144758void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4759 if (browser_plugin_embedder_)
4760 return;
4761 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4762}
4763
[email protected]fc2b46b2014-05-03 16:33:454764gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214765 gfx::Size size;
4766 if (delegate_)
4767 size = delegate_->GetSizeForNewRenderView(this);
4768 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454769 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214770 return size;
4771}
4772
[email protected]ae7eeda2014-07-04 01:53:264773void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4774 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024775 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554776}
4777
[email protected]222f5822014-02-05 23:40:494778void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4779 if (!delegate_)
4780 return;
4781 const gfx::Size new_size = GetPreferredSize();
4782 if (new_size != old_size)
4783 delegate_->UpdatePreferredSize(this, new_size);
4784}
4785
dbeama1b926a2015-08-31 23:17:514786WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4787 const std::string& frame_name) {
4788 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4789 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4790 CreateWebUIControllerForURL(web_ui, url);
4791 if (controller) {
4792 web_ui->AddMessageHandler(new GenericHandler());
4793 web_ui->SetController(controller);
4794 return web_ui;
4795 }
4796
4797 delete web_ui;
4798 return NULL;
4799}
4800
[email protected]34ff1cfc2014-08-20 06:16:054801void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4802 force_disable_overscroll_content_ = force_disable;
4803 if (view_)
4804 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4805}
4806
dalecurtis88c240072015-12-09 02:11:184807void WebContentsImpl::MediaStartedPlaying(
4808 const WebContentsObserver::MediaPlayerId& id) {
4809 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4810}
4811
4812void WebContentsImpl::MediaStoppedPlaying(
4813 const WebContentsObserver::MediaPlayerId& id) {
4814 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4815}
4816
tapted65ff2ea72016-03-01 23:39:004817void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
4818 if (!did_first_set_visible_) {
4819 // If this WebContents has not yet been set to be visible for the first
4820 // time, ignore any requests to make it hidden, since resources would
4821 // immediately be destroyed and only re-created after content loaded. In
4822 // this state the window content is undefined and can show garbage.
4823 // However, the page load mechanism requires an activation call through a
4824 // visibility call to (re)load.
4825 if (visible) {
4826 did_first_set_visible_ = true;
4827 WasShown();
4828 }
4829 return;
4830 }
4831 if (visible == should_normally_be_visible_)
4832 return;
4833
4834 if (visible)
4835 WasShown();
4836 else
4837 WasHidden();
4838}
4839
avid53461d2016-02-25 17:15:044840void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
4841 JavaScriptDialogManager* dialog_manager) {
4842 dialog_manager_ = dialog_manager;
4843}
4844
[email protected]8ff00d72012-10-23 19:12:214845} // namespace content