blob: 37d88b0b19e420f5c9317328983804db93a2e507 [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"
ekaramad2bd4a2f2016-04-06 20:12:4680#include "content/common/text_input_state.h"
[email protected]2c5569662011-03-22 20:45:0281#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3682#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1183#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2884#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4485#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3686#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1787#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1488#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4689#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1590#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0091#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2792#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0093#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3794#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1495#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3096#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3297#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0998#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:1299#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:34100#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:38101#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:42102#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:21103#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:08104#include "content/public/common/browser_plugin_guest_mode.h"
carloskd80262f52015-12-16 14:40:35105#include "content/public/common/browser_side_navigation_policy.h"
[email protected]54087fe2011-10-28 22:02:48106#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54107#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49108#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20109#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:01110#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:03111#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57112#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05113#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40114#include "mojo/common/url_type_converters.h"
115#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]8bfc8272013-09-09 20:10:53116#include "net/http/http_cache.h"
117#include "net/http/http_transaction_factory.h"
118#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34119#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40120#include "skia/public/type_converters.h"
alexmosaedfc6f2016-01-21 23:57:38121#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40122#include "third_party/skia/include/core/SkBitmap.h"
[email protected]a08412b62012-05-29 21:28:56123#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01124#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41125#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52126#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31127
[email protected]583418cc2013-01-17 14:01:10128#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40129#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15130#include "content/browser/android/date_time_chooser_android.h"
dalecurtisc85ed632016-01-13 00:22:46131#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18132#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15133#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10134
[email protected]f66df822012-05-18 16:52:17135#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50136#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57137#endif
[email protected]3e45ba92009-02-20 21:09:00138
fsamuel9cf7bdf2015-11-20 02:19:32139#if defined(MOJO_SHELL_CLIENT)
140#include "content/browser/web_contents/web_contents_view_mus.h"
141#include "content/public/common/mojo_shell_connection.h"
fsamuel6c6da0232015-11-26 05:13:46142#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32143#endif
144
[email protected]8ff00d72012-10-23 19:12:21145namespace content {
[email protected]420ae012009-04-24 05:16:32146namespace {
147
[email protected]960b0372014-05-19 18:01:00148const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41149const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05150
[email protected]155c7f22013-12-09 17:07:18151#if defined(OS_ANDROID)
152const char kWebContentsAndroidKey[] = "web_contents_android";
153#endif // OS_ANDROID
154
[email protected]e4abd3b42013-11-12 18:28:47155base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46156g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
157
[email protected]8bfc8272013-09-09 20:10:53158void NotifyCacheOnIO(
159 scoped_refptr<net::URLRequestContextGetter> request_context,
160 const GURL& url,
161 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58162 net::HttpCache* cache = request_context->GetURLRequestContext()->
163 http_transaction_factory()->GetCache();
164 if (cache)
165 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53166}
167
dcheng57e39e22016-01-21 00:25:38168bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
169 for (FrameTreeNode* node : tree->Nodes()) {
170 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
171 return true;
alexmos4cf2aa32015-07-15 23:40:43172 }
dcheng57e39e22016-01-21 00:25:38173 return false;
[email protected]95640212014-07-26 18:14:30174}
175
[email protected]95640212014-07-26 18:14:30176void SetAccessibilityModeOnFrame(AccessibilityMode mode,
177 RenderFrameHost* frame_host) {
178 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
179}
180
dtseng0dd3fa12015-07-22 19:00:52181void ResetAccessibility(RenderFrameHost* rfh) {
182 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
183}
184
[email protected]420ae012009-04-24 05:16:32185} // namespace
186
[email protected]54944cde2012-12-09 09:24:59187WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21188 FrameTreeNode* opener_node = nullptr;
189 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
190 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
191 params.opener_render_process_id, params.opener_render_frame_id);
192 if (opener_rfh)
193 opener_node = opener_rfh->frame_tree_node();
194 }
195 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19196}
197
198WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59199 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30200 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21201 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30202
203 for (SessionStorageNamespaceMap::const_iterator it =
204 session_storage_namespace_map.begin();
205 it != session_storage_namespace_map.end();
206 ++it) {
207 new_contents->GetController()
208 .SetSessionStorageNamespace(it->first, it->second.get());
209 }
210
[email protected]54944cde2012-12-09 09:24:59211 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19212 return new_contents;
[email protected]a81343d232011-12-27 07:39:20213}
[email protected]746d3052012-05-22 15:15:47214
nickf9acfbe2014-12-23 19:12:37215void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
216 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46217 g_created_callbacks.Get().push_back(callback);
218}
219
nickf9acfbe2014-12-23 19:12:37220void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
221 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46222 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
223 if (g_created_callbacks.Get().at(i).Equals(callback)) {
224 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
225 return;
226 }
227 }
228}
229
avidf38c952015-10-27 13:45:13230WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
231 if (!rvh)
232 return nullptr;
[email protected]746d3052012-05-22 15:15:47233 return rvh->GetDelegate()->GetAsWebContents();
234}
235
[email protected]a86c0e962013-12-17 17:10:39236WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13237 if (!rfh)
238 return nullptr;
239 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39240}
241
[email protected]7fff43e2013-05-21 20:21:10242// WebContentsImpl::DestructionObserver ----------------------------------------
243
244class WebContentsImpl::DestructionObserver : public WebContentsObserver {
245 public:
246 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
247 : WebContentsObserver(watched_contents),
248 owner_(owner) {
249 }
250
251 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58252 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58253 owner_->OnWebContentsDestroyed(
254 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10255 }
256
257 private:
258 WebContentsImpl* owner_;
259
260 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
261};
262
[email protected]8ed16472014-04-11 19:02:48263WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
264 int render_frame_id,
265 ColorChooser* chooser,
266 int identifier)
267 : render_process_id(render_process_id),
268 render_frame_id(render_frame_id),
269 chooser(chooser),
270 identifier(identifier) {
271}
272
273WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
274}
275
lazyboy6ec48b2a2015-06-29 15:18:14276// WebContentsImpl::WebContentsTreeNode ----------------------------------------
277WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
278 : outer_web_contents_(nullptr),
279 outer_contents_frame_tree_node_id_(
nick2482a2d2015-12-18 01:39:37280 FrameTreeNode::kFrameTreeNodeInvalidId) {
lazyboy6ec48b2a2015-06-29 15:18:14281}
282
283WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
284 // Remove child pointer from our parent.
285 if (outer_web_contents_) {
286 ChildrenSet& child_ptrs_in_parent =
287 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
288 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
289 DCHECK(iter != child_ptrs_in_parent.end());
290 child_ptrs_in_parent.erase(this);
291 }
292
293 // Remove parent pointers from our children.
294 // TODO(lazyboy): We should destroy the children WebContentses too. If the
295 // children do not manage their own lifetime, then we would leak their
296 // WebContentses.
297 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
298 child->outer_web_contents_ = nullptr;
299}
300
301void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
302 WebContentsImpl* outer_web_contents,
303 RenderFrameHostImpl* outer_contents_frame) {
304 outer_web_contents_ = outer_web_contents;
305 outer_contents_frame_tree_node_id_ =
306 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
307
308 if (!outer_web_contents_->node_)
309 outer_web_contents_->node_.reset(new WebContentsTreeNode());
310
311 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
312}
313
[email protected]b172aee2012-04-10 17:05:26314// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32315
alexmose201c7cd2015-06-10 17:14:21316WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42317 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22318 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57319 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21320 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01321 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57322 this,
323 this,
324 this,
325 this),
[email protected]6dfed692014-05-22 04:18:03326 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23327 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
328 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34329 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26330 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56331 upload_size_(0),
332 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16333 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47334 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10335 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28336 theme_color_(SK_ColorTRANSPARENT),
337 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29338 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55339 capturer_count_(0),
340 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00341 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57342 is_being_destroyed_(false),
343 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15344 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01345 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39346 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38347 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21348 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
349 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22350 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44351 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55352 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42353 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03354 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49355 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05356 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30357 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57358 geolocation_service_context_(new GeolocationServiceContext()),
waffles1c12bf402016-02-10 17:45:48359 accessibility_mode_(
360 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15361 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35362 bluetooth_connected_device_count_(0),
mohan.reddyaae039a2014-11-21 17:39:50363 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46364 page_scale_factor_is_one_(true),
ekaramad2bd4a2f2016-04-06 20:12:46365 text_input_state_(new TextInputState()),
pkotwicz75ca8ffd2016-02-16 23:10:19366 loading_weak_factory_(this),
367 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55368 frame_tree_.SetFrameRemoveListener(
369 base::Bind(&WebContentsImpl::OnFrameRemoved,
370 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46371#if defined(OS_ANDROID)
372 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
373#else
qinmin58567c82015-01-07 21:00:20374 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46375#endif
csharrisona2280cd2016-02-03 23:21:15376 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
alogvinovf50445a2015-10-30 13:00:12377 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
[email protected]332af7732009-03-11 13:21:35378}
initial.commit09911bf2008-07-26 23:55:29379
[email protected]b172aee2012-04-10 17:05:26380WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32381 is_being_destroyed_ = true;
382
kenrb2a565f82015-09-02 20:24:59383 rwh_input_event_router_.reset();
384
dcheng72be33c2016-01-21 04:11:31385 for (FrameTreeNode* node : frame_tree_.Nodes()) {
386 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
387 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38388 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38389 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31390 }
carlosk35f35af2015-12-01 10:55:40391
dcheng57e39e22016-01-21 00:25:38392 for (RenderWidgetHostImpl* widget : created_widgets_)
393 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26394 created_widgets_.clear();
395
[email protected]3ab9cb82011-06-03 18:02:07396 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15397 if (dialog_manager_)
avi2460c762015-04-17 15:21:54398 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07399
[email protected]8ed16472014-04-11 19:02:48400 if (color_chooser_info_.get())
401 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20402
[email protected]420ae012009-04-24 05:16:32403 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32404
[email protected]ca13a442012-04-17 14:00:12405 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21406 NotificationService::current()->Notify(
407 NOTIFICATION_WEB_CONTENTS_DESTROYED,
408 Source<WebContents>(this),
409 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32410
[email protected]df0c843f2014-05-23 20:37:23411 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14412 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23413 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59414
clamy0e119882015-07-31 16:12:33415 // Manually call the observer methods for the root frame tree node. It is
416 // necessary to manually delete all objects tracking navigations
417 // (NavigationHandle, NavigationRequest) for observers to be properly
418 // notified of these navigations stopping before the WebContents is
419 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23420 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56421
clamy0e119882015-07-31 16:12:33422 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56423 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33424 root->pending_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08425 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33426 }
naskob21fe4872015-02-24 14:15:56427 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33428 root->current_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08429 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33430
431 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35432 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41433 // Do not update state as the WebContents is being destroyed.
434 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33435 if (root->speculative_frame_host()) {
436 root->speculative_frame_host()->SetRenderFrameCreated(false);
437 root->speculative_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08438 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33439 }
440 }
[email protected]f273ee52013-10-18 16:05:27441
naskoa83483fb2015-02-27 16:57:10442 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
443 FrameDeleted(root->current_frame_host()));
444
[email protected]df0c843f2014-05-23 20:37:23445 if (root->pending_render_view_host()) {
446 FOR_EACH_OBSERVER(WebContentsObserver,
447 observers_,
448 RenderViewDeleted(root->pending_render_view_host()));
449 }
[email protected]c06c58c2014-03-12 20:31:59450
[email protected]f273ee52013-10-18 16:05:27451 FOR_EACH_OBSERVER(WebContentsObserver,
452 observers_,
[email protected]df0c843f2014-05-23 20:37:23453 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27454
[email protected]2db9bd72012-04-13 20:20:56455 FOR_EACH_OBSERVER(WebContentsObserver,
456 observers_,
[email protected]12a46832014-05-09 13:35:58457 WebContentsDestroyed());
458
459 FOR_EACH_OBSERVER(WebContentsObserver,
460 observers_,
461 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08462
[email protected]6934a702011-12-20 00:04:51463 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10464
465 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
466 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42467}
468
[email protected]d1198fd2012-08-13 22:50:19469WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59470 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21471 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03472 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21473 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19474
alexmosaedfc6f2016-01-21 23:57:38475 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
476
alexmose201c7cd2015-06-10 17:14:21477 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38478 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21479 new_contents->created_with_opener_ = true;
480 }
481
alexmosaedfc6f2016-01-21 23:57:38482 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
483 // flags, and these flags take effect immediately. An exception is if the
484 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
485 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
486 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
487 if (opener) {
488 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
489 const blink::WebSandboxFlags inherit_flag =
490 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
491 if ((opener_flags & inherit_flag) == inherit_flag) {
492 new_root->SetPendingSandboxFlags(opener_flags);
493 new_root->CommitPendingSandboxFlags();
494 }
495 }
496
alexmose201c7cd2015-06-10 17:14:21497 // This may be true even when opener is null, such as when opening blocked
498 // popups.
alexmos090fae8e2015-05-28 17:09:28499 if (params.created_with_opener)
500 new_contents->created_with_opener_ = true;
501
[email protected]4858e432014-06-23 18:14:17502 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06503 // This makes |new_contents| act as a guest.
504 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16505 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06506 // We are instantiating a WebContents for browser plugin. Set its subframe
507 // bit to true.
508 new_contents->is_subframe_ = true;
509 }
[email protected]54944cde2012-12-09 09:24:59510 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19511 return new_contents;
512}
513
[email protected]95640212014-07-26 18:14:30514// static
515std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
516 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08517 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30518 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30519 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30520 RenderViewHost* rvh = RenderViewHost::From(rwh);
521 if (!rvh)
522 continue;
523 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
524 if (!web_contents)
525 continue;
avidf38c952015-10-27 13:45:13526 if (web_contents->GetRenderViewHost() != rvh)
527 continue;
528 // Because a WebContents can only have one current RVH at a time, there will
529 // be no duplicate WebContents here.
530 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30531 }
532 return result;
533}
534
clamya16aa8172015-05-26 13:07:25535// static
536WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
537 FrameTreeNode* frame_tree_node) {
538 return static_cast<WebContentsImpl*>(
539 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
540}
541
clamy0d32d6d2015-11-24 11:16:26542// static
543WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
544 int render_frame_host_id) {
545 DCHECK_CURRENTLY_ON(BrowserThread::UI);
546 RenderFrameHost* render_frame_host =
547 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
548 if (!render_frame_host)
549 return nullptr;
550
551 return WebContents::FromRenderFrameHost(render_frame_host);
552}
553
[email protected]b0936d22013-11-28 06:47:36554RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21555 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28556}
557
[email protected]7bb761892012-07-20 09:32:47558bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
559 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44560 return OnMessageReceived(render_view_host, NULL, message);
561}
562
563bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
564 RenderFrameHost* render_frame_host,
565 const IPC::Message& message) {
566 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56567 if (GetWebUI() &&
568 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17569 return true;
[email protected]d2353452012-01-19 19:53:56570 }
[email protected]f82d57b52011-04-27 19:13:17571
brettw5a1613dc2015-06-02 05:34:43572 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25573 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33574 if (render_frame_host) {
575 while ((observer = it.GetNext()) != NULL)
576 if (observer->OnMessageReceived(message, render_frame_host))
577 return true;
578 } else {
579 while ((observer = it.GetNext()) != NULL)
580 if (observer->OnMessageReceived(message))
581 return true;
582 }
[email protected]403415a2011-01-10 18:57:53583
[email protected]1d62cf72014-02-07 21:31:57584 // Message handlers should be aware of which
585 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
586 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02587 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57588 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02589 else
[email protected]1d62cf72014-02-07 21:31:57590 render_view_message_source_ = render_view_host;
591
[email protected]724159a2010-12-30 01:11:18592 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33593 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40594 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
595 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05596 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
597 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48598 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
599 OnDocumentLoadedInFrame)
600 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
601 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
602 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
603 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
604 OnSetSelectedColorInColorChooser)
dalecurtis88c240072015-12-09 02:11:18605
dglazkov79c426102015-08-31 21:22:43606 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11607 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25608 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18609 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54610 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18611 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54612 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18613 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41614 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
615 OnDidDisplayContentWithCertificateErrors)
616 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
617 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25618 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26619 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46620 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
621 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21622 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48623 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
624 OnRegisterProtocolHandler)
625 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
626 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01627 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
628 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52629 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10630 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50631 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50632#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00633 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
634 OnPepperInstanceCreated)
635 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
636 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42637 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
638 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50639 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
640 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55641 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40642 OnBrowserPluginMessage(render_frame_host,
643 message))
thestigc4cac8f2014-09-04 21:17:50644#endif
[email protected]41225fe2013-03-29 05:32:02645 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07646 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
647 OnShowValidationMessage)
648 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
649 OnHideValidationMessage)
650 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
651 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15652#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52653 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48654 OnFindMatchRectsReply)
655 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
656 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48657#endif
[email protected]724159a2010-12-30 01:11:18658 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33659 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44660 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57661 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18662
[email protected]724159a2010-12-30 01:11:18663 return handled;
664}
665
nasko907fcb62015-01-28 04:24:11666bool WebContentsImpl::HasValidFrameSource() {
667 if (!render_frame_message_source_) {
668 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18669 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
670 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11671 return false;
672 }
673
674 return true;
675}
676
[email protected]b172aee2012-04-10 17:05:26677void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18678 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21679 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43680 if (delegate_)
681 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18682}
683
[email protected]d1198fd2012-08-13 22:50:19684NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56685 return controller_;
686}
687
[email protected]d1198fd2012-08-13 22:50:19688const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56689 return controller_;
690}
691
[email protected]8ff00d72012-10-23 19:12:21692BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55693 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30694}
695
[email protected]b172aee2012-04-10 17:05:26696const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24697 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32698 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51699 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31700}
701
[email protected]a093ce02013-07-22 20:53:14702const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24703 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32704 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24705 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
706}
707
708const GURL& WebContentsImpl::GetLastCommittedURL() const {
709 // We may not have a navigation entry yet.
710 NavigationEntry* entry = controller_.GetLastCommittedEntry();
711 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
712}
713
[email protected]8ff00d72012-10-23 19:12:21714WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31715 return delegate_;
716}
717
[email protected]8ff00d72012-10-23 19:12:21718void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31719 // TODO(cbentzel): remove this debugging code?
720 if (delegate == delegate_)
721 return;
722 if (delegate_)
723 delegate_->Detach(this);
724 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08725 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31726 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08727 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00728 if (view_)
[email protected]e85165c642014-06-10 14:34:31729 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08730 }
[email protected]be1f56ab2011-12-22 06:55:31731}
732
[email protected]8ff00d72012-10-23 19:12:21733RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21734 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41735 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16736}
737
clamydf1975e2015-02-05 19:12:24738RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41739 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16740}
741
nick53d5cbf2015-04-23 22:50:14742RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
743 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
744 if (!focused_node)
745 return nullptr;
746 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07747}
748
rob3e2a0732016-01-06 21:22:09749RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
750 int frame_tree_node_id) {
751 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
752 return frame ? frame->current_frame_host() : nullptr;
753}
754
[email protected]a86c0e962013-12-17 17:10:39755void WebContentsImpl::ForEachFrame(
756 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38757 for (FrameTreeNode* node : frame_tree_.Nodes()) {
758 on_frame.Run(node->current_frame_host());
759 }
[email protected]a86c0e962013-12-17 17:10:39760}
761
dchengafb53e22016-02-04 08:11:08762std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
763 std::vector<RenderFrameHost*> frame_hosts;
764 for (FrameTreeNode* node : frame_tree_.Nodes())
765 frame_hosts.push_back(node->current_frame_host());
766 return frame_hosts;
767}
768
lukaszacbdf52e2016-01-15 21:19:51769int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
770 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08771 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25772 if (!rfh->IsRenderFrameLive())
773 continue;
774
dchengafb53e22016-02-04 08:11:08775 ++number_of_messages;
776 IPC::Message* message_copy = new IPC::Message(*message);
777 message_copy->set_routing_id(rfh->GetRoutingID());
778 rfh->Send(message_copy);
779 }
[email protected]a86c0e962013-12-17 17:10:39780 delete message;
lukaszacbdf52e2016-01-15 21:19:51781 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39782}
783
lfgdb5c4ed2016-03-04 23:09:07784void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
785 frame_tree_.root()->render_manager()->SendPageMessage(msg);
786}
787
creisc014b402015-04-23 16:41:45788RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21789 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31790}
791
[email protected]6b618e62012-08-16 12:59:18792int WebContentsImpl::GetRoutingID() const {
793 if (!GetRenderViewHost())
794 return MSG_ROUTING_NONE;
795
796 return GetRenderViewHost()->GetRoutingID();
797}
798
creis89a0f782015-05-27 16:13:17799void WebContentsImpl::CancelActiveAndPendingDialogs() {
800 if (dialog_manager_)
801 dialog_manager_->CancelActiveAndPendingDialogs(this);
802 if (browser_plugin_embedder_)
803 browser_plugin_embedder_->CancelGuestDialogs();
804}
805
[email protected]44470a22013-01-24 01:21:54806int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
807 return fullscreen_widget_routing_id_;
808}
809
naskoc0fceff2015-04-30 15:53:52810void WebContentsImpl::ClosePage() {
811 GetRenderViewHost()->ClosePage();
812}
813
[email protected]b172aee2012-04-10 17:05:26814RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21815 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31816}
817
[email protected]4aebbca2013-09-17 22:26:49818RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
819 const {
820 RenderWidgetHost* const widget_host =
821 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
822 GetFullscreenWidgetRoutingID());
823 return widget_host ? widget_host->GetView() : NULL;
824}
825
[email protected]8ff00d72012-10-23 19:12:21826WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31827 return view_.get();
828}
829
yusufod41c5f92015-03-06 00:14:28830SkColor WebContentsImpl::GetThemeColor() const {
831 return theme_color_;
832}
833
[email protected]95640212014-07-26 18:14:30834void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
835 if (mode == accessibility_mode_)
836 return;
837
838 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38839
840 for (FrameTreeNode* node : frame_tree_.Nodes()) {
841 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
842 RenderFrameHost* pending_frame_host =
843 node->render_manager()->pending_frame_host();
844 if (pending_frame_host)
845 SetAccessibilityModeOnFrame(mode, pending_frame_host);
846 }
[email protected]95640212014-07-26 18:14:30847}
848
849void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50850 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30851}
852
853void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50854 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30855}
856
dmazzoni83ba5c82015-04-14 07:11:51857void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
858 // TODO(dmazzoni): http://crbug.com/475608 This only returns the
859 // accessibility tree from the main frame and everything in the
860 // same site instance.
861 GetMainFrame()->RequestAXTreeSnapshot(callback);
862}
863
dbeama1b926a2015-08-31 23:17:51864WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
865 const std::string& frame_name) {
866 DCHECK(!frame_name.empty());
867 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22868}
869
[email protected]8ff00d72012-10-23 19:12:21870WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:40871 WebUI* commited_web_ui = GetCommittedWebUI();
872 return commited_web_ui ? commited_web_ui
873 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:31874}
875
[email protected]8ff00d72012-10-23 19:12:21876WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:40877 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34878}
879
[email protected]86ef6a392012-05-11 22:03:11880void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22881 if (GetUserAgentOverride() == override)
882 return;
883
884 renderer_preferences_.user_agent_override = override;
885
886 // Send the new override string to the renderer.
887 RenderViewHost* host = GetRenderViewHost();
888 if (host)
889 host->SyncRendererPrefs();
890
891 // Reload the page if a load is currently in progress to avoid having
892 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27893 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:25894 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim7dad4b1182016-04-01 14:28:05895 controller_.ReloadBypassingCache(true);
[email protected]8d0f3312012-08-18 01:47:53896
897 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
898 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11899}
900
901const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22902 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11903}
904
[email protected]95640212014-07-26 18:14:30905void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:08906 if (GetAccessibilityMode() != AccessibilityModeOff) {
907 for (RenderFrameHost* rfh : GetAllFrames())
908 ResetAccessibility(rfh);
909 } else {
dtseng0dd3fa12015-07-22 19:00:52910 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:08911 }
[email protected]95640212014-07-26 18:14:30912}
913
914bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
915 return accessibility_mode_ == AccessibilityModeTreeOnly;
916}
917
918bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
919 return accessibility_mode_ == AccessibilityModeComplete;
920}
921
kouhei40f03cb2015-09-24 07:47:01922const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
923 return page_importance_signals_;
924}
925
[email protected]fcf75d42013-12-03 20:11:26926const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55927 // Transient entries take precedence. They are used for interstitial pages
928 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23929 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23930 if (entry) {
jshin1fb76462016-04-05 22:13:03931 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:23932 }
carlosk35f35af2015-12-01 10:55:40933
934 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
935 WebUI* our_web_ui = navigating_web_ui
936 ? navigating_web_ui
937 : GetRenderManager()->current_frame_host()->web_ui();
938
[email protected]7ade2732011-02-10 00:13:58939 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54940 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32941 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54942 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35943 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26944 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54945 if (!title.empty())
946 return title;
947 }
948 }
949
950 // We use the title for the last committed entry rather than a pending
951 // navigation entry. For example, when the user types in a URL, we want to
952 // keep the old page's title until the new load has committed and we get a new
953 // title.
[email protected]96d185d2009-04-24 03:28:54954 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32955
creis072b61f2015-09-28 20:52:24956 // We make an exception for initial navigations. We only want to use the title
957 // from the visible entry if:
958 // 1. The pending entry has been explicitly assigned a title to display.
959 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
960 // which case there is a pending entry index other than -1.
961 //
962 // Otherwise, we want to stick with the last committed entry's title during
963 // new navigations, which have pending entries at index -1 with no title.
964 if (controller_.IsInitialNavigation() &&
965 ((controller_.GetVisibleEntry() &&
966 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
967 controller_.GetPendingEntryIndex() != -1)) {
968 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:47969 }
[email protected]59167c22013-06-03 18:07:32970
[email protected]45d0ef7f2011-01-05 13:46:23971 if (entry) {
jshin1fb76462016-04-05 22:13:03972 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:23973 }
[email protected]987fc3a2011-05-26 14:18:09974
975 // |page_title_when_no_navigation_entry_| is finally used
976 // if no title cannot be retrieved.
977 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54978}
979
avib7348942015-12-25 20:57:10980int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46981 return GetMaxPageIDForSiteInstance(GetSiteInstance());
982}
983
avib7348942015-12-25 20:57:10984int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:26985 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33986 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
987 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46988
[email protected]b6583592012-01-25 19:52:33989 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34990}
991
avib7348942015-12-25 20:57:10992void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:46993 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
994}
995
[email protected]b172aee2012-04-10 17:05:26996void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:10997 SiteInstance* site_instance,
998 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:46999 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331000 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341001}
1002
[email protected]ec6c05f2013-10-23 18:41:571003void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1004 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1005 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571006}
1007
creiscce56cd2014-09-29 22:45:221008SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211009 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541010}
1011
creiscce56cd2014-09-29 22:45:221012SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1013 RenderViewHostImpl* dest_rvh =
1014 GetRenderManager()->pending_render_view_host() ?
1015 GetRenderManager()->pending_render_view_host() :
1016 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581017 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381018}
1019
[email protected]b172aee2012-04-10 17:05:261020bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251021 return frame_tree_.IsLoading() &&
1022 !(ShowingInterstitialPage() &&
1023 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491024}
1025
[email protected]6dfed692014-05-22 04:18:031026bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251027 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031028}
1029
[email protected]b172aee2012-04-10 17:05:261030bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031031 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311032}
1033
[email protected]b172aee2012-04-10 17:05:261034const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311035 return load_state_;
1036}
1037
[email protected]fcf75d42013-12-03 20:11:261038const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311039 return load_state_host_;
1040}
1041
avib7348942015-12-25 20:57:101042uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311043 return upload_size_;
1044}
1045
avib7348942015-12-25 20:57:101046uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311047 return upload_position_;
1048}
1049
[email protected]b172aee2012-04-10 17:05:261050const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541051 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311052}
1053
[email protected]b172aee2012-04-10 17:05:261054bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311055 return displayed_insecure_content_;
1056}
1057
[email protected]222f5822014-02-05 23:40:491058void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251059 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551060 ++capturer_count_;
1061 DVLOG(1) << "There are now " << capturer_count_
1062 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491063
1064 // Note: This provides a hint to upstream code to size the views optimally
1065 // for quality (e.g., to avoid scaling).
1066 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1067 preferred_size_for_capture_ = capture_size;
1068 OnPreferredSizeChanged(preferred_size_);
1069 }
ccameron8807c38f2015-01-17 00:29:191070
1071 // Ensure that all views are un-occluded before capture begins.
1072 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551073}
1074
1075void WebContentsImpl::DecrementCapturerCount() {
1076 --capturer_count_;
1077 DVLOG(1) << "There are now " << capturer_count_
1078 << " capturing(s) of WebContentsImpl@" << this;
1079 DCHECK_LE(0, capturer_count_);
1080
[email protected]5a652232013-02-12 06:15:251081 if (is_being_destroyed_)
1082 return;
1083
[email protected]222f5822014-02-05 23:40:491084 if (capturer_count_ == 0) {
1085 const gfx::Size old_size = preferred_size_for_capture_;
1086 preferred_size_for_capture_ = gfx::Size();
1087 OnPreferredSizeChanged(old_size);
1088 }
1089
[email protected]1ac10dca2013-08-20 20:47:041090 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551091 DVLOG(1) << "Executing delayed WasHidden().";
1092 WasHidden();
1093 }
[email protected]be1f56ab2011-12-22 06:55:311094}
1095
[email protected]f2bd40812013-07-20 04:30:441096int WebContentsImpl::GetCapturerCount() const {
1097 return capturer_count_;
1098}
1099
miu50f97892014-09-22 22:49:521100bool WebContentsImpl::IsAudioMuted() const {
1101 return audio_muter_.get() && audio_muter_->is_muting();
1102}
1103
1104void WebContentsImpl::SetAudioMuted(bool mute) {
1105 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1106 << " for WebContentsImpl@" << this;
1107
1108 if (mute == IsAudioMuted())
1109 return;
1110
1111 if (mute) {
1112 if (!audio_muter_)
1113 audio_muter_.reset(new WebContentsAudioMuter(this));
1114 audio_muter_->StartMuting();
1115 } else {
1116 DCHECK(audio_muter_);
1117 audio_muter_->StopMuting();
1118 }
1119
wjmaclean2f797c782016-01-07 14:52:031120 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1121 DidUpdateAudioMutingState(mute));
1122
miu50f97892014-09-22 22:49:521123 // Notification for UI updates in response to the changed muting state.
1124 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1125}
1126
ortunodf4d7982016-04-08 02:33:351127void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
1128 // Notify for UI updates if the state changes.
1129 bluetooth_connected_device_count_++;
1130 if (bluetooth_connected_device_count_ == 1) {
1131 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1132 }
ortuno32e7db3c2016-03-29 16:14:201133}
1134
ortunodf4d7982016-04-08 02:33:351135void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
1136 // Notify for UI updates if the state changes.
1137 DCHECK(bluetooth_connected_device_count_ != 0);
1138 bluetooth_connected_device_count_--;
1139 if (bluetooth_connected_device_count_ == 0) {
1140 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1141 }
1142}
1143
1144bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1145 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201146}
1147
[email protected]b172aee2012-04-10 17:05:261148bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311149 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1150 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581151 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271152#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581153 crashed_status_ ==
1154 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271155#endif
wfh0d9532a2015-09-02 23:18:581156 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271157 );
[email protected]3c9e1872010-11-18 16:17:491158}
1159
[email protected]b172aee2012-04-10 17:05:261160void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1161 int error_code) {
[email protected]443b80e2010-12-14 00:42:231162 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341163 return;
1164
[email protected]443b80e2010-12-14 00:42:231165 crashed_status_ = status;
1166 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211167 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341168}
1169
[email protected]b172aee2012-04-10 17:05:261170base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311171 return crashed_status_;
1172}
1173
afakhry98241832016-03-11 19:27:471174int WebContentsImpl::GetCrashedErrorCode() const {
1175 return crashed_error_code_;
1176}
1177
[email protected]b172aee2012-04-10 17:05:261178bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311179 return is_being_destroyed_;
1180}
1181
[email protected]7f924832014-08-09 05:57:221182void WebContentsImpl::NotifyNavigationStateChanged(
1183 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541184 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1185 // is fixed.
1186 tracked_objects::ScopedTracker tracking_profile(
1187 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1188 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181189 // Notify the media observer of potential audibility changes.
1190 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271191 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301192 }
1193
[email protected]d5f942ba2008-09-26 19:30:341194 if (delegate_)
1195 delegate_->NavigationStateChanged(this, changed_flags);
1196}
1197
gab0dccfef2015-05-20 18:43:391198base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021199 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331200}
1201
georgesak5582cbe2015-05-22 22:08:071202void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1203 last_active_time_ = last_active_time;
1204}
1205
[email protected]9e2e4632012-07-27 16:38:411206void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541207 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591208
ccameron8807c38f2015-01-17 00:29:191209 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1210 if (view) {
1211 view->Show();
[email protected]789e9152009-08-04 21:59:431212#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191213 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431214#endif
[email protected]de3c5d82014-05-28 22:12:591215 }
[email protected]789e9152009-08-04 21:59:431216 }
[email protected]96d185d2009-04-24 03:28:541217
gab0dccfef2015-05-20 18:43:391218 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381219
[email protected]b9769d82012-02-10 00:23:591220 // The resize rect might have changed while this was inactive -- send the new
1221 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451222 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221223 if (rvh) {
1224 rvh->GetWidget()->ResizeRectChanged(
1225 GetRootWindowResizerRect(rvh->GetWidget()));
1226 }
[email protected]96d185d2009-04-24 03:28:541227
[email protected]c0d9d5672013-10-09 07:38:031228 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1229
[email protected]54597982013-02-06 01:59:551230 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311231}
1232
[email protected]b172aee2012-04-10 17:05:261233void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551234 // If there are entities capturing screenshots or video (e.g., mirroring),
1235 // don't activate the "disable rendering" optimization.
1236 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521237 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551238 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261239 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521240 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331241 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521242 // calls us).
ccameron8807c38f2015-01-17 00:29:191243 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1244 if (view)
1245 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591246 }
[email protected]96d185d2009-04-24 03:28:541247 }
1248
[email protected]c0d9d5672013-10-09 07:38:031249 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1250
[email protected]54597982013-02-06 01:59:551251 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371252}
1253
ccameron8807c38f2015-01-17 00:29:191254void WebContentsImpl::WasOccluded() {
1255 if (capturer_count_ > 0)
1256 return;
1257
1258 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1259 if (view)
1260 view->WasOccluded();
1261 }
1262}
1263
1264void WebContentsImpl::WasUnOccluded() {
1265 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1266 if (view)
1267 view->WasUnOccluded();
1268 }
1269}
1270
[email protected]b172aee2012-04-10 17:05:261271bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311272 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451273 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1274 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311275}
1276
[email protected]1c3f80bd2014-04-08 23:02:061277void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451278 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061279}
1280
lazyboy6ec48b2a2015-06-29 15:18:141281void WebContentsImpl::AttachToOuterWebContentsFrame(
1282 WebContents* outer_web_contents,
1283 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081284 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lfg91a79e12016-04-01 23:52:191285 RenderFrameHostManager* render_manager = GetRenderManager();
1286
1287 // When the WebContents being initialized has an opener, the browser side
1288 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1289 // created. This is needed because the usual initialization happens during
1290 // the first navigation, but when attaching a new window we don't navigate
1291 // before attaching. If the browser side is already initialized, the calls
1292 // below will just early return.
1293 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1294 GetMainFrame()->Init();
1295 if (!render_manager->GetRenderWidgetHostView())
1296 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1297
lazyboy6ec48b2a2015-06-29 15:18:141298 // Create a link to our outer WebContents.
1299 node_.reset(new WebContentsTreeNode());
1300 node_->ConnectToOuterWebContents(
1301 static_cast<WebContentsImpl*>(outer_web_contents),
1302 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1303
1304 DCHECK(outer_contents_frame);
1305
1306 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1307 // SiteInstance of the outer WebContents. The proxy will be used to send
1308 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191309 render_manager->CreateOuterDelegateProxy(
lazyboy6ec48b2a2015-06-29 15:18:141310 outer_contents_frame->GetSiteInstance(),
1311 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1312
lfg91a79e12016-04-01 23:52:191313 render_manager->SetRWHViewForInnerContents(
1314 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391315
1316 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191317 render_manager->GetRenderWidgetHostView())
wjmacleanfab616a2016-03-02 18:40:391318 ->RegisterSurfaceNamespaceId();
lazyboy6ec48b2a2015-06-29 15:18:141319}
1320
[email protected]b172aee2012-04-10 17:05:261321void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381322 for (FrameTreeNode* node : frame_tree_.Nodes())
1323 node->StopLoading();
[email protected]d16609c2013-08-23 06:01:401324 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271325}
1326
[email protected]b172aee2012-04-10 17:05:261327WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441328 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211329 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451330 // before.
[email protected]54944cde2012-12-09 09:24:591331 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451332 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211333 WebContentsImpl* tc =
1334 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191335 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221336 FOR_EACH_OBSERVER(WebContentsObserver,
1337 observers_,
1338 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271339 return tc;
1340}
1341
[email protected]14392a52012-05-02 20:28:441342void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211343 const NotificationSource& source,
1344 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441345 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211346 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1347 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031348 RenderWidgetHostView* view = host->GetView();
1349 if (view == GetFullscreenRenderWidgetHostView()) {
1350 // We cannot just call view_->RestoreFocus() here. On some platforms,
1351 // attempting to focus the currently-invisible WebContentsView will be
1352 // flat-out ignored. Therefore, this boolean is used to track whether
1353 // we will request focus after the fullscreen widget has been
1354 // destroyed.
1355 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1356 } else {
1357 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1358 i != pending_widget_views_.end(); ++i) {
1359 if (host->GetView() == i->second) {
1360 pending_widget_views_.erase(i);
1361 break;
1362 }
[email protected]bafe6cd2012-05-23 23:09:501363 }
1364 }
1365 break;
1366 }
[email protected]14392a52012-05-02 20:28:441367 default:
1368 NOTREACHED();
1369 }
1370}
1371
[email protected]ec6c05f2013-10-23 18:41:571372WebContents* WebContentsImpl::GetWebContents() {
1373 return this;
1374}
1375
[email protected]54944cde2012-12-09 09:24:591376void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211377 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361378 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211379 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431380 should_normally_be_visible_ = !params.initially_hidden;
1381
dcheng3ce04b62015-10-26 23:30:551382 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541383 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551384 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1385 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541386 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551387 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1388 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1389
1390 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1391 if (!site_instance)
1392 site_instance = SiteInstance::Create(params.browser_context);
1393
1394 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1395 // local root by definition.
1396 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1397 // longer be necessary to eagerly grab a routing ID for the view.
1398 // https://crbug.com/545684
1399 int32_t view_routing_id = params.routing_id;
1400 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1401 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1402 view_routing_id = main_frame_widget_routing_id =
1403 site_instance->GetProcess()->GetNextRoutingID();
1404 }
1405
1406 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1407 params.main_frame_routing_id,
1408 main_frame_widget_routing_id);
lukasza464d8692016-02-22 19:26:321409
1410 // blink::FrameTree::setName uses |name| as the |unique_name| for the main
1411 // frame - let's do the same thing here.
1412 std::string unique_name = params.main_frame_name;
1413 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191414
[email protected]fc2b46b2014-05-03 16:33:451415 WebContentsViewDelegate* delegate =
1416 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1417
fsamueladb0033602015-12-09 19:20:411418#if defined(MOJO_SHELL_CLIENT)
1419 if (MojoShellConnection::Get() &&
1420 base::CommandLine::ForCurrentProcess()->HasSwitch(
1421 switches::kUseMusInRenderer)) {
1422 mus::Window* mus_window = aura::GetMusWindow(params.context);
1423 if (mus_window) {
1424 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1425 &render_view_host_delegate_view_));
1426 }
1427 }
1428#endif
1429
1430 if (!view_) {
1431 view_.reset(CreateWebContentsView(this, delegate,
1432 &render_view_host_delegate_view_));
1433 }
fsamuel9cf7bdf2015-11-20 02:19:321434
lazyboy6ec48b2a2015-06-29 15:18:141435 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081436 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
fsamuel9cf7bdf2015-11-20 02:19:321437 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361438 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321439 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191440 }
[email protected]fc2b46b2014-05-03 16:33:451441 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191442 CHECK(view_.get());
1443
[email protected]ed245db2012-12-18 08:00:451444 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591445 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191446
tommyclieb25b2a2014-11-03 19:45:091447#if defined(ENABLE_PLUGINS)
1448 plugin_content_origin_whitelist_.reset(
1449 new PluginContentOriginWhitelist(this));
1450#endif
1451
[email protected]d1198fd2012-08-13 22:50:191452 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211453 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1454 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101455
[email protected]01f83f92014-06-17 14:41:541456 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091457 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541458
mlamouriefdca9d2014-09-16 16:55:401459 manifest_manager_host_.reset(new ManifestManagerHost(this));
1460
mfomitchev2b8b066a2016-01-28 19:23:151461#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101462 date_time_chooser_.reset(new DateTimeChooserAndroid());
1463#endif
fsamuel7310a4262014-12-05 05:06:441464
1465 // BrowserPluginGuest::Init needs to be called after this WebContents has
1466 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1467 if (browser_plugin_guest_)
1468 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371469
1470 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1471 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561472
1473 // If the WebContents creation was renderer-initiated, it means that the
1474 // corresponding RenderView and main RenderFrame have already been created.
1475 // Ensure observers are notified about this.
1476 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431477 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561478 RenderViewCreated(GetRenderViewHost());
1479 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1480 }
naskof5940b9f2015-03-02 23:04:051481
1482 // Ensure that observers are notified of the creation of this WebContents's
1483 // main RenderFrameHost. It must be done here for main frames, since the
1484 // NotifySwappedFromRenderManager expects view_ to already be created and that
1485 // happens after RenderFrameHostManager::Init.
1486 NotifySwappedFromRenderManager(
1487 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191488}
1489
[email protected]7fff43e2013-05-21 20:21:101490void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1491 RemoveDestructionObserver(web_contents);
1492
[email protected]ceee8cd2013-03-08 04:59:511493 // Clear a pending contents that has been closed before being shown.
1494 for (PendingContents::iterator iter = pending_contents_.begin();
1495 iter != pending_contents_.end();
1496 ++iter) {
1497 if (iter->second != web_contents)
1498 continue;
1499 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511500 return;
1501 }
1502 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441503}
1504
[email protected]7fff43e2013-05-21 20:21:101505void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1506 if (!ContainsKey(destruction_observers_, web_contents)) {
1507 destruction_observers_[web_contents] =
1508 new DestructionObserver(this, web_contents);
1509 }
1510}
1511
1512void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1513 DestructionObservers::iterator iter =
1514 destruction_observers_.find(web_contents);
1515 if (iter != destruction_observers_.end()) {
1516 delete destruction_observers_[web_contents];
1517 destruction_observers_.erase(iter);
1518 }
1519}
1520
[email protected]b172aee2012-04-10 17:05:261521void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311522 observers_.AddObserver(observer);
1523}
1524
[email protected]b172aee2012-04-10 17:05:261525void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311526 observers_.RemoveObserver(observer);
1527}
1528
[email protected]948481d2014-06-11 18:32:221529std::set<RenderWidgetHostView*>
1530WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1531 std::set<RenderWidgetHostView*> set;
1532 if (ShowingInterstitialPage()) {
1533 set.insert(GetRenderWidgetHostView());
1534 } else {
dchengafb53e22016-02-04 08:11:081535 for (RenderFrameHost* rfh : GetAllFrames()) {
1536 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1537 ->frame_tree_node()
1538 ->render_manager()
1539 ->GetRenderWidgetHostView();
1540 set.insert(rwhv);
1541 }
[email protected]948481d2014-06-11 18:32:221542 }
[email protected]de3c5d82014-05-28 22:12:591543 return set;
1544}
1545
[email protected]b172aee2012-04-10 17:05:261546void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341547 if (delegate_)
1548 delegate_->ActivateContents(this);
1549}
1550
avi3e4b8512015-11-11 01:55:491551void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1552 if (!RenderViewHostImpl::From(render_widget_host))
1553 return;
1554
[email protected]63954792011-07-11 04:17:481555 if (delegate_)
1556 delegate_->LostCapture();
1557}
1558
lazyboy63f5b312015-11-23 20:19:521559void WebContentsImpl::RenderWidgetCreated(
1560 RenderWidgetHostImpl* render_widget_host) {
1561 created_widgets_.insert(render_widget_host);
1562}
1563
[email protected]b24b68a2012-09-24 21:57:261564void WebContentsImpl::RenderWidgetDeleted(
1565 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521566 // Note that |is_being_destroyed_| can be true at this point as
1567 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1568 // us here.
1569 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261570
lazyboy63f5b312015-11-23 20:19:521571 if (is_being_destroyed_)
1572 return;
[email protected]44470a22013-01-24 01:21:541573
1574 if (render_widget_host &&
1575 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491576 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531577 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541578 FOR_EACH_OBSERVER(WebContentsObserver,
1579 observers_,
1580 DidDestroyFullscreenWidget(
1581 fullscreen_widget_routing_id_));
1582 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031583 if (fullscreen_widget_had_focus_at_shutdown_)
1584 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541585 }
[email protected]b24b68a2012-09-24 21:57:261586}
1587
miu9e14e492014-10-25 02:39:041588void WebContentsImpl::RenderWidgetGotFocus(
1589 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371590 // Notify the observers if an embedded fullscreen widget was focused.
1591 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1592 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1593 NotifyWebContentsFocused();
1594 }
miu9e14e492014-10-25 02:39:041595}
1596
estaded0a0c992015-01-21 14:12:061597void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311598 RenderWidgetHostImpl* render_widget_host,
1599 bool width_changed) {
creisc014b402015-04-23 16:41:451600 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291601 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061602 return;
estaded0a0c992015-01-21 14:12:061603
rouslan2f5993f2015-01-29 00:18:311604 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1605 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061606}
1607
paulmeyer9ef6e4462015-02-24 19:15:101608void WebContentsImpl::ScreenInfoChanged() {
1609 if (browser_plugin_embedder_)
1610 browser_plugin_embedder_->ScreenInfoChanged();
1611}
1612
[email protected]b172aee2012-04-10 17:05:261613bool WebContentsImpl::PreHandleKeyboardEvent(
1614 const NativeWebKeyboardEvent& event,
1615 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481616 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131617 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481618}
1619
[email protected]b172aee2012-04-10 17:05:261620void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101621 if (browser_plugin_embedder_ &&
1622 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1623 return;
1624 }
[email protected]63954792011-07-11 04:17:481625 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131626 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481627}
1628
[email protected]d92026ef2014-03-03 21:04:131629bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461630 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191631#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331632 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1633 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191634 // -the OS already has a gesture to do this through pinch-zoom
1635 // -if a user starts an inertial scroll, let's go, and presses control
1636 // (i.e. control+tab) then the OS's buffered scroll events will come in
1637 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331638 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551639 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331640 !event.canScroll) {
w.shackleton49bcd392016-01-06 17:38:221641 // Count only integer cumulative scrolls as zoom events; this handles
1642 // smooth scroll and regular scroll device behavior.
1643 zoom_scroll_remainder_ += event.wheelTicksY;
1644 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1645 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1646 if (whole_zoom_scroll_remainder_ != 0) {
1647 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1648 }
[email protected]fb3f066e2013-02-12 19:12:521649 return true;
1650 }
[email protected]bccc4472013-04-18 16:37:191651#endif
[email protected]fb3f066e2013-02-12 19:12:521652 return false;
1653}
1654
[email protected]04bce562014-01-30 05:34:541655bool WebContentsImpl::PreHandleGestureEvent(
1656 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031657 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541658}
1659
kenrb2a565f82015-09-02 20:24:591660RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451661 if (!is_being_destroyed_ && GetOuterWebContents())
1662 return GetOuterWebContents()->GetInputEventRouter();
1663
1664 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591665 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1666 return rwh_input_event_router_.get();
1667}
1668
alexmos3fcd0ca2015-10-23 18:18:331669void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1670 // Focus loss may occur while this WebContents is being destroyed. Don't
1671 // send the message in this case, as the main frame's RenderFrameHost and
1672 // other state has already been cleared.
1673 if (is_being_destroyed_)
1674 return;
1675
1676 frame_tree_.ReplicatePageFocus(is_focused);
1677}
1678
alexmosc4cbacb2015-11-21 01:29:221679RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1680 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521681 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221682 return receiving_widget;
1683
1684 // Events for widgets other than the main frame (e.g., popup menus) should be
1685 // forwarded directly to the widget they arrived on.
1686 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1687 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521688
1689 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1690 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221691 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521692
alexmos732ca3a2015-12-08 02:01:021693 // The view may be null if a subframe's renderer process has crashed while
1694 // the subframe has focus. Drop the event in that case. Do not give
1695 // it to the main frame, so that the user doesn't unexpectedly type into the
1696 // wrong frame if a focused subframe renderer crashes while they type.
1697 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1698 if (!view)
1699 return nullptr;
1700
1701 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521702}
1703
mlamouri7a78d6fd2015-01-17 13:23:531704void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1705 // This method is being called to enter renderer-initiated fullscreen mode.
1706 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491707 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371708 if (widget_view) {
1709 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1710 ->ShutdownAndDestroyWidget(true);
1711 }
[email protected]4aebbca2013-09-17 22:26:491712
[email protected]8a5e0ca2011-08-25 06:30:471713 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531714 delegate_->EnterFullscreenModeForTab(this, origin);
1715
1716 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461717 DidToggleFullscreenModeForTab(
1718 IsFullscreenForCurrentTab(
1719 GetRenderViewHost()->GetWidget()),
1720 false));
mlamouri7a78d6fd2015-01-17 13:23:531721}
1722
bokanece34a82016-01-28 19:49:461723void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531724 // This method is being called to leave renderer-initiated fullscreen mode.
1725 // Make sure any existing fullscreen widget is shut down first.
1726 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371727 if (widget_view) {
1728 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1729 ->ShutdownAndDestroyWidget(true);
1730 }
mlamouri7a78d6fd2015-01-17 13:23:531731
hugo.holgersson61288e6c2015-01-28 17:04:401732#if defined(OS_ANDROID)
1733 ContentVideoView* video_view = ContentVideoView::GetInstance();
1734 if (video_view != NULL)
watk98292292016-01-19 22:24:081735 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401736#endif
1737
mlamouri7a78d6fd2015-01-17 13:23:531738 if (delegate_)
1739 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371740
bokanece34a82016-01-28 19:49:461741 // The fullscreen state is communicated to the renderer through a resize
1742 // message. If the change in fullscreen state doesn't cause a view resize
1743 // then we must ensure web contents exit the fullscreen state by explicitly
1744 // sending a resize message. This is required for the situation of the browser
1745 // moving the view into a "browser fullscreen" state and then the contents
1746 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1747 // have the side effect of the view resizing, hence the explicit call here is
1748 // required.
1749 if (!will_cause_resize) {
1750 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1751 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1752 render_widget_host->WasResized();
1753 }
scheib3dcb6c932015-02-23 10:55:581754 }
1755
avibf58fa0c2015-11-11 01:45:521756 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461757 DidToggleFullscreenModeForTab(
1758 IsFullscreenForCurrentTab(
1759 GetRenderViewHost()->GetWidget()),
1760 will_cause_resize));
[email protected]8a5e0ca2011-08-25 06:30:471761}
1762
avibf58fa0c2015-11-11 01:45:521763bool WebContentsImpl::IsFullscreenForCurrentTab(
1764 RenderWidgetHostImpl* render_widget_host) const {
1765 if (!RenderViewHostImpl::From(render_widget_host))
1766 return false;
1767
[email protected]199bba6e2012-04-04 16:19:381768 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121769}
1770
avibf58fa0c2015-11-11 01:45:521771blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1772 RenderWidgetHostImpl* render_widget_host) const {
1773 if (!RenderViewHostImpl::From(render_widget_host))
1774 return blink::WebDisplayModeBrowser;
1775
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121776 return delegate_ ? delegate_->GetDisplayMode(this)
1777 : blink::WebDisplayModeBrowser;
1778}
1779
avic3aa8422015-11-09 20:57:221780void WebContentsImpl::RequestToLockMouse(
1781 RenderWidgetHostImpl* render_widget_host,
1782 bool user_gesture,
1783 bool last_unlocked_by_target) {
1784 if (render_widget_host != GetRenderViewHost()->GetWidget()) {
1785 render_widget_host->GotResponseToLockMouseRequest(false);
1786 return;
[email protected]e9621112011-10-17 05:38:371787 }
avic3aa8422015-11-09 20:57:221788
1789 if (delegate_)
1790 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1791 else
1792 GotResponseToLockMouseRequest(false);
[email protected]e9621112011-10-17 05:38:371793}
1794
avi3e4b8512015-11-11 01:55:491795void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1796 if (!RenderViewHostImpl::From(render_widget_host))
1797 return;
1798
[email protected]e9621112011-10-17 05:38:371799 if (delegate_)
1800 delegate_->LostMouseLock();
1801}
1802
dtrainor5ef644e2015-11-19 00:12:471803void WebContentsImpl::ForwardCompositorProto(
1804 RenderWidgetHostImpl* render_widget_host,
1805 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:471806 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:291807 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:471808}
1809
ekaramada4f42692016-02-11 19:48:371810void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
1811 if (visible)
1812 WasShown();
1813 else
1814 WasHidden();
1815}
1816
[email protected]bafe6cd2012-05-23 23:09:501817void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431818 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551819 int32_t route_id,
1820 int32_t main_frame_route_id,
1821 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131822 const ViewHostMsg_CreateWindow_Params& params,
1823 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501824 // We usually create the new window in the same BrowsingInstance (group of
1825 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551826 // if the opener is being suppressed (in a non-guest), we create a new
1827 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251828 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551829
[email protected]04cbd3d2013-12-04 04:58:201830 // If the opener is to be suppressed, the new window can be in any process.
1831 // Since routing ids are process specific, we must not have one passed in
1832 // as argument here.
1833 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1834
[email protected]bafe6cd2012-05-23 23:09:501835 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431836 params.opener_suppressed && !is_guest
1837 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1838 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501839
alexmos4cf2aa32015-07-15 23:40:431840 // A message to create a new window can only come from a process for a frame
1841 // in this WebContents' FrameTree. If any other process sends the request, it
1842 // is invalid and the process must be terminated.
1843 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:381844 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:431845 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351846 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201847 if (process_handle != base::kNullProcessHandle) {
1848 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391849 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351850 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201851 }
1852 return;
1853 }
1854
[email protected]d1198fd2012-08-13 22:50:191855 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341856 //
1857 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301858 const std::string& partition_id =
1859 GetContentClient()->browser()->
1860 GetStoragePartitionIdForSite(GetBrowserContext(),
1861 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461862 StoragePartition* partition = BrowserContext::GetStoragePartition(
1863 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411864 DOMStorageContextWrapper* dom_storage_context =
1865 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191866 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1867 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1868 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371869
1870 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551871 !delegate_->ShouldCreateWebContents(
1872 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1873 params.window_container_type, params.frame_name, params.target_url,
1874 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011875 if (route_id != MSG_ROUTING_NONE &&
1876 !RenderViewHost::FromID(render_process_id, route_id)) {
1877 // If the embedder didn't create a WebContents for this route, we need to
1878 // delete the RenderView that had already been created.
1879 Send(new ViewMsg_Close(route_id));
1880 }
csharrisona2280cd2016-02-03 23:21:151881 // It's safe to only target the frame because the render process will not
1882 // have a chance to create more frames at this point.
1883 ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
1884 GlobalFrameRoutingId(render_process_id, main_frame_route_id));
[email protected]dd6730412013-08-14 15:03:371885 return;
1886 }
1887
1888 // Create the new web contents. This will automatically create the new
1889 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461890 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591891 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041892 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551893 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121894 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431895 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211896 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061897 create_params.opener_suppressed = params.opener_suppressed;
1898 if (params.disposition == NEW_BACKGROUND_TAB)
1899 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191900 create_params.renderer_initiated_creation =
1901 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061902
[email protected]4858e432014-06-23 18:14:171903 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551904 if (!is_guest) {
1905 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451906 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171907 new_contents = static_cast<WebContentsImpl*>(
1908 WebContents::Create(create_params));
1909 } else {
1910 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551911 }
[email protected]50d326e2014-05-20 17:59:061912 new_contents->GetController().SetSessionStorageNamespace(
1913 partition_id,
1914 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191915
alexmos646fec02015-07-25 00:11:491916 // If the new frame has a name, make sure any SiteInstances that can find
1917 // this named frame have proxies for it. Must be called after
1918 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1919 // GetSessionStorageNamespace.
1920 if (!params.frame_name.empty())
1921 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1922
[email protected]c4538072013-03-18 02:17:551923 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341924 // will be shown immediately).
1925 if (!params.opener_suppressed) {
1926 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451927 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501928
[email protected]d70bea92013-04-05 04:23:341929 // TODO(brettw): It seems bogus that we have to call this function on the
1930 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431931 new_view->CreateViewForWidget(
1932 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341933 }
[email protected]bafe6cd2012-05-23 23:09:501934 // Save the created window associated with the route so we can show it
1935 // later.
1936 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1937 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101938 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501939 }
1940
1941 if (delegate_) {
1942 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071943 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131944 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501945 }
1946
1947 if (params.opener_suppressed) {
1948 // When the opener is suppressed, the original renderer cannot access the
1949 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001950 bool was_blocked = false;
1951 if (delegate_) {
bokan107a47f2015-02-03 23:23:391952 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001953 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391954 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001955 params.user_gesture, &was_blocked);
1956 }
1957 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211958 OpenURLParams open_params(params.target_url,
1959 Referrer(),
1960 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351961 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211962 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301963 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:371964
1965 if (delegate_ && !is_guest &&
1966 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
1967 // We are in asynchronous add new contents path, delay opening url
1968 new_contents->delayed_open_url_params_.reset(
1969 new OpenURLParams(open_params));
1970 } else {
1971 new_contents->OpenURL(open_params);
1972 }
[email protected]eda238a12012-09-07 23:44:001973 }
[email protected]bafe6cd2012-05-23 23:09:501974 }
1975}
1976
avib7348942015-12-25 20:57:101977void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1978 int32_t route_id,
[email protected]180ef242013-11-07 06:50:461979 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:051980 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501981}
1982
avib7348942015-12-25 20:57:101983void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
1984 int32_t route_id) {
piman5d36dae2015-09-24 22:47:051985 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501986}
1987
avib7348942015-12-25 20:57:101988void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1989 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:501990 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461991 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:251992 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:231993 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:511994 // this WebContentsImpl instance. If any other process sends the request,
1995 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:381996 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:251997 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:511998 if (process_handle != base::kNullProcessHandle) {
1999 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392000 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252001 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512002 }
2003 return;
2004 }
2005
[email protected]bafe6cd2012-05-23 23:09:502006 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:052007 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:262008
[email protected]cfd80b02014-05-01 17:46:482009 RenderWidgetHostViewBase* widget_view =
2010 static_cast<RenderWidgetHostViewBase*>(
2011 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192012 if (!widget_view)
2013 return;
[email protected]bafe6cd2012-05-23 23:09:502014 if (!is_fullscreen) {
2015 // Popups should not get activated.
2016 widget_view->SetPopupType(popup_type);
2017 }
2018 // Save the created widget associated with the route so we can show it later.
2019 pending_widget_views_[route_id] = widget_view;
2020
2021#if defined(OS_MACOSX)
2022 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2023 // to allow it to survive the trip without being hosted.
2024 base::mac::NSObjectRetain(widget_view->GetNativeView());
2025#endif
2026}
2027
2028void WebContentsImpl::ShowCreatedWindow(int route_id,
2029 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392030 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502031 bool user_gesture) {
2032 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:002033 if (contents) {
2034 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162035 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382036 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2037 contents->ResumeLoadingCreatedWebContents();
2038
[email protected]eda238a12012-09-07 23:44:002039 if (delegate) {
2040 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392041 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002042 }
2043 }
[email protected]bafe6cd2012-05-23 23:09:502044}
2045
2046void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:392047 const gfx::Rect& initial_rect) {
2048 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502049}
2050
2051void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
2052 ShowCreatedWidget(route_id, true, gfx::Rect());
2053}
2054
2055void WebContentsImpl::ShowCreatedWidget(int route_id,
2056 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392057 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482058 RenderWidgetHostViewBase* widget_host_view =
2059 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502060 if (!widget_host_view)
2061 return;
[email protected]cfd80b02014-05-01 17:46:482062
2063 RenderWidgetHostView* view = NULL;
2064 BrowserPluginGuest* guest = GetBrowserPluginGuest();
2065 if (guest && guest->embedder_web_contents()) {
2066 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
2067 } else {
2068 view = GetRenderWidgetHostView();
2069 }
2070
[email protected]4aebbca2013-09-17 22:26:492071 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312072 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032073 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312074 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492075 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2076 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532077 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492078 } else {
[email protected]cfd80b02014-05-01 17:46:482079 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492080 }
[email protected]4aebbca2013-09-17 22:26:492081 FOR_EACH_OBSERVER(WebContentsObserver,
2082 observers_,
2083 DidShowFullscreenWidget(route_id));
2084 if (!widget_host_view->HasFocus())
2085 widget_host_view->Focus();
2086 } else {
bokan107a47f2015-02-03 23:23:392087 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492088 }
[email protected]89054502012-06-03 10:29:242089
2090 RenderWidgetHostImpl* render_widget_host_impl =
2091 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2092 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312093 // Only allow privileged mouse lock for fullscreen render widget, which is
2094 // used to implement Pepper Flash fullscreen.
2095 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502096
2097#if defined(OS_MACOSX)
2098 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2099 // properly embedded (or purposefully ignored) we can release the retain we
2100 // took in CreateNewWidget().
2101 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2102#endif
2103}
2104
2105WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2106 PendingContents::iterator iter = pending_contents_.find(route_id);
2107
2108 // Certain systems can block the creation of new windows. If we didn't succeed
2109 // in creating one, just return NULL.
2110 if (iter == pending_contents_.end()) {
2111 return NULL;
2112 }
2113
2114 WebContentsImpl* new_contents = iter->second;
2115 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102116 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502117
[email protected]d70bea92013-04-05 04:23:342118 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252119 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342120 return new_contents;
2121
[email protected]bafe6cd2012-05-23 23:09:502122 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432123 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502124 return NULL;
2125
[email protected]bafe6cd2012-05-23 23:09:502126 return new_contents;
2127}
2128
2129RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2130 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2131 if (iter == pending_widget_views_.end()) {
2132 DCHECK(false);
2133 return NULL;
2134 }
2135
2136 RenderWidgetHostView* widget_host_view = iter->second;
2137 pending_widget_views_.erase(route_id);
2138
2139 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2140 if (!widget_host->GetProcess()->HasConnection()) {
2141 // The view has gone away or the renderer crashed. Nothing to do.
2142 return NULL;
2143 }
2144
2145 return widget_host_view;
2146}
2147
[email protected]f13b4202012-06-12 23:53:232148void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092149 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212150 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372151 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232152 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372153 } else {
dcheng59716272016-04-09 05:19:082154 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2155 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372156 }
[email protected]f13b4202012-06-12 23:53:232157}
2158
grunell657d4d82014-09-18 00:09:432159bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2160 MediaStreamType type) {
2161 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2162 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2163 return delegate_ &&
2164 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2165}
2166
[email protected]cc9200432013-07-23 23:02:402167SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2168 SiteInstance* instance) {
2169 return controller_.GetSessionStorageNamespace(instance);
2170}
2171
[email protected]6de7fc482014-06-06 10:46:442172SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2173 return controller_.GetSessionStorageNamespaceMap();
2174}
2175
[email protected]9b159a52013-10-03 17:24:552176FrameTree* WebContentsImpl::GetFrameTree() {
2177 return &frame_tree_;
2178}
2179
lukendc35e7f2014-11-10 19:06:142180void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2181 virtual_keyboard_requested_ = requested;
2182}
2183
2184bool WebContentsImpl::IsVirtualKeyboardRequested() {
2185 return virtual_keyboard_requested_;
2186}
2187
[email protected]95640212014-07-26 18:14:302188AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2189 return accessibility_mode_;
2190}
2191
[email protected]31a71eaf2014-03-13 01:47:362192void WebContentsImpl::AccessibilityEventReceived(
2193 const std::vector<AXEventNotificationDetails>& details) {
2194 FOR_EACH_OBSERVER(
2195 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2196}
2197
dmazzonia656928e2014-09-15 20:28:542198RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402199 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542200 int browser_plugin_instance_id) {
2201 BrowserPluginGuestManager* guest_manager =
2202 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202203 if (!guest_manager)
2204 return nullptr;
2205
dmazzonia656928e2014-09-15 20:28:542206 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442207 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542208 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202209 return nullptr;
2210
dmazzonia656928e2014-09-15 20:28:542211 return guest->GetMainFrame();
2212}
2213
blundellc57b93f2014-10-29 13:19:572214GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2215 return geolocation_service_context_.get();
2216}
2217
alogvinovf50445a2015-10-30 13:00:122218WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2219 return wake_lock_service_context_.get();
2220}
2221
[email protected]edc3af82013-12-12 21:24:072222void WebContentsImpl::OnShowValidationMessage(
2223 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292224 const base::string16& main_text,
2225 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072226 if (delegate_)
2227 delegate_->ShowValidationMessage(
2228 this, anchor_in_root_view, main_text, sub_text);
2229}
2230
2231void WebContentsImpl::OnHideValidationMessage() {
2232 if (delegate_)
2233 delegate_->HideValidationMessage(this);
2234}
2235
2236void WebContentsImpl::OnMoveValidationMessage(
2237 const gfx::Rect& anchor_in_root_view) {
2238 if (delegate_)
2239 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2240}
2241
lfgbb9c28a2016-03-01 03:19:492242void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372243 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2244 if (node->current_frame_host()->GetRenderWidgetHost())
2245 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2246 }
lfgbb9c28a2016-03-01 03:19:492247
lfgdb5c4ed2016-03-04 23:09:072248 RenderWidgetHostViewBase* rwhv =
2249 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2250 if (rwhv) {
2251 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2252 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2253 }
2254
[email protected]32deec62013-05-15 23:55:042255 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442256 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042257}
2258
ekaramad2bd4a2f2016-04-06 20:12:462259const TextInputState* WebContentsImpl::GetTextInputState() {
2260 if (GetOuterWebContents())
2261 return GetOuterWebContents()->GetTextInputState();
2262 // A RWHV should update WebContentsImpl in its destruction path so that state
2263 // type is reset to none.
2264 DCHECK(view_with_active_text_input_ ||
2265 text_input_state_->type == ui::TEXT_INPUT_TYPE_NONE);
2266 return text_input_state_.get();
2267}
2268
2269void WebContentsImpl::UpdateTextInputState(RenderWidgetHostViewBase* rwhv,
2270 bool text_input_state_changed) {
2271 // If there is an outer WebContents, let it process this update.
2272 if (GetOuterWebContents()) {
2273 return GetOuterWebContents()->UpdateTextInputState(
2274 rwhv, text_input_state_changed);
2275 }
2276
2277 // If this RWHV has a text input type of NONE, then there is nothing to
2278 // report to the tab RWHV.
2279 if (view_with_active_text_input_.get() != rwhv &&
2280 rwhv->text_input_state()->type == ui::TEXT_INPUT_TYPE_NONE)
2281 return;
2282
2283 if (rwhv->text_input_state()->type != ui::TEXT_INPUT_TYPE_NONE)
2284 view_with_active_text_input_ = rwhv->GetWeakPtr();
2285 else
2286 view_with_active_text_input_.reset();
2287
2288 *text_input_state_ = *rwhv->text_input_state();
2289
2290 // The top level RWHV should know about the change.
2291 RenderWidgetHostViewBase* tab_rwhv =
2292 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2293 if (tab_rwhv)
2294 tab_rwhv->UpdateInputMethodIfNecessary(text_input_state_changed);
2295}
2296
[email protected]95640212014-07-26 18:14:302297BrowserAccessibilityManager*
2298 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452299 RenderFrameHostImpl* rfh = GetMainFrame();
2300 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302301}
2302
2303BrowserAccessibilityManager*
2304 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452305 RenderFrameHostImpl* rfh = GetMainFrame();
2306 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302307}
2308
mohsen7ab1ec16ec2015-07-02 18:26:232309void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2310 RenderFrameHost* focused_frame = GetFocusedFrame();
2311 if (!focused_frame)
2312 return;
2313
2314 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2315 focused_frame->GetRoutingID(), extent));
2316}
2317
2318void WebContentsImpl::SelectRange(const gfx::Point& base,
2319 const gfx::Point& extent) {
2320 RenderFrameHost* focused_frame = GetFocusedFrame();
2321 if (!focused_frame)
2322 return;
2323
2324 focused_frame->Send(
2325 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2326}
2327
aurimasab0319022015-07-10 21:57:382328void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2329 int end_adjust) {
2330 RenderFrameHost* focused_frame = GetFocusedFrame();
2331 if (!focused_frame)
2332 return;
2333
2334 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2335 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2336}
2337
[email protected]b172aee2012-04-10 17:05:262338void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492339 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232340 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492341 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332342}
2343
avic3aa8422015-11-09 20:57:222344void WebContentsImpl::ResizeDueToAutoResize(
2345 RenderWidgetHostImpl* render_widget_host,
2346 const gfx::Size& new_size) {
2347 if (render_widget_host != GetRenderViewHost()->GetWidget())
2348 return;
2349
[email protected]61e2b3cc2012-03-02 16:13:342350 if (delegate_)
2351 delegate_->ResizeDueToAutoResize(this, new_size);
2352}
2353
[email protected]b172aee2012-04-10 17:05:262354WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202355 if (!delegate_)
2356 return NULL;
[email protected]00c37fc2011-08-02 00:22:502357
[email protected]e5d549d2011-12-28 01:29:202358 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202359 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342360}
2361
[email protected]6b618e62012-08-16 12:59:182362bool WebContentsImpl::Send(IPC::Message* message) {
2363 if (!GetRenderViewHost()) {
2364 delete message;
2365 return false;
2366 }
2367
2368 return GetRenderViewHost()->Send(message);
2369}
2370
[email protected]a86c0e962013-12-17 17:10:392371void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2372 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442373 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392374 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442375}
2376
[email protected]20ca0382013-02-28 19:50:072377void WebContentsImpl::AttachInterstitialPage(
2378 InterstitialPageImpl* interstitial_page) {
2379 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212380 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292381
2382 // Cancel any visible dialogs so that they don't interfere with the
2383 // interstitial.
creis89a0f782015-05-27 16:13:172384 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292385
[email protected]20ca0382013-02-28 19:50:072386 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2387 DidAttachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252388
2389 // Stop the throbber if needed while the interstitial page is shown.
2390 if (frame_tree_.IsLoading())
2391 LoadingStateChanged(true, true, nullptr);
2392}
2393
2394void WebContentsImpl::DidProceedOnInterstitial() {
2395 // The interstitial page should no longer be pausing the throbber.
2396 DCHECK(!(ShowingInterstitialPage() &&
2397 GetRenderManager()->interstitial_page()->pause_throbber()));
2398
2399 // Restart the throbber now that the interstitial page no longer pauses it.
2400 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2401 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072402}
2403
2404void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252405 bool interstitial_pausing_throbber =
2406 ShowingInterstitialPage() &&
2407 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572408 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212409 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072410 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2411 DidDetachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252412
2413 // Restart the throbber if needed now that the interstitial page is going
2414 // away.
2415 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2416 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072417}
2418
avi2b177592014-12-10 02:08:022419void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2420 int history_length) {
2421 SetHistoryOffsetAndLengthForView(
2422 GetRenderViewHost(), history_offset, history_length);
2423}
2424
2425void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2426 RenderViewHost* render_view_host,
2427 int history_offset,
2428 int history_length) {
2429 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2430 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142431}
2432
toyoshim24a4c7ab2016-04-05 09:24:142433void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172434 RenderFrameHost* focused_frame = GetFocusedFrame();
2435 if (!focused_frame)
2436 return;
2437
[email protected]959be4c2014-04-08 15:01:332438 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:142439 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:332440}
2441
megjablon3f5941072016-02-04 23:27:522442void WebContentsImpl::ReloadLoFiImages() {
2443 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2444}
2445
[email protected]959be4c2014-04-08 15:01:332446void WebContentsImpl::Undo() {
2447 RenderFrameHost* focused_frame = GetFocusedFrame();
2448 if (!focused_frame)
2449 return;
2450
2451 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2452 RecordAction(base::UserMetricsAction("Undo"));
2453}
2454
2455void WebContentsImpl::Redo() {
2456 RenderFrameHost* focused_frame = GetFocusedFrame();
2457 if (!focused_frame)
2458 return;
2459 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2460 RecordAction(base::UserMetricsAction("Redo"));
2461}
2462
2463void WebContentsImpl::Cut() {
2464 RenderFrameHost* focused_frame = GetFocusedFrame();
2465 if (!focused_frame)
2466 return;
2467
2468 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2469 RecordAction(base::UserMetricsAction("Cut"));
2470}
2471
2472void WebContentsImpl::Copy() {
2473 RenderFrameHost* focused_frame = GetFocusedFrame();
2474 if (!focused_frame)
2475 return;
2476
2477 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2478 RecordAction(base::UserMetricsAction("Copy"));
2479}
2480
2481void WebContentsImpl::CopyToFindPboard() {
2482#if defined(OS_MACOSX)
2483 RenderFrameHost* focused_frame = GetFocusedFrame();
2484 if (!focused_frame)
2485 return;
2486
2487 // Windows/Linux don't have the concept of a find pasteboard.
2488 focused_frame->Send(
2489 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2490 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2491#endif
2492}
2493
2494void WebContentsImpl::Paste() {
2495 RenderFrameHost* focused_frame = GetFocusedFrame();
2496 if (!focused_frame)
2497 return;
2498
2499 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2500 RecordAction(base::UserMetricsAction("Paste"));
2501}
2502
2503void WebContentsImpl::PasteAndMatchStyle() {
2504 RenderFrameHost* focused_frame = GetFocusedFrame();
2505 if (!focused_frame)
2506 return;
2507
2508 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2509 focused_frame->GetRoutingID()));
2510 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2511}
2512
2513void WebContentsImpl::Delete() {
2514 RenderFrameHost* focused_frame = GetFocusedFrame();
2515 if (!focused_frame)
2516 return;
2517
2518 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2519 RecordAction(base::UserMetricsAction("DeleteSelection"));
2520}
2521
2522void WebContentsImpl::SelectAll() {
2523 RenderFrameHost* focused_frame = GetFocusedFrame();
2524 if (!focused_frame)
2525 return;
2526
2527 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2528 RecordAction(base::UserMetricsAction("SelectAll"));
2529}
2530
2531void WebContentsImpl::Unselect() {
2532 RenderFrameHost* focused_frame = GetFocusedFrame();
2533 if (!focused_frame)
2534 return;
2535
2536 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2537 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172538}
2539
2540void WebContentsImpl::Replace(const base::string16& word) {
2541 RenderFrameHost* focused_frame = GetFocusedFrame();
2542 if (!focused_frame)
2543 return;
2544
[email protected]959be4c2014-04-08 15:01:332545 focused_frame->Send(new InputMsg_Replace(
2546 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172547}
2548
2549void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2550 RenderFrameHost* focused_frame = GetFocusedFrame();
2551 if (!focused_frame)
2552 return;
2553
[email protected]959be4c2014-04-08 15:01:332554 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2555 focused_frame->GetRoutingID(), word));
2556}
2557
2558void WebContentsImpl::NotifyContextMenuClosed(
2559 const CustomContextMenuContext& context) {
2560 RenderFrameHost* focused_frame = GetFocusedFrame();
2561 if (!focused_frame)
2562 return;
2563
2564 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2565 focused_frame->GetRoutingID(), context));
2566}
2567
2568void WebContentsImpl::ExecuteCustomContextMenuCommand(
2569 int action, const CustomContextMenuContext& context) {
2570 RenderFrameHost* focused_frame = GetFocusedFrame();
2571 if (!focused_frame)
2572 return;
2573
2574 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2575 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002576}
2577
[email protected]fc2b46b2014-05-03 16:33:452578gfx::NativeView WebContentsImpl::GetNativeView() {
2579 return view_->GetNativeView();
2580}
2581
2582gfx::NativeView WebContentsImpl::GetContentNativeView() {
2583 return view_->GetContentNativeView();
2584}
2585
2586gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2587 return view_->GetTopLevelNativeWindow();
2588}
2589
2590gfx::Rect WebContentsImpl::GetViewBounds() {
2591 return view_->GetViewBounds();
2592}
2593
2594gfx::Rect WebContentsImpl::GetContainerBounds() {
2595 gfx::Rect rv;
2596 view_->GetContainerBounds(&rv);
2597 return rv;
2598}
2599
2600DropData* WebContentsImpl::GetDropData() {
2601 return view_->GetDropData();
2602}
2603
2604void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042605 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452606}
2607
2608void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042609 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452610}
2611
2612void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042613 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452614}
2615
2616void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042617 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452618}
2619
[email protected]b172aee2012-04-10 17:05:262620void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272621 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212622 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542623 return;
2624 }
[email protected]0b431992014-06-24 00:08:032625 RenderWidgetHostView* const fullscreen_view =
2626 GetFullscreenRenderWidgetHostView();
2627 if (fullscreen_view) {
2628 fullscreen_view->Focus();
2629 return;
2630 }
creisc014b402015-04-23 16:41:452631 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542632}
2633
[email protected]b172aee2012-04-10 17:05:262634bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212635 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542636}
2637
[email protected]b172aee2012-04-10 17:05:262638InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212639 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222640}
2641
[email protected]b172aee2012-04-10 17:05:262642bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162643 // WebKit creates Document object when MIME type is application/xhtml+xml,
2644 // so we also support this MIME type.
2645 return contents_mime_type_ == "text/html" ||
2646 contents_mime_type_ == "text/xml" ||
2647 contents_mime_type_ == "application/xhtml+xml" ||
2648 contents_mime_type_ == "text/plain" ||
2649 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252650 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162651}
2652
[email protected]b172aee2012-04-10 17:05:262653void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592654 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162655 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552656 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192657 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142658 return;
[email protected]c7dd2f62011-07-18 15:57:592659 }
2660
2661 Stop();
2662
2663 // Create the save package and possibly prompt the user for the name to save
2664 // the page as. The user prompt is an asynchronous operation that runs on
2665 // another thread.
2666 save_package_ = new SavePackage(this);
2667 save_package_->GetSaveInfo();
2668}
2669
2670// Used in automated testing to bypass prompting the user for file names.
2671// Instead, the names and paths are hard coded rather than running them through
2672// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342673bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2674 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212675 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592676 // Stop the page from navigating.
2677 Stop();
2678
2679 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212680 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592681}
2682
[email protected]3c71576ce2013-07-23 02:00:012683void WebContentsImpl::SaveFrame(const GURL& url,
2684 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372685 SaveFrameWithHeaders(url, referrer, std::string());
2686}
2687
2688void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2689 const Referrer& referrer,
2690 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192691 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012692 return;
sammc92af61552014-11-19 23:27:402693 if (delegate_ && delegate_->SaveFrame(url, referrer))
2694 return;
2695
nasko89ad7742015-03-05 22:14:192696 // TODO(nasko): This check for main frame is incorrect and should be fixed
2697 // by explicitly passing in which frame this method should target.
2698 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012699
2700 DownloadManager* dlm =
2701 BrowserContext::GetDownloadManager(GetBrowserContext());
2702 if (!dlm)
2703 return;
avib7348942015-12-25 20:57:102704 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012705 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272706 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012707 if (entry)
2708 post_id = entry->GetPostID();
2709 }
dcheng59716272016-04-09 05:19:082710 std::unique_ptr<DownloadUrlParameters> params(
[email protected]3c71576ce2013-07-23 02:00:012711 DownloadUrlParameters::FromWebContents(this, url));
2712 params->set_referrer(referrer);
2713 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012714 if (post_id >= 0)
2715 params->set_method("POST");
2716 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372717
2718 if (headers.empty()) {
2719 params->set_prefer_cache(true);
2720 } else {
brettw26dab8f02015-08-08 00:28:472721 for (const base::StringPiece& key_value :
2722 base::SplitStringPiece(
2723 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2724 std::vector<std::string> pair = base::SplitString(
2725 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372726 DCHECK_EQ(2ul, pair.size());
2727 params->add_request_header(pair[0], pair[1]);
2728 }
2729 }
dcheng36b6aec92015-12-26 06:16:362730 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012731}
2732
[email protected]b172aee2012-04-10 17:05:262733void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342734 const base::FilePath& file,
avib7348942015-12-25 20:57:102735 const base::Callback<void(int64_t)>& callback) {
[email protected]18516cf92013-08-28 18:19:482736 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122737}
2738
[email protected]b172aee2012-04-10 17:05:262739const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272740 return contents_mime_type_;
2741}
2742
[email protected]b172aee2012-04-10 17:05:262743bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272744 return notify_disconnection_;
2745}
2746
[email protected]b172aee2012-04-10 17:05:262747void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312748 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182749 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162750}
2751
[email protected]b172aee2012-04-10 17:05:262752void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542753 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182754 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162755}
2756
[email protected]8ff00d72012-10-23 19:12:212757RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272758 return &renderer_preferences_;
2759}
2760
[email protected]e35ccd52012-05-23 16:22:472761void WebContentsImpl::Close() {
2762 Close(GetRenderViewHost());
2763}
2764
[email protected]cf200a562013-05-03 16:24:292765void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462766 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292767 if (browser_plugin_embedder_.get())
2768 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2769 screen_x, screen_y, operation);
2770 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452771 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2772 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292773}
2774
[email protected]d60f3702013-12-26 16:30:242775void WebContentsImpl::DidGetResourceResponseStart(
2776 const ResourceRequestDetails& details) {
2777 controller_.ssl_manager()->DidStartResourceResponse(details);
2778
2779 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2780 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242781}
2782
2783void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462784 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242785 const ResourceRedirectDetails& details) {
2786 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2787
2788 FOR_EACH_OBSERVER(
2789 WebContentsObserver,
2790 observers_,
creis114ca1b2014-11-13 23:51:462791 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242792
2793 // TODO(avi): Remove. http://crbug.com/170921
2794 NotificationService::current()->Notify(
2795 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2796 Source<WebContents>(this),
2797 Details<const ResourceRedirectDetails>(&details));
2798}
2799
calamity7fe55ce2015-04-10 03:59:372800void WebContentsImpl::NotifyWebContentsFocused() {
2801 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2802}
2803
[email protected]b172aee2012-04-10 17:05:262804void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522805 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452806 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292807 if (browser_plugin_embedder_.get())
2808 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342809}
2810
[email protected]e35ccd52012-05-23 16:22:472811void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:532812 OnUserInteraction(GetRenderViewHost()->GetWidget(),
2813 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:472814}
2815
[email protected]b172aee2012-04-10 17:05:262816void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272817 closed_by_user_gesture_ = value;
2818}
2819
[email protected]b172aee2012-04-10 17:05:262820bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272821 return closed_by_user_gesture_;
2822}
2823
[email protected]b172aee2012-04-10 17:05:262824void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502825 if (!delegate_)
2826 return;
2827
[email protected]6286a372013-10-09 04:03:272828 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2829 if (!entry)
[email protected]1788e772010-12-15 16:40:502830 return;
2831
[email protected]6286a372013-10-09 04:03:272832 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122833}
2834
[email protected]b172aee2012-04-10 17:05:262835void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042836 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272837 if (!delegate_)
2838 return;
2839
[email protected]691aa2f2013-05-28 22:52:042840 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272841}
2842
[email protected]b172aee2012-04-10 17:05:262843int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272844 return minimum_zoom_percent_;
2845}
2846
[email protected]b172aee2012-04-10 17:05:262847int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272848 return maximum_zoom_percent_;
2849}
2850
mcnee432e47d2015-11-09 19:37:462851void WebContentsImpl::SetPageScale(float page_scale_factor) {
2852 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242853}
2854
[email protected]b172aee2012-04-10 17:05:262855gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492856 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232857}
2858
[email protected]b172aee2012-04-10 17:05:262859bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052860 if (GetBrowserPluginGuest())
2861 return GetBrowserPluginGuest()->LockMouse(allowed);
2862
creisc014b402015-04-23 16:41:452863 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432864 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2865 allowed)
creisc014b402015-04-23 16:41:452866 : false;
[email protected]0bfbf882011-12-22 18:19:272867}
2868
[email protected]b172aee2012-04-10 17:05:262869bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212870 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502871}
2872
alexmose201c7cd2015-06-10 17:14:212873WebContentsImpl* WebContentsImpl::GetOpener() const {
2874 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2875 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572876}
2877
[email protected]cb805452013-05-22 15:16:212878void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482879 if (!color_chooser_info_.get())
2880 return;
2881 RenderFrameHost* rfh = RenderFrameHost::FromID(
2882 color_chooser_info_->render_process_id,
2883 color_chooser_info_->render_frame_id);
2884 if (!rfh)
2885 return;
2886
2887 rfh->Send(new FrameMsg_DidChooseColorResponse(
2888 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202889}
2890
[email protected]cb805452013-05-22 15:16:212891void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482892 if (!color_chooser_info_.get())
2893 return;
2894 RenderFrameHost* rfh = RenderFrameHost::FromID(
2895 color_chooser_info_->render_process_id,
2896 color_chooser_info_->render_frame_id);
2897 if (!rfh)
2898 return;
2899
2900 rfh->Send(new FrameMsg_DidEndColorChooser(
2901 rfh->GetRoutingID(), color_chooser_info_->identifier));
2902 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202903}
2904
halton.huoca2eabd2015-07-06 08:17:402905int WebContentsImpl::DownloadImage(
2906 const GURL& url,
2907 bool is_favicon,
2908 uint32_t max_bitmap_size,
2909 bool bypass_cache,
2910 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552911 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402912 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:062913 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:402914 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552915 const int download_id = ++next_image_download_id;
2916 if (!mojo_image_downloader) {
2917 // If the renderer process is dead (i.e. crash, or memory pressure on
2918 // Android), the downloader service will be invalid. Pre-Mojo, this would
2919 // hang the callback indefinetly since the IPC would be dropped. Now,
2920 // respond with a 400 HTTP error code to indicate that something went wrong.
2921 BrowserThread::PostTask(
2922 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:192923 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:522924 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
2925 nullptr, nullptr));
amistry9f01b772015-07-29 01:54:552926 return download_id;
2927 }
2928
halton.huoca2eabd2015-07-06 08:17:402929 mojo_image_downloader->DownloadImage(
leon.hancbc4bc3c2016-02-26 07:08:522930 mojo::String::From(url), is_favicon, max_bitmap_size, bypass_cache,
2931 base::Bind(&WebContentsImpl::OnDidDownloadImage,
2932 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:552933 return download_id;
[email protected]795c28972012-12-06 06:13:392934}
2935
[email protected]5dcaf8e2013-12-28 01:31:422936bool WebContentsImpl::IsSubframe() const {
2937 return is_subframe_;
2938}
2939
[email protected]36ec24f2014-01-09 00:32:082940void WebContentsImpl::Find(int request_id,
2941 const base::string16& search_text,
2942 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:332943 // Cowardly refuse to search for no text.
2944 if (search_text.empty()) {
2945 NOTREACHED();
2946 return;
2947 }
2948
raymes0fa0be52014-10-13 20:38:092949 // See if a top level browser plugin handles the find request first.
paulmeyer95703b92015-08-10 17:38:472950 if (browser_plugin_embedder_ &&
2951 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2952 return;
raymes0fa0be52014-10-13 20:38:092953 }
paulmeyer5d0a5f02016-01-21 20:15:522954 GetMainFrame()->Send(new FrameMsg_Find(GetMainFrame()->GetRoutingID(),
2955 request_id, search_text, options));
[email protected]36ec24f2014-01-09 00:32:082956}
2957
2958void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012959 // See if a top level browser plugin handles the stop finding request first.
paulmeyer95703b92015-08-10 17:38:472960 if (browser_plugin_embedder_ &&
2961 browser_plugin_embedder_->StopFinding(action)) {
2962 return;
raymes2bc64182015-02-06 01:23:012963 }
paulmeyer5d0a5f02016-01-21 20:15:522964 GetMainFrame()->Send(
2965 new FrameMsg_StopFinding(GetMainFrame()->GetRoutingID(), action));
[email protected]36ec24f2014-01-09 00:32:082966}
2967
[email protected]4fe53add2014-04-08 19:53:362968void WebContentsImpl::InsertCSS(const std::string& css) {
2969 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2970 GetMainFrame()->GetRoutingID(), css));
2971}
2972
dalecurtisbc6572e12014-09-12 19:22:302973bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:152974 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302975}
2976
mlamouriefdca9d2014-09-16 16:55:402977void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2978 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2979}
2980
dominickn6919ce32015-10-15 01:52:282981void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
2982 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
2983}
2984
bokanece34a82016-01-28 19:49:462985void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532986 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:432987 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:462988 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:532989}
2990
mariakhomenko44bdc4732015-04-29 01:55:382991void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:372992 if (delayed_open_url_params_.get()) {
2993 OpenURL(*delayed_open_url_params_.get());
2994 delayed_open_url_params_.reset(nullptr);
2995 return;
2996 }
2997
mariakhomenko44bdc4732015-04-29 01:55:382998 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
2999 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163000 if (is_resume_pending_) {
3001 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133002 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163003 GetMainFrame()->Init();
3004 }
mariakhomenko44bdc4732015-04-29 01:55:383005}
3006
[email protected]b172aee2012-04-10 17:05:263007bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263008 // When the browser is started with about:blank as the startup URL, focus
3009 // the location bar (which will also select its contents) so people can
3010 // simply begin typing to navigate elsewhere.
3011 //
3012 // We need to be careful not to trigger this for anything other than the
3013 // startup navigation. In particular, if we allow an attacker to open a
3014 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3015 // end of the new URL to be scrolled into view instead of the start,
3016 // allowing the attacker to spoof other URLs. The conditions checked here
3017 // are all aimed at ensuring no such attacker-controlled navigation can
3018 // trigger this.
3019 //
3020 // Note that we check the pending entry instead of the visible one; for the
3021 // startup URL case these are the same, but for the attacker-controlled
3022 // navigation case the visible entry is the committed "about:blank" URL and
3023 // the pending entry is the problematic navigation elsewhere.
3024 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3025 if (controller_.IsInitialNavigation() && entry &&
3026 !entry->is_renderer_initiated() &&
3027 entry->GetURL() == GURL(url::kAboutBlankURL)) {
[email protected]0c9406632013-02-08 01:13:333028 return true;
palmerc70cb1f2016-03-04 23:41:263029 }
[email protected]0c9406632013-02-08 01:13:333030 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273031}
3032
[email protected]b172aee2012-04-10 17:05:263033void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273034 if (delegate_)
3035 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213036}
3037
clamy0e119882015-07-31 16:12:333038void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
3039 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3040 DidStartNavigation(navigation_handle));
3041}
3042
3043void WebContentsImpl::DidRedirectNavigation(
3044 NavigationHandle* navigation_handle) {
3045 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3046 DidRedirectNavigation(navigation_handle));
3047}
3048
clamyefca29e2015-09-17 00:22:113049void WebContentsImpl::ReadyToCommitNavigation(
3050 NavigationHandle* navigation_handle) {
3051 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3052 ReadyToCommitNavigation(navigation_handle));
3053}
3054
clamy0e119882015-07-31 16:12:333055void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
3056 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3057 DidFinishNavigation(navigation_handle));
3058}
3059
[email protected]52913802013-12-10 05:52:183060void WebContentsImpl::DidStartProvisionalLoad(
3061 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183062 const GURL& validated_url,
3063 bool is_error_page,
3064 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:103065 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483066 FOR_EACH_OBSERVER(
3067 WebContentsObserver,
3068 observers_,
3069 DidStartProvisionalLoadForFrame(
3070 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:083071
3072 // Notify accessibility if this is a reload.
3073 NavigationEntry* entry = controller_.GetVisibleEntry();
3074 if (entry && ui::PageTransitionCoreTypeIs(
3075 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
3076 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3077 BrowserAccessibilityManager* manager =
3078 ftn->current_frame_host()->browser_accessibility_manager();
3079 if (manager)
3080 manager->UserIsReloading();
3081 }
[email protected]400992b2012-06-14 00:03:543082}
3083
[email protected]3109fbb72014-01-06 23:57:153084void WebContentsImpl::DidFailProvisionalLoadWithError(
3085 RenderFrameHostImpl* render_frame_host,
3086 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
3087 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:313088 FOR_EACH_OBSERVER(WebContentsObserver,
3089 observers_,
3090 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:313091 validated_url,
3092 params.error_code,
gsennton6fbb38692015-06-24 19:23:553093 params.error_description,
3094 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:083095
3096 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3097 BrowserAccessibilityManager* manager =
3098 ftn->current_frame_host()->browser_accessibility_manager();
3099 if (manager)
3100 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153101}
3102
[email protected]b80624c2014-02-09 02:46:553103void WebContentsImpl::DidFailLoadWithError(
3104 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553105 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553106 int error_code,
gsennton6fbb38692015-06-24 19:23:553107 const base::string16& error_description,
3108 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:143109 FOR_EACH_OBSERVER(
3110 WebContentsObserver,
3111 observers_,
gsennton6fbb38692015-06-24 19:23:553112 DidFailLoad(render_frame_host, url, error_code, error_description,
3113 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553114}
3115
[email protected]52913802013-12-10 05:52:183116void WebContentsImpl::NotifyChangedNavigationState(
3117 InvalidateTypes changed_flags) {
3118 NotifyNavigationStateChanged(changed_flags);
3119}
3120
[email protected]3691e5cf2014-01-22 10:16:203121void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:203122 const GURL& url,
3123 NavigationController::ReloadType reload_type) {
3124 // Notify observers about navigation.
3125 FOR_EACH_OBSERVER(
3126 WebContentsObserver,
3127 observers_,
3128 DidStartNavigationToPendingEntry(url, reload_type));
3129}
3130
[email protected]8cb834e2014-03-06 14:23:233131void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3132 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503133 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3134 // weak pointer of sorts.
3135 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3136 const int32_t frame_id = render_frame_host->GetRoutingID();
3137
[email protected]65920f332014-03-04 21:14:183138 WebContents* new_contents = OpenURL(params);
3139
dchengb907f7332015-01-07 20:35:503140 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183141 // Notify observers.
3142 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3143 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463144 render_frame_host,
[email protected]65920f332014-03-04 21:14:183145 params.url,
3146 params.referrer,
3147 params.disposition,
creis114ca1b2014-11-13 23:51:463148 params.transition));
[email protected]65920f332014-03-04 21:14:183149 }
3150}
3151
creis29460272015-12-16 04:38:223152bool WebContentsImpl::ShouldTransferNavigation() {
3153 if (!delegate_)
3154 return true;
3155 return delegate_->ShouldTransferNavigation();
3156}
3157
[email protected]aa62afd2014-04-22 19:22:463158bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3159 if (!delegate_)
3160 return false;
3161 return delegate_->ShouldPreserveAbortedURLs(this);
3162}
3163
[email protected]37567b432014-02-12 01:12:223164void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433165 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223166 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353167 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223168 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483169 FOR_EACH_OBSERVER(WebContentsObserver,
3170 observers_,
3171 DidCommitProvisionalLoadForFrame(
3172 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083173
3174 BrowserAccessibilityManager* manager =
3175 render_frame_host->browser_accessibility_manager();
3176 if (manager)
3177 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223178}
3179
[email protected]0d0f4c492014-04-02 06:42:573180void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233181 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573182 // Ensure fullscreen mode is exited before committing the navigation to a
3183 // different page. The next page will not start out assuming it is in
3184 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233185 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193186 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573187 return;
3188 }
avibf58fa0c2015-11-11 01:45:523189 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463190 ExitFullscreen(false);
avibf58fa0c2015-11-11 01:45:523191 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573192}
3193
[email protected]37567b432014-02-12 01:12:223194void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283195 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223196 const LoadCommittedDetails& details,
3197 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3198 if (details.is_navigation_to_different_page()) {
3199 // Clear the status bubble. This is a workaround for a bug where WebKit
3200 // doesn't let us know that the cursor left an element during a
3201 // transition (this is also why the mouse cursor remains as a hand after
3202 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3203 // clear the bubble when a user navigates to a named anchor in the same
3204 // page.
sky8b00392d2015-01-10 00:30:283205 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003206
3207 RenderWidgetHostViewBase* rwhvb =
3208 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3209 if (rwhvb)
3210 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283211
peter90afaba2015-06-01 12:05:293212 did_first_visually_non_empty_paint_ = false;
3213
yusufod41c5f92015-03-06 00:14:283214 // Reset theme color on navigation to new page.
3215 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223216 }
3217
3218 if (!details.is_in_page) {
3219 // Once the main frame is navigated, we're no longer considered to have
3220 // displayed insecure content.
3221 displayed_insecure_content_ = false;
3222 SSLManager::NotifySSLInternalStateChanged(
3223 GetController().GetBrowserContext());
3224 }
3225
3226 // Notify observers about navigation.
3227 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3228 DidNavigateMainFrame(details, params));
3229
[email protected]e85165c642014-06-10 14:34:313230 if (delegate_)
[email protected]37567b432014-02-12 01:12:223231 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313232 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223233}
3234
3235void WebContentsImpl::DidNavigateAnyFramePostCommit(
3236 RenderFrameHostImpl* render_frame_host,
3237 const LoadCommittedDetails& details,
3238 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103239 // Now that something has committed, we don't need to track whether the
3240 // initial page has been accessed.
3241 has_accessed_initial_document_ = false;
3242
[email protected]37567b432014-02-12 01:12:223243 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173244 if (!details.is_in_page)
3245 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223246
avid53461d2016-02-25 17:15:043247 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3248 // again.
3249 if (params.gesture == NavigationGestureUser && dialog_manager_)
3250 dialog_manager_->ResetDialogState(this);
3251
[email protected]37567b432014-02-12 01:12:223252 // Notify observers about navigation.
3253 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093254 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223255}
3256
3257void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3258 contents_mime_type_ = mime_type;
3259}
3260
[email protected]277857a2014-06-03 10:38:013261bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313262 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053263 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313264 return false;
3265
[email protected]37567b432014-02-12 01:12:223266 if (delegate_)
3267 return delegate_->CanOverscrollContent();
3268
3269 return false;
3270}
3271
[email protected]37b64c52014-07-11 21:14:053272void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293273 // Update the theme color. This is to be published to observers after the
3274 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283275 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293276
3277 if (did_first_visually_non_empty_paint_ &&
3278 last_sent_theme_color_ != theme_color_) {
3279 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3280 DidChangeThemeColor(theme_color_));
3281 last_sent_theme_color_ = theme_color_;
3282 }
[email protected]e7104762014-06-20 19:17:253283}
3284
[email protected]b172aee2012-04-10 17:05:263285void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183286 const GURL& url,
[email protected]70435962011-08-02 20:13:283287 const std::string& security_info,
3288 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183289 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403290 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533291 SSLStatus status;
3292 if (!DeserializeSecurityInfo(security_info, &status)) {
3293 bad_message::ReceivedBadMessage(
3294 GetRenderProcessHost(),
3295 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3296 return;
3297 }
[email protected]724159a2010-12-30 01:11:183298
3299 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593300 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213301 LoadFromMemoryCacheDetails details(
rob1ca070f2016-01-12 01:06:263302 url, status.cert_id, status.cert_status, http_method, mime_type,
3303 resource_type);
[email protected]724159a2010-12-30 01:11:183304
[email protected]b0f724c2013-09-05 04:21:133305 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3306
3307 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3308 DidLoadResourceFromMemoryCache(details));
3309
[email protected]8bfc8272013-09-09 20:10:533310 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3311 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403312 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533313 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3314 GetRenderProcessHost()->GetID()) :
jam608f2992016-03-31 16:35:343315 GetRenderProcessHost()->GetStoragePartition()->
3316 GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533317 BrowserThread::PostTask(
3318 BrowserThread::IO,
3319 FROM_HERE,
3320 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3321 }
[email protected]724159a2010-12-30 01:11:183322}
3323
[email protected]b172aee2012-04-10 17:05:263324void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393325 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183326 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193327 SSLManager::NotifySSLInternalStateChanged(
3328 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183329}
3330
estark910b4572015-12-09 20:55:413331void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3332 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583333 LOG(WARNING) << security_origin << " ran insecure content from "
3334 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393335 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413336 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293337 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393338 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183339 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193340 SSLManager::NotifySSLInternalStateChanged(
3341 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183342}
3343
estark910b4572015-12-09 20:55:413344void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3345 const GURL& url,
3346 const std::string& security_info) {
3347 SSLStatus ssl;
3348 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3349 bad_message::ReceivedBadMessage(
3350 GetRenderProcessHost(),
3351 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3352 return;
3353 }
3354
3355 displayed_insecure_content_ = true;
3356 SSLManager::NotifySSLInternalStateChanged(
3357 GetController().GetBrowserContext());
3358}
3359
3360void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3361 const GURL& security_origin,
3362 const GURL& url,
3363 const std::string& security_info) {
3364 SSLStatus ssl;
3365 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3366 bad_message::ReceivedBadMessage(
3367 GetRenderProcessHost(),
3368 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3369 return;
3370 }
3371
3372 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3373 SSLManager::NotifySSLInternalStateChanged(
3374 GetController().GetBrowserContext());
3375}
3376
[email protected]501052ff2014-02-21 22:19:073377void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113378 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473379 return;
naskofbd033392015-01-27 02:34:473380
[email protected]1d62cf72014-02-07 21:31:573381 RenderFrameHostImpl* rfh =
3382 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143383 FOR_EACH_OBSERVER(
3384 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183385}
3386
naskofbd033392015-01-27 02:34:473387void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113388 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123389 return;
[email protected]a1b99262013-12-27 21:56:223390
[email protected]8b3af1e2014-01-24 13:29:123391 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443392 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373393 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423394 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373395
[email protected]61ac9e242014-03-21 20:55:263396 RenderFrameHostImpl* rfh =
3397 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143398 FOR_EACH_OBSERVER(
3399 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313400}
3401
[email protected]b172aee2012-04-10 17:05:263402void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573403 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3404 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263405}
3406
[email protected]b172aee2012-04-10 17:05:263407void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303408 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263409 minimum_zoom_percent_ = minimum_percent;
3410 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263411}
3412
mcnee432e47d2015-11-09 19:37:463413void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3414 bool is_one = page_scale_factor == 1.f;
3415 if (is_one != page_scale_factor_is_one_) {
3416 page_scale_factor_is_one_ = is_one;
3417
3418 HostZoomMapImpl* host_zoom_map =
3419 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3420
3421 if (host_zoom_map && GetRenderProcessHost()) {
3422 host_zoom_map->SetPageScaleFactorIsOneForView(
3423 GetRenderProcessHost()->GetID(), GetRoutingID(),
3424 page_scale_factor_is_one_);
3425 }
3426 }
3427
3428 FOR_EACH_OBSERVER(WebContentsObserver,
3429 observers_,
3430 OnPageScaleFactorChanged(page_scale_factor));
3431}
3432
[email protected]b172aee2012-04-10 17:05:263433void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343434 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433435 if (!delegate_)
3436 return;
3437
[email protected]b9535422012-02-09 01:47:593438 ChildProcessSecurityPolicyImpl* policy =
3439 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223440 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593441 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213442}
3443
[email protected]b172aee2012-04-10 17:05:263444void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3445 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263446 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363447 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433448 if (!delegate_)
3449 return;
3450
[email protected]b9535422012-02-09 01:47:593451 ChildProcessSecurityPolicyImpl* policy =
3452 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323453 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593454 return;
[email protected]8f810632013-06-06 22:33:323455
[email protected]c125e532014-05-10 20:39:063456 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203457}
3458
[email protected]f5273e52014-07-14 16:30:203459void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3460 const GURL& url,
3461 bool user_gesture) {
3462 if (!delegate_)
3463 return;
3464
3465 ChildProcessSecurityPolicyImpl* policy =
3466 ChildProcessSecurityPolicyImpl::GetInstance();
3467 if (policy->IsPseudoScheme(protocol))
3468 return;
3469
3470 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3471}
3472
kouhei40f03cb2015-09-24 07:47:013473void WebContentsImpl::OnUpdatePageImportanceSignals(
3474 const PageImportanceSignals& signals) {
3475 page_importance_signals_ = signals;
3476}
3477
[email protected]b172aee2012-04-10 17:05:263478void WebContentsImpl::OnFindReply(int request_id,
3479 int number_of_matches,
3480 const gfx::Rect& selection_rect,
3481 int active_match_ordinal,
3482 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433483 if (delegate_) {
3484 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3485 active_match_ordinal, final_update);
3486 }
[email protected]b888919c2011-09-02 00:32:163487}
3488
mfomitchev2b8b066a2016-01-28 19:23:153489#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313490void WebContentsImpl::OnFindMatchRectsReply(
3491 int version,
3492 const std::vector<gfx::RectF>& rects,
3493 const gfx::RectF& active_rect) {
3494 if (delegate_)
3495 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3496}
[email protected]583418cc2013-01-17 14:01:103497
[email protected]1ff427972013-02-07 21:14:073498void WebContentsImpl::OnOpenDateTimeDialog(
3499 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173500 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093501 GetRenderViewHost(),
3502 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133503 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093504 value.minimum,
3505 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173506 value.step,
3507 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103508}
[email protected]59363fc92012-09-05 03:46:313509#endif
3510
avi60bd4902015-09-23 20:39:243511void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3512 std::string json = json_string;
3513 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3514 Source<WebContents>(this),
3515 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403516}
3517
[email protected]b172aee2012-04-10 17:05:263518void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3519 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103520 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253521 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103522 AppCacheAccessed(manifest_url, blocked_by_policy));
3523}
3524
[email protected]8bc5ff02013-11-29 06:34:033525void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483526 int color_chooser_id,
3527 SkColor color,
3528 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113529 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003530 return;
nasko907fcb62015-01-28 04:24:113531
[email protected]aa62afd2014-04-22 19:22:463532 ColorChooser* new_color_chooser = delegate_ ?
3533 delegate_->OpenColorChooser(this, color, suggestions) :
3534 NULL;
[email protected]820957a2014-01-14 14:56:303535 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213536 return;
[email protected]8ed16472014-04-11 19:02:483537 if (color_chooser_info_.get())
3538 color_chooser_info_->chooser->End();
3539
3540 color_chooser_info_.reset(new ColorChooserInfo(
3541 render_frame_message_source_->GetProcess()->GetID(),
3542 render_frame_message_source_->GetRoutingID(),
3543 new_color_chooser,
3544 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203545}
3546
[email protected]b172aee2012-04-10 17:05:263547void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483548 if (color_chooser_info_ &&
3549 color_chooser_id == color_chooser_info_->identifier)
3550 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203551}
3552
[email protected]b172aee2012-04-10 17:05:263553void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323554 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483555 if (color_chooser_info_ &&
3556 color_chooser_id == color_chooser_info_->identifier)
3557 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203558}
3559
[email protected]d0759f492012-04-19 22:50:503560// This exists for render views that don't have a WebUI, but do have WebUI
3561// bindings enabled.
3562void WebContentsImpl::OnWebUISend(const GURL& source_url,
3563 const std::string& name,
3564 const base::ListValue& args) {
3565 if (delegate_)
3566 delegate_->WebUISend(this, source_url, name, args);
3567}
3568
thestigc4cac8f2014-09-04 21:17:503569#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003570void WebContentsImpl::OnPepperInstanceCreated() {
3571 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3572}
3573
3574void WebContentsImpl::OnPepperInstanceDeleted() {
3575 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3576}
3577
tommyclie6633ca72014-10-31 00:40:423578void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3579 const base::FilePath& path,
3580 bool is_hung) {
3581 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3582
3583 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3584 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3585}
3586
3587void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3588 base::ProcessId plugin_pid) {
3589 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3590 PluginCrashed(plugin_path, plugin_pid));
3591}
3592
[email protected]d8415ad92012-08-23 14:40:503593void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443594 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503595 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343596 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163597 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443598 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163599 return;
[email protected]d8415ad92012-08-23 14:40:503600 }
3601
[email protected]8c8fc292012-11-23 18:57:163602 if (!delegate_->RequestPpapiBrokerPermission(
3603 this, url, plugin_path,
3604 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443605 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163606 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443607 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163608 }
[email protected]d8415ad92012-08-23 14:40:503609}
3610
[email protected]ea0309c2013-08-06 19:35:443611void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503612 bool result) {
[email protected]ea0309c2013-08-06 19:35:443613 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503614}
3615
fsamuel833ee7c2015-02-13 23:40:403616void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3617 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393618 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143619 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403620 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373621}
tommyclie6633ca72014-10-31 00:40:423622#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373623
[email protected]795c28972012-12-06 06:13:393624void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393625 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063626 // We get updated favicon URLs after the page stops loading. If a cross-site
3627 // navigation occurs while a page is still loading, the initial page
3628 // may stop loading and send us updated favicon URLs after the navigation
3629 // for the new page has committed.
3630 RenderViewHostImpl* rvhi =
3631 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3632 if (!rvhi->is_active())
3633 return;
3634
[email protected]795c28972012-12-06 06:13:393635 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293636 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393637}
3638
avayvod41634b12015-07-08 17:07:053639void WebContentsImpl::OnMediaSessionStateChanged() {
3640 MediaSession* session = MediaSession::Get(this);
3641 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3642 MediaSessionStateChanged(session->IsControllable(),
mlamouri2d1bfbd2016-03-17 13:14:543643 session->IsSuspended(),
3644 session->metadata()));
avayvod41634b12015-07-08 17:07:053645}
3646
3647void WebContentsImpl::ResumeMediaSession() {
mlamouri918734092016-03-12 04:47:523648 MediaSession::Get(this)->Resume(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053649}
3650
3651void WebContentsImpl::SuspendMediaSession() {
mlamouri918734092016-03-12 04:47:523652 MediaSession::Get(this)->Suspend(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053653}
3654
mlamouri4c4fbed2015-08-17 15:51:013655void WebContentsImpl::StopMediaSession() {
mlamouri918734092016-03-12 04:47:523656 MediaSession::Get(this)->Stop(MediaSession::SuspendType::UI);
mlamouri4c4fbed2015-08-17 15:51:013657}
3658
[email protected]50279492014-05-05 23:24:293659void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153660 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293661 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283662
peter90afaba2015-06-01 12:05:293663 did_first_visually_non_empty_paint_ = true;
3664
yusufod41c5f92015-03-06 00:14:283665 if (theme_color_ != last_sent_theme_color_) {
3666 // Theme color should have updated by now if there was one.
3667 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3668 DidChangeThemeColor(theme_color_));
3669 last_sent_theme_color_ = theme_color_;
3670 }
[email protected]9f268072013-11-07 00:02:153671}
[email protected]d9030b82013-07-19 08:26:063672
[email protected]e67ebf32013-02-13 11:07:193673void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013674 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073675 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013676
estark5ea80e52015-06-19 18:43:123677 SecurityStyleExplanations security_style_explanations;
3678 SecurityStyle security_style =
3679 delegate_->GetSecurityStyle(this, &security_style_explanations);
3680 FOR_EACH_OBSERVER(
3681 WebContentsObserver, observers_,
3682 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013683 }
[email protected]e67ebf32013-02-13 11:07:193684}
3685
[email protected]17e286e2013-03-01 23:29:393686void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3687 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3688 BeforeFormRepostWarningShow());
3689}
3690
[email protected]ec6c05f2013-10-23 18:41:573691void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3692 Activate();
3693 if (delegate_)
3694 delegate_->ShowRepostFormWarningDialog(this);
3695}
3696
[email protected]b4c84012014-04-28 19:51:103697bool WebContentsImpl::HasAccessedInitialDocument() {
3698 return has_accessed_initial_document_;
3699}
3700
[email protected]b172aee2012-04-10 17:05:263701void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463702 // If we are creating a RVH for a restored controller, then we need to make
3703 // sure the RenderView starts with a next_page_id_ larger than the number
3704 // of restored entries. This must be called before the RenderView starts
3705 // navigating (to avoid a race between the browser updating max_page_id and
3706 // the renderer updating next_page_id_). Because of this, we only call this
3707 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563708 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583709 if (max_restored_page_id >
3710 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3711 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3712 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323713}
3714
[email protected]b172aee2012-04-10 17:05:263715bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263716 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323717 // For file URLs without a title, use the pathname instead. In the case of a
3718 // synthesized title, we don't want the update to count toward the "one set
3719 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263720 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323721 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513722 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243723 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323724 explicit_set = false; // Don't count synthetic titles toward the set limit.
3725 } else {
[email protected]8af69c6c2014-03-03 19:05:313726 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323727 explicit_set = true;
3728 }
3729
[email protected]987fc3a2011-05-26 14:18:093730 // If a page is created via window.open and never navigated,
3731 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553732 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093733 if (entry) {
[email protected]36fc0392011-12-25 03:59:513734 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093735 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323736
[email protected]36fc0392011-12-25 03:59:513737 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093738 } else {
3739 if (page_title_when_no_navigation_entry_ == final_title)
3740 return false; // Nothing changed, don't bother.
3741
3742 page_title_when_no_navigation_entry_ = final_title;
3743 }
[email protected]420ae012009-04-24 05:16:323744
[email protected]420ae012009-04-24 05:16:323745 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233746 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323747
[email protected]66798902013-10-01 18:40:163748 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533749 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163750
[email protected]420ae012009-04-24 05:16:323751 return true;
3752}
3753
fdegansa696e5112015-04-17 01:57:593754void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003755 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003756 if (delegate_)
fdegansa696e5112015-04-17 01:57:593757 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003758}
3759
3760void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343761 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003762 loading_weak_factory_.InvalidateWeakPtrs();
3763 loading_last_progress_update_ = base::TimeTicks();
3764}
3765
clamy44e84ce2016-02-22 15:38:253766// Notifies the RenderWidgetHost instance about the fact that the page is
3767// loading, or done loading.
3768void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3769 bool due_to_interstitial,
3770 LoadNotificationDetails* details) {
3771 // Do not send notifications about loading changes in the FrameTree while the
3772 // interstitial page is pausing the throbber.
3773 if (ShowingInterstitialPage() &&
3774 GetRenderManager()->interstitial_page()->pause_throbber() &&
3775 !due_to_interstitial) {
3776 return;
3777 }
3778
3779 bool is_loading = IsLoading();
3780
3781 if (!is_loading) {
3782 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3783 base::string16());
3784 load_state_host_.clear();
3785 upload_size_ = 0;
3786 upload_position_ = 0;
3787 }
3788
3789 GetRenderManager()->SetIsLoading(is_loading);
3790
3791 waiting_for_response_ = is_loading;
3792 is_load_to_different_document_ = to_different_document;
3793
3794 if (delegate_)
3795 delegate_->LoadingStateChanged(this, to_different_document);
3796 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3797
3798 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3799 if (is_loading) {
3800 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3801 this, "URL", url, "Main FrameTreeNode id",
3802 GetFrameTree()->root()->frame_tree_node_id());
3803 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
3804 } else {
3805 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3806 this, "URL", url);
3807 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
3808 }
3809
3810 // TODO(avi): Remove. http://crbug.com/170921
3811 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3812 NotificationDetails det = NotificationService::NoDetails();
3813 if (details)
3814 det = Details<LoadNotificationDetails>(details);
3815 NotificationService::current()->Notify(
3816 type, Source<NavigationController>(&controller_), det);
3817}
3818
[email protected]02d7b6e2014-06-24 21:01:503819void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3820 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323821 // After sending out a swap notification, we need to send a disconnect
3822 // notification so that clients that pick up a pointer to |this| can NULL the
3823 // pointer. See Bug 1230284.
3824 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113825 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283826 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113827
[email protected]7a846df2012-09-20 19:17:393828 // Ensure that the associated embedder gets cleared after a RenderViewHost
3829 // gets swapped, so we don't reuse the same embedder next time a
3830 // RenderViewHost is attached to this WebContents.
3831 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323832}
3833
[email protected]02d7b6e2014-06-24 21:01:503834void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3835 RenderFrameHost* new_host) {
3836 FOR_EACH_OBSERVER(WebContentsObserver,
3837 observers_,
3838 RenderFrameHostChanged(old_host, new_host));
3839}
3840
[email protected]da7a7182013-09-06 08:11:113841// TODO(avi): Remove this entire function because this notification is already
3842// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263843void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323844 if (!notify_disconnection_)
3845 return;
3846
3847 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213848 NotificationService::current()->Notify(
3849 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3850 Source<WebContents>(this),
3851 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323852}
3853
[email protected]cbb1ef592013-06-05 19:49:463854void WebContentsImpl::NotifyNavigationEntryCommitted(
3855 const LoadCommittedDetails& load_details) {
3856 FOR_EACH_OBSERVER(
3857 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3858}
3859
[email protected]f114fa42013-12-06 17:06:443860bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3861 const IPC::Message& message) {
3862 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313863}
3864
[email protected]c31a84802014-04-03 15:55:493865const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3866 return GetLastCommittedURL();
3867}
3868
[email protected]b849847b2013-12-10 21:57:583869void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583870 FOR_EACH_OBSERVER(WebContentsObserver,
3871 observers_,
3872 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303873 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
clamy91b7abf2016-03-24 15:17:453874
3875 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
3876 return;
3877
3878 NavigationEntry* entry = controller_.GetPendingEntry();
3879 if (entry && entry->IsViewSourceMode()) {
3880 // Put the renderer in view source mode.
3881 render_frame_host->Send(
3882 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
3883 }
[email protected]b849847b2013-12-10 21:57:583884}
3885
3886void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3887 FOR_EACH_OBSERVER(WebContentsObserver,
3888 observers_,
3889 RenderFrameDeleted(render_frame_host));
3890}
3891
[email protected]a09d53ce2014-01-31 00:46:423892void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3893 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103894 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423895 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103896 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423897 return;
3898
[email protected]077e704b2014-05-23 19:24:103899 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3900 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423901}
3902
[email protected]87de04b02014-04-08 22:14:493903void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013904 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493905 const base::string16& message,
3906 const base::string16& default_prompt,
3907 const GURL& frame_url,
3908 JavaScriptMessageType javascript_message_type,
3909 IPC::Message* reply_msg) {
3910 // Suppress JavaScript dialogs when requested. Also suppress messages when
3911 // showing an interstitial as it's shown over the previous page and we don't
3912 // want the hidden page's dialogs to interfere with the interstitial.
3913 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503914 ShowingInterstitialPage() || !delegate_ ||
3915 delegate_->ShouldSuppressDialogs(this) ||
3916 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493917
3918 if (!suppress_this_message) {
mathiash72a5e462014-11-19 08:18:503919 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493920 dialog_manager_->RunJavaScriptDialog(
jshin1fb76462016-04-05 22:13:033921 this, frame_url, javascript_message_type, message, default_prompt,
palmer4e0ae10d2015-09-03 23:38:413922 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013923 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413924 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493925 &suppress_this_message);
3926 }
3927
3928 if (suppress_this_message) {
3929 // If we are suppressing messages, just reply as if the user immediately
3930 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013931 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3932 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283933 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493934 }
3935
3936 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3937 // http://crbug.com/288961 ). The only safe thing to do here is return.
3938}
3939
3940void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013941 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493942 bool is_reload,
3943 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013944 RenderFrameHostImpl* rfhi =
3945 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493946 if (delegate_)
3947 delegate_->WillRunBeforeUnloadConfirm();
3948
3949 bool suppress_this_message =
nasko19736cc9f2016-04-08 22:38:453950 !rfhi->is_active() ||
creis36e228b2015-06-08 18:48:023951 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:503952 delegate_->ShouldSuppressDialogs(this) ||
3953 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493954 if (suppress_this_message) {
3955 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3956 return;
3957 }
3958
3959 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503960 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493961 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:423962 this, is_reload,
[email protected]87de04b02014-04-08 22:14:493963 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013964 render_frame_host->GetProcess()->GetID(),
3965 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283966 false));
[email protected]87de04b02014-04-08 22:14:493967}
3968
[email protected]a86c0e962013-12-17 17:10:393969WebContents* WebContentsImpl::GetAsWebContents() {
3970 return this;
3971}
3972
[email protected]7912e822014-04-16 02:37:033973bool WebContentsImpl::IsNeverVisible() {
3974 if (!delegate_)
3975 return false;
3976 return delegate_->IsNeverVisible(this);
3977}
3978
[email protected]5a3bdf52012-05-24 15:12:573979RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3980 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323981}
3982
[email protected]8ff00d72012-10-23 19:12:213983RendererPreferences WebContentsImpl::GetRendererPrefs(
3984 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463985 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513986}
3987
avic3aa8422015-11-09 20:57:223988gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
3989 RenderWidgetHostImpl* render_widget_host) const {
3990 if (!RenderViewHostImpl::From(render_widget_host))
3991 return gfx::Rect();
3992
[email protected]b7a756d42012-01-23 18:08:173993 if (delegate_)
3994 return delegate_->GetRootWindowResizerRect();
3995 return gfx::Rect();
3996}
3997
[email protected]7a846df2012-09-20 19:17:393998void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273999 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394000 browser_plugin_embedder_.reset();
4001}
4002
[email protected]b172aee2012-04-10 17:05:264003void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444004 // Don't send notifications if we are just creating a swapped-out RVH for
4005 // the opener chain. These won't be used for view-source or WebUI, so it's
4006 // ok to return early.
creiscce56cd2014-09-29 22:45:224007 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444008 return;
4009
[email protected]86f98a22013-03-20 14:35:004010 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314011 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084012
[email protected]8ff00d72012-10-23 19:12:214013 NotificationService::current()->Notify(
4014 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4015 Source<WebContents>(this),
4016 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324017
[email protected]60780f412013-02-25 16:34:104018 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264019
4020 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:254021 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:324022}
4023
[email protected]b172aee2012-04-10 17:05:264024void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524025 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324026 // Don't notify the world, since this came from a renderer in the
4027 // background.
4028 return;
4029 }
4030
[email protected]da7a7182013-09-06 08:11:114031 notify_disconnection_ = true;
4032 // TODO(avi): Remove. http://crbug.com/170921
4033 NotificationService::current()->Notify(
4034 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4035 Source<WebContents>(this),
4036 NotificationService::NoDetails());
4037
[email protected]be1f56ab2011-12-22 06:55:314038 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234039 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304040
4041 // Restore the focus to the tab (otherwise the focus will be on the top
4042 // window).
[email protected]484ae5912010-09-29 19:16:144043 if (was_crashed && !FocusLocationBarByDefault() &&
4044 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064045 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144046 }
[email protected]32ded2212011-11-10 18:51:434047
[email protected]d8c660432011-12-22 20:51:254048 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:324049}
4050
[email protected]ec6a7eb2013-04-22 17:34:224051void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4052 base::TerminationStatus status,
4053 int error_code) {
[email protected]151a63d2011-12-20 22:32:524054 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324055 // The pending page's RenderViewHost is gone.
4056 return;
4057 }
4058
[email protected]2fcdcc32014-03-05 02:14:074059 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4060 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:524061 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:464062 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074063
[email protected]698191dc2014-02-25 01:06:134064 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174065 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134066
[email protected]f738bdcb2014-07-11 20:40:444067 if (delegate_)
4068 delegate_->HideValidationMessage(this);
4069
[email protected]960b0372014-05-19 18:01:004070 // Reset the loading progress. TODO(avi): What does it mean to have a
4071 // "renderer crash" when there is more than one renderer process serving a
4072 // webpage? Once this function is called at a more granular frame level, we
4073 // probably will need to more granularly reset the state here.
4074 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254075 NotifyDisconnected();
4076 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004077
[email protected]d8c660432011-12-22 20:51:254078 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:274079 observers_,
[email protected]58d5cfe2013-07-10 02:40:524080 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:324081}
4082
[email protected]b172aee2012-04-10 17:05:264083void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:254084 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:064085}
4086
[email protected]b172aee2012-04-10 17:05:264087void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:104088 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:044089 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384090 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4091
creise1d3e5b2014-12-01 18:21:574092 // Ensure that this state update comes from a RenderViewHost that belongs to
4093 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414094 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574095 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414096 return;
[email protected]420ae012009-04-24 05:16:324097
avi286019ce2015-07-29 01:26:584098 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:324099 // when the user is scrolling and entering form data, as well as when we're
4100 // leaving a page, in which case our state may have already been moved to
4101 // the next page. The navigation controller will look up the appropriate
4102 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:584103 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:114104 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584105 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:114106 if (!entry)
[email protected]420ae012009-04-24 05:16:324107 return;
[email protected]420ae012009-04-24 05:16:324108
nasko346969912015-12-16 22:36:474109 // Sanity check that ensures nav_entry_id and page_id point to the same
4110 // navigation entry.
4111 if (rvhi->GetMainFrame()) {
4112 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4113 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4114 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534115
nasko346969912015-12-16 22:36:474116 DCHECK_EQ(entry, new_entry);
4117 }
creisd63f6c4a2015-11-06 19:05:534118
[email protected]691aa2f2013-05-28 22:52:044119 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324120 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044121 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114122 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324123}
4124
sky8b00392d2015-01-10 00:30:284125void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4126 const GURL& url) {
4127 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4128 // If we're fullscreen only update the url if it's from the fullscreen
4129 // renderer.
4130 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444131 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284132 return;
4133 }
[email protected]6934a702011-12-20 00:04:514134 if (delegate_)
avi450ce00e2014-09-24 01:58:524135 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324136}
4137
[email protected]b172aee2012-04-10 17:05:264138void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104139#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294140 // The UI may be in an event-tracking loop, such as between the
4141 // mouse-down and mouse-up in text selection or a button click.
4142 // Defer the close until after tracking is complete, so that we
4143 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294144 // TODO(shess): This could get more fine-grained. For instance,
4145 // closing a tab in another window while selecting text in the
4146 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104147 if (view_->IsEventTracking()) {
4148 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294149 return;
4150 }
[email protected]60780f412013-02-25 16:34:104151#endif
[email protected]07707302009-11-06 00:50:294152
[email protected]420ae012009-04-24 05:16:324153 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524154 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514155 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324156}
4157
[email protected]66bbadaf2014-03-28 16:25:544158void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574159 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4160 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574161}
4162
[email protected]b172aee2012-04-10 17:05:264163void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514164 if (delegate_ && delegate_->IsPopupOrPanel(this))
4165 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324166}
4167
fdegansa696e5112015-04-17 01:57:594168void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094169 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254170 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084171
4172 // Notify accessibility that the user is navigating away from the
4173 // current document.
4174 //
4175 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084176 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594177 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084178 if (manager)
4179 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324180}
4181
fdegansc73eec22015-03-19 14:47:544182void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084183 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324184
[email protected]9595fd82013-04-19 21:28:494185 // Use the last committed entry rather than the active one, in case a
4186 // pending entry has been created.
4187 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204188 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494189
[email protected]420ae012009-04-24 05:16:324190 // An entry may not exist for a stop when loading an initial blank page or
4191 // if an iframe injected by script into a blank page finishes loading.
4192 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204193 base::TimeDelta elapsed =
4194 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324195
4196 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514197 entry->GetVirtualURL(),
4198 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:324199 elapsed,
4200 &controller_,
4201 controller_.GetCurrentEntryIndex()));
4202 }
4203
clamy44e84ce2016-02-22 15:38:254204 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324205}
4206
fdegansa696e5112015-04-17 01:57:594207void WebContentsImpl::DidChangeLoadProgress() {
4208 double load_progress = frame_tree_.load_progress();
4209
4210 // The delegate is notified immediately for the first and last updates. Also,
4211 // since the message loop may be pretty busy when a page is loaded, it might
4212 // not execute a posted task in a timely manner so the progress report is sent
4213 // immediately if enough time has passed.
4214 base::TimeDelta min_delay =
4215 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4216 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4217 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4218
4219 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4220 // If there is a pending task to send progress, it is now obsolete.
4221 loading_weak_factory_.InvalidateWeakPtrs();
4222
4223 // Notify the load progress change.
4224 SendChangeLoadProgress();
4225
4226 // Clean-up the states if needed.
4227 if (load_progress == 1.0)
4228 ResetLoadProgressState();
4229 return;
4230 }
4231
4232 if (loading_weak_factory_.HasWeakPtrs())
4233 return;
4234
skyostil95082a62015-06-05 19:53:074235 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4236 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4237 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594238 min_delay);
4239}
4240
[email protected]b172aee2012-04-10 17:05:264241void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164242 controller_.DiscardNonCommittedEntries();
4243
4244 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214245 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164246}
4247
[email protected]59167c22013-06-03 18:07:324248void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104249 has_accessed_initial_document_ = true;
4250
[email protected]d1371bf8e2014-04-19 03:26:244251 // We may have left a failed browser-initiated navigation in the address bar
4252 // to let the user edit it and try again. Clear it now that content might
4253 // show up underneath it.
4254 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454255 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244256
[email protected]59167c22013-06-03 18:07:324257 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504258 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324259}
4260
alexmosbe2f4c32015-03-10 02:30:234261void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4262 const std::string& name) {
4263 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4264 FrameNameChanged(render_frame_host, name));
4265}
4266
[email protected]39f2f9252014-05-03 00:54:014267void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294268 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094269 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294270 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094271
4272 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214273 NotificationService::current()->Notify(
4274 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4275 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294276 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084277}
4278
creis8eb8ef22015-11-04 22:51:384279void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4280 const PageState& page_state) {
4281 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4282
4283 // The state update affects the last NavigationEntry associated with the given
4284 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4285 // in the case of an UpdateState from a frame being swapped out). We track
4286 // which entry this is in the RenderFrameHost's nav_entry_id.
4287 RenderFrameHostImpl* rfhi =
4288 static_cast<RenderFrameHostImpl*>(render_frame_host);
4289 NavigationEntryImpl* entry =
4290 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4291 if (!entry)
4292 return;
4293
4294 FrameNavigationEntry* frame_entry =
4295 entry->GetFrameEntry(rfhi->frame_tree_node());
4296 if (!frame_entry)
4297 return;
4298
creisd06a9422015-11-11 03:08:454299 // The SiteInstance might not match if we do a cross-process navigation with
4300 // replacement (e.g., auto-subframe), in which case the swap out of the old
4301 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4302 // has already been replaced and destroyed.
4303 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4304 return;
4305
creis8eb8ef22015-11-04 22:51:384306 if (page_state == frame_entry->page_state())
4307 return; // Nothing to update.
4308
4309 frame_entry->set_page_state(page_state);
4310 controller_.NotifyEntryChanged(entry);
4311}
4312
[email protected]ef3adfc2014-05-11 00:04:544313void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104314 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544315 const base::string16& title,
4316 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544317 // If we have a title, that's a pretty good indication that we've started
4318 // getting useful data.
4319 SetNotWaitingForResponse();
4320
4321 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584322 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544323 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584324 render_frame_host->GetSiteInstance(), page_id);
4325
creis081bc102016-02-26 00:56:274326 // TODO(creis): Find a way to use nav entry IDs to locate the entry to update,
4327 // and intentionally skip updates when the most recent commit was ignored.
4328 // See https://crbug.com/577449.
[email protected]ef3adfc2014-05-11 00:04:544329
4330 // We can handle title updates when we don't have an entry in
4331 // UpdateTitleForEntry, but only if the update is from the current RVH.
4332 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584333 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544334 return;
4335
4336 // TODO(evan): make use of title_direction.
4337 // http://code.google.com/p/chromium/issues/detail?id=27094
4338 if (!UpdateTitleForEntry(entry, title))
4339 return;
4340
4341 // Broadcast notifications when the UI should be updated.
4342 if (entry == controller_.GetEntryAtOffset(0))
4343 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4344}
4345
4346void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4347 const std::string& encoding) {
4348 SetEncoding(encoding);
4349}
4350
[email protected]39f2f9252014-05-03 00:54:014351void WebContentsImpl::DocumentAvailableInMainFrame(
4352 RenderViewHost* render_view_host) {
4353 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4354 DocumentAvailableInMainFrame());
4355}
naskoc0fceff2015-04-30 15:53:524356
[email protected]e1c3a552012-05-04 20:51:324357void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4358 // Tell the active RenderViewHost to run unload handlers and close, as long
4359 // as the request came from a RenderViewHost in the same BrowsingInstance.
4360 // In most cases, we receive this from a swapped out RenderViewHost.
4361 // It is possible to receive it from one that has just been swapped in,
4362 // in which case we might as well deliver the message anyway.
4363 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524364 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324365}
4366
alexmose7da5a12015-04-09 02:22:164367bool WebContentsImpl::ShouldRouteMessageEvent(
4368 RenderFrameHost* target_rfh,
4369 SiteInstance* source_site_instance) const {
4370 // Allow the message if this WebContents is dedicated to a browser plugin
4371 // guest.
[email protected]0eba810b2012-10-18 03:19:364372 // Note: This check means that an embedder could theoretically receive a
4373 // postMessage from anyone (not just its own guests). However, this is
4374 // probably not a risk for apps since other pages won't have references
4375 // to App windows.
alexmose7da5a12015-04-09 02:22:164376 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4377}
[email protected]f546640b2012-05-15 00:03:494378
alexmos58729042015-06-18 23:20:004379void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164380 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4381 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494382
alexmose7da5a12015-04-09 02:22:164383 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144384 // If this message is going to outer WebContents from inner WebContents,
4385 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4386 // already created a RenderFrameProxyHost for that purpose.
4387 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084388 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144389 return;
4390 }
4391
lfg812874d2016-02-09 22:26:134392 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064393 // We create a RenderFrameProxyHost for the embedder in the guest's render
4394 // process but we intentionally do not expose the embedder's opener chain
4395 // to it.
4396 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4397 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494398 } else {
alexmos58729042015-06-18 23:20:004399 RenderFrameHostImpl* source_rfhi =
4400 static_cast<RenderFrameHostImpl*>(source_rfh);
4401 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394402 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494403 }
4404 }
[email protected]f546640b2012-05-15 00:03:494405}
4406
avib7348942015-12-25 20:57:104407bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264408 const base::string16& message,
avib7348942015-12-25 20:57:104409 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264410 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254411 if (!delegate_)
4412 return false;
4413 return delegate_->AddMessageToConsole(this, level, message, line_no,
4414 source_id);
4415}
4416
dominickn9c7ceaa32016-02-27 01:52:534417void WebContentsImpl::OnUserInteraction(
4418 RenderWidgetHostImpl* render_widget_host,
4419 const blink::WebInputEvent::Type type) {
4420 // Ignore when the renderer is swapped out.
4421 // TODO(dominickn,creis): support widgets for out-of-process iframes.
avic3aa8422015-11-09 20:57:224422 if (render_widget_host != GetRenderViewHost()->GetWidget())
4423 return;
4424
dominickn2dd142dd2015-10-29 05:30:504425 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4426 DidGetUserInteraction(type));
dominickn9c7ceaa32016-02-27 01:52:534427
4428 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4429 // Exclude scroll events as user gestures for resource load dispatches.
4430 // rdh is NULL in unittests.
4431 if (rdh && type != blink::WebInputEvent::MouseWheel)
4432 rdh->OnUserGesture(this);
dominickn2dd142dd2015-10-29 05:30:504433}
4434
[email protected]b172aee2012-04-10 17:05:264435void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444436 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254437 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444438}
4439
avic3aa8422015-11-09 20:57:224440void WebContentsImpl::RendererUnresponsive(
4441 RenderWidgetHostImpl* render_widget_host) {
afakhry98241832016-03-11 19:27:474442 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4443 OnRendererUnresponsive(render_widget_host));
4444
[email protected]992db4c2011-05-12 15:37:154445 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224446 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154447 return;
4448
creiscce56cd2014-09-29 22:45:224449 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224450 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584451
[email protected]e5fc1632011-08-08 07:51:534452 // Ignore renderer unresponsive event if debugger is attached to the tab
4453 // since the event may be a result of the renderer sitting on a breakpoint.
4454 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364455 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534456 return;
4457
clamy226727e2015-06-29 10:28:474458 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224459 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324460 // Hang occurred while firing the beforeunload/unload handler.
4461 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224462 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324463
[email protected]fa944cb82013-11-15 17:51:214464 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324465 return;
4466
4467 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564468 // nothing we can do to recover. If the hang is in the beforeunload handler,
4469 // pretend the beforeunload listeners have all fired and allow the delegate
4470 // to continue closing; the user will not have the option of cancelling the
4471 // close. Otherwise, pretend the unload listeners have all fired and close
4472 // the tab.
4473 bool close = true;
clamy226727e2015-06-29 10:28:474474 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564475 delegate_->BeforeUnloadFired(this, true, &close);
4476 }
4477 if (close)
avic3aa8422015-11-09 20:57:224478 Close();
[email protected]420ae012009-04-24 05:16:324479 return;
4480 }
4481
creisc014b402015-04-23 16:41:454482 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474483 return;
4484
[email protected]6934a702011-12-20 00:04:514485 if (delegate_)
4486 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324487}
4488
avic3aa8422015-11-09 20:57:224489void WebContentsImpl::RendererResponsive(
4490 RenderWidgetHostImpl* render_widget_host) {
4491 if (render_widget_host != GetRenderViewHost()->GetWidget())
4492 return;
4493
[email protected]6934a702011-12-20 00:04:514494 if (delegate_)
4495 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324496}
4497
[email protected]b172aee2012-04-10 17:05:264498void WebContentsImpl::LoadStateChanged(
4499 const GURL& url,
4500 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104501 uint64_t upload_position,
4502 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544503 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4504 // is fixed.
4505 tracked_objects::ScopedTracker tracking_profile1(
4506 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4507 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324508 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564509 upload_position_ = upload_position;
4510 upload_size_ = upload_size;
jshin1fb76462016-04-05 22:13:034511 load_state_host_ = url_formatter::IDNToUnicode(url.host());
[email protected]9c235f042011-08-10 22:28:214512 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324513 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464514 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224515 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4516 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464517 }
[email protected]420ae012009-04-24 05:16:324518}
4519
[email protected]b172aee2012-04-10 17:05:264520void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554521 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324522 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124523 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4524 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514525 if (delegate_)
4526 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094527 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324528}
4529
[email protected]58d5cfe2013-07-10 02:40:524530void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544531 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234532 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224533 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544534}
4535
[email protected]b172aee2012-04-10 17:05:264536void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104537 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214538 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264539 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4540 // here during container initialization and normal window size will be set
4541 // later. In case of tab duplication this resizing to 0x0 prevents setting
4542 // normal size later so just ignore it.
4543 if (!size.IsEmpty())
4544 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324545}
4546
[email protected]af905902013-10-01 21:38:514547void WebContentsImpl::CancelModalDialogsForRenderManager() {
4548 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544549 // deferrer would prevent us from swapping out. We also clear the state
4550 // because this is a cross-process navigation, which means that it's a new
4551 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174552 //
4553 // Note that we don't bother telling browser_plugin_embedder_ because the
4554 // cross-process navigation will either destroy the browser plugins or not
4555 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514556 if (dialog_manager_)
avi2460c762015-04-17 15:21:544557 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514558}
4559
[email protected]02d7b6e2014-06-24 21:01:504560void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4561 RenderFrameHost* new_host,
4562 bool is_main_frame) {
4563 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054564 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504565 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084566
[email protected]02d7b6e2014-06-24 21:01:504567 // Make sure the visible RVH reflects the new delegate's preferences.
4568 if (delegate_)
4569 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394570
[email protected]02d7b6e2014-06-24 21:01:504571 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4572 }
4573
4574 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544575}
4576
naskof5940b9f2015-03-02 23:04:054577void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4578 RenderViewHost* old_host,
4579 RenderViewHost* new_host) {
4580 NotifyViewSwapped(old_host, new_host);
4581}
4582
[email protected]b172aee2012-04-10 17:05:264583NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194584 return GetController();
[email protected]3a3d47472010-07-15 21:03:544585}
4586
dcheng59716272016-04-09 05:19:084587std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294588 const GURL& url) {
dcheng59716272016-04-09 05:19:084589 return std::unique_ptr<WebUIImpl>(
4590 static_cast<WebUIImpl*>(CreateWebUI(url, std::string())));
[email protected]420ae012009-04-24 05:16:324591}
4592
[email protected]10f417c52011-12-28 21:04:234593NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264594 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324595 return controller_.GetLastCommittedEntry();
4596}
4597
lfgbede6392015-09-11 21:54:064598void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4599 RenderViewHost* render_view_host) {
4600 RenderWidgetHostViewBase* rwh_view = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:144601 bool is_guest_in_site_per_process =
4602 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084603 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lfgbede6392015-09-11 21:54:064604 if (is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164605 RenderWidgetHostViewChildFrame* rwh_view_child =
avif9ab5d942015-10-15 14:05:444606 new RenderWidgetHostViewChildFrame(render_view_host->GetWidget());
[email protected]bffc8302014-01-23 20:52:164607 rwh_view = rwh_view_child;
4608 } else {
avif9ab5d942015-10-15 14:05:444609 rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]bffc8302014-01-23 20:52:164610 }
[email protected]1a98a932009-11-17 00:12:524611
[email protected]420ae012009-04-24 05:16:324612 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444613 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214614 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064615}
4616
4617bool WebContentsImpl::CreateRenderViewForRenderManager(
4618 RenderViewHost* render_view_host,
4619 int opener_frame_routing_id,
4620 int proxy_routing_id,
4621 const FrameReplicationState& replicated_frame_state) {
4622 TRACE_EVENT0("browser,navigation",
4623 "WebContentsImpl::CreateRenderViewForRenderManager");
4624
4625 if (proxy_routing_id == MSG_ROUTING_NONE)
4626 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324627
[email protected]74ce1ad2011-12-16 21:51:464628 // Make sure we use the correct starting page_id in the new RenderView.
4629 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104630 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584631 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464632
alexmos5ac402d2015-07-09 07:51:104633 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4634 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4635 max_page_id, replicated_frame_state,
4636 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524637 return false;
[email protected]14392a52012-05-02 20:28:444638 }
[email protected]a4127722011-04-27 23:13:524639
avi2b177592014-12-10 02:08:024640 SetHistoryOffsetAndLengthForView(render_view_host,
4641 controller_.GetLastCommittedEntryIndex(),
4642 controller_.GetEntryCount());
4643
[email protected]a220b5932013-09-21 03:47:444644#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504645 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4646 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444647 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444648 if (rwh_view) {
4649 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4650 render_widget_host->WasResized();
4651 }
[email protected]f8233cc2011-05-31 20:24:504652#endif
4653
[email protected]420ae012009-04-24 05:16:324654 return true;
4655}
4656
[email protected]82307f6b2014-08-07 03:30:124657bool WebContentsImpl::CreateRenderFrameForRenderManager(
4658 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044659 int proxy_routing_id,
4660 int opener_routing_id,
japhete6adf142014-10-31 00:01:494661 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044662 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434663 TRACE_EVENT0("browser,navigation",
4664 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124665
4666 RenderFrameHostImpl* rfh =
4667 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044668 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4669 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124670 return false;
4671
4672 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4673 // RenderFrameHost will have to be associated with the appropriate
4674 // RenderWidgetHostView or a new one should be created here.
4675
4676 return true;
4677}
4678
mfomitchev2b8b066a2016-01-28 19:23:154679#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454680
[email protected]155c7f22013-12-09 17:07:184681base::android::ScopedJavaLocalRef<jobject>
4682WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404683 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564684 return GetWebContentsAndroid()->GetJavaObject();
4685}
[email protected]155c7f22013-12-09 17:07:184686
[email protected]0e813a52014-08-13 10:34:564687WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184688 WebContentsAndroid* web_contents_android =
4689 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4690 if (!web_contents_android) {
4691 web_contents_android = new WebContentsAndroid(this);
4692 SetUserData(kWebContentsAndroidKey, web_contents_android);
4693 }
[email protected]0e813a52014-08-13 10:34:564694 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184695}
4696
[email protected]7d244f12013-08-22 21:41:514697bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064698 return CreateRenderViewForRenderManager(
4699 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064700 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514701}
[email protected]fc2b46b2014-05-03 16:33:454702
4703#elif defined(OS_MACOSX)
4704
[email protected]75f4df72014-07-16 22:39:424705void WebContentsImpl::SetAllowOtherViews(bool allow) {
4706 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454707}
4708
[email protected]75f4df72014-07-16 22:39:424709bool WebContentsImpl::GetAllowOtherViews() {
4710 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454711}
4712
[email protected]7d244f12013-08-22 21:41:514713#endif
4714
pkotwicz75ca8ffd2016-02-16 23:10:194715void WebContentsImpl::OnDidDownloadImage(
4716 const ImageDownloadCallback& callback,
4717 int id,
4718 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:524719 int32_t http_status_code,
jamescook70246212016-03-25 19:56:044720 mojo::Array<skia::mojom::BitmapPtr> images,
leon.hancbc4bc3c2016-02-26 07:08:524721 mojo::Array<mojo::SizePtr> original_image_sizes) {
4722 const std::vector<SkBitmap> bitmaps = images.To<std::vector<SkBitmap>>();
4723 const std::vector<gfx::Size> sizes =
4724 original_image_sizes.To<std::vector<gfx::Size>>();
pkotwicz75ca8ffd2016-02-16 23:10:194725
leon.hancbc4bc3c2016-02-26 07:08:524726 callback.Run(id, http_status_code, image_url, bitmaps, sizes);
pkotwicz75ca8ffd2016-02-16 23:10:194727}
4728
[email protected]6fba26d2014-04-29 09:38:284729void WebContentsImpl::OnDialogClosed(int render_process_id,
4730 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264731 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494732 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264733 bool success,
[email protected]fcf75d42013-12-03 20:11:264734 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284735 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4736 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494737 last_dialog_suppressed_ = dialog_was_suppressed;
4738
[email protected]beb440c2009-11-06 04:08:544739 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:234740 // It is possible for the current RenderFrameHost to have changed in the
4741 // meantime. Do not reset the navigation state in that case.
4742 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:254743 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:234744 controller_.DiscardNonCommittedEntries();
4745 }
[email protected]ec8e8b02013-06-19 04:57:104746
[email protected]6d65a462013-06-21 21:29:124747 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4748 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544749 }
[email protected]87de04b02014-04-08 22:14:494750
[email protected]beb440c2009-11-06 04:08:544751 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284752 if (rfh) {
4753 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4754 dialog_was_suppressed);
4755 } else {
4756 // Don't leak the sync IPC reply if the RFH or process is gone.
4757 delete reply_msg;
4758 }
[email protected]beb440c2009-11-06 04:08:544759}
4760
[email protected]b172aee2012-04-10 17:05:264761void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544762 if (encoding == last_reported_encoding_)
4763 return;
4764 last_reported_encoding_ = encoding;
4765
4766 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124767 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104768}
[email protected]f45d2a72010-03-08 23:28:354769
[email protected]1ac10dca2013-08-20 20:47:044770bool WebContentsImpl::IsHidden() {
4771 return capturer_count_ == 0 && !should_normally_be_visible_;
4772}
4773
rob97250742015-12-10 17:45:154774int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144775 if (node_ && node_->outer_web_contents())
4776 return node_->outer_contents_frame_tree_node_id();
4777
nick2482a2d2015-12-18 01:39:374778 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144779}
4780
[email protected]b0936d22013-11-28 06:47:364781RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214782 return frame_tree_.root()->render_manager();
4783}
4784
lazyboy8e16ddfd2015-09-28 03:41:564785WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4786 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4787 if (node_)
4788 return node_->outer_web_contents();
4789 } else {
4790 if (GetBrowserPluginGuest())
4791 return GetBrowserPluginGuest()->embedder_web_contents();
4792 }
4793 return nullptr;
4794}
4795
[email protected]f8497342013-02-05 22:15:024796BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394797 return browser_plugin_guest_.get();
4798}
4799
[email protected]738f57a2013-06-29 21:06:544800void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4801 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144802 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544803 browser_plugin_guest_.reset(guest);
4804}
4805
[email protected]f8497342013-02-05 22:15:024806BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394807 return browser_plugin_embedder_.get();
4808}
[email protected]8ff00d72012-10-23 19:12:214809
fsamuel60b42282015-03-10 03:29:144810void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4811 if (browser_plugin_embedder_)
4812 return;
4813 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4814}
4815
[email protected]fc2b46b2014-05-03 16:33:454816gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214817 gfx::Size size;
4818 if (delegate_)
4819 size = delegate_->GetSizeForNewRenderView(this);
4820 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454821 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214822 return size;
4823}
4824
[email protected]ae7eeda2014-07-04 01:53:264825void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4826 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024827 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554828}
4829
[email protected]222f5822014-02-05 23:40:494830void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4831 if (!delegate_)
4832 return;
4833 const gfx::Size new_size = GetPreferredSize();
4834 if (new_size != old_size)
4835 delegate_->UpdatePreferredSize(this, new_size);
4836}
4837
dbeama1b926a2015-08-31 23:17:514838WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4839 const std::string& frame_name) {
4840 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4841 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4842 CreateWebUIControllerForURL(web_ui, url);
4843 if (controller) {
4844 web_ui->AddMessageHandler(new GenericHandler());
4845 web_ui->SetController(controller);
4846 return web_ui;
4847 }
4848
4849 delete web_ui;
4850 return NULL;
4851}
4852
[email protected]34ff1cfc2014-08-20 06:16:054853void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4854 force_disable_overscroll_content_ = force_disable;
4855 if (view_)
4856 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4857}
4858
dalecurtis88c240072015-12-09 02:11:184859void WebContentsImpl::MediaStartedPlaying(
4860 const WebContentsObserver::MediaPlayerId& id) {
4861 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4862}
4863
4864void WebContentsImpl::MediaStoppedPlaying(
4865 const WebContentsObserver::MediaPlayerId& id) {
4866 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4867}
4868
tapted65ff2ea72016-03-01 23:39:004869void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
4870 if (!did_first_set_visible_) {
4871 // If this WebContents has not yet been set to be visible for the first
4872 // time, ignore any requests to make it hidden, since resources would
4873 // immediately be destroyed and only re-created after content loaded. In
4874 // this state the window content is undefined and can show garbage.
4875 // However, the page load mechanism requires an activation call through a
4876 // visibility call to (re)load.
4877 if (visible) {
4878 did_first_set_visible_ = true;
4879 WasShown();
4880 }
4881 return;
4882 }
4883 if (visible == should_normally_be_visible_)
4884 return;
4885
4886 if (visible)
4887 WasShown();
4888 else
4889 WasHidden();
4890}
4891
avid53461d2016-02-25 17:15:044892void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
4893 JavaScriptDialogManager* dialog_manager) {
4894 dialog_manager_ = dialog_manager;
4895}
4896
[email protected]8ff00d72012-10-23 19:12:214897} // namespace content