blob: 20db239f6acf4ade0c194e8f65e0d95abc1f283a [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"
[email protected]bffc8302014-01-23 20:52:1648#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5749#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0550#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4451#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4052#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3053#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5254#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1855#include "content/browser/media/media_web_contents_observer.h"
[email protected]0bc7f3542013-10-21 15:05:5356#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0957#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3058#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5059#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3260#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5061#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5962#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4863#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0964#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3365#include "content/browser/site_instance_impl.h"
alogvinovf50445a2015-10-30 13:00:1266#include "content/browser/wake_lock/wake_lock_service_context.h"
[email protected]b5a40842012-11-28 15:26:1167#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5868#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0369#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5670#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1471#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4272#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4473#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1774#include "content/common/input_messages.h"
avi286019ce2015-07-29 01:26:5875#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5176#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0277#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3678#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1179#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2880#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4481#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3682#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1783#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1484#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4685#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1586#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0087#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2788#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0089#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3790#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1491#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3092#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3293#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0994#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:1295#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:3496#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3897#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4298#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:2199#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:08100#include "content/public/common/browser_plugin_guest_mode.h"
carloskd80262f52015-12-16 14:40:35101#include "content/public/common/browser_side_navigation_policy.h"
[email protected]54087fe2011-10-28 22:02:48102#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54103#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49104#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20105#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:01106#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:03107#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57108#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05109#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40110#include "mojo/common/url_type_converters.h"
111#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]8bfc8272013-09-09 20:10:53112#include "net/http/http_cache.h"
113#include "net/http/http_transaction_factory.h"
114#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34115#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40116#include "skia/public/type_converters.h"
alexmosaedfc6f2016-01-21 23:57:38117#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40118#include "third_party/skia/include/core/SkBitmap.h"
[email protected]a08412b62012-05-29 21:28:56119#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01120#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41121#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52122#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31123
[email protected]583418cc2013-01-17 14:01:10124#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40125#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15126#include "content/browser/android/date_time_chooser_android.h"
avayvod41634b12015-07-08 17:07:05127#include "content/browser/media/android/media_session.h"
dalecurtisc85ed632016-01-13 00:22:46128#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18129#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15130#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10131
[email protected]f66df822012-05-18 16:52:17132#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50133#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57134#endif
[email protected]3e45ba92009-02-20 21:09:00135
fsamuel9cf7bdf2015-11-20 02:19:32136#if defined(MOJO_SHELL_CLIENT)
137#include "content/browser/web_contents/web_contents_view_mus.h"
138#include "content/public/common/mojo_shell_connection.h"
fsamuel6c6da0232015-11-26 05:13:46139#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32140#endif
141
[email protected]8ff00d72012-10-23 19:12:21142namespace content {
[email protected]420ae012009-04-24 05:16:32143namespace {
144
[email protected]960b0372014-05-19 18:01:00145const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41146const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05147
[email protected]155c7f22013-12-09 17:07:18148#if defined(OS_ANDROID)
149const char kWebContentsAndroidKey[] = "web_contents_android";
150#endif // OS_ANDROID
151
[email protected]e4abd3b42013-11-12 18:28:47152base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46153g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
154
halton.huoca2eabd2015-07-06 08:17:40155static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback,
156 int id,
157 const GURL& image_url,
158 image_downloader::DownloadResultPtr result) {
159 DCHECK(result);
160
161 const std::vector<SkBitmap> images =
162 result->images.To<std::vector<SkBitmap>>();
163 const std::vector<gfx::Size> original_image_sizes =
164 result->original_image_sizes.To<std::vector<gfx::Size>>();
165
166 callback.Run(id, result->http_status_code, image_url, images,
167 original_image_sizes);
[email protected]795c28972012-12-06 06:13:39168}
169
[email protected]8bfc8272013-09-09 20:10:53170void NotifyCacheOnIO(
171 scoped_refptr<net::URLRequestContextGetter> request_context,
172 const GURL& url,
173 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58174 net::HttpCache* cache = request_context->GetURLRequestContext()->
175 http_transaction_factory()->GetCache();
176 if (cache)
177 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53178}
179
dcheng57e39e22016-01-21 00:25:38180bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
181 for (FrameTreeNode* node : tree->Nodes()) {
182 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
183 return true;
alexmos4cf2aa32015-07-15 23:40:43184 }
dcheng57e39e22016-01-21 00:25:38185 return false;
[email protected]95640212014-07-26 18:14:30186}
187
[email protected]95640212014-07-26 18:14:30188void SetAccessibilityModeOnFrame(AccessibilityMode mode,
189 RenderFrameHost* frame_host) {
190 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
191}
192
dtseng0dd3fa12015-07-22 19:00:52193void ResetAccessibility(RenderFrameHost* rfh) {
194 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
195}
196
[email protected]420ae012009-04-24 05:16:32197} // namespace
198
[email protected]54944cde2012-12-09 09:24:59199WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21200 FrameTreeNode* opener_node = nullptr;
201 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
202 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
203 params.opener_render_process_id, params.opener_render_frame_id);
204 if (opener_rfh)
205 opener_node = opener_rfh->frame_tree_node();
206 }
207 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19208}
209
210WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59211 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30212 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21213 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30214
215 for (SessionStorageNamespaceMap::const_iterator it =
216 session_storage_namespace_map.begin();
217 it != session_storage_namespace_map.end();
218 ++it) {
219 new_contents->GetController()
220 .SetSessionStorageNamespace(it->first, it->second.get());
221 }
222
[email protected]54944cde2012-12-09 09:24:59223 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19224 return new_contents;
[email protected]a81343d232011-12-27 07:39:20225}
[email protected]746d3052012-05-22 15:15:47226
nickf9acfbe2014-12-23 19:12:37227void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
228 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46229 g_created_callbacks.Get().push_back(callback);
230}
231
nickf9acfbe2014-12-23 19:12:37232void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
233 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46234 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
235 if (g_created_callbacks.Get().at(i).Equals(callback)) {
236 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
237 return;
238 }
239 }
240}
241
avidf38c952015-10-27 13:45:13242WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
243 if (!rvh)
244 return nullptr;
[email protected]746d3052012-05-22 15:15:47245 return rvh->GetDelegate()->GetAsWebContents();
246}
247
[email protected]a86c0e962013-12-17 17:10:39248WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13249 if (!rfh)
250 return nullptr;
251 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39252}
253
[email protected]7fff43e2013-05-21 20:21:10254// WebContentsImpl::DestructionObserver ----------------------------------------
255
256class WebContentsImpl::DestructionObserver : public WebContentsObserver {
257 public:
258 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
259 : WebContentsObserver(watched_contents),
260 owner_(owner) {
261 }
262
263 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58264 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58265 owner_->OnWebContentsDestroyed(
266 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10267 }
268
269 private:
270 WebContentsImpl* owner_;
271
272 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
273};
274
[email protected]8ed16472014-04-11 19:02:48275WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
276 int render_frame_id,
277 ColorChooser* chooser,
278 int identifier)
279 : render_process_id(render_process_id),
280 render_frame_id(render_frame_id),
281 chooser(chooser),
282 identifier(identifier) {
283}
284
285WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
286}
287
lazyboy6ec48b2a2015-06-29 15:18:14288// WebContentsImpl::WebContentsTreeNode ----------------------------------------
289WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
290 : outer_web_contents_(nullptr),
291 outer_contents_frame_tree_node_id_(
nick2482a2d2015-12-18 01:39:37292 FrameTreeNode::kFrameTreeNodeInvalidId) {
lazyboy6ec48b2a2015-06-29 15:18:14293}
294
295WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
296 // Remove child pointer from our parent.
297 if (outer_web_contents_) {
298 ChildrenSet& child_ptrs_in_parent =
299 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
300 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
301 DCHECK(iter != child_ptrs_in_parent.end());
302 child_ptrs_in_parent.erase(this);
303 }
304
305 // Remove parent pointers from our children.
306 // TODO(lazyboy): We should destroy the children WebContentses too. If the
307 // children do not manage their own lifetime, then we would leak their
308 // WebContentses.
309 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
310 child->outer_web_contents_ = nullptr;
311}
312
313void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
314 WebContentsImpl* outer_web_contents,
315 RenderFrameHostImpl* outer_contents_frame) {
316 outer_web_contents_ = outer_web_contents;
317 outer_contents_frame_tree_node_id_ =
318 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
319
320 if (!outer_web_contents_->node_)
321 outer_web_contents_->node_.reset(new WebContentsTreeNode());
322
323 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
324}
325
[email protected]b172aee2012-04-10 17:05:26326// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32327
alexmose201c7cd2015-06-10 17:14:21328WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42329 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22330 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57331 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21332 created_with_opener_(false),
[email protected]2ceee8f2014-01-14 18:02:08333#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41334 accessible_parent_(NULL),
335#endif
[email protected]6ea6bdf2013-12-06 13:35:01336 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57337 this,
338 this,
339 this,
340 this),
[email protected]6dfed692014-05-22 04:18:03341 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23342 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
343 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34344 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26345 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56346 upload_size_(0),
347 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16348 is_resume_pending_(false),
clamydb73eb6c2016-02-10 13:27:56349 paused_throbber_for_interstitial_(false),
[email protected]f17a0ee2010-05-17 17:38:47350 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10351 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28352 theme_color_(SK_ColorTRANSPARENT),
353 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29354 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55355 capturer_count_(0),
356 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57357 is_being_destroyed_(false),
358 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15359 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01360 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39361 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38362 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21363 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
364 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22365 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44366 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55367 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42368 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03369 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49370 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05371 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30372 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57373 geolocation_service_context_(new GeolocationServiceContext()),
clamydb73eb6c2016-02-10 13:27:56374 accessibility_mode_(BrowserAccessibilityStateImpl::GetInstance()
375 ->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15376 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50377 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46378 page_scale_factor_is_one_(true),
mohan.reddy371ad9142014-09-17 08:01:46379 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55380 frame_tree_.SetFrameRemoveListener(
381 base::Bind(&WebContentsImpl::OnFrameRemoved,
382 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46383#if defined(OS_ANDROID)
384 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
385#else
qinmin58567c82015-01-07 21:00:20386 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46387#endif
csharrisona2280cd2016-02-03 23:21:15388 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
alogvinovf50445a2015-10-30 13:00:12389 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
[email protected]332af7732009-03-11 13:21:35390}
initial.commit09911bf2008-07-26 23:55:29391
[email protected]b172aee2012-04-10 17:05:26392WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32393 is_being_destroyed_ = true;
394
kenrb2a565f82015-09-02 20:24:59395 rwh_input_event_router_.reset();
396
dcheng72be33c2016-01-21 04:11:31397 for (FrameTreeNode* node : frame_tree_.Nodes()) {
398 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
399 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38400 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38401 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31402 }
carlosk35f35af2015-12-01 10:55:40403
dcheng57e39e22016-01-21 00:25:38404 for (RenderWidgetHostImpl* widget : created_widgets_)
405 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26406 created_widgets_.clear();
407
[email protected]3ab9cb82011-06-03 18:02:07408 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15409 if (dialog_manager_)
avi2460c762015-04-17 15:21:54410 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07411
[email protected]8ed16472014-04-11 19:02:48412 if (color_chooser_info_.get())
413 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20414
[email protected]420ae012009-04-24 05:16:32415 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32416
[email protected]ca13a442012-04-17 14:00:12417 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21418 NotificationService::current()->Notify(
419 NOTIFICATION_WEB_CONTENTS_DESTROYED,
420 Source<WebContents>(this),
421 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32422
[email protected]df0c843f2014-05-23 20:37:23423 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14424 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23425 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59426
clamy0e119882015-07-31 16:12:33427 // Manually call the observer methods for the root frame tree node. It is
428 // necessary to manually delete all objects tracking navigations
429 // (NavigationHandle, NavigationRequest) for observers to be properly
430 // notified of these navigations stopping before the WebContents is
431 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23432 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56433
clamy0e119882015-07-31 16:12:33434 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56435 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33436 root->pending_frame_host()->SetNavigationHandle(
437 scoped_ptr<NavigationHandleImpl>());
438 }
naskob21fe4872015-02-24 14:15:56439 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33440 root->current_frame_host()->SetNavigationHandle(
441 scoped_ptr<NavigationHandleImpl>());
442
443 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35444 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41445 // Do not update state as the WebContents is being destroyed.
446 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33447 if (root->speculative_frame_host()) {
448 root->speculative_frame_host()->SetRenderFrameCreated(false);
449 root->speculative_frame_host()->SetNavigationHandle(
450 scoped_ptr<NavigationHandleImpl>());
451 }
452 }
[email protected]f273ee52013-10-18 16:05:27453
naskoa83483fb2015-02-27 16:57:10454 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
455 FrameDeleted(root->current_frame_host()));
456
[email protected]df0c843f2014-05-23 20:37:23457 if (root->pending_render_view_host()) {
458 FOR_EACH_OBSERVER(WebContentsObserver,
459 observers_,
460 RenderViewDeleted(root->pending_render_view_host()));
461 }
[email protected]c06c58c2014-03-12 20:31:59462
[email protected]f273ee52013-10-18 16:05:27463 FOR_EACH_OBSERVER(WebContentsObserver,
464 observers_,
[email protected]df0c843f2014-05-23 20:37:23465 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27466
[email protected]2db9bd72012-04-13 20:20:56467 FOR_EACH_OBSERVER(WebContentsObserver,
468 observers_,
[email protected]12a46832014-05-09 13:35:58469 WebContentsDestroyed());
470
471 FOR_EACH_OBSERVER(WebContentsObserver,
472 observers_,
473 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08474
[email protected]6934a702011-12-20 00:04:51475 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10476
477 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
478 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42479}
480
[email protected]d1198fd2012-08-13 22:50:19481WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59482 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21483 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03484 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21485 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19486
alexmosaedfc6f2016-01-21 23:57:38487 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
488
alexmose201c7cd2015-06-10 17:14:21489 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38490 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21491 new_contents->created_with_opener_ = true;
492 }
493
alexmosaedfc6f2016-01-21 23:57:38494 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
495 // flags, and these flags take effect immediately. An exception is if the
496 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
497 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
498 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
499 if (opener) {
500 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
501 const blink::WebSandboxFlags inherit_flag =
502 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
503 if ((opener_flags & inherit_flag) == inherit_flag) {
504 new_root->SetPendingSandboxFlags(opener_flags);
505 new_root->CommitPendingSandboxFlags();
506 }
507 }
508
alexmose201c7cd2015-06-10 17:14:21509 // This may be true even when opener is null, such as when opening blocked
510 // popups.
alexmos090fae8e2015-05-28 17:09:28511 if (params.created_with_opener)
512 new_contents->created_with_opener_ = true;
513
[email protected]4858e432014-06-23 18:14:17514 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06515 // This makes |new_contents| act as a guest.
516 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16517 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06518 // We are instantiating a WebContents for browser plugin. Set its subframe
519 // bit to true.
520 new_contents->is_subframe_ = true;
521 }
[email protected]54944cde2012-12-09 09:24:59522 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19523 return new_contents;
524}
525
[email protected]95640212014-07-26 18:14:30526// static
527std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
528 std::vector<WebContentsImpl*> result;
529 scoped_ptr<RenderWidgetHostIterator> widgets(
530 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30531 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30532 RenderViewHost* rvh = RenderViewHost::From(rwh);
533 if (!rvh)
534 continue;
535 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
536 if (!web_contents)
537 continue;
avidf38c952015-10-27 13:45:13538 if (web_contents->GetRenderViewHost() != rvh)
539 continue;
540 // Because a WebContents can only have one current RVH at a time, there will
541 // be no duplicate WebContents here.
542 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30543 }
544 return result;
545}
546
clamya16aa8172015-05-26 13:07:25547// static
548WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
549 FrameTreeNode* frame_tree_node) {
550 return static_cast<WebContentsImpl*>(
551 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
552}
553
clamy0d32d6d2015-11-24 11:16:26554// static
555WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
556 int render_frame_host_id) {
557 DCHECK_CURRENTLY_ON(BrowserThread::UI);
558 RenderFrameHost* render_frame_host =
559 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
560 if (!render_frame_host)
561 return nullptr;
562
563 return WebContents::FromRenderFrameHost(render_frame_host);
564}
565
[email protected]b0936d22013-11-28 06:47:36566RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21567 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28568}
569
[email protected]7bb761892012-07-20 09:32:47570bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
571 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44572 return OnMessageReceived(render_view_host, NULL, message);
573}
574
575bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
576 RenderFrameHost* render_frame_host,
577 const IPC::Message& message) {
578 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56579 if (GetWebUI() &&
580 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17581 return true;
[email protected]d2353452012-01-19 19:53:56582 }
[email protected]f82d57b52011-04-27 19:13:17583
brettw5a1613dc2015-06-02 05:34:43584 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25585 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33586 if (render_frame_host) {
587 while ((observer = it.GetNext()) != NULL)
588 if (observer->OnMessageReceived(message, render_frame_host))
589 return true;
590 } else {
591 while ((observer = it.GetNext()) != NULL)
592 if (observer->OnMessageReceived(message))
593 return true;
594 }
[email protected]403415a2011-01-10 18:57:53595
[email protected]1d62cf72014-02-07 21:31:57596 // Message handlers should be aware of which
597 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
598 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02599 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57600 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02601 else
[email protected]1d62cf72014-02-07 21:31:57602 render_view_message_source_ = render_view_host;
603
[email protected]724159a2010-12-30 01:11:18604 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33605 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40606 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
607 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05608 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
609 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48610 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
611 OnDocumentLoadedInFrame)
612 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
613 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
614 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
615 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
616 OnSetSelectedColorInColorChooser)
dalecurtis88c240072015-12-09 02:11:18617
dglazkov79c426102015-08-31 21:22:43618 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11619 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25620 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18621 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54622 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18623 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54624 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18625 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41626 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
627 OnDidDisplayContentWithCertificateErrors)
628 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
629 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25630 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26631 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46632 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
633 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21634 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48635 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
636 OnRegisterProtocolHandler)
637 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
638 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01639 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
640 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52641 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10642 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50643 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50644#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00645 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
646 OnPepperInstanceCreated)
647 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
648 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42649 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
650 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50651 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
652 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55653 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40654 OnBrowserPluginMessage(render_frame_host,
655 message))
thestigc4cac8f2014-09-04 21:17:50656#endif
[email protected]41225fe2013-03-29 05:32:02657 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07658 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
659 OnShowValidationMessage)
660 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
661 OnHideValidationMessage)
662 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
663 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15664#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52665 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48666 OnFindMatchRectsReply)
667 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
668 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48669#endif
[email protected]724159a2010-12-30 01:11:18670 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33671 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44672 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57673 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18674
[email protected]724159a2010-12-30 01:11:18675 return handled;
676}
677
nasko907fcb62015-01-28 04:24:11678bool WebContentsImpl::HasValidFrameSource() {
679 if (!render_frame_message_source_) {
680 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18681 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
682 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11683 return false;
684 }
685
686 return true;
687}
688
[email protected]b172aee2012-04-10 17:05:26689void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18690 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21691 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43692 if (delegate_)
693 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18694}
695
[email protected]d1198fd2012-08-13 22:50:19696NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56697 return controller_;
698}
699
[email protected]d1198fd2012-08-13 22:50:19700const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56701 return controller_;
702}
703
[email protected]8ff00d72012-10-23 19:12:21704BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55705 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30706}
707
[email protected]b172aee2012-04-10 17:05:26708const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24709 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32710 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51711 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31712}
713
[email protected]a093ce02013-07-22 20:53:14714const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24715 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32716 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24717 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
718}
719
720const GURL& WebContentsImpl::GetLastCommittedURL() const {
721 // We may not have a navigation entry yet.
722 NavigationEntry* entry = controller_.GetLastCommittedEntry();
723 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
724}
725
[email protected]8ff00d72012-10-23 19:12:21726WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31727 return delegate_;
728}
729
[email protected]8ff00d72012-10-23 19:12:21730void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31731 // TODO(cbentzel): remove this debugging code?
732 if (delegate == delegate_)
733 return;
734 if (delegate_)
735 delegate_->Detach(this);
736 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08737 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31738 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08739 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00740 if (view_)
[email protected]e85165c642014-06-10 14:34:31741 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08742 }
[email protected]be1f56ab2011-12-22 06:55:31743}
744
[email protected]8ff00d72012-10-23 19:12:21745RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21746 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41747 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16748}
749
clamydf1975e2015-02-05 19:12:24750RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41751 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16752}
753
nick53d5cbf2015-04-23 22:50:14754RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
755 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
756 if (!focused_node)
757 return nullptr;
758 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07759}
760
rob3e2a0732016-01-06 21:22:09761RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
762 int frame_tree_node_id) {
763 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
764 return frame ? frame->current_frame_host() : nullptr;
765}
766
[email protected]a86c0e962013-12-17 17:10:39767void WebContentsImpl::ForEachFrame(
768 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38769 for (FrameTreeNode* node : frame_tree_.Nodes()) {
770 on_frame.Run(node->current_frame_host());
771 }
[email protected]a86c0e962013-12-17 17:10:39772}
773
dchengafb53e22016-02-04 08:11:08774std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
775 std::vector<RenderFrameHost*> frame_hosts;
776 for (FrameTreeNode* node : frame_tree_.Nodes())
777 frame_hosts.push_back(node->current_frame_host());
778 return frame_hosts;
779}
780
lukaszacbdf52e2016-01-15 21:19:51781int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
782 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08783 for (RenderFrameHost* rfh : GetAllFrames()) {
784 ++number_of_messages;
785 IPC::Message* message_copy = new IPC::Message(*message);
786 message_copy->set_routing_id(rfh->GetRoutingID());
787 rfh->Send(message_copy);
788 }
[email protected]a86c0e962013-12-17 17:10:39789 delete message;
lukaszacbdf52e2016-01-15 21:19:51790 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39791}
792
creisc014b402015-04-23 16:41:45793RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21794 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31795}
796
[email protected]6b618e62012-08-16 12:59:18797int WebContentsImpl::GetRoutingID() const {
798 if (!GetRenderViewHost())
799 return MSG_ROUTING_NONE;
800
801 return GetRenderViewHost()->GetRoutingID();
802}
803
creis89a0f782015-05-27 16:13:17804void WebContentsImpl::CancelActiveAndPendingDialogs() {
805 if (dialog_manager_)
806 dialog_manager_->CancelActiveAndPendingDialogs(this);
807 if (browser_plugin_embedder_)
808 browser_plugin_embedder_->CancelGuestDialogs();
809}
810
[email protected]44470a22013-01-24 01:21:54811int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
812 return fullscreen_widget_routing_id_;
813}
814
naskoc0fceff2015-04-30 15:53:52815void WebContentsImpl::ClosePage() {
816 GetRenderViewHost()->ClosePage();
817}
818
[email protected]b172aee2012-04-10 17:05:26819RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21820 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31821}
822
[email protected]4aebbca2013-09-17 22:26:49823RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
824 const {
825 RenderWidgetHost* const widget_host =
826 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
827 GetFullscreenWidgetRoutingID());
828 return widget_host ? widget_host->GetView() : NULL;
829}
830
[email protected]8ff00d72012-10-23 19:12:21831WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31832 return view_.get();
833}
834
yusufod41c5f92015-03-06 00:14:28835SkColor WebContentsImpl::GetThemeColor() const {
836 return theme_color_;
837}
838
[email protected]95640212014-07-26 18:14:30839void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
840 if (mode == accessibility_mode_)
841 return;
842
843 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38844
845 for (FrameTreeNode* node : frame_tree_.Nodes()) {
846 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
847 RenderFrameHost* pending_frame_host =
848 node->render_manager()->pending_frame_host();
849 if (pending_frame_host)
850 SetAccessibilityModeOnFrame(mode, pending_frame_host);
851 }
[email protected]95640212014-07-26 18:14:30852}
853
854void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50855 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30856}
857
858void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50859 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30860}
861
dmazzoni83ba5c82015-04-14 07:11:51862void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
863 // TODO(dmazzoni): http://crbug.com/475608 This only returns the
864 // accessibility tree from the main frame and everything in the
865 // same site instance.
866 GetMainFrame()->RequestAXTreeSnapshot(callback);
867}
868
dbeama1b926a2015-08-31 23:17:51869WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
870 const std::string& frame_name) {
871 DCHECK(!frame_name.empty());
872 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22873}
874
[email protected]8ff00d72012-10-23 19:12:21875WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:40876 WebUI* commited_web_ui = GetCommittedWebUI();
877 return commited_web_ui ? commited_web_ui
878 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:31879}
880
[email protected]8ff00d72012-10-23 19:12:21881WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:40882 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34883}
884
[email protected]86ef6a392012-05-11 22:03:11885void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22886 if (GetUserAgentOverride() == override)
887 return;
888
889 renderer_preferences_.user_agent_override = override;
890
891 // Send the new override string to the renderer.
892 RenderViewHost* host = GetRenderViewHost();
893 if (host)
894 host->SyncRendererPrefs();
895
896 // Reload the page if a load is currently in progress to avoid having
897 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27898 NavigationEntry* entry = controller_.GetVisibleEntry();
clamydb73eb6c2016-02-10 13:27:56899 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
[email protected]bf70edce2012-06-20 22:32:22900 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53901
902 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
903 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11904}
905
906const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22907 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11908}
909
[email protected]95640212014-07-26 18:14:30910void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:08911 if (GetAccessibilityMode() != AccessibilityModeOff) {
912 for (RenderFrameHost* rfh : GetAllFrames())
913 ResetAccessibility(rfh);
914 } else {
dtseng0dd3fa12015-07-22 19:00:52915 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:08916 }
[email protected]95640212014-07-26 18:14:30917}
918
919bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
920 return accessibility_mode_ == AccessibilityModeTreeOnly;
921}
922
923bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
924 return accessibility_mode_ == AccessibilityModeComplete;
925}
926
[email protected]2ceee8f2014-01-14 18:02:08927#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41928void WebContentsImpl::SetParentNativeViewAccessible(
929gfx::NativeViewAccessible accessible_parent) {
930 accessible_parent_ = accessible_parent;
creisc014b402015-04-23 16:41:45931 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:30932 if (rfh)
933 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41934}
935#endif
936
kouhei40f03cb2015-09-24 07:47:01937const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
938 return page_importance_signals_;
939}
940
[email protected]fcf75d42013-12-03 20:11:26941const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55942 // Transient entries take precedence. They are used for interstitial pages
943 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23944 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08945 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21946 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30947 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23948 if (entry) {
[email protected]b5cca982011-05-26 04:42:08949 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23950 }
carlosk35f35af2015-12-01 10:55:40951
952 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
953 WebUI* our_web_ui = navigating_web_ui
954 ? navigating_web_ui
955 : GetRenderManager()->current_frame_host()->web_ui();
956
[email protected]7ade2732011-02-10 00:13:58957 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54958 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32959 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54960 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35961 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26962 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54963 if (!title.empty())
964 return title;
965 }
966 }
967
968 // We use the title for the last committed entry rather than a pending
969 // navigation entry. For example, when the user types in a URL, we want to
970 // keep the old page's title until the new load has committed and we get a new
971 // title.
[email protected]96d185d2009-04-24 03:28:54972 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32973
creis072b61f2015-09-28 20:52:24974 // We make an exception for initial navigations. We only want to use the title
975 // from the visible entry if:
976 // 1. The pending entry has been explicitly assigned a title to display.
977 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
978 // which case there is a pending entry index other than -1.
979 //
980 // Otherwise, we want to stick with the last committed entry's title during
981 // new navigations, which have pending entries at index -1 with no title.
982 if (controller_.IsInitialNavigation() &&
983 ((controller_.GetVisibleEntry() &&
984 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
985 controller_.GetPendingEntryIndex() != -1)) {
986 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:47987 }
[email protected]59167c22013-06-03 18:07:32988
[email protected]45d0ef7f2011-01-05 13:46:23989 if (entry) {
[email protected]b5cca982011-05-26 04:42:08990 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23991 }
[email protected]987fc3a2011-05-26 14:18:09992
993 // |page_title_when_no_navigation_entry_| is finally used
994 // if no title cannot be retrieved.
995 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54996}
997
avib7348942015-12-25 20:57:10998int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46999 return GetMaxPageIDForSiteInstance(GetSiteInstance());
1000}
1001
avib7348942015-12-25 20:57:101002int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:261003 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:331004 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
1005 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:461006
[email protected]b6583592012-01-25 19:52:331007 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:341008}
1009
avib7348942015-12-25 20:57:101010void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461011 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
1012}
1013
[email protected]b172aee2012-04-10 17:05:261014void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:101015 SiteInstance* site_instance,
1016 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461017 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331018 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341019}
1020
[email protected]ec6c05f2013-10-23 18:41:571021void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1022 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1023 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571024}
1025
creiscce56cd2014-09-29 22:45:221026SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211027 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541028}
1029
creiscce56cd2014-09-29 22:45:221030SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1031 RenderViewHostImpl* dest_rvh =
1032 GetRenderManager()->pending_render_view_host() ?
1033 GetRenderManager()->pending_render_view_host() :
1034 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581035 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381036}
1037
[email protected]b172aee2012-04-10 17:05:261038bool WebContentsImpl::IsLoading() const {
clamydb73eb6c2016-02-10 13:27:561039 return frame_tree_.IsLoading() && !paused_throbber_for_interstitial_;
[email protected]3c9e1872010-11-18 16:17:491040}
1041
[email protected]6dfed692014-05-22 04:18:031042bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamydb73eb6c2016-02-10 13:27:561043 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031044}
1045
[email protected]b172aee2012-04-10 17:05:261046bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031047 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311048}
1049
[email protected]b172aee2012-04-10 17:05:261050const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311051 return load_state_;
1052}
1053
[email protected]fcf75d42013-12-03 20:11:261054const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311055 return load_state_host_;
1056}
1057
avib7348942015-12-25 20:57:101058uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311059 return upload_size_;
1060}
1061
avib7348942015-12-25 20:57:101062uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311063 return upload_position_;
1064}
1065
[email protected]b172aee2012-04-10 17:05:261066const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541067 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311068}
1069
[email protected]b172aee2012-04-10 17:05:261070bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311071 return displayed_insecure_content_;
1072}
1073
[email protected]222f5822014-02-05 23:40:491074void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251075 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551076 ++capturer_count_;
1077 DVLOG(1) << "There are now " << capturer_count_
1078 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491079
1080 // Note: This provides a hint to upstream code to size the views optimally
1081 // for quality (e.g., to avoid scaling).
1082 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1083 preferred_size_for_capture_ = capture_size;
1084 OnPreferredSizeChanged(preferred_size_);
1085 }
ccameron8807c38f2015-01-17 00:29:191086
1087 // Ensure that all views are un-occluded before capture begins.
1088 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551089}
1090
1091void WebContentsImpl::DecrementCapturerCount() {
1092 --capturer_count_;
1093 DVLOG(1) << "There are now " << capturer_count_
1094 << " capturing(s) of WebContentsImpl@" << this;
1095 DCHECK_LE(0, capturer_count_);
1096
[email protected]5a652232013-02-12 06:15:251097 if (is_being_destroyed_)
1098 return;
1099
[email protected]222f5822014-02-05 23:40:491100 if (capturer_count_ == 0) {
1101 const gfx::Size old_size = preferred_size_for_capture_;
1102 preferred_size_for_capture_ = gfx::Size();
1103 OnPreferredSizeChanged(old_size);
1104 }
1105
[email protected]1ac10dca2013-08-20 20:47:041106 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551107 DVLOG(1) << "Executing delayed WasHidden().";
1108 WasHidden();
1109 }
[email protected]be1f56ab2011-12-22 06:55:311110}
1111
[email protected]f2bd40812013-07-20 04:30:441112int WebContentsImpl::GetCapturerCount() const {
1113 return capturer_count_;
1114}
1115
miu50f97892014-09-22 22:49:521116bool WebContentsImpl::IsAudioMuted() const {
1117 return audio_muter_.get() && audio_muter_->is_muting();
1118}
1119
1120void WebContentsImpl::SetAudioMuted(bool mute) {
1121 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1122 << " for WebContentsImpl@" << this;
1123
1124 if (mute == IsAudioMuted())
1125 return;
1126
1127 if (mute) {
1128 if (!audio_muter_)
1129 audio_muter_.reset(new WebContentsAudioMuter(this));
1130 audio_muter_->StartMuting();
1131 } else {
1132 DCHECK(audio_muter_);
1133 audio_muter_->StopMuting();
1134 }
1135
wjmaclean2f797c782016-01-07 14:52:031136 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1137 DidUpdateAudioMutingState(mute));
1138
miu50f97892014-09-22 22:49:521139 // Notification for UI updates in response to the changed muting state.
1140 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1141}
1142
[email protected]b172aee2012-04-10 17:05:261143bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311144 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1145 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581146 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271147#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581148 crashed_status_ ==
1149 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271150#endif
wfh0d9532a2015-09-02 23:18:581151 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271152 );
[email protected]3c9e1872010-11-18 16:17:491153}
1154
[email protected]b172aee2012-04-10 17:05:261155void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1156 int error_code) {
[email protected]443b80e2010-12-14 00:42:231157 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341158 return;
1159
[email protected]443b80e2010-12-14 00:42:231160 crashed_status_ = status;
1161 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211162 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341163}
1164
[email protected]b172aee2012-04-10 17:05:261165base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311166 return crashed_status_;
1167}
1168
[email protected]b172aee2012-04-10 17:05:261169bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311170 return is_being_destroyed_;
1171}
1172
[email protected]7f924832014-08-09 05:57:221173void WebContentsImpl::NotifyNavigationStateChanged(
1174 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541175 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1176 // is fixed.
1177 tracked_objects::ScopedTracker tracking_profile(
1178 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1179 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181180 // Notify the media observer of potential audibility changes.
1181 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271182 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301183 }
1184
[email protected]d5f942ba2008-09-26 19:30:341185 if (delegate_)
1186 delegate_->NavigationStateChanged(this, changed_flags);
1187}
1188
gab0dccfef2015-05-20 18:43:391189base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021190 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331191}
1192
georgesak5582cbe2015-05-22 22:08:071193void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1194 last_active_time_ = last_active_time;
1195}
1196
[email protected]9e2e4632012-07-27 16:38:411197void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541198 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591199
ccameron8807c38f2015-01-17 00:29:191200 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1201 if (view) {
1202 view->Show();
[email protected]789e9152009-08-04 21:59:431203#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191204 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431205#endif
[email protected]de3c5d82014-05-28 22:12:591206 }
[email protected]789e9152009-08-04 21:59:431207 }
[email protected]96d185d2009-04-24 03:28:541208
gab0dccfef2015-05-20 18:43:391209 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381210
[email protected]b9769d82012-02-10 00:23:591211 // The resize rect might have changed while this was inactive -- send the new
1212 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451213 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221214 if (rvh) {
1215 rvh->GetWidget()->ResizeRectChanged(
1216 GetRootWindowResizerRect(rvh->GetWidget()));
1217 }
[email protected]96d185d2009-04-24 03:28:541218
[email protected]c0d9d5672013-10-09 07:38:031219 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1220
[email protected]54597982013-02-06 01:59:551221 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311222}
1223
[email protected]b172aee2012-04-10 17:05:261224void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551225 // If there are entities capturing screenshots or video (e.g., mirroring),
1226 // don't activate the "disable rendering" optimization.
1227 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521228 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551229 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261230 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521231 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331232 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521233 // calls us).
ccameron8807c38f2015-01-17 00:29:191234 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1235 if (view)
1236 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591237 }
[email protected]96d185d2009-04-24 03:28:541238 }
1239
[email protected]c0d9d5672013-10-09 07:38:031240 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1241
[email protected]54597982013-02-06 01:59:551242 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371243}
1244
ccameron8807c38f2015-01-17 00:29:191245void WebContentsImpl::WasOccluded() {
1246 if (capturer_count_ > 0)
1247 return;
1248
1249 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1250 if (view)
1251 view->WasOccluded();
1252 }
1253}
1254
1255void WebContentsImpl::WasUnOccluded() {
1256 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1257 if (view)
1258 view->WasUnOccluded();
1259 }
1260}
1261
[email protected]b172aee2012-04-10 17:05:261262bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311263 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451264 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1265 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311266}
1267
[email protected]1c3f80bd2014-04-08 23:02:061268void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451269 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061270}
1271
lazyboy6ec48b2a2015-06-29 15:18:141272void WebContentsImpl::AttachToOuterWebContentsFrame(
1273 WebContents* outer_web_contents,
1274 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081275 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lazyboy6ec48b2a2015-06-29 15:18:141276 // Create a link to our outer WebContents.
1277 node_.reset(new WebContentsTreeNode());
1278 node_->ConnectToOuterWebContents(
1279 static_cast<WebContentsImpl*>(outer_web_contents),
1280 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1281
1282 DCHECK(outer_contents_frame);
1283
1284 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1285 // SiteInstance of the outer WebContents. The proxy will be used to send
1286 // postMessage to the inner WebContents.
1287 GetRenderManager()->CreateOuterDelegateProxy(
1288 outer_contents_frame->GetSiteInstance(),
1289 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1290
1291 GetRenderManager()->SetRWHViewForInnerContents(
1292 GetRenderManager()->GetRenderWidgetHostView());
1293}
1294
[email protected]b172aee2012-04-10 17:05:261295void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381296 for (FrameTreeNode* node : frame_tree_.Nodes())
1297 node->StopLoading();
[email protected]d16609c2013-08-23 06:01:401298 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271299}
1300
[email protected]b172aee2012-04-10 17:05:261301WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441302 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211303 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451304 // before.
[email protected]54944cde2012-12-09 09:24:591305 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451306 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211307 WebContentsImpl* tc =
1308 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191309 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221310 FOR_EACH_OBSERVER(WebContentsObserver,
1311 observers_,
1312 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271313 return tc;
1314}
1315
[email protected]14392a52012-05-02 20:28:441316void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211317 const NotificationSource& source,
1318 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441319 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211320 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1321 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031322 RenderWidgetHostView* view = host->GetView();
1323 if (view == GetFullscreenRenderWidgetHostView()) {
1324 // We cannot just call view_->RestoreFocus() here. On some platforms,
1325 // attempting to focus the currently-invisible WebContentsView will be
1326 // flat-out ignored. Therefore, this boolean is used to track whether
1327 // we will request focus after the fullscreen widget has been
1328 // destroyed.
1329 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1330 } else {
1331 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1332 i != pending_widget_views_.end(); ++i) {
1333 if (host->GetView() == i->second) {
1334 pending_widget_views_.erase(i);
1335 break;
1336 }
[email protected]bafe6cd2012-05-23 23:09:501337 }
1338 }
1339 break;
1340 }
[email protected]14392a52012-05-02 20:28:441341 default:
1342 NOTREACHED();
1343 }
1344}
1345
[email protected]ec6c05f2013-10-23 18:41:571346WebContents* WebContentsImpl::GetWebContents() {
1347 return this;
1348}
1349
[email protected]54944cde2012-12-09 09:24:591350void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211351 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361352 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211353 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431354 should_normally_be_visible_ = !params.initially_hidden;
1355
dcheng3ce04b62015-10-26 23:30:551356 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541357 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551358 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1359 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541360 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551361 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1362 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1363
1364 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1365 if (!site_instance)
1366 site_instance = SiteInstance::Create(params.browser_context);
1367
1368 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1369 // local root by definition.
1370 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1371 // longer be necessary to eagerly grab a routing ID for the view.
1372 // https://crbug.com/545684
1373 int32_t view_routing_id = params.routing_id;
1374 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1375 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1376 view_routing_id = main_frame_widget_routing_id =
1377 site_instance->GetProcess()->GetNextRoutingID();
1378 }
1379
1380 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1381 params.main_frame_routing_id,
1382 main_frame_widget_routing_id);
naskoc9f51dd2015-05-13 00:39:281383 frame_tree_.root()->SetFrameName(params.main_frame_name);
[email protected]d1198fd2012-08-13 22:50:191384
[email protected]fc2b46b2014-05-03 16:33:451385 WebContentsViewDelegate* delegate =
1386 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1387
fsamueladb0033602015-12-09 19:20:411388#if defined(MOJO_SHELL_CLIENT)
1389 if (MojoShellConnection::Get() &&
1390 base::CommandLine::ForCurrentProcess()->HasSwitch(
1391 switches::kUseMusInRenderer)) {
1392 mus::Window* mus_window = aura::GetMusWindow(params.context);
1393 if (mus_window) {
1394 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1395 &render_view_host_delegate_view_));
1396 }
1397 }
1398#endif
1399
1400 if (!view_) {
1401 view_.reset(CreateWebContentsView(this, delegate,
1402 &render_view_host_delegate_view_));
1403 }
fsamuel9cf7bdf2015-11-20 02:19:321404
lazyboy6ec48b2a2015-06-29 15:18:141405 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081406 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
fsamuel9cf7bdf2015-11-20 02:19:321407 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361408 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321409 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191410 }
[email protected]fc2b46b2014-05-03 16:33:451411 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191412 CHECK(view_.get());
1413
[email protected]ed245db2012-12-18 08:00:451414 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591415 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191416
tommyclieb25b2a2014-11-03 19:45:091417#if defined(ENABLE_PLUGINS)
1418 plugin_content_origin_whitelist_.reset(
1419 new PluginContentOriginWhitelist(this));
1420#endif
1421
[email protected]d1198fd2012-08-13 22:50:191422 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211423 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1424 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101425
[email protected]01f83f92014-06-17 14:41:541426 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091427 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541428
mlamouriefdca9d2014-09-16 16:55:401429 manifest_manager_host_.reset(new ManifestManagerHost(this));
1430
mfomitchev2b8b066a2016-01-28 19:23:151431#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101432 date_time_chooser_.reset(new DateTimeChooserAndroid());
1433#endif
fsamuel7310a4262014-12-05 05:06:441434
1435 // BrowserPluginGuest::Init needs to be called after this WebContents has
1436 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1437 if (browser_plugin_guest_)
1438 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371439
1440 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1441 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561442
1443 // If the WebContents creation was renderer-initiated, it means that the
1444 // corresponding RenderView and main RenderFrame have already been created.
1445 // Ensure observers are notified about this.
1446 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431447 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561448 RenderViewCreated(GetRenderViewHost());
1449 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1450 }
naskof5940b9f2015-03-02 23:04:051451
1452 // Ensure that observers are notified of the creation of this WebContents's
1453 // main RenderFrameHost. It must be done here for main frames, since the
1454 // NotifySwappedFromRenderManager expects view_ to already be created and that
1455 // happens after RenderFrameHostManager::Init.
1456 NotifySwappedFromRenderManager(
1457 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191458}
1459
[email protected]7fff43e2013-05-21 20:21:101460void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1461 RemoveDestructionObserver(web_contents);
1462
[email protected]ceee8cd2013-03-08 04:59:511463 // Clear a pending contents that has been closed before being shown.
1464 for (PendingContents::iterator iter = pending_contents_.begin();
1465 iter != pending_contents_.end();
1466 ++iter) {
1467 if (iter->second != web_contents)
1468 continue;
1469 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511470 return;
1471 }
1472 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441473}
1474
[email protected]7fff43e2013-05-21 20:21:101475void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1476 if (!ContainsKey(destruction_observers_, web_contents)) {
1477 destruction_observers_[web_contents] =
1478 new DestructionObserver(this, web_contents);
1479 }
1480}
1481
1482void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1483 DestructionObservers::iterator iter =
1484 destruction_observers_.find(web_contents);
1485 if (iter != destruction_observers_.end()) {
1486 delete destruction_observers_[web_contents];
1487 destruction_observers_.erase(iter);
1488 }
1489}
1490
[email protected]b172aee2012-04-10 17:05:261491void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311492 observers_.AddObserver(observer);
1493}
1494
[email protected]b172aee2012-04-10 17:05:261495void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311496 observers_.RemoveObserver(observer);
1497}
1498
[email protected]948481d2014-06-11 18:32:221499std::set<RenderWidgetHostView*>
1500WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1501 std::set<RenderWidgetHostView*> set;
1502 if (ShowingInterstitialPage()) {
1503 set.insert(GetRenderWidgetHostView());
1504 } else {
dchengafb53e22016-02-04 08:11:081505 for (RenderFrameHost* rfh : GetAllFrames()) {
1506 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1507 ->frame_tree_node()
1508 ->render_manager()
1509 ->GetRenderWidgetHostView();
1510 set.insert(rwhv);
1511 }
[email protected]948481d2014-06-11 18:32:221512 }
[email protected]de3c5d82014-05-28 22:12:591513 return set;
1514}
1515
[email protected]b172aee2012-04-10 17:05:261516void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341517 if (delegate_)
1518 delegate_->ActivateContents(this);
1519}
1520
avi3e4b8512015-11-11 01:55:491521void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1522 if (!RenderViewHostImpl::From(render_widget_host))
1523 return;
1524
[email protected]63954792011-07-11 04:17:481525 if (delegate_)
1526 delegate_->LostCapture();
1527}
1528
lazyboy63f5b312015-11-23 20:19:521529void WebContentsImpl::RenderWidgetCreated(
1530 RenderWidgetHostImpl* render_widget_host) {
1531 created_widgets_.insert(render_widget_host);
1532}
1533
[email protected]b24b68a2012-09-24 21:57:261534void WebContentsImpl::RenderWidgetDeleted(
1535 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521536 // Note that |is_being_destroyed_| can be true at this point as
1537 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1538 // us here.
1539 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261540
lazyboy63f5b312015-11-23 20:19:521541 if (is_being_destroyed_)
1542 return;
[email protected]44470a22013-01-24 01:21:541543
1544 if (render_widget_host &&
1545 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491546 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531547 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541548 FOR_EACH_OBSERVER(WebContentsObserver,
1549 observers_,
1550 DidDestroyFullscreenWidget(
1551 fullscreen_widget_routing_id_));
1552 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031553 if (fullscreen_widget_had_focus_at_shutdown_)
1554 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541555 }
[email protected]b24b68a2012-09-24 21:57:261556}
1557
miu9e14e492014-10-25 02:39:041558void WebContentsImpl::RenderWidgetGotFocus(
1559 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371560 // Notify the observers if an embedded fullscreen widget was focused.
1561 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1562 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1563 NotifyWebContentsFocused();
1564 }
miu9e14e492014-10-25 02:39:041565}
1566
estaded0a0c992015-01-21 14:12:061567void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311568 RenderWidgetHostImpl* render_widget_host,
1569 bool width_changed) {
creisc014b402015-04-23 16:41:451570 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291571 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061572 return;
estaded0a0c992015-01-21 14:12:061573
rouslan2f5993f2015-01-29 00:18:311574 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1575 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061576}
1577
paulmeyer9ef6e4462015-02-24 19:15:101578void WebContentsImpl::ScreenInfoChanged() {
1579 if (browser_plugin_embedder_)
1580 browser_plugin_embedder_->ScreenInfoChanged();
1581}
1582
[email protected]b172aee2012-04-10 17:05:261583bool WebContentsImpl::PreHandleKeyboardEvent(
1584 const NativeWebKeyboardEvent& event,
1585 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481586 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131587 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481588}
1589
[email protected]b172aee2012-04-10 17:05:261590void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101591 if (browser_plugin_embedder_ &&
1592 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1593 return;
1594 }
[email protected]63954792011-07-11 04:17:481595 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131596 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481597}
1598
[email protected]d92026ef2014-03-03 21:04:131599bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461600 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191601#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331602 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1603 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191604 // -the OS already has a gesture to do this through pinch-zoom
1605 // -if a user starts an inertial scroll, let's go, and presses control
1606 // (i.e. control+tab) then the OS's buffered scroll events will come in
1607 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331608 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551609 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331610 !event.canScroll) {
w.shackleton49bcd392016-01-06 17:38:221611 // Count only integer cumulative scrolls as zoom events; this handles
1612 // smooth scroll and regular scroll device behavior.
1613 zoom_scroll_remainder_ += event.wheelTicksY;
1614 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1615 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1616 if (whole_zoom_scroll_remainder_ != 0) {
1617 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1618 }
[email protected]fb3f066e2013-02-12 19:12:521619 return true;
1620 }
[email protected]bccc4472013-04-18 16:37:191621#endif
[email protected]fb3f066e2013-02-12 19:12:521622 return false;
1623}
1624
[email protected]04bce562014-01-30 05:34:541625bool WebContentsImpl::PreHandleGestureEvent(
1626 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031627 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541628}
1629
kenrb2a565f82015-09-02 20:24:591630RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451631 if (!is_being_destroyed_ && GetOuterWebContents())
1632 return GetOuterWebContents()->GetInputEventRouter();
1633
1634 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591635 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1636 return rwh_input_event_router_.get();
1637}
1638
alexmos3fcd0ca2015-10-23 18:18:331639void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1640 // Focus loss may occur while this WebContents is being destroyed. Don't
1641 // send the message in this case, as the main frame's RenderFrameHost and
1642 // other state has already been cleared.
1643 if (is_being_destroyed_)
1644 return;
1645
1646 frame_tree_.ReplicatePageFocus(is_focused);
1647}
1648
alexmosc4cbacb2015-11-21 01:29:221649RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1650 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521651 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221652 return receiving_widget;
1653
1654 // Events for widgets other than the main frame (e.g., popup menus) should be
1655 // forwarded directly to the widget they arrived on.
1656 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1657 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521658
1659 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1660 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221661 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521662
alexmos732ca3a2015-12-08 02:01:021663 // The view may be null if a subframe's renderer process has crashed while
1664 // the subframe has focus. Drop the event in that case. Do not give
1665 // it to the main frame, so that the user doesn't unexpectedly type into the
1666 // wrong frame if a focused subframe renderer crashes while they type.
1667 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1668 if (!view)
1669 return nullptr;
1670
1671 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521672}
1673
mlamouri7a78d6fd2015-01-17 13:23:531674void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1675 // This method is being called to enter renderer-initiated fullscreen mode.
1676 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491677 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371678 if (widget_view) {
1679 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1680 ->ShutdownAndDestroyWidget(true);
1681 }
[email protected]4aebbca2013-09-17 22:26:491682
[email protected]8a5e0ca2011-08-25 06:30:471683 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531684 delegate_->EnterFullscreenModeForTab(this, origin);
1685
1686 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461687 DidToggleFullscreenModeForTab(
1688 IsFullscreenForCurrentTab(
1689 GetRenderViewHost()->GetWidget()),
1690 false));
mlamouri7a78d6fd2015-01-17 13:23:531691}
1692
bokanece34a82016-01-28 19:49:461693void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531694 // This method is being called to leave renderer-initiated fullscreen mode.
1695 // Make sure any existing fullscreen widget is shut down first.
1696 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371697 if (widget_view) {
1698 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1699 ->ShutdownAndDestroyWidget(true);
1700 }
mlamouri7a78d6fd2015-01-17 13:23:531701
hugo.holgersson61288e6c2015-01-28 17:04:401702#if defined(OS_ANDROID)
1703 ContentVideoView* video_view = ContentVideoView::GetInstance();
1704 if (video_view != NULL)
watk98292292016-01-19 22:24:081705 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401706#endif
1707
mlamouri7a78d6fd2015-01-17 13:23:531708 if (delegate_)
1709 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371710
bokanece34a82016-01-28 19:49:461711 // The fullscreen state is communicated to the renderer through a resize
1712 // message. If the change in fullscreen state doesn't cause a view resize
1713 // then we must ensure web contents exit the fullscreen state by explicitly
1714 // sending a resize message. This is required for the situation of the browser
1715 // moving the view into a "browser fullscreen" state and then the contents
1716 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1717 // have the side effect of the view resizing, hence the explicit call here is
1718 // required.
1719 if (!will_cause_resize) {
1720 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1721 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1722 render_widget_host->WasResized();
1723 }
scheib3dcb6c932015-02-23 10:55:581724 }
1725
avibf58fa0c2015-11-11 01:45:521726 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461727 DidToggleFullscreenModeForTab(
1728 IsFullscreenForCurrentTab(
1729 GetRenderViewHost()->GetWidget()),
1730 will_cause_resize));
[email protected]8a5e0ca2011-08-25 06:30:471731}
1732
avibf58fa0c2015-11-11 01:45:521733bool WebContentsImpl::IsFullscreenForCurrentTab(
1734 RenderWidgetHostImpl* render_widget_host) const {
1735 if (!RenderViewHostImpl::From(render_widget_host))
1736 return false;
1737
[email protected]199bba6e2012-04-04 16:19:381738 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121739}
1740
avibf58fa0c2015-11-11 01:45:521741blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1742 RenderWidgetHostImpl* render_widget_host) const {
1743 if (!RenderViewHostImpl::From(render_widget_host))
1744 return blink::WebDisplayModeBrowser;
1745
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121746 return delegate_ ? delegate_->GetDisplayMode(this)
1747 : blink::WebDisplayModeBrowser;
1748}
1749
avic3aa8422015-11-09 20:57:221750void WebContentsImpl::RequestToLockMouse(
1751 RenderWidgetHostImpl* render_widget_host,
1752 bool user_gesture,
1753 bool last_unlocked_by_target) {
1754 if (render_widget_host != GetRenderViewHost()->GetWidget()) {
1755 render_widget_host->GotResponseToLockMouseRequest(false);
1756 return;
[email protected]e9621112011-10-17 05:38:371757 }
avic3aa8422015-11-09 20:57:221758
1759 if (delegate_)
1760 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1761 else
1762 GotResponseToLockMouseRequest(false);
[email protected]e9621112011-10-17 05:38:371763}
1764
avi3e4b8512015-11-11 01:55:491765void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1766 if (!RenderViewHostImpl::From(render_widget_host))
1767 return;
1768
[email protected]e9621112011-10-17 05:38:371769 if (delegate_)
1770 delegate_->LostMouseLock();
1771}
1772
dtrainor5ef644e2015-11-19 00:12:471773void WebContentsImpl::ForwardCompositorProto(
1774 RenderWidgetHostImpl* render_widget_host,
1775 const std::vector<uint8_t>& proto) {
1776 if (render_widget_host != GetRenderViewHost()->GetWidget())
1777 return;
1778
1779 if (delegate_)
1780 delegate_->ForwardCompositorProto(proto);
1781}
1782
[email protected]bafe6cd2012-05-23 23:09:501783void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431784 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551785 int32_t route_id,
1786 int32_t main_frame_route_id,
1787 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131788 const ViewHostMsg_CreateWindow_Params& params,
1789 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501790 // We usually create the new window in the same BrowsingInstance (group of
1791 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551792 // if the opener is being suppressed (in a non-guest), we create a new
1793 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251794 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551795
nickd30fd962015-07-27 21:51:081796 if (is_guest && BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:141797 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1798 // yet.
1799 NOTREACHED();
1800 }
1801
[email protected]04cbd3d2013-12-04 04:58:201802 // If the opener is to be suppressed, the new window can be in any process.
1803 // Since routing ids are process specific, we must not have one passed in
1804 // as argument here.
1805 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1806
[email protected]bafe6cd2012-05-23 23:09:501807 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431808 params.opener_suppressed && !is_guest
1809 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1810 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501811
alexmos4cf2aa32015-07-15 23:40:431812 // A message to create a new window can only come from a process for a frame
1813 // in this WebContents' FrameTree. If any other process sends the request, it
1814 // is invalid and the process must be terminated.
1815 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:381816 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:431817 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351818 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201819 if (process_handle != base::kNullProcessHandle) {
1820 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391821 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351822 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201823 }
1824 return;
1825 }
1826
[email protected]d1198fd2012-08-13 22:50:191827 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341828 //
1829 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301830 const std::string& partition_id =
1831 GetContentClient()->browser()->
1832 GetStoragePartitionIdForSite(GetBrowserContext(),
1833 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461834 StoragePartition* partition = BrowserContext::GetStoragePartition(
1835 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411836 DOMStorageContextWrapper* dom_storage_context =
1837 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191838 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1839 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1840 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371841
1842 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551843 !delegate_->ShouldCreateWebContents(
1844 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1845 params.window_container_type, params.frame_name, params.target_url,
1846 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011847 if (route_id != MSG_ROUTING_NONE &&
1848 !RenderViewHost::FromID(render_process_id, route_id)) {
1849 // If the embedder didn't create a WebContents for this route, we need to
1850 // delete the RenderView that had already been created.
1851 Send(new ViewMsg_Close(route_id));
1852 }
csharrisona2280cd2016-02-03 23:21:151853 // It's safe to only target the frame because the render process will not
1854 // have a chance to create more frames at this point.
1855 ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
1856 GlobalFrameRoutingId(render_process_id, main_frame_route_id));
[email protected]dd6730412013-08-14 15:03:371857 return;
1858 }
1859
1860 // Create the new web contents. This will automatically create the new
1861 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461862 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591863 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041864 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551865 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121866 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431867 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211868 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061869 create_params.opener_suppressed = params.opener_suppressed;
1870 if (params.disposition == NEW_BACKGROUND_TAB)
1871 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191872 create_params.renderer_initiated_creation =
1873 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061874
[email protected]4858e432014-06-23 18:14:171875 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551876 if (!is_guest) {
1877 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451878 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171879 new_contents = static_cast<WebContentsImpl*>(
1880 WebContents::Create(create_params));
1881 } else {
1882 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551883 }
[email protected]50d326e2014-05-20 17:59:061884 new_contents->GetController().SetSessionStorageNamespace(
1885 partition_id,
1886 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191887
alexmos646fec02015-07-25 00:11:491888 // If the new frame has a name, make sure any SiteInstances that can find
1889 // this named frame have proxies for it. Must be called after
1890 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1891 // GetSessionStorageNamespace.
1892 if (!params.frame_name.empty())
1893 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1894
[email protected]c4538072013-03-18 02:17:551895 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341896 // will be shown immediately).
1897 if (!params.opener_suppressed) {
1898 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451899 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501900
[email protected]d70bea92013-04-05 04:23:341901 // TODO(brettw): It seems bogus that we have to call this function on the
1902 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431903 new_view->CreateViewForWidget(
1904 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341905 }
[email protected]bafe6cd2012-05-23 23:09:501906 // Save the created window associated with the route so we can show it
1907 // later.
1908 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1909 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101910 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501911 }
1912
1913 if (delegate_) {
1914 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071915 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131916 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501917 }
1918
1919 if (params.opener_suppressed) {
1920 // When the opener is suppressed, the original renderer cannot access the
1921 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001922 bool was_blocked = false;
1923 if (delegate_) {
bokan107a47f2015-02-03 23:23:391924 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001925 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391926 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001927 params.user_gesture, &was_blocked);
1928 }
1929 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211930 OpenURLParams open_params(params.target_url,
1931 Referrer(),
1932 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351933 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211934 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301935 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:371936
1937 if (delegate_ && !is_guest &&
1938 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
1939 // We are in asynchronous add new contents path, delay opening url
1940 new_contents->delayed_open_url_params_.reset(
1941 new OpenURLParams(open_params));
1942 } else {
1943 new_contents->OpenURL(open_params);
1944 }
[email protected]eda238a12012-09-07 23:44:001945 }
[email protected]bafe6cd2012-05-23 23:09:501946 }
1947}
1948
avib7348942015-12-25 20:57:101949void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1950 int32_t route_id,
[email protected]180ef242013-11-07 06:50:461951 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:051952 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501953}
1954
avib7348942015-12-25 20:57:101955void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
1956 int32_t route_id) {
piman5d36dae2015-09-24 22:47:051957 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501958}
1959
avib7348942015-12-25 20:57:101960void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1961 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:501962 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461963 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211964 RenderProcessHost* process = GetRenderProcessHost();
kenrbb46f86a2015-12-07 07:53:231965 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:511966 // this WebContentsImpl instance. If any other process sends the request,
1967 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:381968 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
jaekyun37e572a32014-12-04 23:33:351969 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1970 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511971 if (process_handle != base::kNullProcessHandle) {
1972 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391973 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351974 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511975 }
1976 return;
1977 }
1978
[email protected]bafe6cd2012-05-23 23:09:501979 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:051980 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261981
[email protected]cfd80b02014-05-01 17:46:481982 RenderWidgetHostViewBase* widget_view =
1983 static_cast<RenderWidgetHostViewBase*>(
1984 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191985 if (!widget_view)
1986 return;
[email protected]bafe6cd2012-05-23 23:09:501987 if (!is_fullscreen) {
1988 // Popups should not get activated.
1989 widget_view->SetPopupType(popup_type);
1990 }
1991 // Save the created widget associated with the route so we can show it later.
1992 pending_widget_views_[route_id] = widget_view;
1993
1994#if defined(OS_MACOSX)
1995 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1996 // to allow it to survive the trip without being hosted.
1997 base::mac::NSObjectRetain(widget_view->GetNativeView());
1998#endif
1999}
2000
2001void WebContentsImpl::ShowCreatedWindow(int route_id,
2002 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392003 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502004 bool user_gesture) {
2005 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:002006 if (contents) {
2007 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162008 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382009 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2010 contents->ResumeLoadingCreatedWebContents();
2011
[email protected]eda238a12012-09-07 23:44:002012 if (delegate) {
2013 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392014 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002015 }
2016 }
[email protected]bafe6cd2012-05-23 23:09:502017}
2018
2019void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:392020 const gfx::Rect& initial_rect) {
2021 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502022}
2023
2024void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
2025 ShowCreatedWidget(route_id, true, gfx::Rect());
2026}
2027
2028void WebContentsImpl::ShowCreatedWidget(int route_id,
2029 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392030 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482031 RenderWidgetHostViewBase* widget_host_view =
2032 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502033 if (!widget_host_view)
2034 return;
[email protected]cfd80b02014-05-01 17:46:482035
2036 RenderWidgetHostView* view = NULL;
2037 BrowserPluginGuest* guest = GetBrowserPluginGuest();
2038 if (guest && guest->embedder_web_contents()) {
2039 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
2040 } else {
2041 view = GetRenderWidgetHostView();
2042 }
2043
[email protected]4aebbca2013-09-17 22:26:492044 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312045 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032046 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312047 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492048 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2049 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532050 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492051 } else {
[email protected]cfd80b02014-05-01 17:46:482052 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492053 }
[email protected]4aebbca2013-09-17 22:26:492054 FOR_EACH_OBSERVER(WebContentsObserver,
2055 observers_,
2056 DidShowFullscreenWidget(route_id));
2057 if (!widget_host_view->HasFocus())
2058 widget_host_view->Focus();
2059 } else {
bokan107a47f2015-02-03 23:23:392060 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492061 }
[email protected]89054502012-06-03 10:29:242062
2063 RenderWidgetHostImpl* render_widget_host_impl =
2064 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2065 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312066 // Only allow privileged mouse lock for fullscreen render widget, which is
2067 // used to implement Pepper Flash fullscreen.
2068 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502069
2070#if defined(OS_MACOSX)
2071 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2072 // properly embedded (or purposefully ignored) we can release the retain we
2073 // took in CreateNewWidget().
2074 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2075#endif
2076}
2077
2078WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2079 PendingContents::iterator iter = pending_contents_.find(route_id);
2080
2081 // Certain systems can block the creation of new windows. If we didn't succeed
2082 // in creating one, just return NULL.
2083 if (iter == pending_contents_.end()) {
2084 return NULL;
2085 }
2086
2087 WebContentsImpl* new_contents = iter->second;
2088 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102089 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502090
[email protected]d70bea92013-04-05 04:23:342091 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252092 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342093 return new_contents;
2094
[email protected]bafe6cd2012-05-23 23:09:502095 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432096 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502097 return NULL;
2098
[email protected]bafe6cd2012-05-23 23:09:502099 return new_contents;
2100}
2101
2102RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2103 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2104 if (iter == pending_widget_views_.end()) {
2105 DCHECK(false);
2106 return NULL;
2107 }
2108
2109 RenderWidgetHostView* widget_host_view = iter->second;
2110 pending_widget_views_.erase(route_id);
2111
2112 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2113 if (!widget_host->GetProcess()->HasConnection()) {
2114 // The view has gone away or the renderer crashed. Nothing to do.
2115 return NULL;
2116 }
2117
2118 return widget_host_view;
2119}
2120
[email protected]f13b4202012-06-12 23:53:232121void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092122 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212123 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372124 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232125 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372126 } else {
2127 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:042128 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:372129 scoped_ptr<MediaStreamUI>());
2130 }
[email protected]f13b4202012-06-12 23:53:232131}
2132
grunell657d4d82014-09-18 00:09:432133bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2134 MediaStreamType type) {
2135 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2136 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2137 return delegate_ &&
2138 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2139}
2140
[email protected]cc9200432013-07-23 23:02:402141SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2142 SiteInstance* instance) {
2143 return controller_.GetSessionStorageNamespace(instance);
2144}
2145
[email protected]6de7fc482014-06-06 10:46:442146SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2147 return controller_.GetSessionStorageNamespaceMap();
2148}
2149
[email protected]9b159a52013-10-03 17:24:552150FrameTree* WebContentsImpl::GetFrameTree() {
2151 return &frame_tree_;
2152}
2153
lukendc35e7f2014-11-10 19:06:142154void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2155 virtual_keyboard_requested_ = requested;
2156}
2157
2158bool WebContentsImpl::IsVirtualKeyboardRequested() {
2159 return virtual_keyboard_requested_;
2160}
2161
[email protected]95640212014-07-26 18:14:302162AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2163 return accessibility_mode_;
2164}
2165
[email protected]31a71eaf2014-03-13 01:47:362166void WebContentsImpl::AccessibilityEventReceived(
2167 const std::vector<AXEventNotificationDetails>& details) {
2168 FOR_EACH_OBSERVER(
2169 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2170}
2171
dmazzonia656928e2014-09-15 20:28:542172RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402173 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542174 int browser_plugin_instance_id) {
2175 BrowserPluginGuestManager* guest_manager =
2176 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202177 if (!guest_manager)
2178 return nullptr;
2179
dmazzonia656928e2014-09-15 20:28:542180 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442181 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542182 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202183 return nullptr;
2184
dmazzonia656928e2014-09-15 20:28:542185 return guest->GetMainFrame();
2186}
2187
blundellc57b93f2014-10-29 13:19:572188GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2189 return geolocation_service_context_.get();
2190}
2191
alogvinovf50445a2015-10-30 13:00:122192WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2193 return wake_lock_service_context_.get();
2194}
2195
[email protected]edc3af82013-12-12 21:24:072196void WebContentsImpl::OnShowValidationMessage(
2197 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292198 const base::string16& main_text,
2199 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072200 if (delegate_)
2201 delegate_->ShowValidationMessage(
2202 this, anchor_in_root_view, main_text, sub_text);
2203}
2204
2205void WebContentsImpl::OnHideValidationMessage() {
2206 if (delegate_)
2207 delegate_->HideValidationMessage(this);
2208}
2209
2210void WebContentsImpl::OnMoveValidationMessage(
2211 const gfx::Rect& anchor_in_root_view) {
2212 if (delegate_)
2213 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2214}
2215
[email protected]32deec62013-05-15 23:55:042216void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
2217 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442218 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042219}
2220
[email protected]95640212014-07-26 18:14:302221BrowserAccessibilityManager*
2222 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452223 RenderFrameHostImpl* rfh = GetMainFrame();
2224 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302225}
2226
2227BrowserAccessibilityManager*
2228 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452229 RenderFrameHostImpl* rfh = GetMainFrame();
2230 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302231}
2232
mohsen7ab1ec16ec2015-07-02 18:26:232233void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2234 RenderFrameHost* focused_frame = GetFocusedFrame();
2235 if (!focused_frame)
2236 return;
2237
2238 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2239 focused_frame->GetRoutingID(), extent));
2240}
2241
2242void WebContentsImpl::SelectRange(const gfx::Point& base,
2243 const gfx::Point& extent) {
2244 RenderFrameHost* focused_frame = GetFocusedFrame();
2245 if (!focused_frame)
2246 return;
2247
2248 focused_frame->Send(
2249 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2250}
2251
aurimasab0319022015-07-10 21:57:382252void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2253 int end_adjust) {
2254 RenderFrameHost* focused_frame = GetFocusedFrame();
2255 if (!focused_frame)
2256 return;
2257
2258 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2259 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2260}
2261
[email protected]b172aee2012-04-10 17:05:262262void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492263 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232264 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492265 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332266}
2267
avic3aa8422015-11-09 20:57:222268void WebContentsImpl::ResizeDueToAutoResize(
2269 RenderWidgetHostImpl* render_widget_host,
2270 const gfx::Size& new_size) {
2271 if (render_widget_host != GetRenderViewHost()->GetWidget())
2272 return;
2273
[email protected]61e2b3cc2012-03-02 16:13:342274 if (delegate_)
2275 delegate_->ResizeDueToAutoResize(this, new_size);
2276}
2277
[email protected]b172aee2012-04-10 17:05:262278WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202279 if (!delegate_)
2280 return NULL;
[email protected]00c37fc2011-08-02 00:22:502281
[email protected]e5d549d2011-12-28 01:29:202282 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202283 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342284}
2285
[email protected]6b618e62012-08-16 12:59:182286bool WebContentsImpl::Send(IPC::Message* message) {
2287 if (!GetRenderViewHost()) {
2288 delete message;
2289 return false;
2290 }
2291
2292 return GetRenderViewHost()->Send(message);
2293}
2294
[email protected]a86c0e962013-12-17 17:10:392295void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2296 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442297 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392298 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442299}
2300
[email protected]20ca0382013-02-28 19:50:072301void WebContentsImpl::AttachInterstitialPage(
2302 InterstitialPageImpl* interstitial_page) {
2303 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212304 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292305
2306 // Cancel any visible dialogs so that they don't interfere with the
2307 // interstitial.
creis89a0f782015-05-27 16:13:172308 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292309
[email protected]20ca0382013-02-28 19:50:072310 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2311 DidAttachInterstitialPage());
clamydb73eb6c2016-02-10 13:27:562312
2313 // Stop the throbber if needed while the interstitial page is shown.
2314 if (IsLoading())
2315 LoadingStateChanged(false, true, true, nullptr);
2316}
2317
2318void WebContentsImpl::DidProceedOnInterstitial() {
2319 // Restart the throbber now that the interstitial page is going away.
2320 if (paused_throbber_for_interstitial_) {
2321 if (frame_tree_.IsLoading())
2322 LoadingStateChanged(true, true, false, nullptr);
2323 }
[email protected]20ca0382013-02-28 19:50:072324}
2325
2326void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:572327 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212328 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072329 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2330 DidDetachInterstitialPage());
clamydb73eb6c2016-02-10 13:27:562331 // Restart the throbber now that the interstitial page is going away.
2332 if (paused_throbber_for_interstitial_) {
2333 if (frame_tree_.IsLoading())
2334 LoadingStateChanged(true, true, false, nullptr);
2335 }
[email protected]20ca0382013-02-28 19:50:072336}
2337
avi2b177592014-12-10 02:08:022338void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2339 int history_length) {
2340 SetHistoryOffsetAndLengthForView(
2341 GetRenderViewHost(), history_offset, history_length);
2342}
2343
2344void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2345 RenderViewHost* render_view_host,
2346 int history_offset,
2347 int history_length) {
2348 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2349 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142350}
2351
[email protected]4fed3702014-04-01 09:08:002352void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172353 RenderFrameHost* focused_frame = GetFocusedFrame();
2354 if (!focused_frame)
2355 return;
2356
[email protected]959be4c2014-04-08 15:01:332357 focused_frame->Send(new FrameMsg_Reload(
2358 focused_frame->GetRoutingID(), ignore_cache));
2359}
2360
megjablon3f5941072016-02-04 23:27:522361void WebContentsImpl::ReloadLoFiImages() {
2362 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2363}
2364
[email protected]959be4c2014-04-08 15:01:332365void WebContentsImpl::Undo() {
2366 RenderFrameHost* focused_frame = GetFocusedFrame();
2367 if (!focused_frame)
2368 return;
2369
2370 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2371 RecordAction(base::UserMetricsAction("Undo"));
2372}
2373
2374void WebContentsImpl::Redo() {
2375 RenderFrameHost* focused_frame = GetFocusedFrame();
2376 if (!focused_frame)
2377 return;
2378 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2379 RecordAction(base::UserMetricsAction("Redo"));
2380}
2381
2382void WebContentsImpl::Cut() {
2383 RenderFrameHost* focused_frame = GetFocusedFrame();
2384 if (!focused_frame)
2385 return;
2386
2387 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2388 RecordAction(base::UserMetricsAction("Cut"));
2389}
2390
2391void WebContentsImpl::Copy() {
2392 RenderFrameHost* focused_frame = GetFocusedFrame();
2393 if (!focused_frame)
2394 return;
2395
2396 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2397 RecordAction(base::UserMetricsAction("Copy"));
2398}
2399
2400void WebContentsImpl::CopyToFindPboard() {
2401#if defined(OS_MACOSX)
2402 RenderFrameHost* focused_frame = GetFocusedFrame();
2403 if (!focused_frame)
2404 return;
2405
2406 // Windows/Linux don't have the concept of a find pasteboard.
2407 focused_frame->Send(
2408 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2409 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2410#endif
2411}
2412
2413void WebContentsImpl::Paste() {
2414 RenderFrameHost* focused_frame = GetFocusedFrame();
2415 if (!focused_frame)
2416 return;
2417
2418 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2419 RecordAction(base::UserMetricsAction("Paste"));
2420}
2421
2422void WebContentsImpl::PasteAndMatchStyle() {
2423 RenderFrameHost* focused_frame = GetFocusedFrame();
2424 if (!focused_frame)
2425 return;
2426
2427 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2428 focused_frame->GetRoutingID()));
2429 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2430}
2431
2432void WebContentsImpl::Delete() {
2433 RenderFrameHost* focused_frame = GetFocusedFrame();
2434 if (!focused_frame)
2435 return;
2436
2437 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2438 RecordAction(base::UserMetricsAction("DeleteSelection"));
2439}
2440
2441void WebContentsImpl::SelectAll() {
2442 RenderFrameHost* focused_frame = GetFocusedFrame();
2443 if (!focused_frame)
2444 return;
2445
2446 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2447 RecordAction(base::UserMetricsAction("SelectAll"));
2448}
2449
2450void WebContentsImpl::Unselect() {
2451 RenderFrameHost* focused_frame = GetFocusedFrame();
2452 if (!focused_frame)
2453 return;
2454
2455 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2456 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172457}
2458
2459void WebContentsImpl::Replace(const base::string16& word) {
2460 RenderFrameHost* focused_frame = GetFocusedFrame();
2461 if (!focused_frame)
2462 return;
2463
[email protected]959be4c2014-04-08 15:01:332464 focused_frame->Send(new InputMsg_Replace(
2465 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172466}
2467
2468void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2469 RenderFrameHost* focused_frame = GetFocusedFrame();
2470 if (!focused_frame)
2471 return;
2472
[email protected]959be4c2014-04-08 15:01:332473 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2474 focused_frame->GetRoutingID(), word));
2475}
2476
2477void WebContentsImpl::NotifyContextMenuClosed(
2478 const CustomContextMenuContext& context) {
2479 RenderFrameHost* focused_frame = GetFocusedFrame();
2480 if (!focused_frame)
2481 return;
2482
2483 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2484 focused_frame->GetRoutingID(), context));
2485}
2486
2487void WebContentsImpl::ExecuteCustomContextMenuCommand(
2488 int action, const CustomContextMenuContext& context) {
2489 RenderFrameHost* focused_frame = GetFocusedFrame();
2490 if (!focused_frame)
2491 return;
2492
2493 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2494 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002495}
2496
[email protected]fc2b46b2014-05-03 16:33:452497gfx::NativeView WebContentsImpl::GetNativeView() {
2498 return view_->GetNativeView();
2499}
2500
2501gfx::NativeView WebContentsImpl::GetContentNativeView() {
2502 return view_->GetContentNativeView();
2503}
2504
2505gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2506 return view_->GetTopLevelNativeWindow();
2507}
2508
2509gfx::Rect WebContentsImpl::GetViewBounds() {
2510 return view_->GetViewBounds();
2511}
2512
2513gfx::Rect WebContentsImpl::GetContainerBounds() {
2514 gfx::Rect rv;
2515 view_->GetContainerBounds(&rv);
2516 return rv;
2517}
2518
2519DropData* WebContentsImpl::GetDropData() {
2520 return view_->GetDropData();
2521}
2522
2523void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042524 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452525}
2526
2527void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042528 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452529}
2530
2531void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042532 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452533}
2534
2535void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042536 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452537}
2538
[email protected]b172aee2012-04-10 17:05:262539void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272540 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212541 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542542 return;
2543 }
[email protected]0b431992014-06-24 00:08:032544 RenderWidgetHostView* const fullscreen_view =
2545 GetFullscreenRenderWidgetHostView();
2546 if (fullscreen_view) {
2547 fullscreen_view->Focus();
2548 return;
2549 }
creisc014b402015-04-23 16:41:452550 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542551}
2552
[email protected]b172aee2012-04-10 17:05:262553bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212554 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542555}
2556
[email protected]b172aee2012-04-10 17:05:262557InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212558 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222559}
2560
[email protected]b172aee2012-04-10 17:05:262561bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162562 // WebKit creates Document object when MIME type is application/xhtml+xml,
2563 // so we also support this MIME type.
2564 return contents_mime_type_ == "text/html" ||
2565 contents_mime_type_ == "text/xml" ||
2566 contents_mime_type_ == "application/xhtml+xml" ||
2567 contents_mime_type_ == "text/plain" ||
2568 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252569 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162570}
2571
[email protected]b172aee2012-04-10 17:05:262572void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592573 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162574 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552575 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192576 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142577 return;
[email protected]c7dd2f62011-07-18 15:57:592578 }
2579
2580 Stop();
2581
2582 // Create the save package and possibly prompt the user for the name to save
2583 // the page as. The user prompt is an asynchronous operation that runs on
2584 // another thread.
2585 save_package_ = new SavePackage(this);
2586 save_package_->GetSaveInfo();
2587}
2588
2589// Used in automated testing to bypass prompting the user for file names.
2590// Instead, the names and paths are hard coded rather than running them through
2591// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342592bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2593 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212594 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592595 // Stop the page from navigating.
2596 Stop();
2597
2598 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212599 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592600}
2601
[email protected]3c71576ce2013-07-23 02:00:012602void WebContentsImpl::SaveFrame(const GURL& url,
2603 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372604 SaveFrameWithHeaders(url, referrer, std::string());
2605}
2606
2607void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2608 const Referrer& referrer,
2609 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192610 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012611 return;
sammc92af61552014-11-19 23:27:402612 if (delegate_ && delegate_->SaveFrame(url, referrer))
2613 return;
2614
nasko89ad7742015-03-05 22:14:192615 // TODO(nasko): This check for main frame is incorrect and should be fixed
2616 // by explicitly passing in which frame this method should target.
2617 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012618
2619 DownloadManager* dlm =
2620 BrowserContext::GetDownloadManager(GetBrowserContext());
2621 if (!dlm)
2622 return;
avib7348942015-12-25 20:57:102623 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012624 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272625 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012626 if (entry)
2627 post_id = entry->GetPostID();
2628 }
2629 scoped_ptr<DownloadUrlParameters> params(
2630 DownloadUrlParameters::FromWebContents(this, url));
2631 params->set_referrer(referrer);
2632 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012633 if (post_id >= 0)
2634 params->set_method("POST");
2635 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372636
2637 if (headers.empty()) {
2638 params->set_prefer_cache(true);
2639 } else {
brettw26dab8f02015-08-08 00:28:472640 for (const base::StringPiece& key_value :
2641 base::SplitStringPiece(
2642 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2643 std::vector<std::string> pair = base::SplitString(
2644 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372645 DCHECK_EQ(2ul, pair.size());
2646 params->add_request_header(pair[0], pair[1]);
2647 }
2648 }
dcheng36b6aec92015-12-26 06:16:362649 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012650}
2651
[email protected]b172aee2012-04-10 17:05:262652void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342653 const base::FilePath& file,
avib7348942015-12-25 20:57:102654 const base::Callback<void(int64_t)>& callback) {
[email protected]18516cf92013-08-28 18:19:482655 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122656}
2657
[email protected]b172aee2012-04-10 17:05:262658const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272659 return contents_mime_type_;
2660}
2661
[email protected]b172aee2012-04-10 17:05:262662bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272663 return notify_disconnection_;
2664}
2665
[email protected]b172aee2012-04-10 17:05:262666void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312667 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182668 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162669}
2670
[email protected]b172aee2012-04-10 17:05:262671void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542672 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182673 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162674}
2675
[email protected]8ff00d72012-10-23 19:12:212676RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272677 return &renderer_preferences_;
2678}
2679
[email protected]e35ccd52012-05-23 16:22:472680void WebContentsImpl::Close() {
2681 Close(GetRenderViewHost());
2682}
2683
[email protected]cf200a562013-05-03 16:24:292684void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462685 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292686 if (browser_plugin_embedder_.get())
2687 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2688 screen_x, screen_y, operation);
2689 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452690 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2691 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292692}
2693
[email protected]d60f3702013-12-26 16:30:242694void WebContentsImpl::DidGetResourceResponseStart(
2695 const ResourceRequestDetails& details) {
2696 controller_.ssl_manager()->DidStartResourceResponse(details);
2697
2698 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2699 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242700}
2701
2702void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462703 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242704 const ResourceRedirectDetails& details) {
2705 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2706
2707 FOR_EACH_OBSERVER(
2708 WebContentsObserver,
2709 observers_,
creis114ca1b2014-11-13 23:51:462710 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242711
2712 // TODO(avi): Remove. http://crbug.com/170921
2713 NotificationService::current()->Notify(
2714 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2715 Source<WebContents>(this),
2716 Details<const ResourceRedirectDetails>(&details));
[email protected]d60f3702013-12-26 16:30:242717}
2718
calamity7fe55ce2015-04-10 03:59:372719void WebContentsImpl::NotifyWebContentsFocused() {
2720 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2721}
2722
[email protected]b172aee2012-04-10 17:05:262723void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522724 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452725 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292726 if (browser_plugin_embedder_.get())
2727 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342728}
2729
[email protected]e35ccd52012-05-23 16:22:472730void WebContentsImpl::UserGestureDone() {
avic3aa8422015-11-09 20:57:222731 OnUserGesture(GetRenderViewHost()->GetWidget());
[email protected]e35ccd52012-05-23 16:22:472732}
2733
[email protected]b172aee2012-04-10 17:05:262734void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272735 closed_by_user_gesture_ = value;
2736}
2737
[email protected]b172aee2012-04-10 17:05:262738bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272739 return closed_by_user_gesture_;
2740}
2741
[email protected]b172aee2012-04-10 17:05:262742void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502743 if (!delegate_)
2744 return;
2745
[email protected]6286a372013-10-09 04:03:272746 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2747 if (!entry)
[email protected]1788e772010-12-15 16:40:502748 return;
2749
[email protected]6286a372013-10-09 04:03:272750 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122751}
2752
[email protected]b172aee2012-04-10 17:05:262753void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042754 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272755 if (!delegate_)
2756 return;
2757
[email protected]691aa2f2013-05-28 22:52:042758 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272759}
2760
[email protected]b172aee2012-04-10 17:05:262761int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272762 return minimum_zoom_percent_;
2763}
2764
[email protected]b172aee2012-04-10 17:05:262765int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272766 return maximum_zoom_percent_;
2767}
2768
mcnee432e47d2015-11-09 19:37:462769void WebContentsImpl::SetPageScale(float page_scale_factor) {
2770 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242771}
2772
[email protected]b172aee2012-04-10 17:05:262773gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492774 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232775}
2776
[email protected]b172aee2012-04-10 17:05:262777bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052778 if (GetBrowserPluginGuest())
2779 return GetBrowserPluginGuest()->LockMouse(allowed);
2780
creisc014b402015-04-23 16:41:452781 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432782 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2783 allowed)
creisc014b402015-04-23 16:41:452784 : false;
[email protected]0bfbf882011-12-22 18:19:272785}
2786
[email protected]b172aee2012-04-10 17:05:262787bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212788 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502789}
2790
alexmose201c7cd2015-06-10 17:14:212791WebContentsImpl* WebContentsImpl::GetOpener() const {
2792 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2793 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572794}
2795
[email protected]cb805452013-05-22 15:16:212796void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482797 if (!color_chooser_info_.get())
2798 return;
2799 RenderFrameHost* rfh = RenderFrameHost::FromID(
2800 color_chooser_info_->render_process_id,
2801 color_chooser_info_->render_frame_id);
2802 if (!rfh)
2803 return;
2804
2805 rfh->Send(new FrameMsg_DidChooseColorResponse(
2806 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202807}
2808
[email protected]cb805452013-05-22 15:16:212809void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482810 if (!color_chooser_info_.get())
2811 return;
2812 RenderFrameHost* rfh = RenderFrameHost::FromID(
2813 color_chooser_info_->render_process_id,
2814 color_chooser_info_->render_frame_id);
2815 if (!rfh)
2816 return;
2817
2818 rfh->Send(new FrameMsg_DidEndColorChooser(
2819 rfh->GetRoutingID(), color_chooser_info_->identifier));
2820 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202821}
2822
halton.huoca2eabd2015-07-06 08:17:402823int WebContentsImpl::DownloadImage(
2824 const GURL& url,
2825 bool is_favicon,
2826 uint32_t max_bitmap_size,
2827 bool bypass_cache,
2828 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552829 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402830 static int next_image_download_id = 0;
2831 const image_downloader::ImageDownloaderPtr& mojo_image_downloader =
2832 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552833 const int download_id = ++next_image_download_id;
2834 if (!mojo_image_downloader) {
2835 // If the renderer process is dead (i.e. crash, or memory pressure on
2836 // Android), the downloader service will be invalid. Pre-Mojo, this would
2837 // hang the callback indefinetly since the IPC would be dropped. Now,
2838 // respond with a 400 HTTP error code to indicate that something went wrong.
2839 BrowserThread::PostTask(
2840 BrowserThread::UI, FROM_HERE,
2841 base::Bind(&WebContents::ImageDownloadCallback::Run,
2842 base::Owned(new ImageDownloadCallback(callback)),
2843 download_id, 400, url, std::vector<SkBitmap>(),
2844 std::vector<gfx::Size>()));
2845 return download_id;
2846 }
2847
halton.huoca2eabd2015-07-06 08:17:402848 image_downloader::DownloadRequestPtr req =
2849 image_downloader::DownloadRequest::New();
2850
2851 req->url = mojo::String::From(url);
2852 req->is_favicon = is_favicon;
2853 req->max_bitmap_size = max_bitmap_size;
2854 req->bypass_cache = bypass_cache;
2855
2856 mojo_image_downloader->DownloadImage(
dcheng36b6aec92015-12-26 06:16:362857 std::move(req),
amistry9f01b772015-07-29 01:54:552858 base::Bind(&DidDownloadImage, callback, download_id, url));
2859 return download_id;
[email protected]795c28972012-12-06 06:13:392860}
2861
[email protected]5dcaf8e2013-12-28 01:31:422862bool WebContentsImpl::IsSubframe() const {
2863 return is_subframe_;
2864}
2865
[email protected]36ec24f2014-01-09 00:32:082866void WebContentsImpl::Find(int request_id,
2867 const base::string16& search_text,
2868 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:332869 // Cowardly refuse to search for no text.
2870 if (search_text.empty()) {
2871 NOTREACHED();
2872 return;
2873 }
2874
raymes0fa0be52014-10-13 20:38:092875 // See if a top level browser plugin handles the find request first.
paulmeyer95703b92015-08-10 17:38:472876 if (browser_plugin_embedder_ &&
2877 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2878 return;
raymes0fa0be52014-10-13 20:38:092879 }
paulmeyer5d0a5f02016-01-21 20:15:522880 GetMainFrame()->Send(new FrameMsg_Find(GetMainFrame()->GetRoutingID(),
2881 request_id, search_text, options));
[email protected]36ec24f2014-01-09 00:32:082882}
2883
2884void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012885 // See if a top level browser plugin handles the stop finding request first.
paulmeyer95703b92015-08-10 17:38:472886 if (browser_plugin_embedder_ &&
2887 browser_plugin_embedder_->StopFinding(action)) {
2888 return;
raymes2bc64182015-02-06 01:23:012889 }
paulmeyer5d0a5f02016-01-21 20:15:522890 GetMainFrame()->Send(
2891 new FrameMsg_StopFinding(GetMainFrame()->GetRoutingID(), action));
[email protected]36ec24f2014-01-09 00:32:082892}
2893
[email protected]4fe53add2014-04-08 19:53:362894void WebContentsImpl::InsertCSS(const std::string& css) {
2895 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2896 GetMainFrame()->GetRoutingID(), css));
2897}
2898
dalecurtisbc6572e12014-09-12 19:22:302899bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:152900 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302901}
2902
mlamouriefdca9d2014-09-16 16:55:402903void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2904 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2905}
2906
dominickn6919ce32015-10-15 01:52:282907void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
2908 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
2909}
2910
bokanece34a82016-01-28 19:49:462911void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532912 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:432913 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:462914 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:532915}
2916
mariakhomenko44bdc4732015-04-29 01:55:382917void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:372918 if (delayed_open_url_params_.get()) {
2919 OpenURL(*delayed_open_url_params_.get());
2920 delayed_open_url_params_.reset(nullptr);
2921 return;
2922 }
2923
mariakhomenko44bdc4732015-04-29 01:55:382924 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
2925 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:162926 if (is_resume_pending_) {
2927 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:132928 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:162929 GetMainFrame()->Init();
2930 }
mariakhomenko44bdc4732015-04-29 01:55:382931}
2932
[email protected]b172aee2012-04-10 17:05:262933bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272934 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172935 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332936 return true;
2937 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272938}
2939
[email protected]b172aee2012-04-10 17:05:262940void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272941 if (delegate_)
2942 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212943}
2944
clamy0e119882015-07-31 16:12:332945void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
2946 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2947 DidStartNavigation(navigation_handle));
2948}
2949
2950void WebContentsImpl::DidRedirectNavigation(
2951 NavigationHandle* navigation_handle) {
2952 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2953 DidRedirectNavigation(navigation_handle));
2954}
2955
clamyefca29e2015-09-17 00:22:112956void WebContentsImpl::ReadyToCommitNavigation(
2957 NavigationHandle* navigation_handle) {
2958 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2959 ReadyToCommitNavigation(navigation_handle));
2960}
2961
clamy0e119882015-07-31 16:12:332962void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
2963 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2964 DidFinishNavigation(navigation_handle));
2965}
2966
[email protected]52913802013-12-10 05:52:182967void WebContentsImpl::DidStartProvisionalLoad(
2968 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182969 const GURL& validated_url,
2970 bool is_error_page,
2971 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102972 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482973 FOR_EACH_OBSERVER(
2974 WebContentsObserver,
2975 observers_,
2976 DidStartProvisionalLoadForFrame(
2977 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:082978
2979 // Notify accessibility if this is a reload.
2980 NavigationEntry* entry = controller_.GetVisibleEntry();
2981 if (entry && ui::PageTransitionCoreTypeIs(
2982 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
2983 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2984 BrowserAccessibilityManager* manager =
2985 ftn->current_frame_host()->browser_accessibility_manager();
2986 if (manager)
2987 manager->UserIsReloading();
2988 }
[email protected]400992b2012-06-14 00:03:542989}
2990
[email protected]3109fbb72014-01-06 23:57:152991void WebContentsImpl::DidFailProvisionalLoadWithError(
2992 RenderFrameHostImpl* render_frame_host,
2993 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2994 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312995 FOR_EACH_OBSERVER(WebContentsObserver,
2996 observers_,
2997 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312998 validated_url,
2999 params.error_code,
gsennton6fbb38692015-06-24 19:23:553000 params.error_description,
3001 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:083002
3003 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3004 BrowserAccessibilityManager* manager =
3005 ftn->current_frame_host()->browser_accessibility_manager();
3006 if (manager)
3007 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153008}
3009
[email protected]b80624c2014-02-09 02:46:553010void WebContentsImpl::DidFailLoadWithError(
3011 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553012 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553013 int error_code,
gsennton6fbb38692015-06-24 19:23:553014 const base::string16& error_description,
3015 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:143016 FOR_EACH_OBSERVER(
3017 WebContentsObserver,
3018 observers_,
gsennton6fbb38692015-06-24 19:23:553019 DidFailLoad(render_frame_host, url, error_code, error_description,
3020 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553021}
3022
[email protected]52913802013-12-10 05:52:183023void WebContentsImpl::NotifyChangedNavigationState(
3024 InvalidateTypes changed_flags) {
3025 NotifyNavigationStateChanged(changed_flags);
3026}
3027
[email protected]3691e5cf2014-01-22 10:16:203028void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:203029 const GURL& url,
3030 NavigationController::ReloadType reload_type) {
3031 // Notify observers about navigation.
3032 FOR_EACH_OBSERVER(
3033 WebContentsObserver,
3034 observers_,
3035 DidStartNavigationToPendingEntry(url, reload_type));
3036}
3037
[email protected]8cb834e2014-03-06 14:23:233038void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3039 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503040 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3041 // weak pointer of sorts.
3042 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3043 const int32_t frame_id = render_frame_host->GetRoutingID();
3044
[email protected]65920f332014-03-04 21:14:183045 WebContents* new_contents = OpenURL(params);
3046
dchengb907f7332015-01-07 20:35:503047 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183048 // Notify observers.
3049 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3050 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463051 render_frame_host,
[email protected]65920f332014-03-04 21:14:183052 params.url,
3053 params.referrer,
3054 params.disposition,
creis114ca1b2014-11-13 23:51:463055 params.transition));
[email protected]65920f332014-03-04 21:14:183056 }
3057}
3058
creis29460272015-12-16 04:38:223059bool WebContentsImpl::ShouldTransferNavigation() {
3060 if (!delegate_)
3061 return true;
3062 return delegate_->ShouldTransferNavigation();
3063}
3064
[email protected]aa62afd2014-04-22 19:22:463065bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3066 if (!delegate_)
3067 return false;
3068 return delegate_->ShouldPreserveAbortedURLs(this);
3069}
3070
[email protected]37567b432014-02-12 01:12:223071void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433072 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223073 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353074 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223075 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483076 FOR_EACH_OBSERVER(WebContentsObserver,
3077 observers_,
3078 DidCommitProvisionalLoadForFrame(
3079 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083080
3081 BrowserAccessibilityManager* manager =
3082 render_frame_host->browser_accessibility_manager();
3083 if (manager)
3084 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223085}
3086
[email protected]0d0f4c492014-04-02 06:42:573087void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233088 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573089 // Ensure fullscreen mode is exited before committing the navigation to a
3090 // different page. The next page will not start out assuming it is in
3091 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233092 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193093 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573094 return;
3095 }
avibf58fa0c2015-11-11 01:45:523096 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463097 ExitFullscreen(false);
avibf58fa0c2015-11-11 01:45:523098 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573099}
3100
[email protected]37567b432014-02-12 01:12:223101void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283102 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223103 const LoadCommittedDetails& details,
3104 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3105 if (details.is_navigation_to_different_page()) {
3106 // Clear the status bubble. This is a workaround for a bug where WebKit
3107 // doesn't let us know that the cursor left an element during a
3108 // transition (this is also why the mouse cursor remains as a hand after
3109 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3110 // clear the bubble when a user navigates to a named anchor in the same
3111 // page.
sky8b00392d2015-01-10 00:30:283112 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003113
3114 RenderWidgetHostViewBase* rwhvb =
3115 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3116 if (rwhvb)
3117 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283118
peter90afaba2015-06-01 12:05:293119 did_first_visually_non_empty_paint_ = false;
3120
yusufod41c5f92015-03-06 00:14:283121 // Reset theme color on navigation to new page.
3122 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223123 }
3124
3125 if (!details.is_in_page) {
3126 // Once the main frame is navigated, we're no longer considered to have
3127 // displayed insecure content.
3128 displayed_insecure_content_ = false;
3129 SSLManager::NotifySSLInternalStateChanged(
3130 GetController().GetBrowserContext());
3131 }
3132
3133 // Notify observers about navigation.
3134 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3135 DidNavigateMainFrame(details, params));
3136
[email protected]e85165c642014-06-10 14:34:313137 if (delegate_)
[email protected]37567b432014-02-12 01:12:223138 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313139 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223140}
3141
3142void WebContentsImpl::DidNavigateAnyFramePostCommit(
3143 RenderFrameHostImpl* render_frame_host,
3144 const LoadCommittedDetails& details,
3145 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103146 // Now that something has committed, we don't need to track whether the
3147 // initial page has been accessed.
3148 has_accessed_initial_document_ = false;
3149
[email protected]37567b432014-02-12 01:12:223150 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173151 if (!details.is_in_page)
3152 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223153
3154 // Notify observers about navigation.
3155 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093156 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223157}
3158
3159void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3160 contents_mime_type_ = mime_type;
3161}
3162
[email protected]277857a2014-06-03 10:38:013163bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313164 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053165 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313166 return false;
3167
[email protected]37567b432014-02-12 01:12:223168 if (delegate_)
3169 return delegate_->CanOverscrollContent();
3170
3171 return false;
3172}
3173
[email protected]37b64c52014-07-11 21:14:053174void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293175 // Update the theme color. This is to be published to observers after the
3176 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283177 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293178
3179 if (did_first_visually_non_empty_paint_ &&
3180 last_sent_theme_color_ != theme_color_) {
3181 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3182 DidChangeThemeColor(theme_color_));
3183 last_sent_theme_color_ = theme_color_;
3184 }
[email protected]e7104762014-06-20 19:17:253185}
3186
[email protected]b172aee2012-04-10 17:05:263187void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183188 const GURL& url,
[email protected]70435962011-08-02 20:13:283189 const std::string& security_info,
3190 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183191 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403192 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533193 SSLStatus status;
3194 if (!DeserializeSecurityInfo(security_info, &status)) {
3195 bad_message::ReceivedBadMessage(
3196 GetRenderProcessHost(),
3197 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3198 return;
3199 }
[email protected]724159a2010-12-30 01:11:183200
3201 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593202 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213203 LoadFromMemoryCacheDetails details(
rob1ca070f2016-01-12 01:06:263204 url, status.cert_id, status.cert_status, http_method, mime_type,
3205 resource_type);
[email protected]724159a2010-12-30 01:11:183206
[email protected]b0f724c2013-09-05 04:21:133207 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3208
3209 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3210 DidLoadResourceFromMemoryCache(details));
3211
[email protected]8bfc8272013-09-09 20:10:533212 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3213 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403214 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533215 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3216 GetRenderProcessHost()->GetID()) :
3217 GetBrowserContext()->GetRequestContextForRenderProcess(
3218 GetRenderProcessHost()->GetID()));
3219 BrowserThread::PostTask(
3220 BrowserThread::IO,
3221 FROM_HERE,
3222 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3223 }
[email protected]724159a2010-12-30 01:11:183224}
3225
[email protected]b172aee2012-04-10 17:05:263226void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393227 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183228 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193229 SSLManager::NotifySSLInternalStateChanged(
3230 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183231}
3232
estark910b4572015-12-09 20:55:413233void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3234 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583235 LOG(WARNING) << security_origin << " ran insecure content from "
3236 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393237 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413238 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293239 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393240 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183241 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193242 SSLManager::NotifySSLInternalStateChanged(
3243 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183244}
3245
estark910b4572015-12-09 20:55:413246void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3247 const GURL& url,
3248 const std::string& security_info) {
3249 SSLStatus ssl;
3250 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3251 bad_message::ReceivedBadMessage(
3252 GetRenderProcessHost(),
3253 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3254 return;
3255 }
3256
3257 displayed_insecure_content_ = true;
3258 SSLManager::NotifySSLInternalStateChanged(
3259 GetController().GetBrowserContext());
3260}
3261
3262void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3263 const GURL& security_origin,
3264 const GURL& url,
3265 const std::string& security_info) {
3266 SSLStatus ssl;
3267 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3268 bad_message::ReceivedBadMessage(
3269 GetRenderProcessHost(),
3270 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3271 return;
3272 }
3273
3274 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3275 SSLManager::NotifySSLInternalStateChanged(
3276 GetController().GetBrowserContext());
3277}
3278
[email protected]501052ff2014-02-21 22:19:073279void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113280 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473281 return;
naskofbd033392015-01-27 02:34:473282
[email protected]1d62cf72014-02-07 21:31:573283 RenderFrameHostImpl* rfh =
3284 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143285 FOR_EACH_OBSERVER(
3286 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183287}
3288
naskofbd033392015-01-27 02:34:473289void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113290 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123291 return;
[email protected]a1b99262013-12-27 21:56:223292
[email protected]8b3af1e2014-01-24 13:29:123293 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443294 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373295 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423296 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373297
[email protected]61ac9e242014-03-21 20:55:263298 RenderFrameHostImpl* rfh =
3299 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143300 FOR_EACH_OBSERVER(
3301 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313302}
3303
[email protected]b172aee2012-04-10 17:05:263304void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573305 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3306 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263307}
3308
[email protected]b172aee2012-04-10 17:05:263309void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303310 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263311 minimum_zoom_percent_ = minimum_percent;
3312 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263313}
3314
mcnee432e47d2015-11-09 19:37:463315void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3316 bool is_one = page_scale_factor == 1.f;
3317 if (is_one != page_scale_factor_is_one_) {
3318 page_scale_factor_is_one_ = is_one;
3319
3320 HostZoomMapImpl* host_zoom_map =
3321 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3322
3323 if (host_zoom_map && GetRenderProcessHost()) {
3324 host_zoom_map->SetPageScaleFactorIsOneForView(
3325 GetRenderProcessHost()->GetID(), GetRoutingID(),
3326 page_scale_factor_is_one_);
3327 }
3328 }
3329
3330 FOR_EACH_OBSERVER(WebContentsObserver,
3331 observers_,
3332 OnPageScaleFactorChanged(page_scale_factor));
3333}
3334
[email protected]b172aee2012-04-10 17:05:263335void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343336 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433337 if (!delegate_)
3338 return;
3339
[email protected]b9535422012-02-09 01:47:593340 ChildProcessSecurityPolicyImpl* policy =
3341 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223342 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593343 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213344}
3345
[email protected]b172aee2012-04-10 17:05:263346void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3347 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263348 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363349 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433350 if (!delegate_)
3351 return;
3352
[email protected]b9535422012-02-09 01:47:593353 ChildProcessSecurityPolicyImpl* policy =
3354 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323355 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593356 return;
[email protected]8f810632013-06-06 22:33:323357
[email protected]c125e532014-05-10 20:39:063358 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203359}
3360
[email protected]f5273e52014-07-14 16:30:203361void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3362 const GURL& url,
3363 bool user_gesture) {
3364 if (!delegate_)
3365 return;
3366
3367 ChildProcessSecurityPolicyImpl* policy =
3368 ChildProcessSecurityPolicyImpl::GetInstance();
3369 if (policy->IsPseudoScheme(protocol))
3370 return;
3371
3372 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3373}
3374
kouhei40f03cb2015-09-24 07:47:013375void WebContentsImpl::OnUpdatePageImportanceSignals(
3376 const PageImportanceSignals& signals) {
3377 page_importance_signals_ = signals;
3378}
3379
[email protected]b172aee2012-04-10 17:05:263380void WebContentsImpl::OnFindReply(int request_id,
3381 int number_of_matches,
3382 const gfx::Rect& selection_rect,
3383 int active_match_ordinal,
3384 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433385 if (delegate_) {
3386 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3387 active_match_ordinal, final_update);
3388 }
[email protected]b888919c2011-09-02 00:32:163389}
3390
mfomitchev2b8b066a2016-01-28 19:23:153391#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313392void WebContentsImpl::OnFindMatchRectsReply(
3393 int version,
3394 const std::vector<gfx::RectF>& rects,
3395 const gfx::RectF& active_rect) {
3396 if (delegate_)
3397 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3398}
[email protected]583418cc2013-01-17 14:01:103399
[email protected]1ff427972013-02-07 21:14:073400void WebContentsImpl::OnOpenDateTimeDialog(
3401 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173402 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093403 GetRenderViewHost(),
3404 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133405 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093406 value.minimum,
3407 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173408 value.step,
3409 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103410}
[email protected]59363fc92012-09-05 03:46:313411#endif
3412
avi60bd4902015-09-23 20:39:243413void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3414 std::string json = json_string;
3415 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3416 Source<WebContents>(this),
3417 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403418}
3419
[email protected]b172aee2012-04-10 17:05:263420void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3421 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103422 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253423 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103424 AppCacheAccessed(manifest_url, blocked_by_policy));
3425}
3426
[email protected]8bc5ff02013-11-29 06:34:033427void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483428 int color_chooser_id,
3429 SkColor color,
3430 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113431 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003432 return;
nasko907fcb62015-01-28 04:24:113433
[email protected]aa62afd2014-04-22 19:22:463434 ColorChooser* new_color_chooser = delegate_ ?
3435 delegate_->OpenColorChooser(this, color, suggestions) :
3436 NULL;
[email protected]820957a2014-01-14 14:56:303437 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213438 return;
[email protected]8ed16472014-04-11 19:02:483439 if (color_chooser_info_.get())
3440 color_chooser_info_->chooser->End();
3441
3442 color_chooser_info_.reset(new ColorChooserInfo(
3443 render_frame_message_source_->GetProcess()->GetID(),
3444 render_frame_message_source_->GetRoutingID(),
3445 new_color_chooser,
3446 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203447}
3448
[email protected]b172aee2012-04-10 17:05:263449void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483450 if (color_chooser_info_ &&
3451 color_chooser_id == color_chooser_info_->identifier)
3452 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203453}
3454
[email protected]b172aee2012-04-10 17:05:263455void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323456 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483457 if (color_chooser_info_ &&
3458 color_chooser_id == color_chooser_info_->identifier)
3459 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203460}
3461
[email protected]d0759f492012-04-19 22:50:503462// This exists for render views that don't have a WebUI, but do have WebUI
3463// bindings enabled.
3464void WebContentsImpl::OnWebUISend(const GURL& source_url,
3465 const std::string& name,
3466 const base::ListValue& args) {
3467 if (delegate_)
3468 delegate_->WebUISend(this, source_url, name, args);
3469}
3470
thestigc4cac8f2014-09-04 21:17:503471#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003472void WebContentsImpl::OnPepperInstanceCreated() {
3473 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3474}
3475
3476void WebContentsImpl::OnPepperInstanceDeleted() {
3477 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3478}
3479
tommyclie6633ca72014-10-31 00:40:423480void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3481 const base::FilePath& path,
3482 bool is_hung) {
3483 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3484
3485 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3486 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3487}
3488
3489void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3490 base::ProcessId plugin_pid) {
3491 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3492 PluginCrashed(plugin_path, plugin_pid));
3493}
3494
[email protected]d8415ad92012-08-23 14:40:503495void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443496 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503497 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343498 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163499 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443500 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163501 return;
[email protected]d8415ad92012-08-23 14:40:503502 }
3503
[email protected]8c8fc292012-11-23 18:57:163504 if (!delegate_->RequestPpapiBrokerPermission(
3505 this, url, plugin_path,
3506 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443507 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163508 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443509 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163510 }
[email protected]d8415ad92012-08-23 14:40:503511}
3512
[email protected]ea0309c2013-08-06 19:35:443513void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503514 bool result) {
[email protected]ea0309c2013-08-06 19:35:443515 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503516}
3517
fsamuel833ee7c2015-02-13 23:40:403518void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3519 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393520 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143521 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403522 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373523}
tommyclie6633ca72014-10-31 00:40:423524#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373525
[email protected]795c28972012-12-06 06:13:393526void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393527 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063528 // We get updated favicon URLs after the page stops loading. If a cross-site
3529 // navigation occurs while a page is still loading, the initial page
3530 // may stop loading and send us updated favicon URLs after the navigation
3531 // for the new page has committed.
3532 RenderViewHostImpl* rvhi =
3533 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3534 if (!rvhi->is_active())
3535 return;
3536
[email protected]795c28972012-12-06 06:13:393537 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293538 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393539}
3540
avayvod41634b12015-07-08 17:07:053541#if defined(OS_ANDROID)
3542
3543void WebContentsImpl::OnMediaSessionStateChanged() {
3544 MediaSession* session = MediaSession::Get(this);
3545 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3546 MediaSessionStateChanged(session->IsControllable(),
3547 session->IsSuspended()));
3548}
3549
3550void WebContentsImpl::ResumeMediaSession() {
3551 MediaSession::Get(this)->Resume();
3552}
3553
3554void WebContentsImpl::SuspendMediaSession() {
3555 MediaSession::Get(this)->Suspend();
3556}
3557
mlamouri4c4fbed2015-08-17 15:51:013558void WebContentsImpl::StopMediaSession() {
3559 MediaSession::Get(this)->Stop();
3560}
3561
avayvod41634b12015-07-08 17:07:053562#endif // defined(OS_ANDROID)
3563
[email protected]50279492014-05-05 23:24:293564void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153565 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293566 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283567
peter90afaba2015-06-01 12:05:293568 did_first_visually_non_empty_paint_ = true;
3569
yusufod41c5f92015-03-06 00:14:283570 if (theme_color_ != last_sent_theme_color_) {
3571 // Theme color should have updated by now if there was one.
3572 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3573 DidChangeThemeColor(theme_color_));
3574 last_sent_theme_color_ = theme_color_;
3575 }
[email protected]9f268072013-11-07 00:02:153576}
[email protected]d9030b82013-07-19 08:26:063577
[email protected]e67ebf32013-02-13 11:07:193578void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013579 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073580 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013581
estark5ea80e52015-06-19 18:43:123582 SecurityStyleExplanations security_style_explanations;
3583 SecurityStyle security_style =
3584 delegate_->GetSecurityStyle(this, &security_style_explanations);
3585 FOR_EACH_OBSERVER(
3586 WebContentsObserver, observers_,
3587 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013588 }
[email protected]e67ebf32013-02-13 11:07:193589}
3590
[email protected]17e286e2013-03-01 23:29:393591void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3592 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3593 BeforeFormRepostWarningShow());
3594}
3595
[email protected]ec6c05f2013-10-23 18:41:573596void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3597 Activate();
3598 if (delegate_)
3599 delegate_->ShowRepostFormWarningDialog(this);
3600}
3601
[email protected]b4c84012014-04-28 19:51:103602bool WebContentsImpl::HasAccessedInitialDocument() {
3603 return has_accessed_initial_document_;
3604}
3605
[email protected]96d185d2009-04-24 03:28:543606// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593607// loading, or done loading.
clamydb73eb6c2016-02-10 13:27:563608void WebContentsImpl::LoadingStateChanged(bool is_loading,
3609 bool to_different_document,
3610 bool pause_throbber_for_interstitial,
3611 LoadNotificationDetails* details) {
3612 // Do not send notifications about loading while the interstitial is showing.
3613 if (paused_throbber_for_interstitial_ && pause_throbber_for_interstitial)
[email protected]96d185d2009-04-24 03:28:543614 return;
3615
clamydb73eb6c2016-02-10 13:27:563616 // Update whether the interstitial state.
3617 paused_throbber_for_interstitial_ = pause_throbber_for_interstitial;
3618
[email protected]96d185d2009-04-24 03:28:543619 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263620 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3621 base::string16());
[email protected]96d185d2009-04-24 03:28:543622 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563623 upload_size_ = 0;
3624 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543625 }
3626
[email protected]fa944cb82013-11-15 17:51:213627 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543628
[email protected]96d185d2009-04-24 03:28:543629 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033630 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543631
[email protected]6ebdc9b2010-09-27 16:55:573632 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093633 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213634 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543635
[email protected]eab61442013-11-14 18:35:483636 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593637 if (is_loading) {
carloskc13951a2015-12-30 16:51:543638 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3639 this, "URL", url, "Main FrameTreeNode id",
3640 GetFrameTree()->root()->frame_tree_node_id());
fdegans6ce28f52015-03-19 12:52:223641 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]91621872013-10-08 04:04:593642 } else {
naskob8744d22014-08-28 17:07:433643 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3644 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223645 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]91621872013-10-08 04:04:593646 }
[email protected]66798902013-10-01 18:40:163647
3648 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213649 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3650 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543651 if (details)
[email protected]8ff00d72012-10-23 19:12:213652 det = Details<LoadNotificationDetails>(details);
3653 NotificationService::current()->Notify(
3654 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543655}
3656
[email protected]b172aee2012-04-10 17:05:263657void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463658 // If we are creating a RVH for a restored controller, then we need to make
3659 // sure the RenderView starts with a next_page_id_ larger than the number
3660 // of restored entries. This must be called before the RenderView starts
3661 // navigating (to avoid a race between the browser updating max_page_id and
3662 // the renderer updating next_page_id_). Because of this, we only call this
3663 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563664 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583665 if (max_restored_page_id >
3666 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3667 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3668 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323669}
3670
[email protected]b172aee2012-04-10 17:05:263671bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263672 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323673 // For file URLs without a title, use the pathname instead. In the case of a
3674 // synthesized title, we don't want the update to count toward the "one set
3675 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263676 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323677 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513678 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243679 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323680 explicit_set = false; // Don't count synthetic titles toward the set limit.
3681 } else {
[email protected]8af69c6c2014-03-03 19:05:313682 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323683 explicit_set = true;
3684 }
3685
[email protected]987fc3a2011-05-26 14:18:093686 // If a page is created via window.open and never navigated,
3687 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553688 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093689 if (entry) {
[email protected]36fc0392011-12-25 03:59:513690 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093691 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323692
[email protected]36fc0392011-12-25 03:59:513693 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093694 } else {
3695 if (page_title_when_no_navigation_entry_ == final_title)
3696 return false; // Nothing changed, don't bother.
3697
3698 page_title_when_no_navigation_entry_ = final_title;
3699 }
[email protected]420ae012009-04-24 05:16:323700
[email protected]420ae012009-04-24 05:16:323701 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233702 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323703
[email protected]66798902013-10-01 18:40:163704 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533705 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163706
[email protected]420ae012009-04-24 05:16:323707 return true;
3708}
3709
fdegansa696e5112015-04-17 01:57:593710void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003711 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003712 if (delegate_)
fdegansa696e5112015-04-17 01:57:593713 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003714}
3715
3716void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343717 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003718 loading_weak_factory_.InvalidateWeakPtrs();
3719 loading_last_progress_update_ = base::TimeTicks();
3720}
3721
[email protected]02d7b6e2014-06-24 21:01:503722void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3723 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323724 // After sending out a swap notification, we need to send a disconnect
3725 // notification so that clients that pick up a pointer to |this| can NULL the
3726 // pointer. See Bug 1230284.
3727 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113728 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283729 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113730
[email protected]7a846df2012-09-20 19:17:393731 // Ensure that the associated embedder gets cleared after a RenderViewHost
3732 // gets swapped, so we don't reuse the same embedder next time a
3733 // RenderViewHost is attached to this WebContents.
3734 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323735}
3736
[email protected]02d7b6e2014-06-24 21:01:503737void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3738 RenderFrameHost* new_host) {
3739 FOR_EACH_OBSERVER(WebContentsObserver,
3740 observers_,
3741 RenderFrameHostChanged(old_host, new_host));
3742}
3743
[email protected]da7a7182013-09-06 08:11:113744// TODO(avi): Remove this entire function because this notification is already
3745// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263746void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323747 if (!notify_disconnection_)
3748 return;
3749
3750 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213751 NotificationService::current()->Notify(
3752 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3753 Source<WebContents>(this),
3754 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323755}
3756
[email protected]cbb1ef592013-06-05 19:49:463757void WebContentsImpl::NotifyNavigationEntryCommitted(
3758 const LoadCommittedDetails& load_details) {
3759 FOR_EACH_OBSERVER(
3760 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3761}
3762
[email protected]f114fa42013-12-06 17:06:443763bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3764 const IPC::Message& message) {
3765 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313766}
3767
[email protected]c31a84802014-04-03 15:55:493768const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3769 return GetLastCommittedURL();
3770}
3771
[email protected]b849847b2013-12-10 21:57:583772void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583773 FOR_EACH_OBSERVER(WebContentsObserver,
3774 observers_,
3775 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303776 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583777}
3778
3779void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3780 FOR_EACH_OBSERVER(WebContentsObserver,
3781 observers_,
3782 RenderFrameDeleted(render_frame_host));
3783}
3784
[email protected]a09d53ce2014-01-31 00:46:423785void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3786 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103787 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423788 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103789 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423790 return;
3791
[email protected]077e704b2014-05-23 19:24:103792 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3793 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423794}
3795
[email protected]87de04b02014-04-08 22:14:493796void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013797 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493798 const base::string16& message,
3799 const base::string16& default_prompt,
3800 const GURL& frame_url,
3801 JavaScriptMessageType javascript_message_type,
3802 IPC::Message* reply_msg) {
3803 // Suppress JavaScript dialogs when requested. Also suppress messages when
3804 // showing an interstitial as it's shown over the previous page and we don't
3805 // want the hidden page's dialogs to interfere with the interstitial.
3806 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223807 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503808 ShowingInterstitialPage() || !delegate_ ||
3809 delegate_->ShouldSuppressDialogs(this) ||
3810 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493811
3812 if (!suppress_this_message) {
3813 std::string accept_lang = GetContentClient()->browser()->
3814 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503815 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493816 dialog_manager_->RunJavaScriptDialog(
palmer4e0ae10d2015-09-03 23:38:413817 this, frame_url, accept_lang, javascript_message_type, message,
[email protected]87de04b02014-04-08 22:14:493818 default_prompt,
palmer4e0ae10d2015-09-03 23:38:413819 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013820 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413821 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493822 &suppress_this_message);
3823 }
3824
3825 if (suppress_this_message) {
3826 // If we are suppressing messages, just reply as if the user immediately
3827 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013828 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3829 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283830 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493831 }
3832
3833 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3834 // http://crbug.com/288961 ). The only safe thing to do here is return.
3835}
3836
3837void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013838 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493839 const base::string16& message,
3840 bool is_reload,
3841 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013842 RenderFrameHostImpl* rfhi =
3843 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493844 if (delegate_)
3845 delegate_->WillRunBeforeUnloadConfirm();
3846
3847 bool suppress_this_message =
creis36e228b2015-06-08 18:48:023848 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT ||
3849 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:503850 delegate_->ShouldSuppressDialogs(this) ||
3851 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493852 if (suppress_this_message) {
3853 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3854 return;
3855 }
3856
3857 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503858 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493859 dialog_manager_->RunBeforeUnloadDialog(
3860 this, message, is_reload,
3861 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013862 render_frame_host->GetProcess()->GetID(),
3863 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283864 false));
[email protected]87de04b02014-04-08 22:14:493865}
3866
[email protected]a86c0e962013-12-17 17:10:393867WebContents* WebContentsImpl::GetAsWebContents() {
3868 return this;
3869}
3870
[email protected]7912e822014-04-16 02:37:033871bool WebContentsImpl::IsNeverVisible() {
3872 if (!delegate_)
3873 return false;
3874 return delegate_->IsNeverVisible(this);
3875}
3876
[email protected]95640212014-07-26 18:14:303877#if defined(OS_WIN)
3878gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3879 return accessible_parent_;
3880}
3881#endif
3882
[email protected]5a3bdf52012-05-24 15:12:573883RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3884 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323885}
3886
[email protected]8ff00d72012-10-23 19:12:213887RendererPreferences WebContentsImpl::GetRendererPrefs(
3888 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463889 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513890}
3891
avic3aa8422015-11-09 20:57:223892gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
3893 RenderWidgetHostImpl* render_widget_host) const {
3894 if (!RenderViewHostImpl::From(render_widget_host))
3895 return gfx::Rect();
3896
[email protected]b7a756d42012-01-23 18:08:173897 if (delegate_)
3898 return delegate_->GetRootWindowResizerRect();
3899 return gfx::Rect();
3900}
3901
[email protected]7a846df2012-09-20 19:17:393902void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273903 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393904 browser_plugin_embedder_.reset();
3905}
3906
[email protected]b172aee2012-04-10 17:05:263907void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443908 // Don't send notifications if we are just creating a swapped-out RVH for
3909 // the opener chain. These won't be used for view-source or WebUI, so it's
3910 // ok to return early.
creiscce56cd2014-09-29 22:45:223911 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443912 return;
3913
[email protected]86f98a22013-03-20 14:35:003914 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313915 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083916
[email protected]8ff00d72012-10-23 19:12:213917 NotificationService::current()->Notify(
3918 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3919 Source<WebContents>(this),
3920 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323921
[email protected]6286a372013-10-09 04:03:273922 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333923 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323924 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183925 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583926 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323927 }
[email protected]0666aef2009-05-13 19:48:083928
[email protected]60780f412013-02-25 16:34:103929 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263930
3931 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253932 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:323933}
3934
[email protected]b172aee2012-04-10 17:05:263935void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523936 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323937 // Don't notify the world, since this came from a renderer in the
3938 // background.
3939 return;
3940 }
3941
[email protected]da7a7182013-09-06 08:11:113942 notify_disconnection_ = true;
3943 // TODO(avi): Remove. http://crbug.com/170921
3944 NotificationService::current()->Notify(
3945 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3946 Source<WebContents>(this),
3947 NotificationService::NoDetails());
3948
[email protected]be1f56ab2011-12-22 06:55:313949 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233950 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303951
3952 // Restore the focus to the tab (otherwise the focus will be on the top
3953 // window).
[email protected]484ae5912010-09-29 19:16:143954 if (was_crashed && !FocusLocationBarByDefault() &&
3955 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063956 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143957 }
[email protected]32ded2212011-11-10 18:51:433958
[email protected]d8c660432011-12-22 20:51:253959 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323960}
3961
[email protected]ec6a7eb2013-04-22 17:34:223962void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3963 base::TerminationStatus status,
3964 int error_code) {
[email protected]151a63d2011-12-20 22:32:523965 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323966 // The pending page's RenderViewHost is gone.
3967 return;
3968 }
3969
[email protected]2fcdcc32014-03-05 02:14:073970 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3971 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:523972 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463973 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:073974
[email protected]698191dc2014-02-25 01:06:133975 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:173976 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:133977
[email protected]f738bdcb2014-07-11 20:40:443978 if (delegate_)
3979 delegate_->HideValidationMessage(this);
3980
[email protected]960b0372014-05-19 18:01:003981 // Reset the loading progress. TODO(avi): What does it mean to have a
3982 // "renderer crash" when there is more than one renderer process serving a
3983 // webpage? Once this function is called at a more granular frame level, we
3984 // probably will need to more granularly reset the state here.
3985 ResetLoadProgressState();
clamydb73eb6c2016-02-10 13:27:563986 NotifyDisconnected();
3987 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:003988
[email protected]d8c660432011-12-22 20:51:253989 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273990 observers_,
[email protected]58d5cfe2013-07-10 02:40:523991 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323992}
3993
[email protected]b172aee2012-04-10 17:05:263994void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253995 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063996}
3997
[email protected]b172aee2012-04-10 17:05:263998void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:103999 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:044000 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384001 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4002
creise1d3e5b2014-12-01 18:21:574003 // Ensure that this state update comes from a RenderViewHost that belongs to
4004 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414005 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574006 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414007 return;
[email protected]420ae012009-04-24 05:16:324008
avi286019ce2015-07-29 01:26:584009 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:324010 // when the user is scrolling and entering form data, as well as when we're
4011 // leaving a page, in which case our state may have already been moved to
4012 // the next page. The navigation controller will look up the appropriate
4013 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:584014 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:114015 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584016 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:114017 if (!entry)
[email protected]420ae012009-04-24 05:16:324018 return;
[email protected]420ae012009-04-24 05:16:324019
nasko346969912015-12-16 22:36:474020 // Sanity check that ensures nav_entry_id and page_id point to the same
4021 // navigation entry.
4022 if (rvhi->GetMainFrame()) {
4023 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4024 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4025 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534026
nasko346969912015-12-16 22:36:474027 DCHECK_EQ(entry, new_entry);
4028 }
creisd63f6c4a2015-11-06 19:05:534029
[email protected]691aa2f2013-05-28 22:52:044030 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324031 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044032 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114033 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324034}
4035
sky8b00392d2015-01-10 00:30:284036void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4037 const GURL& url) {
4038 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4039 // If we're fullscreen only update the url if it's from the fullscreen
4040 // renderer.
4041 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444042 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284043 return;
4044 }
[email protected]6934a702011-12-20 00:04:514045 if (delegate_)
avi450ce00e2014-09-24 01:58:524046 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324047}
4048
[email protected]b172aee2012-04-10 17:05:264049void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104050#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294051 // The UI may be in an event-tracking loop, such as between the
4052 // mouse-down and mouse-up in text selection or a button click.
4053 // Defer the close until after tracking is complete, so that we
4054 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294055 // TODO(shess): This could get more fine-grained. For instance,
4056 // closing a tab in another window while selecting text in the
4057 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104058 if (view_->IsEventTracking()) {
4059 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294060 return;
4061 }
[email protected]60780f412013-02-25 16:34:104062#endif
[email protected]07707302009-11-06 00:50:294063
[email protected]420ae012009-04-24 05:16:324064 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524065 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514066 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324067}
4068
[email protected]66bbadaf2014-03-28 16:25:544069void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574070 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4071 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574072}
4073
[email protected]b172aee2012-04-10 17:05:264074void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514075 if (delegate_ && delegate_->IsPopupOrPanel(this))
4076 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324077}
4078
fdegansa696e5112015-04-17 01:57:594079void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094080 bool to_different_document) {
clamydb73eb6c2016-02-10 13:27:564081 LoadingStateChanged(true, to_different_document,
4082 paused_throbber_for_interstitial_, nullptr);
dmazzonibf8cec42015-02-08 08:28:084083
4084 // Notify accessibility that the user is navigating away from the
4085 // current document.
4086 //
4087 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084088 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594089 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084090 if (manager)
4091 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324092}
4093
fdegansc73eec22015-03-19 14:47:544094void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:324095 scoped_ptr<LoadNotificationDetails> details;
4096
[email protected]9595fd82013-04-19 21:28:494097 // Use the last committed entry rather than the active one, in case a
4098 // pending entry has been created.
4099 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204100 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494101
[email protected]420ae012009-04-24 05:16:324102 // An entry may not exist for a stop when loading an initial blank page or
4103 // if an iframe injected by script into a blank page finishes loading.
4104 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204105 base::TimeDelta elapsed =
4106 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324107
4108 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514109 entry->GetVirtualURL(),
4110 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:324111 elapsed,
4112 &controller_,
4113 controller_.GetCurrentEntryIndex()));
4114 }
4115
clamydb73eb6c2016-02-10 13:27:564116 LoadingStateChanged(false, true, paused_throbber_for_interstitial_,
4117 details.get());
[email protected]420ae012009-04-24 05:16:324118}
4119
fdegansa696e5112015-04-17 01:57:594120void WebContentsImpl::DidChangeLoadProgress() {
4121 double load_progress = frame_tree_.load_progress();
4122
4123 // The delegate is notified immediately for the first and last updates. Also,
4124 // since the message loop may be pretty busy when a page is loaded, it might
4125 // not execute a posted task in a timely manner so the progress report is sent
4126 // immediately if enough time has passed.
4127 base::TimeDelta min_delay =
4128 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4129 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4130 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4131
4132 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4133 // If there is a pending task to send progress, it is now obsolete.
4134 loading_weak_factory_.InvalidateWeakPtrs();
4135
4136 // Notify the load progress change.
4137 SendChangeLoadProgress();
4138
4139 // Clean-up the states if needed.
4140 if (load_progress == 1.0)
4141 ResetLoadProgressState();
4142 return;
4143 }
4144
4145 if (loading_weak_factory_.HasWeakPtrs())
4146 return;
4147
skyostil95082a62015-06-05 19:53:074148 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4149 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4150 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594151 min_delay);
4152}
4153
[email protected]b172aee2012-04-10 17:05:264154void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164155 controller_.DiscardNonCommittedEntries();
4156
4157 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214158 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164159}
4160
[email protected]59167c22013-06-03 18:07:324161void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104162 has_accessed_initial_document_ = true;
4163
[email protected]d1371bf8e2014-04-19 03:26:244164 // We may have left a failed browser-initiated navigation in the address bar
4165 // to let the user edit it and try again. Clear it now that content might
4166 // show up underneath it.
4167 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454168 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244169
[email protected]59167c22013-06-03 18:07:324170 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504171 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324172}
4173
alexmosbe2f4c32015-03-10 02:30:234174void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4175 const std::string& name) {
4176 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4177 FrameNameChanged(render_frame_host, name));
4178}
4179
[email protected]39f2f9252014-05-03 00:54:014180void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294181 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094182 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294183 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094184
4185 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214186 NotificationService::current()->Notify(
4187 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4188 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294189 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084190}
4191
creis8eb8ef22015-11-04 22:51:384192void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4193 const PageState& page_state) {
4194 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4195
4196 // The state update affects the last NavigationEntry associated with the given
4197 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4198 // in the case of an UpdateState from a frame being swapped out). We track
4199 // which entry this is in the RenderFrameHost's nav_entry_id.
4200 RenderFrameHostImpl* rfhi =
4201 static_cast<RenderFrameHostImpl*>(render_frame_host);
4202 NavigationEntryImpl* entry =
4203 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4204 if (!entry)
4205 return;
4206
4207 FrameNavigationEntry* frame_entry =
4208 entry->GetFrameEntry(rfhi->frame_tree_node());
4209 if (!frame_entry)
4210 return;
4211
creisd06a9422015-11-11 03:08:454212 // The SiteInstance might not match if we do a cross-process navigation with
4213 // replacement (e.g., auto-subframe), in which case the swap out of the old
4214 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4215 // has already been replaced and destroyed.
4216 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4217 return;
4218
creis8eb8ef22015-11-04 22:51:384219 if (page_state == frame_entry->page_state())
4220 return; // Nothing to update.
4221
4222 frame_entry->set_page_state(page_state);
4223 controller_.NotifyEntryChanged(entry);
4224}
4225
[email protected]ef3adfc2014-05-11 00:04:544226void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104227 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544228 const base::string16& title,
4229 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544230 // If we have a title, that's a pretty good indication that we've started
4231 // getting useful data.
4232 SetNotWaitingForResponse();
4233
4234 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584235 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544236 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584237 render_frame_host->GetSiteInstance(), page_id);
4238
creisd63f6c4a2015-11-06 19:05:534239 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4240 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
4241 DCHECK_EQ(entry, new_entry);
[email protected]ef3adfc2014-05-11 00:04:544242
4243 // We can handle title updates when we don't have an entry in
4244 // UpdateTitleForEntry, but only if the update is from the current RVH.
4245 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584246 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544247 return;
4248
4249 // TODO(evan): make use of title_direction.
4250 // http://code.google.com/p/chromium/issues/detail?id=27094
4251 if (!UpdateTitleForEntry(entry, title))
4252 return;
4253
4254 // Broadcast notifications when the UI should be updated.
4255 if (entry == controller_.GetEntryAtOffset(0))
4256 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4257}
4258
4259void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4260 const std::string& encoding) {
4261 SetEncoding(encoding);
4262}
4263
[email protected]39f2f9252014-05-03 00:54:014264void WebContentsImpl::DocumentAvailableInMainFrame(
4265 RenderViewHost* render_view_host) {
4266 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4267 DocumentAvailableInMainFrame());
4268}
naskoc0fceff2015-04-30 15:53:524269
[email protected]e1c3a552012-05-04 20:51:324270void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4271 // Tell the active RenderViewHost to run unload handlers and close, as long
4272 // as the request came from a RenderViewHost in the same BrowsingInstance.
4273 // In most cases, we receive this from a swapped out RenderViewHost.
4274 // It is possible to receive it from one that has just been swapped in,
4275 // in which case we might as well deliver the message anyway.
4276 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524277 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324278}
4279
alexmose7da5a12015-04-09 02:22:164280bool WebContentsImpl::ShouldRouteMessageEvent(
4281 RenderFrameHost* target_rfh,
4282 SiteInstance* source_site_instance) const {
4283 // Allow the message if this WebContents is dedicated to a browser plugin
4284 // guest.
[email protected]0eba810b2012-10-18 03:19:364285 // Note: This check means that an embedder could theoretically receive a
4286 // postMessage from anyone (not just its own guests). However, this is
4287 // probably not a risk for apps since other pages won't have references
4288 // to App windows.
alexmose7da5a12015-04-09 02:22:164289 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4290}
[email protected]f546640b2012-05-15 00:03:494291
alexmos58729042015-06-18 23:20:004292void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164293 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4294 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494295
alexmose7da5a12015-04-09 02:22:164296 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144297 // If this message is going to outer WebContents from inner WebContents,
4298 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4299 // already created a RenderFrameProxyHost for that purpose.
4300 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084301 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144302 return;
4303 }
4304
lfg812874d2016-02-09 22:26:134305 if (this != source_web_contents && GetBrowserPluginGuest()) {
nasko5fb985b2015-08-20 17:28:164306 // We create a swapped out RenderView or RenderFrameProxyHost for the
4307 // embedder in the guest's render process but we intentionally do not
4308 // expose the embedder's opener chain to it.
4309 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
4310 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4311 GetSiteInstance());
4312 } else {
4313 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance());
4314 }
[email protected]f546640b2012-05-15 00:03:494315 } else {
alexmos58729042015-06-18 23:20:004316 RenderFrameHostImpl* source_rfhi =
4317 static_cast<RenderFrameHostImpl*>(source_rfh);
4318 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394319 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494320 }
4321 }
[email protected]f546640b2012-05-15 00:03:494322}
4323
avib7348942015-12-25 20:57:104324bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264325 const base::string16& message,
avib7348942015-12-25 20:57:104326 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264327 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254328 if (!delegate_)
4329 return false;
4330 return delegate_->AddMessageToConsole(this, level, message, line_no,
4331 source_id);
4332}
4333
[email protected]0eba810b2012-10-18 03:19:364334int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214335 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294336 int render_view_routing_id = MSG_ROUTING_NONE;
nickac60e75472015-07-31 00:44:354337 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
nasko4c0feb62015-06-05 18:37:064338 GetRenderManager()->CreateRenderFrameProxy(instance);
4339 } else {
4340 GetRenderManager()->CreateRenderFrame(
carlosk35f35af2015-12-01 10:55:404341 instance, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN,
nasko4c0feb62015-06-05 18:37:064342 &render_view_routing_id);
4343 }
carlosk37f793792014-11-27 15:08:294344 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364345}
4346
avic3aa8422015-11-09 20:57:224347void WebContentsImpl::OnUserGesture(RenderWidgetHostImpl* render_widget_host) {
4348 if (render_widget_host != GetRenderViewHost()->GetWidget())
4349 return;
4350
[email protected]ddb85052011-05-18 14:40:274351 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254352 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224353
[email protected]ea114722012-03-12 01:11:254354 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174355 if (rdh) // NULL in unittests.
4356 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254357}
4358
dominickn2dd142dd2015-10-29 05:30:504359void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) {
4360 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4361 DidGetUserInteraction(type));
4362}
4363
[email protected]b172aee2012-04-10 17:05:264364void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444365 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254366 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444367}
4368
avic3aa8422015-11-09 20:57:224369void WebContentsImpl::RendererUnresponsive(
4370 RenderWidgetHostImpl* render_widget_host) {
[email protected]992db4c2011-05-12 15:37:154371 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224372 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154373 return;
4374
creiscce56cd2014-09-29 22:45:224375 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224376 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584377
[email protected]e5fc1632011-08-08 07:51:534378 // Ignore renderer unresponsive event if debugger is attached to the tab
4379 // since the event may be a result of the renderer sitting on a breakpoint.
4380 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364381 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534382 return;
4383
clamy226727e2015-06-29 10:28:474384 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224385 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324386 // Hang occurred while firing the beforeunload/unload handler.
4387 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224388 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324389
[email protected]fa944cb82013-11-15 17:51:214390 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324391 return;
4392
4393 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564394 // nothing we can do to recover. If the hang is in the beforeunload handler,
4395 // pretend the beforeunload listeners have all fired and allow the delegate
4396 // to continue closing; the user will not have the option of cancelling the
4397 // close. Otherwise, pretend the unload listeners have all fired and close
4398 // the tab.
4399 bool close = true;
clamy226727e2015-06-29 10:28:474400 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564401 delegate_->BeforeUnloadFired(this, true, &close);
4402 }
4403 if (close)
avic3aa8422015-11-09 20:57:224404 Close();
[email protected]420ae012009-04-24 05:16:324405 return;
4406 }
4407
creisc014b402015-04-23 16:41:454408 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474409 return;
4410
[email protected]6934a702011-12-20 00:04:514411 if (delegate_)
4412 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324413}
4414
avic3aa8422015-11-09 20:57:224415void WebContentsImpl::RendererResponsive(
4416 RenderWidgetHostImpl* render_widget_host) {
4417 if (render_widget_host != GetRenderViewHost()->GetWidget())
4418 return;
4419
[email protected]6934a702011-12-20 00:04:514420 if (delegate_)
4421 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324422}
4423
[email protected]b172aee2012-04-10 17:05:264424void WebContentsImpl::LoadStateChanged(
4425 const GURL& url,
4426 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104427 uint64_t upload_position,
4428 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544429 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4430 // is fixed.
4431 tracked_objects::ScopedTracker tracking_profile1(
4432 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4433 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324434 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564435 upload_position_ = upload_position;
4436 upload_size_ = upload_size;
rsleevi24f64dc22015-08-07 21:39:214437 load_state_host_ = url_formatter::IDNToUnicode(
4438 url.host(),
4439 GetContentClient()->browser()->GetAcceptLangs(GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214440 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324441 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464442 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224443 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4444 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464445 }
[email protected]420ae012009-04-24 05:16:324446}
4447
[email protected]b172aee2012-04-10 17:05:264448void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554449 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324450 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124451 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4452 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514453 if (delegate_)
4454 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094455 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324456}
4457
[email protected]58d5cfe2013-07-10 02:40:524458void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544459 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234460 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224461 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544462}
4463
[email protected]b172aee2012-04-10 17:05:264464void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104465 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214466 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264467 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4468 // here during container initialization and normal window size will be set
4469 // later. In case of tab duplication this resizing to 0x0 prevents setting
4470 // normal size later so just ignore it.
4471 if (!size.IsEmpty())
4472 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324473}
4474
[email protected]af905902013-10-01 21:38:514475void WebContentsImpl::CancelModalDialogsForRenderManager() {
4476 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544477 // deferrer would prevent us from swapping out. We also clear the state
4478 // because this is a cross-process navigation, which means that it's a new
4479 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174480 //
4481 // Note that we don't bother telling browser_plugin_embedder_ because the
4482 // cross-process navigation will either destroy the browser plugins or not
4483 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514484 if (dialog_manager_)
avi2460c762015-04-17 15:21:544485 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514486}
4487
[email protected]02d7b6e2014-06-24 21:01:504488void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4489 RenderFrameHost* new_host,
4490 bool is_main_frame) {
4491 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054492 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504493 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084494
[email protected]02d7b6e2014-06-24 21:01:504495 // Make sure the visible RVH reflects the new delegate's preferences.
4496 if (delegate_)
4497 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394498
[email protected]02d7b6e2014-06-24 21:01:504499 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4500 }
4501
4502 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544503}
4504
naskof5940b9f2015-03-02 23:04:054505void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4506 RenderViewHost* old_host,
4507 RenderViewHost* new_host) {
4508 NotifyViewSwapped(old_host, new_host);
4509}
4510
[email protected]b172aee2012-04-10 17:05:264511NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194512 return GetController();
[email protected]3a3d47472010-07-15 21:03:544513}
4514
carlosk35f35af2015-12-01 10:55:404515scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294516 const GURL& url) {
dbeama1b926a2015-08-31 23:17:514517 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(
4518 url, std::string())));
[email protected]420ae012009-04-24 05:16:324519}
4520
[email protected]10f417c52011-12-28 21:04:234521NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264522 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324523 return controller_.GetLastCommittedEntry();
4524}
4525
lfgbede6392015-09-11 21:54:064526void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4527 RenderViewHost* render_view_host) {
4528 RenderWidgetHostViewBase* rwh_view = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:144529 bool is_guest_in_site_per_process =
4530 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084531 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lfgbede6392015-09-11 21:54:064532 if (is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164533 RenderWidgetHostViewChildFrame* rwh_view_child =
avif9ab5d942015-10-15 14:05:444534 new RenderWidgetHostViewChildFrame(render_view_host->GetWidget());
[email protected]bffc8302014-01-23 20:52:164535 rwh_view = rwh_view_child;
4536 } else {
avif9ab5d942015-10-15 14:05:444537 rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]bffc8302014-01-23 20:52:164538 }
[email protected]1a98a932009-11-17 00:12:524539
[email protected]420ae012009-04-24 05:16:324540 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444541 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214542 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064543}
4544
4545bool WebContentsImpl::CreateRenderViewForRenderManager(
4546 RenderViewHost* render_view_host,
4547 int opener_frame_routing_id,
4548 int proxy_routing_id,
4549 const FrameReplicationState& replicated_frame_state) {
4550 TRACE_EVENT0("browser,navigation",
4551 "WebContentsImpl::CreateRenderViewForRenderManager");
4552
4553 if (proxy_routing_id == MSG_ROUTING_NONE)
4554 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324555
[email protected]74ce1ad2011-12-16 21:51:464556 // Make sure we use the correct starting page_id in the new RenderView.
4557 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104558 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584559 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464560
alexmos5ac402d2015-07-09 07:51:104561 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4562 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4563 max_page_id, replicated_frame_state,
4564 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524565 return false;
[email protected]14392a52012-05-02 20:28:444566 }
[email protected]a4127722011-04-27 23:13:524567
avi2b177592014-12-10 02:08:024568 SetHistoryOffsetAndLengthForView(render_view_host,
4569 controller_.GetLastCommittedEntryIndex(),
4570 controller_.GetEntryCount());
4571
[email protected]a220b5932013-09-21 03:47:444572#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504573 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4574 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444575 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444576 if (rwh_view) {
4577 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4578 render_widget_host->WasResized();
4579 }
[email protected]f8233cc2011-05-31 20:24:504580#endif
4581
[email protected]420ae012009-04-24 05:16:324582 return true;
4583}
4584
[email protected]82307f6b2014-08-07 03:30:124585bool WebContentsImpl::CreateRenderFrameForRenderManager(
4586 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044587 int proxy_routing_id,
4588 int opener_routing_id,
japhete6adf142014-10-31 00:01:494589 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044590 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434591 TRACE_EVENT0("browser,navigation",
4592 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124593
4594 RenderFrameHostImpl* rfh =
4595 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044596 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4597 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124598 return false;
4599
4600 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4601 // RenderFrameHost will have to be associated with the appropriate
4602 // RenderWidgetHostView or a new one should be created here.
4603
4604 return true;
4605}
4606
mfomitchev2b8b066a2016-01-28 19:23:154607#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454608
[email protected]155c7f22013-12-09 17:07:184609base::android::ScopedJavaLocalRef<jobject>
4610WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404611 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564612 return GetWebContentsAndroid()->GetJavaObject();
4613}
[email protected]155c7f22013-12-09 17:07:184614
[email protected]0e813a52014-08-13 10:34:564615WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184616 WebContentsAndroid* web_contents_android =
4617 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4618 if (!web_contents_android) {
4619 web_contents_android = new WebContentsAndroid(this);
4620 SetUserData(kWebContentsAndroidKey, web_contents_android);
4621 }
[email protected]0e813a52014-08-13 10:34:564622 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184623}
4624
[email protected]7d244f12013-08-22 21:41:514625bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064626 return CreateRenderViewForRenderManager(
4627 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064628 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514629}
[email protected]fc2b46b2014-05-03 16:33:454630
4631#elif defined(OS_MACOSX)
4632
[email protected]75f4df72014-07-16 22:39:424633void WebContentsImpl::SetAllowOtherViews(bool allow) {
4634 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454635}
4636
[email protected]75f4df72014-07-16 22:39:424637bool WebContentsImpl::GetAllowOtherViews() {
4638 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454639}
4640
[email protected]7d244f12013-08-22 21:41:514641#endif
4642
[email protected]6fba26d2014-04-29 09:38:284643void WebContentsImpl::OnDialogClosed(int render_process_id,
4644 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264645 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494646 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264647 bool success,
[email protected]fcf75d42013-12-03 20:11:264648 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284649 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4650 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494651 last_dialog_suppressed_ = dialog_was_suppressed;
4652
[email protected]beb440c2009-11-06 04:08:544653 if (is_showing_before_unload_dialog_ && !success) {
[email protected]6fba26d2014-04-29 09:38:284654 if (rfh)
clamydb73eb6c2016-02-10 13:27:564655 rfh->frame_tree_node()->BeforeUnloadCanceled();
[email protected]15d160c02012-07-04 10:52:354656 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104657
[email protected]6d65a462013-06-21 21:29:124658 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4659 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544660 }
[email protected]87de04b02014-04-08 22:14:494661
[email protected]beb440c2009-11-06 04:08:544662 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284663 if (rfh) {
4664 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4665 dialog_was_suppressed);
4666 } else {
4667 // Don't leak the sync IPC reply if the RFH or process is gone.
4668 delete reply_msg;
4669 }
[email protected]beb440c2009-11-06 04:08:544670}
4671
[email protected]b172aee2012-04-10 17:05:264672void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544673 if (encoding == last_reported_encoding_)
4674 return;
4675 last_reported_encoding_ = encoding;
4676
4677 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124678 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104679}
[email protected]f45d2a72010-03-08 23:28:354680
[email protected]1ac10dca2013-08-20 20:47:044681bool WebContentsImpl::IsHidden() {
4682 return capturer_count_ == 0 && !should_normally_be_visible_;
4683}
4684
rob97250742015-12-10 17:45:154685int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144686 if (node_ && node_->outer_web_contents())
4687 return node_->outer_contents_frame_tree_node_id();
4688
nick2482a2d2015-12-18 01:39:374689 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144690}
4691
[email protected]b0936d22013-11-28 06:47:364692RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214693 return frame_tree_.root()->render_manager();
4694}
4695
lazyboy8e16ddfd2015-09-28 03:41:564696WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4697 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4698 if (node_)
4699 return node_->outer_web_contents();
4700 } else {
4701 if (GetBrowserPluginGuest())
4702 return GetBrowserPluginGuest()->embedder_web_contents();
4703 }
4704 return nullptr;
4705}
4706
[email protected]f8497342013-02-05 22:15:024707BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394708 return browser_plugin_guest_.get();
4709}
4710
[email protected]738f57a2013-06-29 21:06:544711void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4712 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144713 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544714 browser_plugin_guest_.reset(guest);
4715}
4716
[email protected]f8497342013-02-05 22:15:024717BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394718 return browser_plugin_embedder_.get();
4719}
[email protected]8ff00d72012-10-23 19:12:214720
fsamuel60b42282015-03-10 03:29:144721void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4722 if (browser_plugin_embedder_)
4723 return;
4724 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4725}
4726
[email protected]fc2b46b2014-05-03 16:33:454727gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214728 gfx::Size size;
4729 if (delegate_)
4730 size = delegate_->GetSizeForNewRenderView(this);
4731 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454732 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214733 return size;
4734}
4735
[email protected]ae7eeda2014-07-04 01:53:264736void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4737 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024738 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554739}
4740
[email protected]222f5822014-02-05 23:40:494741void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4742 if (!delegate_)
4743 return;
4744 const gfx::Size new_size = GetPreferredSize();
4745 if (new_size != old_size)
4746 delegate_->UpdatePreferredSize(this, new_size);
4747}
4748
dbeama1b926a2015-08-31 23:17:514749WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4750 const std::string& frame_name) {
4751 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4752 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4753 CreateWebUIControllerForURL(web_ui, url);
4754 if (controller) {
4755 web_ui->AddMessageHandler(new GenericHandler());
4756 web_ui->SetController(controller);
4757 return web_ui;
4758 }
4759
4760 delete web_ui;
4761 return NULL;
4762}
4763
[email protected]34ff1cfc2014-08-20 06:16:054764void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4765 force_disable_overscroll_content_ = force_disable;
4766 if (view_)
4767 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4768}
4769
dalecurtis88c240072015-12-09 02:11:184770void WebContentsImpl::MediaStartedPlaying(
4771 const WebContentsObserver::MediaPlayerId& id) {
4772 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4773}
4774
4775void WebContentsImpl::MediaStoppedPlaying(
4776 const WebContentsObserver::MediaPlayerId& id) {
4777 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4778}
4779
[email protected]8ff00d72012-10-23 19:12:214780} // namespace content