blob: e02c77031447bd168bd78da1759ae6fdceb488a9 [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),
waffles1c12bf402016-02-10 17:45:48341 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03342 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23343 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
344 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34345 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26346 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56347 upload_size_(0),
348 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16349 is_resume_pending_(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()),
waffles1c12bf402016-02-10 17:45:48374 accessibility_mode_(
375 BrowserAccessibilityStateImpl::GetInstance()->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();
waffles1c12bf402016-02-10 17:45:48899 if (is_loading_ && 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 {
waffles1c12bf402016-02-10 17:45:481039 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:491040}
1041
[email protected]6dfed692014-05-22 04:18:031042bool WebContentsImpl::IsLoadingToDifferentDocument() const {
waffles1c12bf402016-02-10 17:45:481043 return is_loading_ && 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) {
kenrba26d15092016-02-10 22:00:251964 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
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)) {
kenrba26d15092016-02-10 22:00:251969 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:511970 if (process_handle != base::kNullProcessHandle) {
1971 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391972 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:251973 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511974 }
1975 return;
1976 }
1977
[email protected]bafe6cd2012-05-23 23:09:501978 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:051979 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261980
[email protected]cfd80b02014-05-01 17:46:481981 RenderWidgetHostViewBase* widget_view =
1982 static_cast<RenderWidgetHostViewBase*>(
1983 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191984 if (!widget_view)
1985 return;
[email protected]bafe6cd2012-05-23 23:09:501986 if (!is_fullscreen) {
1987 // Popups should not get activated.
1988 widget_view->SetPopupType(popup_type);
1989 }
1990 // Save the created widget associated with the route so we can show it later.
1991 pending_widget_views_[route_id] = widget_view;
1992
1993#if defined(OS_MACOSX)
1994 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1995 // to allow it to survive the trip without being hosted.
1996 base::mac::NSObjectRetain(widget_view->GetNativeView());
1997#endif
1998}
1999
2000void WebContentsImpl::ShowCreatedWindow(int route_id,
2001 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392002 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502003 bool user_gesture) {
2004 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:002005 if (contents) {
2006 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162007 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382008 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2009 contents->ResumeLoadingCreatedWebContents();
2010
[email protected]eda238a12012-09-07 23:44:002011 if (delegate) {
2012 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392013 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002014 }
2015 }
[email protected]bafe6cd2012-05-23 23:09:502016}
2017
2018void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:392019 const gfx::Rect& initial_rect) {
2020 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502021}
2022
2023void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
2024 ShowCreatedWidget(route_id, true, gfx::Rect());
2025}
2026
2027void WebContentsImpl::ShowCreatedWidget(int route_id,
2028 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392029 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482030 RenderWidgetHostViewBase* widget_host_view =
2031 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502032 if (!widget_host_view)
2033 return;
[email protected]cfd80b02014-05-01 17:46:482034
2035 RenderWidgetHostView* view = NULL;
2036 BrowserPluginGuest* guest = GetBrowserPluginGuest();
2037 if (guest && guest->embedder_web_contents()) {
2038 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
2039 } else {
2040 view = GetRenderWidgetHostView();
2041 }
2042
[email protected]4aebbca2013-09-17 22:26:492043 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312044 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032045 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312046 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492047 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2048 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532049 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492050 } else {
[email protected]cfd80b02014-05-01 17:46:482051 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492052 }
[email protected]4aebbca2013-09-17 22:26:492053 FOR_EACH_OBSERVER(WebContentsObserver,
2054 observers_,
2055 DidShowFullscreenWidget(route_id));
2056 if (!widget_host_view->HasFocus())
2057 widget_host_view->Focus();
2058 } else {
bokan107a47f2015-02-03 23:23:392059 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492060 }
[email protected]89054502012-06-03 10:29:242061
2062 RenderWidgetHostImpl* render_widget_host_impl =
2063 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2064 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312065 // Only allow privileged mouse lock for fullscreen render widget, which is
2066 // used to implement Pepper Flash fullscreen.
2067 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502068
2069#if defined(OS_MACOSX)
2070 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2071 // properly embedded (or purposefully ignored) we can release the retain we
2072 // took in CreateNewWidget().
2073 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2074#endif
2075}
2076
2077WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2078 PendingContents::iterator iter = pending_contents_.find(route_id);
2079
2080 // Certain systems can block the creation of new windows. If we didn't succeed
2081 // in creating one, just return NULL.
2082 if (iter == pending_contents_.end()) {
2083 return NULL;
2084 }
2085
2086 WebContentsImpl* new_contents = iter->second;
2087 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102088 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502089
[email protected]d70bea92013-04-05 04:23:342090 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252091 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342092 return new_contents;
2093
[email protected]bafe6cd2012-05-23 23:09:502094 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432095 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502096 return NULL;
2097
[email protected]bafe6cd2012-05-23 23:09:502098 return new_contents;
2099}
2100
2101RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2102 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2103 if (iter == pending_widget_views_.end()) {
2104 DCHECK(false);
2105 return NULL;
2106 }
2107
2108 RenderWidgetHostView* widget_host_view = iter->second;
2109 pending_widget_views_.erase(route_id);
2110
2111 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2112 if (!widget_host->GetProcess()->HasConnection()) {
2113 // The view has gone away or the renderer crashed. Nothing to do.
2114 return NULL;
2115 }
2116
2117 return widget_host_view;
2118}
2119
[email protected]f13b4202012-06-12 23:53:232120void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092121 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212122 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372123 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232124 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372125 } else {
2126 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:042127 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:372128 scoped_ptr<MediaStreamUI>());
2129 }
[email protected]f13b4202012-06-12 23:53:232130}
2131
grunell657d4d82014-09-18 00:09:432132bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2133 MediaStreamType type) {
2134 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2135 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2136 return delegate_ &&
2137 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2138}
2139
[email protected]cc9200432013-07-23 23:02:402140SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2141 SiteInstance* instance) {
2142 return controller_.GetSessionStorageNamespace(instance);
2143}
2144
[email protected]6de7fc482014-06-06 10:46:442145SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2146 return controller_.GetSessionStorageNamespaceMap();
2147}
2148
[email protected]9b159a52013-10-03 17:24:552149FrameTree* WebContentsImpl::GetFrameTree() {
2150 return &frame_tree_;
2151}
2152
lukendc35e7f2014-11-10 19:06:142153void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2154 virtual_keyboard_requested_ = requested;
2155}
2156
2157bool WebContentsImpl::IsVirtualKeyboardRequested() {
2158 return virtual_keyboard_requested_;
2159}
2160
[email protected]95640212014-07-26 18:14:302161AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2162 return accessibility_mode_;
2163}
2164
[email protected]31a71eaf2014-03-13 01:47:362165void WebContentsImpl::AccessibilityEventReceived(
2166 const std::vector<AXEventNotificationDetails>& details) {
2167 FOR_EACH_OBSERVER(
2168 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2169}
2170
dmazzonia656928e2014-09-15 20:28:542171RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402172 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542173 int browser_plugin_instance_id) {
2174 BrowserPluginGuestManager* guest_manager =
2175 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202176 if (!guest_manager)
2177 return nullptr;
2178
dmazzonia656928e2014-09-15 20:28:542179 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442180 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542181 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202182 return nullptr;
2183
dmazzonia656928e2014-09-15 20:28:542184 return guest->GetMainFrame();
2185}
2186
blundellc57b93f2014-10-29 13:19:572187GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2188 return geolocation_service_context_.get();
2189}
2190
alogvinovf50445a2015-10-30 13:00:122191WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2192 return wake_lock_service_context_.get();
2193}
2194
[email protected]edc3af82013-12-12 21:24:072195void WebContentsImpl::OnShowValidationMessage(
2196 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292197 const base::string16& main_text,
2198 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072199 if (delegate_)
2200 delegate_->ShowValidationMessage(
2201 this, anchor_in_root_view, main_text, sub_text);
2202}
2203
2204void WebContentsImpl::OnHideValidationMessage() {
2205 if (delegate_)
2206 delegate_->HideValidationMessage(this);
2207}
2208
2209void WebContentsImpl::OnMoveValidationMessage(
2210 const gfx::Rect& anchor_in_root_view) {
2211 if (delegate_)
2212 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2213}
2214
[email protected]32deec62013-05-15 23:55:042215void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
2216 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442217 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042218}
2219
[email protected]95640212014-07-26 18:14:302220BrowserAccessibilityManager*
2221 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452222 RenderFrameHostImpl* rfh = GetMainFrame();
2223 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302224}
2225
2226BrowserAccessibilityManager*
2227 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452228 RenderFrameHostImpl* rfh = GetMainFrame();
2229 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302230}
2231
mohsen7ab1ec16ec2015-07-02 18:26:232232void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2233 RenderFrameHost* focused_frame = GetFocusedFrame();
2234 if (!focused_frame)
2235 return;
2236
2237 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2238 focused_frame->GetRoutingID(), extent));
2239}
2240
2241void WebContentsImpl::SelectRange(const gfx::Point& base,
2242 const gfx::Point& extent) {
2243 RenderFrameHost* focused_frame = GetFocusedFrame();
2244 if (!focused_frame)
2245 return;
2246
2247 focused_frame->Send(
2248 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2249}
2250
aurimasab0319022015-07-10 21:57:382251void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2252 int end_adjust) {
2253 RenderFrameHost* focused_frame = GetFocusedFrame();
2254 if (!focused_frame)
2255 return;
2256
2257 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2258 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2259}
2260
[email protected]b172aee2012-04-10 17:05:262261void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492262 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232263 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492264 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332265}
2266
avic3aa8422015-11-09 20:57:222267void WebContentsImpl::ResizeDueToAutoResize(
2268 RenderWidgetHostImpl* render_widget_host,
2269 const gfx::Size& new_size) {
2270 if (render_widget_host != GetRenderViewHost()->GetWidget())
2271 return;
2272
[email protected]61e2b3cc2012-03-02 16:13:342273 if (delegate_)
2274 delegate_->ResizeDueToAutoResize(this, new_size);
2275}
2276
[email protected]b172aee2012-04-10 17:05:262277WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202278 if (!delegate_)
2279 return NULL;
[email protected]00c37fc2011-08-02 00:22:502280
[email protected]e5d549d2011-12-28 01:29:202281 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202282 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342283}
2284
[email protected]6b618e62012-08-16 12:59:182285bool WebContentsImpl::Send(IPC::Message* message) {
2286 if (!GetRenderViewHost()) {
2287 delete message;
2288 return false;
2289 }
2290
2291 return GetRenderViewHost()->Send(message);
2292}
2293
[email protected]a86c0e962013-12-17 17:10:392294void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2295 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442296 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392297 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442298}
2299
[email protected]20ca0382013-02-28 19:50:072300void WebContentsImpl::AttachInterstitialPage(
2301 InterstitialPageImpl* interstitial_page) {
2302 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212303 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292304
2305 // Cancel any visible dialogs so that they don't interfere with the
2306 // interstitial.
creis89a0f782015-05-27 16:13:172307 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292308
[email protected]20ca0382013-02-28 19:50:072309 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2310 DidAttachInterstitialPage());
2311}
2312
2313void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:572314 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212315 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072316 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2317 DidDetachInterstitialPage());
2318}
2319
avi2b177592014-12-10 02:08:022320void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2321 int history_length) {
2322 SetHistoryOffsetAndLengthForView(
2323 GetRenderViewHost(), history_offset, history_length);
2324}
2325
2326void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2327 RenderViewHost* render_view_host,
2328 int history_offset,
2329 int history_length) {
2330 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2331 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142332}
2333
[email protected]4fed3702014-04-01 09:08:002334void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172335 RenderFrameHost* focused_frame = GetFocusedFrame();
2336 if (!focused_frame)
2337 return;
2338
[email protected]959be4c2014-04-08 15:01:332339 focused_frame->Send(new FrameMsg_Reload(
2340 focused_frame->GetRoutingID(), ignore_cache));
2341}
2342
megjablon3f5941072016-02-04 23:27:522343void WebContentsImpl::ReloadLoFiImages() {
2344 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2345}
2346
[email protected]959be4c2014-04-08 15:01:332347void WebContentsImpl::Undo() {
2348 RenderFrameHost* focused_frame = GetFocusedFrame();
2349 if (!focused_frame)
2350 return;
2351
2352 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2353 RecordAction(base::UserMetricsAction("Undo"));
2354}
2355
2356void WebContentsImpl::Redo() {
2357 RenderFrameHost* focused_frame = GetFocusedFrame();
2358 if (!focused_frame)
2359 return;
2360 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2361 RecordAction(base::UserMetricsAction("Redo"));
2362}
2363
2364void WebContentsImpl::Cut() {
2365 RenderFrameHost* focused_frame = GetFocusedFrame();
2366 if (!focused_frame)
2367 return;
2368
2369 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2370 RecordAction(base::UserMetricsAction("Cut"));
2371}
2372
2373void WebContentsImpl::Copy() {
2374 RenderFrameHost* focused_frame = GetFocusedFrame();
2375 if (!focused_frame)
2376 return;
2377
2378 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2379 RecordAction(base::UserMetricsAction("Copy"));
2380}
2381
2382void WebContentsImpl::CopyToFindPboard() {
2383#if defined(OS_MACOSX)
2384 RenderFrameHost* focused_frame = GetFocusedFrame();
2385 if (!focused_frame)
2386 return;
2387
2388 // Windows/Linux don't have the concept of a find pasteboard.
2389 focused_frame->Send(
2390 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2391 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2392#endif
2393}
2394
2395void WebContentsImpl::Paste() {
2396 RenderFrameHost* focused_frame = GetFocusedFrame();
2397 if (!focused_frame)
2398 return;
2399
2400 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2401 RecordAction(base::UserMetricsAction("Paste"));
2402}
2403
2404void WebContentsImpl::PasteAndMatchStyle() {
2405 RenderFrameHost* focused_frame = GetFocusedFrame();
2406 if (!focused_frame)
2407 return;
2408
2409 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2410 focused_frame->GetRoutingID()));
2411 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2412}
2413
2414void WebContentsImpl::Delete() {
2415 RenderFrameHost* focused_frame = GetFocusedFrame();
2416 if (!focused_frame)
2417 return;
2418
2419 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2420 RecordAction(base::UserMetricsAction("DeleteSelection"));
2421}
2422
2423void WebContentsImpl::SelectAll() {
2424 RenderFrameHost* focused_frame = GetFocusedFrame();
2425 if (!focused_frame)
2426 return;
2427
2428 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2429 RecordAction(base::UserMetricsAction("SelectAll"));
2430}
2431
2432void WebContentsImpl::Unselect() {
2433 RenderFrameHost* focused_frame = GetFocusedFrame();
2434 if (!focused_frame)
2435 return;
2436
2437 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2438 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172439}
2440
2441void WebContentsImpl::Replace(const base::string16& word) {
2442 RenderFrameHost* focused_frame = GetFocusedFrame();
2443 if (!focused_frame)
2444 return;
2445
[email protected]959be4c2014-04-08 15:01:332446 focused_frame->Send(new InputMsg_Replace(
2447 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172448}
2449
2450void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2451 RenderFrameHost* focused_frame = GetFocusedFrame();
2452 if (!focused_frame)
2453 return;
2454
[email protected]959be4c2014-04-08 15:01:332455 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2456 focused_frame->GetRoutingID(), word));
2457}
2458
2459void WebContentsImpl::NotifyContextMenuClosed(
2460 const CustomContextMenuContext& context) {
2461 RenderFrameHost* focused_frame = GetFocusedFrame();
2462 if (!focused_frame)
2463 return;
2464
2465 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2466 focused_frame->GetRoutingID(), context));
2467}
2468
2469void WebContentsImpl::ExecuteCustomContextMenuCommand(
2470 int action, const CustomContextMenuContext& context) {
2471 RenderFrameHost* focused_frame = GetFocusedFrame();
2472 if (!focused_frame)
2473 return;
2474
2475 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2476 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002477}
2478
[email protected]fc2b46b2014-05-03 16:33:452479gfx::NativeView WebContentsImpl::GetNativeView() {
2480 return view_->GetNativeView();
2481}
2482
2483gfx::NativeView WebContentsImpl::GetContentNativeView() {
2484 return view_->GetContentNativeView();
2485}
2486
2487gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2488 return view_->GetTopLevelNativeWindow();
2489}
2490
2491gfx::Rect WebContentsImpl::GetViewBounds() {
2492 return view_->GetViewBounds();
2493}
2494
2495gfx::Rect WebContentsImpl::GetContainerBounds() {
2496 gfx::Rect rv;
2497 view_->GetContainerBounds(&rv);
2498 return rv;
2499}
2500
2501DropData* WebContentsImpl::GetDropData() {
2502 return view_->GetDropData();
2503}
2504
2505void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042506 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452507}
2508
2509void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042510 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452511}
2512
2513void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042514 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452515}
2516
2517void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042518 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452519}
2520
[email protected]b172aee2012-04-10 17:05:262521void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272522 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212523 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542524 return;
2525 }
[email protected]0b431992014-06-24 00:08:032526 RenderWidgetHostView* const fullscreen_view =
2527 GetFullscreenRenderWidgetHostView();
2528 if (fullscreen_view) {
2529 fullscreen_view->Focus();
2530 return;
2531 }
creisc014b402015-04-23 16:41:452532 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542533}
2534
[email protected]b172aee2012-04-10 17:05:262535bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212536 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542537}
2538
[email protected]b172aee2012-04-10 17:05:262539InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212540 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222541}
2542
[email protected]b172aee2012-04-10 17:05:262543bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162544 // WebKit creates Document object when MIME type is application/xhtml+xml,
2545 // so we also support this MIME type.
2546 return contents_mime_type_ == "text/html" ||
2547 contents_mime_type_ == "text/xml" ||
2548 contents_mime_type_ == "application/xhtml+xml" ||
2549 contents_mime_type_ == "text/plain" ||
2550 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252551 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162552}
2553
[email protected]b172aee2012-04-10 17:05:262554void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592555 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162556 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552557 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192558 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142559 return;
[email protected]c7dd2f62011-07-18 15:57:592560 }
2561
2562 Stop();
2563
2564 // Create the save package and possibly prompt the user for the name to save
2565 // the page as. The user prompt is an asynchronous operation that runs on
2566 // another thread.
2567 save_package_ = new SavePackage(this);
2568 save_package_->GetSaveInfo();
2569}
2570
2571// Used in automated testing to bypass prompting the user for file names.
2572// Instead, the names and paths are hard coded rather than running them through
2573// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342574bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2575 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212576 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592577 // Stop the page from navigating.
2578 Stop();
2579
2580 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212581 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592582}
2583
[email protected]3c71576ce2013-07-23 02:00:012584void WebContentsImpl::SaveFrame(const GURL& url,
2585 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372586 SaveFrameWithHeaders(url, referrer, std::string());
2587}
2588
2589void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2590 const Referrer& referrer,
2591 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192592 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012593 return;
sammc92af61552014-11-19 23:27:402594 if (delegate_ && delegate_->SaveFrame(url, referrer))
2595 return;
2596
nasko89ad7742015-03-05 22:14:192597 // TODO(nasko): This check for main frame is incorrect and should be fixed
2598 // by explicitly passing in which frame this method should target.
2599 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012600
2601 DownloadManager* dlm =
2602 BrowserContext::GetDownloadManager(GetBrowserContext());
2603 if (!dlm)
2604 return;
avib7348942015-12-25 20:57:102605 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012606 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272607 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012608 if (entry)
2609 post_id = entry->GetPostID();
2610 }
2611 scoped_ptr<DownloadUrlParameters> params(
2612 DownloadUrlParameters::FromWebContents(this, url));
2613 params->set_referrer(referrer);
2614 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012615 if (post_id >= 0)
2616 params->set_method("POST");
2617 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372618
2619 if (headers.empty()) {
2620 params->set_prefer_cache(true);
2621 } else {
brettw26dab8f02015-08-08 00:28:472622 for (const base::StringPiece& key_value :
2623 base::SplitStringPiece(
2624 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2625 std::vector<std::string> pair = base::SplitString(
2626 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372627 DCHECK_EQ(2ul, pair.size());
2628 params->add_request_header(pair[0], pair[1]);
2629 }
2630 }
dcheng36b6aec92015-12-26 06:16:362631 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012632}
2633
[email protected]b172aee2012-04-10 17:05:262634void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342635 const base::FilePath& file,
avib7348942015-12-25 20:57:102636 const base::Callback<void(int64_t)>& callback) {
[email protected]18516cf92013-08-28 18:19:482637 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122638}
2639
[email protected]b172aee2012-04-10 17:05:262640const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272641 return contents_mime_type_;
2642}
2643
[email protected]b172aee2012-04-10 17:05:262644bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272645 return notify_disconnection_;
2646}
2647
[email protected]b172aee2012-04-10 17:05:262648void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312649 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182650 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162651}
2652
[email protected]b172aee2012-04-10 17:05:262653void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542654 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182655 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162656}
2657
[email protected]8ff00d72012-10-23 19:12:212658RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272659 return &renderer_preferences_;
2660}
2661
[email protected]e35ccd52012-05-23 16:22:472662void WebContentsImpl::Close() {
2663 Close(GetRenderViewHost());
2664}
2665
[email protected]cf200a562013-05-03 16:24:292666void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462667 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292668 if (browser_plugin_embedder_.get())
2669 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2670 screen_x, screen_y, operation);
2671 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452672 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2673 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292674}
2675
[email protected]d60f3702013-12-26 16:30:242676void WebContentsImpl::DidGetResourceResponseStart(
2677 const ResourceRequestDetails& details) {
2678 controller_.ssl_manager()->DidStartResourceResponse(details);
2679
2680 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2681 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242682}
2683
2684void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462685 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242686 const ResourceRedirectDetails& details) {
2687 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2688
2689 FOR_EACH_OBSERVER(
2690 WebContentsObserver,
2691 observers_,
creis114ca1b2014-11-13 23:51:462692 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242693
2694 // TODO(avi): Remove. http://crbug.com/170921
2695 NotificationService::current()->Notify(
2696 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2697 Source<WebContents>(this),
2698 Details<const ResourceRedirectDetails>(&details));
[email protected]d60f3702013-12-26 16:30:242699}
2700
calamity7fe55ce2015-04-10 03:59:372701void WebContentsImpl::NotifyWebContentsFocused() {
2702 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2703}
2704
[email protected]b172aee2012-04-10 17:05:262705void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522706 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452707 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292708 if (browser_plugin_embedder_.get())
2709 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342710}
2711
[email protected]e35ccd52012-05-23 16:22:472712void WebContentsImpl::UserGestureDone() {
avic3aa8422015-11-09 20:57:222713 OnUserGesture(GetRenderViewHost()->GetWidget());
[email protected]e35ccd52012-05-23 16:22:472714}
2715
[email protected]b172aee2012-04-10 17:05:262716void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272717 closed_by_user_gesture_ = value;
2718}
2719
[email protected]b172aee2012-04-10 17:05:262720bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272721 return closed_by_user_gesture_;
2722}
2723
[email protected]b172aee2012-04-10 17:05:262724void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502725 if (!delegate_)
2726 return;
2727
[email protected]6286a372013-10-09 04:03:272728 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2729 if (!entry)
[email protected]1788e772010-12-15 16:40:502730 return;
2731
[email protected]6286a372013-10-09 04:03:272732 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122733}
2734
[email protected]b172aee2012-04-10 17:05:262735void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042736 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272737 if (!delegate_)
2738 return;
2739
[email protected]691aa2f2013-05-28 22:52:042740 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272741}
2742
[email protected]b172aee2012-04-10 17:05:262743int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272744 return minimum_zoom_percent_;
2745}
2746
[email protected]b172aee2012-04-10 17:05:262747int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272748 return maximum_zoom_percent_;
2749}
2750
mcnee432e47d2015-11-09 19:37:462751void WebContentsImpl::SetPageScale(float page_scale_factor) {
2752 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242753}
2754
[email protected]b172aee2012-04-10 17:05:262755gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492756 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232757}
2758
[email protected]b172aee2012-04-10 17:05:262759bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052760 if (GetBrowserPluginGuest())
2761 return GetBrowserPluginGuest()->LockMouse(allowed);
2762
creisc014b402015-04-23 16:41:452763 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432764 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2765 allowed)
creisc014b402015-04-23 16:41:452766 : false;
[email protected]0bfbf882011-12-22 18:19:272767}
2768
[email protected]b172aee2012-04-10 17:05:262769bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212770 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502771}
2772
alexmose201c7cd2015-06-10 17:14:212773WebContentsImpl* WebContentsImpl::GetOpener() const {
2774 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2775 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572776}
2777
[email protected]cb805452013-05-22 15:16:212778void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482779 if (!color_chooser_info_.get())
2780 return;
2781 RenderFrameHost* rfh = RenderFrameHost::FromID(
2782 color_chooser_info_->render_process_id,
2783 color_chooser_info_->render_frame_id);
2784 if (!rfh)
2785 return;
2786
2787 rfh->Send(new FrameMsg_DidChooseColorResponse(
2788 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202789}
2790
[email protected]cb805452013-05-22 15:16:212791void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482792 if (!color_chooser_info_.get())
2793 return;
2794 RenderFrameHost* rfh = RenderFrameHost::FromID(
2795 color_chooser_info_->render_process_id,
2796 color_chooser_info_->render_frame_id);
2797 if (!rfh)
2798 return;
2799
2800 rfh->Send(new FrameMsg_DidEndColorChooser(
2801 rfh->GetRoutingID(), color_chooser_info_->identifier));
2802 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202803}
2804
halton.huoca2eabd2015-07-06 08:17:402805int WebContentsImpl::DownloadImage(
2806 const GURL& url,
2807 bool is_favicon,
2808 uint32_t max_bitmap_size,
2809 bool bypass_cache,
2810 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552811 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402812 static int next_image_download_id = 0;
2813 const image_downloader::ImageDownloaderPtr& mojo_image_downloader =
2814 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552815 const int download_id = ++next_image_download_id;
2816 if (!mojo_image_downloader) {
2817 // If the renderer process is dead (i.e. crash, or memory pressure on
2818 // Android), the downloader service will be invalid. Pre-Mojo, this would
2819 // hang the callback indefinetly since the IPC would be dropped. Now,
2820 // respond with a 400 HTTP error code to indicate that something went wrong.
2821 BrowserThread::PostTask(
2822 BrowserThread::UI, FROM_HERE,
2823 base::Bind(&WebContents::ImageDownloadCallback::Run,
2824 base::Owned(new ImageDownloadCallback(callback)),
2825 download_id, 400, url, std::vector<SkBitmap>(),
2826 std::vector<gfx::Size>()));
2827 return download_id;
2828 }
2829
halton.huoca2eabd2015-07-06 08:17:402830 image_downloader::DownloadRequestPtr req =
2831 image_downloader::DownloadRequest::New();
2832
2833 req->url = mojo::String::From(url);
2834 req->is_favicon = is_favicon;
2835 req->max_bitmap_size = max_bitmap_size;
2836 req->bypass_cache = bypass_cache;
2837
2838 mojo_image_downloader->DownloadImage(
dcheng36b6aec92015-12-26 06:16:362839 std::move(req),
amistry9f01b772015-07-29 01:54:552840 base::Bind(&DidDownloadImage, callback, download_id, url));
2841 return download_id;
[email protected]795c28972012-12-06 06:13:392842}
2843
[email protected]5dcaf8e2013-12-28 01:31:422844bool WebContentsImpl::IsSubframe() const {
2845 return is_subframe_;
2846}
2847
[email protected]36ec24f2014-01-09 00:32:082848void WebContentsImpl::Find(int request_id,
2849 const base::string16& search_text,
2850 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:332851 // Cowardly refuse to search for no text.
2852 if (search_text.empty()) {
2853 NOTREACHED();
2854 return;
2855 }
2856
raymes0fa0be52014-10-13 20:38:092857 // See if a top level browser plugin handles the find request first.
paulmeyer95703b92015-08-10 17:38:472858 if (browser_plugin_embedder_ &&
2859 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2860 return;
raymes0fa0be52014-10-13 20:38:092861 }
paulmeyer5d0a5f02016-01-21 20:15:522862 GetMainFrame()->Send(new FrameMsg_Find(GetMainFrame()->GetRoutingID(),
2863 request_id, search_text, options));
[email protected]36ec24f2014-01-09 00:32:082864}
2865
2866void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012867 // See if a top level browser plugin handles the stop finding request first.
paulmeyer95703b92015-08-10 17:38:472868 if (browser_plugin_embedder_ &&
2869 browser_plugin_embedder_->StopFinding(action)) {
2870 return;
raymes2bc64182015-02-06 01:23:012871 }
paulmeyer5d0a5f02016-01-21 20:15:522872 GetMainFrame()->Send(
2873 new FrameMsg_StopFinding(GetMainFrame()->GetRoutingID(), action));
[email protected]36ec24f2014-01-09 00:32:082874}
2875
[email protected]4fe53add2014-04-08 19:53:362876void WebContentsImpl::InsertCSS(const std::string& css) {
2877 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2878 GetMainFrame()->GetRoutingID(), css));
2879}
2880
dalecurtisbc6572e12014-09-12 19:22:302881bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:152882 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302883}
2884
mlamouriefdca9d2014-09-16 16:55:402885void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2886 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2887}
2888
dominickn6919ce32015-10-15 01:52:282889void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
2890 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
2891}
2892
bokanece34a82016-01-28 19:49:462893void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532894 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:432895 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:462896 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:532897}
2898
mariakhomenko44bdc4732015-04-29 01:55:382899void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:372900 if (delayed_open_url_params_.get()) {
2901 OpenURL(*delayed_open_url_params_.get());
2902 delayed_open_url_params_.reset(nullptr);
2903 return;
2904 }
2905
mariakhomenko44bdc4732015-04-29 01:55:382906 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
2907 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:162908 if (is_resume_pending_) {
2909 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:132910 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:162911 GetMainFrame()->Init();
2912 }
mariakhomenko44bdc4732015-04-29 01:55:382913}
2914
[email protected]b172aee2012-04-10 17:05:262915bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272916 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172917 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332918 return true;
2919 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272920}
2921
[email protected]b172aee2012-04-10 17:05:262922void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272923 if (delegate_)
2924 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212925}
2926
clamy0e119882015-07-31 16:12:332927void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
2928 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2929 DidStartNavigation(navigation_handle));
2930}
2931
2932void WebContentsImpl::DidRedirectNavigation(
2933 NavigationHandle* navigation_handle) {
2934 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2935 DidRedirectNavigation(navigation_handle));
2936}
2937
clamyefca29e2015-09-17 00:22:112938void WebContentsImpl::ReadyToCommitNavigation(
2939 NavigationHandle* navigation_handle) {
2940 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2941 ReadyToCommitNavigation(navigation_handle));
2942}
2943
clamy0e119882015-07-31 16:12:332944void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
2945 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2946 DidFinishNavigation(navigation_handle));
2947}
2948
[email protected]52913802013-12-10 05:52:182949void WebContentsImpl::DidStartProvisionalLoad(
2950 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182951 const GURL& validated_url,
2952 bool is_error_page,
2953 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102954 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482955 FOR_EACH_OBSERVER(
2956 WebContentsObserver,
2957 observers_,
2958 DidStartProvisionalLoadForFrame(
2959 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:082960
2961 // Notify accessibility if this is a reload.
2962 NavigationEntry* entry = controller_.GetVisibleEntry();
2963 if (entry && ui::PageTransitionCoreTypeIs(
2964 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
2965 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2966 BrowserAccessibilityManager* manager =
2967 ftn->current_frame_host()->browser_accessibility_manager();
2968 if (manager)
2969 manager->UserIsReloading();
2970 }
[email protected]400992b2012-06-14 00:03:542971}
2972
[email protected]3109fbb72014-01-06 23:57:152973void WebContentsImpl::DidFailProvisionalLoadWithError(
2974 RenderFrameHostImpl* render_frame_host,
2975 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2976 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312977 FOR_EACH_OBSERVER(WebContentsObserver,
2978 observers_,
2979 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312980 validated_url,
2981 params.error_code,
gsennton6fbb38692015-06-24 19:23:552982 params.error_description,
2983 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:082984
2985 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2986 BrowserAccessibilityManager* manager =
2987 ftn->current_frame_host()->browser_accessibility_manager();
2988 if (manager)
2989 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:152990}
2991
[email protected]b80624c2014-02-09 02:46:552992void WebContentsImpl::DidFailLoadWithError(
2993 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552994 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552995 int error_code,
gsennton6fbb38692015-06-24 19:23:552996 const base::string16& error_description,
2997 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:142998 FOR_EACH_OBSERVER(
2999 WebContentsObserver,
3000 observers_,
gsennton6fbb38692015-06-24 19:23:553001 DidFailLoad(render_frame_host, url, error_code, error_description,
3002 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553003}
3004
[email protected]52913802013-12-10 05:52:183005void WebContentsImpl::NotifyChangedNavigationState(
3006 InvalidateTypes changed_flags) {
3007 NotifyNavigationStateChanged(changed_flags);
3008}
3009
[email protected]3691e5cf2014-01-22 10:16:203010void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:203011 const GURL& url,
3012 NavigationController::ReloadType reload_type) {
3013 // Notify observers about navigation.
3014 FOR_EACH_OBSERVER(
3015 WebContentsObserver,
3016 observers_,
3017 DidStartNavigationToPendingEntry(url, reload_type));
3018}
3019
[email protected]8cb834e2014-03-06 14:23:233020void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3021 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503022 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3023 // weak pointer of sorts.
3024 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3025 const int32_t frame_id = render_frame_host->GetRoutingID();
3026
[email protected]65920f332014-03-04 21:14:183027 WebContents* new_contents = OpenURL(params);
3028
dchengb907f7332015-01-07 20:35:503029 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183030 // Notify observers.
3031 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3032 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463033 render_frame_host,
[email protected]65920f332014-03-04 21:14:183034 params.url,
3035 params.referrer,
3036 params.disposition,
creis114ca1b2014-11-13 23:51:463037 params.transition));
[email protected]65920f332014-03-04 21:14:183038 }
3039}
3040
creis29460272015-12-16 04:38:223041bool WebContentsImpl::ShouldTransferNavigation() {
3042 if (!delegate_)
3043 return true;
3044 return delegate_->ShouldTransferNavigation();
3045}
3046
[email protected]aa62afd2014-04-22 19:22:463047bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3048 if (!delegate_)
3049 return false;
3050 return delegate_->ShouldPreserveAbortedURLs(this);
3051}
3052
[email protected]37567b432014-02-12 01:12:223053void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433054 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223055 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353056 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223057 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483058 FOR_EACH_OBSERVER(WebContentsObserver,
3059 observers_,
3060 DidCommitProvisionalLoadForFrame(
3061 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083062
3063 BrowserAccessibilityManager* manager =
3064 render_frame_host->browser_accessibility_manager();
3065 if (manager)
3066 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223067}
3068
[email protected]0d0f4c492014-04-02 06:42:573069void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233070 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573071 // Ensure fullscreen mode is exited before committing the navigation to a
3072 // different page. The next page will not start out assuming it is in
3073 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233074 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193075 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573076 return;
3077 }
avibf58fa0c2015-11-11 01:45:523078 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463079 ExitFullscreen(false);
avibf58fa0c2015-11-11 01:45:523080 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573081}
3082
[email protected]37567b432014-02-12 01:12:223083void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283084 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223085 const LoadCommittedDetails& details,
3086 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3087 if (details.is_navigation_to_different_page()) {
3088 // Clear the status bubble. This is a workaround for a bug where WebKit
3089 // doesn't let us know that the cursor left an element during a
3090 // transition (this is also why the mouse cursor remains as a hand after
3091 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3092 // clear the bubble when a user navigates to a named anchor in the same
3093 // page.
sky8b00392d2015-01-10 00:30:283094 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003095
3096 RenderWidgetHostViewBase* rwhvb =
3097 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3098 if (rwhvb)
3099 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283100
peter90afaba2015-06-01 12:05:293101 did_first_visually_non_empty_paint_ = false;
3102
yusufod41c5f92015-03-06 00:14:283103 // Reset theme color on navigation to new page.
3104 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223105 }
3106
3107 if (!details.is_in_page) {
3108 // Once the main frame is navigated, we're no longer considered to have
3109 // displayed insecure content.
3110 displayed_insecure_content_ = false;
3111 SSLManager::NotifySSLInternalStateChanged(
3112 GetController().GetBrowserContext());
3113 }
3114
3115 // Notify observers about navigation.
3116 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3117 DidNavigateMainFrame(details, params));
3118
[email protected]e85165c642014-06-10 14:34:313119 if (delegate_)
[email protected]37567b432014-02-12 01:12:223120 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313121 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223122}
3123
3124void WebContentsImpl::DidNavigateAnyFramePostCommit(
3125 RenderFrameHostImpl* render_frame_host,
3126 const LoadCommittedDetails& details,
3127 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103128 // Now that something has committed, we don't need to track whether the
3129 // initial page has been accessed.
3130 has_accessed_initial_document_ = false;
3131
[email protected]37567b432014-02-12 01:12:223132 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173133 if (!details.is_in_page)
3134 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223135
3136 // Notify observers about navigation.
3137 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093138 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223139}
3140
3141void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3142 contents_mime_type_ = mime_type;
3143}
3144
[email protected]277857a2014-06-03 10:38:013145bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313146 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053147 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313148 return false;
3149
[email protected]37567b432014-02-12 01:12:223150 if (delegate_)
3151 return delegate_->CanOverscrollContent();
3152
3153 return false;
3154}
3155
[email protected]37b64c52014-07-11 21:14:053156void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293157 // Update the theme color. This is to be published to observers after the
3158 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283159 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293160
3161 if (did_first_visually_non_empty_paint_ &&
3162 last_sent_theme_color_ != theme_color_) {
3163 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3164 DidChangeThemeColor(theme_color_));
3165 last_sent_theme_color_ = theme_color_;
3166 }
[email protected]e7104762014-06-20 19:17:253167}
3168
[email protected]b172aee2012-04-10 17:05:263169void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183170 const GURL& url,
[email protected]70435962011-08-02 20:13:283171 const std::string& security_info,
3172 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183173 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403174 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533175 SSLStatus status;
3176 if (!DeserializeSecurityInfo(security_info, &status)) {
3177 bad_message::ReceivedBadMessage(
3178 GetRenderProcessHost(),
3179 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3180 return;
3181 }
[email protected]724159a2010-12-30 01:11:183182
3183 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593184 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213185 LoadFromMemoryCacheDetails details(
rob1ca070f2016-01-12 01:06:263186 url, status.cert_id, status.cert_status, http_method, mime_type,
3187 resource_type);
[email protected]724159a2010-12-30 01:11:183188
[email protected]b0f724c2013-09-05 04:21:133189 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3190
3191 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3192 DidLoadResourceFromMemoryCache(details));
3193
[email protected]8bfc8272013-09-09 20:10:533194 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3195 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403196 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533197 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3198 GetRenderProcessHost()->GetID()) :
3199 GetBrowserContext()->GetRequestContextForRenderProcess(
3200 GetRenderProcessHost()->GetID()));
3201 BrowserThread::PostTask(
3202 BrowserThread::IO,
3203 FROM_HERE,
3204 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3205 }
[email protected]724159a2010-12-30 01:11:183206}
3207
[email protected]b172aee2012-04-10 17:05:263208void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393209 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183210 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193211 SSLManager::NotifySSLInternalStateChanged(
3212 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183213}
3214
estark910b4572015-12-09 20:55:413215void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3216 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583217 LOG(WARNING) << security_origin << " ran insecure content from "
3218 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393219 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413220 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293221 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393222 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183223 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193224 SSLManager::NotifySSLInternalStateChanged(
3225 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183226}
3227
estark910b4572015-12-09 20:55:413228void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3229 const GURL& url,
3230 const std::string& security_info) {
3231 SSLStatus ssl;
3232 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3233 bad_message::ReceivedBadMessage(
3234 GetRenderProcessHost(),
3235 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3236 return;
3237 }
3238
3239 displayed_insecure_content_ = true;
3240 SSLManager::NotifySSLInternalStateChanged(
3241 GetController().GetBrowserContext());
3242}
3243
3244void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3245 const GURL& security_origin,
3246 const GURL& url,
3247 const std::string& security_info) {
3248 SSLStatus ssl;
3249 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3250 bad_message::ReceivedBadMessage(
3251 GetRenderProcessHost(),
3252 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3253 return;
3254 }
3255
3256 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3257 SSLManager::NotifySSLInternalStateChanged(
3258 GetController().GetBrowserContext());
3259}
3260
[email protected]501052ff2014-02-21 22:19:073261void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113262 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473263 return;
naskofbd033392015-01-27 02:34:473264
[email protected]1d62cf72014-02-07 21:31:573265 RenderFrameHostImpl* rfh =
3266 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143267 FOR_EACH_OBSERVER(
3268 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183269}
3270
naskofbd033392015-01-27 02:34:473271void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113272 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123273 return;
[email protected]a1b99262013-12-27 21:56:223274
[email protected]8b3af1e2014-01-24 13:29:123275 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443276 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373277 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423278 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373279
[email protected]61ac9e242014-03-21 20:55:263280 RenderFrameHostImpl* rfh =
3281 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143282 FOR_EACH_OBSERVER(
3283 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313284}
3285
[email protected]b172aee2012-04-10 17:05:263286void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573287 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3288 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263289}
3290
[email protected]b172aee2012-04-10 17:05:263291void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303292 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263293 minimum_zoom_percent_ = minimum_percent;
3294 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263295}
3296
mcnee432e47d2015-11-09 19:37:463297void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3298 bool is_one = page_scale_factor == 1.f;
3299 if (is_one != page_scale_factor_is_one_) {
3300 page_scale_factor_is_one_ = is_one;
3301
3302 HostZoomMapImpl* host_zoom_map =
3303 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3304
3305 if (host_zoom_map && GetRenderProcessHost()) {
3306 host_zoom_map->SetPageScaleFactorIsOneForView(
3307 GetRenderProcessHost()->GetID(), GetRoutingID(),
3308 page_scale_factor_is_one_);
3309 }
3310 }
3311
3312 FOR_EACH_OBSERVER(WebContentsObserver,
3313 observers_,
3314 OnPageScaleFactorChanged(page_scale_factor));
3315}
3316
[email protected]b172aee2012-04-10 17:05:263317void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343318 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433319 if (!delegate_)
3320 return;
3321
[email protected]b9535422012-02-09 01:47:593322 ChildProcessSecurityPolicyImpl* policy =
3323 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223324 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593325 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213326}
3327
[email protected]b172aee2012-04-10 17:05:263328void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3329 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263330 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363331 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433332 if (!delegate_)
3333 return;
3334
[email protected]b9535422012-02-09 01:47:593335 ChildProcessSecurityPolicyImpl* policy =
3336 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323337 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593338 return;
[email protected]8f810632013-06-06 22:33:323339
[email protected]c125e532014-05-10 20:39:063340 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203341}
3342
[email protected]f5273e52014-07-14 16:30:203343void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3344 const GURL& url,
3345 bool user_gesture) {
3346 if (!delegate_)
3347 return;
3348
3349 ChildProcessSecurityPolicyImpl* policy =
3350 ChildProcessSecurityPolicyImpl::GetInstance();
3351 if (policy->IsPseudoScheme(protocol))
3352 return;
3353
3354 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3355}
3356
kouhei40f03cb2015-09-24 07:47:013357void WebContentsImpl::OnUpdatePageImportanceSignals(
3358 const PageImportanceSignals& signals) {
3359 page_importance_signals_ = signals;
3360}
3361
[email protected]b172aee2012-04-10 17:05:263362void WebContentsImpl::OnFindReply(int request_id,
3363 int number_of_matches,
3364 const gfx::Rect& selection_rect,
3365 int active_match_ordinal,
3366 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433367 if (delegate_) {
3368 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3369 active_match_ordinal, final_update);
3370 }
[email protected]b888919c2011-09-02 00:32:163371}
3372
mfomitchev2b8b066a2016-01-28 19:23:153373#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313374void WebContentsImpl::OnFindMatchRectsReply(
3375 int version,
3376 const std::vector<gfx::RectF>& rects,
3377 const gfx::RectF& active_rect) {
3378 if (delegate_)
3379 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3380}
[email protected]583418cc2013-01-17 14:01:103381
[email protected]1ff427972013-02-07 21:14:073382void WebContentsImpl::OnOpenDateTimeDialog(
3383 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173384 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093385 GetRenderViewHost(),
3386 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133387 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093388 value.minimum,
3389 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173390 value.step,
3391 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103392}
[email protected]59363fc92012-09-05 03:46:313393#endif
3394
avi60bd4902015-09-23 20:39:243395void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3396 std::string json = json_string;
3397 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3398 Source<WebContents>(this),
3399 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403400}
3401
[email protected]b172aee2012-04-10 17:05:263402void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3403 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103404 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253405 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103406 AppCacheAccessed(manifest_url, blocked_by_policy));
3407}
3408
[email protected]8bc5ff02013-11-29 06:34:033409void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483410 int color_chooser_id,
3411 SkColor color,
3412 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113413 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003414 return;
nasko907fcb62015-01-28 04:24:113415
[email protected]aa62afd2014-04-22 19:22:463416 ColorChooser* new_color_chooser = delegate_ ?
3417 delegate_->OpenColorChooser(this, color, suggestions) :
3418 NULL;
[email protected]820957a2014-01-14 14:56:303419 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213420 return;
[email protected]8ed16472014-04-11 19:02:483421 if (color_chooser_info_.get())
3422 color_chooser_info_->chooser->End();
3423
3424 color_chooser_info_.reset(new ColorChooserInfo(
3425 render_frame_message_source_->GetProcess()->GetID(),
3426 render_frame_message_source_->GetRoutingID(),
3427 new_color_chooser,
3428 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203429}
3430
[email protected]b172aee2012-04-10 17:05:263431void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483432 if (color_chooser_info_ &&
3433 color_chooser_id == color_chooser_info_->identifier)
3434 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203435}
3436
[email protected]b172aee2012-04-10 17:05:263437void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323438 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483439 if (color_chooser_info_ &&
3440 color_chooser_id == color_chooser_info_->identifier)
3441 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203442}
3443
[email protected]d0759f492012-04-19 22:50:503444// This exists for render views that don't have a WebUI, but do have WebUI
3445// bindings enabled.
3446void WebContentsImpl::OnWebUISend(const GURL& source_url,
3447 const std::string& name,
3448 const base::ListValue& args) {
3449 if (delegate_)
3450 delegate_->WebUISend(this, source_url, name, args);
3451}
3452
thestigc4cac8f2014-09-04 21:17:503453#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003454void WebContentsImpl::OnPepperInstanceCreated() {
3455 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3456}
3457
3458void WebContentsImpl::OnPepperInstanceDeleted() {
3459 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3460}
3461
tommyclie6633ca72014-10-31 00:40:423462void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3463 const base::FilePath& path,
3464 bool is_hung) {
3465 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3466
3467 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3468 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3469}
3470
3471void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3472 base::ProcessId plugin_pid) {
3473 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3474 PluginCrashed(plugin_path, plugin_pid));
3475}
3476
[email protected]d8415ad92012-08-23 14:40:503477void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443478 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503479 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343480 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163481 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443482 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163483 return;
[email protected]d8415ad92012-08-23 14:40:503484 }
3485
[email protected]8c8fc292012-11-23 18:57:163486 if (!delegate_->RequestPpapiBrokerPermission(
3487 this, url, plugin_path,
3488 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443489 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163490 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443491 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163492 }
[email protected]d8415ad92012-08-23 14:40:503493}
3494
[email protected]ea0309c2013-08-06 19:35:443495void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503496 bool result) {
[email protected]ea0309c2013-08-06 19:35:443497 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503498}
3499
fsamuel833ee7c2015-02-13 23:40:403500void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3501 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393502 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143503 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403504 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373505}
tommyclie6633ca72014-10-31 00:40:423506#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373507
[email protected]795c28972012-12-06 06:13:393508void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393509 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063510 // We get updated favicon URLs after the page stops loading. If a cross-site
3511 // navigation occurs while a page is still loading, the initial page
3512 // may stop loading and send us updated favicon URLs after the navigation
3513 // for the new page has committed.
3514 RenderViewHostImpl* rvhi =
3515 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3516 if (!rvhi->is_active())
3517 return;
3518
[email protected]795c28972012-12-06 06:13:393519 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293520 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393521}
3522
avayvod41634b12015-07-08 17:07:053523#if defined(OS_ANDROID)
3524
3525void WebContentsImpl::OnMediaSessionStateChanged() {
3526 MediaSession* session = MediaSession::Get(this);
3527 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3528 MediaSessionStateChanged(session->IsControllable(),
3529 session->IsSuspended()));
3530}
3531
3532void WebContentsImpl::ResumeMediaSession() {
3533 MediaSession::Get(this)->Resume();
3534}
3535
3536void WebContentsImpl::SuspendMediaSession() {
3537 MediaSession::Get(this)->Suspend();
3538}
3539
mlamouri4c4fbed2015-08-17 15:51:013540void WebContentsImpl::StopMediaSession() {
3541 MediaSession::Get(this)->Stop();
3542}
3543
avayvod41634b12015-07-08 17:07:053544#endif // defined(OS_ANDROID)
3545
[email protected]50279492014-05-05 23:24:293546void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153547 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293548 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283549
peter90afaba2015-06-01 12:05:293550 did_first_visually_non_empty_paint_ = true;
3551
yusufod41c5f92015-03-06 00:14:283552 if (theme_color_ != last_sent_theme_color_) {
3553 // Theme color should have updated by now if there was one.
3554 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3555 DidChangeThemeColor(theme_color_));
3556 last_sent_theme_color_ = theme_color_;
3557 }
[email protected]9f268072013-11-07 00:02:153558}
[email protected]d9030b82013-07-19 08:26:063559
[email protected]e67ebf32013-02-13 11:07:193560void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013561 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073562 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013563
estark5ea80e52015-06-19 18:43:123564 SecurityStyleExplanations security_style_explanations;
3565 SecurityStyle security_style =
3566 delegate_->GetSecurityStyle(this, &security_style_explanations);
3567 FOR_EACH_OBSERVER(
3568 WebContentsObserver, observers_,
3569 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013570 }
[email protected]e67ebf32013-02-13 11:07:193571}
3572
[email protected]17e286e2013-03-01 23:29:393573void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3574 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3575 BeforeFormRepostWarningShow());
3576}
3577
[email protected]ec6c05f2013-10-23 18:41:573578void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3579 Activate();
3580 if (delegate_)
3581 delegate_->ShowRepostFormWarningDialog(this);
3582}
3583
[email protected]b4c84012014-04-28 19:51:103584bool WebContentsImpl::HasAccessedInitialDocument() {
3585 return has_accessed_initial_document_;
3586}
3587
[email protected]96d185d2009-04-24 03:28:543588// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593589// loading, or done loading.
waffles1c12bf402016-02-10 17:45:483590void WebContentsImpl::SetIsLoading(bool is_loading,
3591 bool to_different_document,
3592 LoadNotificationDetails* details) {
3593 if (is_loading == is_loading_)
[email protected]96d185d2009-04-24 03:28:543594 return;
3595
3596 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263597 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3598 base::string16());
[email protected]96d185d2009-04-24 03:28:543599 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563600 upload_size_ = 0;
3601 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543602 }
3603
[email protected]fa944cb82013-11-15 17:51:213604 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543605
waffles1c12bf402016-02-10 17:45:483606 is_loading_ = is_loading;
[email protected]96d185d2009-04-24 03:28:543607 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033608 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543609
[email protected]6ebdc9b2010-09-27 16:55:573610 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093611 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213612 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543613
[email protected]eab61442013-11-14 18:35:483614 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593615 if (is_loading) {
carloskc13951a2015-12-30 16:51:543616 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3617 this, "URL", url, "Main FrameTreeNode id",
3618 GetFrameTree()->root()->frame_tree_node_id());
fdegans6ce28f52015-03-19 12:52:223619 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]91621872013-10-08 04:04:593620 } else {
naskob8744d22014-08-28 17:07:433621 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3622 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223623 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]91621872013-10-08 04:04:593624 }
[email protected]66798902013-10-01 18:40:163625
3626 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213627 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3628 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543629 if (details)
[email protected]8ff00d72012-10-23 19:12:213630 det = Details<LoadNotificationDetails>(details);
3631 NotificationService::current()->Notify(
3632 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543633}
3634
[email protected]b172aee2012-04-10 17:05:263635void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463636 // If we are creating a RVH for a restored controller, then we need to make
3637 // sure the RenderView starts with a next_page_id_ larger than the number
3638 // of restored entries. This must be called before the RenderView starts
3639 // navigating (to avoid a race between the browser updating max_page_id and
3640 // the renderer updating next_page_id_). Because of this, we only call this
3641 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563642 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583643 if (max_restored_page_id >
3644 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3645 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3646 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323647}
3648
[email protected]b172aee2012-04-10 17:05:263649bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263650 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323651 // For file URLs without a title, use the pathname instead. In the case of a
3652 // synthesized title, we don't want the update to count toward the "one set
3653 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263654 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323655 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513656 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243657 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323658 explicit_set = false; // Don't count synthetic titles toward the set limit.
3659 } else {
[email protected]8af69c6c2014-03-03 19:05:313660 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323661 explicit_set = true;
3662 }
3663
[email protected]987fc3a2011-05-26 14:18:093664 // If a page is created via window.open and never navigated,
3665 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553666 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093667 if (entry) {
[email protected]36fc0392011-12-25 03:59:513668 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093669 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323670
[email protected]36fc0392011-12-25 03:59:513671 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093672 } else {
3673 if (page_title_when_no_navigation_entry_ == final_title)
3674 return false; // Nothing changed, don't bother.
3675
3676 page_title_when_no_navigation_entry_ = final_title;
3677 }
[email protected]420ae012009-04-24 05:16:323678
[email protected]420ae012009-04-24 05:16:323679 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233680 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323681
[email protected]66798902013-10-01 18:40:163682 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533683 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163684
[email protected]420ae012009-04-24 05:16:323685 return true;
3686}
3687
fdegansa696e5112015-04-17 01:57:593688void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003689 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003690 if (delegate_)
fdegansa696e5112015-04-17 01:57:593691 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003692}
3693
3694void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343695 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003696 loading_weak_factory_.InvalidateWeakPtrs();
3697 loading_last_progress_update_ = base::TimeTicks();
3698}
3699
[email protected]02d7b6e2014-06-24 21:01:503700void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3701 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323702 // After sending out a swap notification, we need to send a disconnect
3703 // notification so that clients that pick up a pointer to |this| can NULL the
3704 // pointer. See Bug 1230284.
3705 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113706 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283707 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113708
[email protected]7a846df2012-09-20 19:17:393709 // Ensure that the associated embedder gets cleared after a RenderViewHost
3710 // gets swapped, so we don't reuse the same embedder next time a
3711 // RenderViewHost is attached to this WebContents.
3712 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323713}
3714
[email protected]02d7b6e2014-06-24 21:01:503715void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3716 RenderFrameHost* new_host) {
3717 FOR_EACH_OBSERVER(WebContentsObserver,
3718 observers_,
3719 RenderFrameHostChanged(old_host, new_host));
3720}
3721
[email protected]da7a7182013-09-06 08:11:113722// TODO(avi): Remove this entire function because this notification is already
3723// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263724void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323725 if (!notify_disconnection_)
3726 return;
3727
3728 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213729 NotificationService::current()->Notify(
3730 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3731 Source<WebContents>(this),
3732 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323733}
3734
[email protected]cbb1ef592013-06-05 19:49:463735void WebContentsImpl::NotifyNavigationEntryCommitted(
3736 const LoadCommittedDetails& load_details) {
3737 FOR_EACH_OBSERVER(
3738 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3739}
3740
[email protected]f114fa42013-12-06 17:06:443741bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3742 const IPC::Message& message) {
3743 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313744}
3745
[email protected]c31a84802014-04-03 15:55:493746const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3747 return GetLastCommittedURL();
3748}
3749
[email protected]b849847b2013-12-10 21:57:583750void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583751 FOR_EACH_OBSERVER(WebContentsObserver,
3752 observers_,
3753 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303754 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583755}
3756
3757void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3758 FOR_EACH_OBSERVER(WebContentsObserver,
3759 observers_,
3760 RenderFrameDeleted(render_frame_host));
3761}
3762
[email protected]a09d53ce2014-01-31 00:46:423763void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3764 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103765 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423766 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103767 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423768 return;
3769
[email protected]077e704b2014-05-23 19:24:103770 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3771 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423772}
3773
[email protected]87de04b02014-04-08 22:14:493774void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013775 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493776 const base::string16& message,
3777 const base::string16& default_prompt,
3778 const GURL& frame_url,
3779 JavaScriptMessageType javascript_message_type,
3780 IPC::Message* reply_msg) {
3781 // Suppress JavaScript dialogs when requested. Also suppress messages when
3782 // showing an interstitial as it's shown over the previous page and we don't
3783 // want the hidden page's dialogs to interfere with the interstitial.
3784 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223785 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503786 ShowingInterstitialPage() || !delegate_ ||
3787 delegate_->ShouldSuppressDialogs(this) ||
3788 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493789
3790 if (!suppress_this_message) {
3791 std::string accept_lang = GetContentClient()->browser()->
3792 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503793 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493794 dialog_manager_->RunJavaScriptDialog(
palmer4e0ae10d2015-09-03 23:38:413795 this, frame_url, accept_lang, javascript_message_type, message,
[email protected]87de04b02014-04-08 22:14:493796 default_prompt,
palmer4e0ae10d2015-09-03 23:38:413797 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013798 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413799 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493800 &suppress_this_message);
3801 }
3802
3803 if (suppress_this_message) {
3804 // If we are suppressing messages, just reply as if the user immediately
3805 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013806 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3807 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283808 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493809 }
3810
3811 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3812 // http://crbug.com/288961 ). The only safe thing to do here is return.
3813}
3814
3815void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013816 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493817 const base::string16& message,
3818 bool is_reload,
3819 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013820 RenderFrameHostImpl* rfhi =
3821 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493822 if (delegate_)
3823 delegate_->WillRunBeforeUnloadConfirm();
3824
3825 bool suppress_this_message =
creis36e228b2015-06-08 18:48:023826 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT ||
3827 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:503828 delegate_->ShouldSuppressDialogs(this) ||
3829 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493830 if (suppress_this_message) {
3831 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3832 return;
3833 }
3834
3835 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503836 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493837 dialog_manager_->RunBeforeUnloadDialog(
3838 this, message, is_reload,
3839 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013840 render_frame_host->GetProcess()->GetID(),
3841 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283842 false));
[email protected]87de04b02014-04-08 22:14:493843}
3844
[email protected]a86c0e962013-12-17 17:10:393845WebContents* WebContentsImpl::GetAsWebContents() {
3846 return this;
3847}
3848
[email protected]7912e822014-04-16 02:37:033849bool WebContentsImpl::IsNeverVisible() {
3850 if (!delegate_)
3851 return false;
3852 return delegate_->IsNeverVisible(this);
3853}
3854
[email protected]95640212014-07-26 18:14:303855#if defined(OS_WIN)
3856gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3857 return accessible_parent_;
3858}
3859#endif
3860
[email protected]5a3bdf52012-05-24 15:12:573861RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3862 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323863}
3864
[email protected]8ff00d72012-10-23 19:12:213865RendererPreferences WebContentsImpl::GetRendererPrefs(
3866 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463867 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513868}
3869
avic3aa8422015-11-09 20:57:223870gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
3871 RenderWidgetHostImpl* render_widget_host) const {
3872 if (!RenderViewHostImpl::From(render_widget_host))
3873 return gfx::Rect();
3874
[email protected]b7a756d42012-01-23 18:08:173875 if (delegate_)
3876 return delegate_->GetRootWindowResizerRect();
3877 return gfx::Rect();
3878}
3879
[email protected]7a846df2012-09-20 19:17:393880void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273881 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393882 browser_plugin_embedder_.reset();
3883}
3884
[email protected]b172aee2012-04-10 17:05:263885void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443886 // Don't send notifications if we are just creating a swapped-out RVH for
3887 // the opener chain. These won't be used for view-source or WebUI, so it's
3888 // ok to return early.
creiscce56cd2014-09-29 22:45:223889 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443890 return;
3891
[email protected]86f98a22013-03-20 14:35:003892 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313893 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083894
[email protected]8ff00d72012-10-23 19:12:213895 NotificationService::current()->Notify(
3896 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3897 Source<WebContents>(this),
3898 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323899
[email protected]6286a372013-10-09 04:03:273900 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333901 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323902 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183903 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583904 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323905 }
[email protected]0666aef2009-05-13 19:48:083906
[email protected]60780f412013-02-25 16:34:103907 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263908
3909 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253910 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:323911}
3912
[email protected]b172aee2012-04-10 17:05:263913void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523914 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323915 // Don't notify the world, since this came from a renderer in the
3916 // background.
3917 return;
3918 }
3919
[email protected]da7a7182013-09-06 08:11:113920 notify_disconnection_ = true;
3921 // TODO(avi): Remove. http://crbug.com/170921
3922 NotificationService::current()->Notify(
3923 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3924 Source<WebContents>(this),
3925 NotificationService::NoDetails());
3926
[email protected]be1f56ab2011-12-22 06:55:313927 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233928 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303929
3930 // Restore the focus to the tab (otherwise the focus will be on the top
3931 // window).
[email protected]484ae5912010-09-29 19:16:143932 if (was_crashed && !FocusLocationBarByDefault() &&
3933 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063934 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143935 }
[email protected]32ded2212011-11-10 18:51:433936
[email protected]d8c660432011-12-22 20:51:253937 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323938}
3939
[email protected]ec6a7eb2013-04-22 17:34:223940void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3941 base::TerminationStatus status,
3942 int error_code) {
[email protected]151a63d2011-12-20 22:32:523943 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323944 // The pending page's RenderViewHost is gone.
3945 return;
3946 }
3947
[email protected]2fcdcc32014-03-05 02:14:073948 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3949 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:523950 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463951 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:073952
[email protected]698191dc2014-02-25 01:06:133953 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:173954 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:133955
[email protected]f738bdcb2014-07-11 20:40:443956 if (delegate_)
3957 delegate_->HideValidationMessage(this);
3958
waffles1c12bf402016-02-10 17:45:483959 SetIsLoading(false, true, nullptr);
3960 NotifyDisconnected();
3961 SetIsCrashed(status, error_code);
3962
[email protected]960b0372014-05-19 18:01:003963 // Reset the loading progress. TODO(avi): What does it mean to have a
3964 // "renderer crash" when there is more than one renderer process serving a
3965 // webpage? Once this function is called at a more granular frame level, we
3966 // probably will need to more granularly reset the state here.
3967 ResetLoadProgressState();
[email protected]960b0372014-05-19 18:01:003968
[email protected]d8c660432011-12-22 20:51:253969 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273970 observers_,
[email protected]58d5cfe2013-07-10 02:40:523971 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323972}
3973
[email protected]b172aee2012-04-10 17:05:263974void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253975 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063976}
3977
[email protected]b172aee2012-04-10 17:05:263978void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:103979 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:043980 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:383981 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
3982
creise1d3e5b2014-12-01 18:21:573983 // Ensure that this state update comes from a RenderViewHost that belongs to
3984 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413985 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:573986 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413987 return;
[email protected]420ae012009-04-24 05:16:323988
avi286019ce2015-07-29 01:26:583989 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:323990 // when the user is scrolling and entering form data, as well as when we're
3991 // leaving a page, in which case our state may have already been moved to
3992 // the next page. The navigation controller will look up the appropriate
3993 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:583994 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:113995 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:583996 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:113997 if (!entry)
[email protected]420ae012009-04-24 05:16:323998 return;
[email protected]420ae012009-04-24 05:16:323999
nasko346969912015-12-16 22:36:474000 // Sanity check that ensures nav_entry_id and page_id point to the same
4001 // navigation entry.
4002 if (rvhi->GetMainFrame()) {
4003 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4004 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4005 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534006
nasko346969912015-12-16 22:36:474007 DCHECK_EQ(entry, new_entry);
4008 }
creisd63f6c4a2015-11-06 19:05:534009
[email protected]691aa2f2013-05-28 22:52:044010 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324011 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044012 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114013 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324014}
4015
sky8b00392d2015-01-10 00:30:284016void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4017 const GURL& url) {
4018 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4019 // If we're fullscreen only update the url if it's from the fullscreen
4020 // renderer.
4021 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444022 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284023 return;
4024 }
[email protected]6934a702011-12-20 00:04:514025 if (delegate_)
avi450ce00e2014-09-24 01:58:524026 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324027}
4028
[email protected]b172aee2012-04-10 17:05:264029void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104030#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294031 // The UI may be in an event-tracking loop, such as between the
4032 // mouse-down and mouse-up in text selection or a button click.
4033 // Defer the close until after tracking is complete, so that we
4034 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294035 // TODO(shess): This could get more fine-grained. For instance,
4036 // closing a tab in another window while selecting text in the
4037 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104038 if (view_->IsEventTracking()) {
4039 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294040 return;
4041 }
[email protected]60780f412013-02-25 16:34:104042#endif
[email protected]07707302009-11-06 00:50:294043
[email protected]420ae012009-04-24 05:16:324044 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524045 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514046 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324047}
4048
[email protected]66bbadaf2014-03-28 16:25:544049void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574050 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4051 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574052}
4053
[email protected]b172aee2012-04-10 17:05:264054void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514055 if (delegate_ && delegate_->IsPopupOrPanel(this))
4056 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324057}
4058
fdegansa696e5112015-04-17 01:57:594059void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094060 bool to_different_document) {
waffles1c12bf402016-02-10 17:45:484061 SetIsLoading(true, to_different_document, nullptr);
dmazzonibf8cec42015-02-08 08:28:084062
4063 // Notify accessibility that the user is navigating away from the
4064 // current document.
4065 //
4066 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084067 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594068 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084069 if (manager)
4070 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324071}
4072
fdegansc73eec22015-03-19 14:47:544073void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:324074 scoped_ptr<LoadNotificationDetails> details;
4075
[email protected]9595fd82013-04-19 21:28:494076 // Use the last committed entry rather than the active one, in case a
4077 // pending entry has been created.
4078 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204079 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494080
[email protected]420ae012009-04-24 05:16:324081 // An entry may not exist for a stop when loading an initial blank page or
4082 // if an iframe injected by script into a blank page finishes loading.
4083 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204084 base::TimeDelta elapsed =
4085 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324086
4087 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514088 entry->GetVirtualURL(),
4089 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:324090 elapsed,
4091 &controller_,
4092 controller_.GetCurrentEntryIndex()));
4093 }
4094
waffles1c12bf402016-02-10 17:45:484095 SetIsLoading(false, true, details.get());
[email protected]420ae012009-04-24 05:16:324096}
4097
fdegansa696e5112015-04-17 01:57:594098void WebContentsImpl::DidChangeLoadProgress() {
4099 double load_progress = frame_tree_.load_progress();
4100
4101 // The delegate is notified immediately for the first and last updates. Also,
4102 // since the message loop may be pretty busy when a page is loaded, it might
4103 // not execute a posted task in a timely manner so the progress report is sent
4104 // immediately if enough time has passed.
4105 base::TimeDelta min_delay =
4106 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4107 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4108 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4109
4110 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4111 // If there is a pending task to send progress, it is now obsolete.
4112 loading_weak_factory_.InvalidateWeakPtrs();
4113
4114 // Notify the load progress change.
4115 SendChangeLoadProgress();
4116
4117 // Clean-up the states if needed.
4118 if (load_progress == 1.0)
4119 ResetLoadProgressState();
4120 return;
4121 }
4122
4123 if (loading_weak_factory_.HasWeakPtrs())
4124 return;
4125
skyostil95082a62015-06-05 19:53:074126 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4127 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4128 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594129 min_delay);
4130}
4131
[email protected]b172aee2012-04-10 17:05:264132void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164133 controller_.DiscardNonCommittedEntries();
4134
4135 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214136 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164137}
4138
[email protected]59167c22013-06-03 18:07:324139void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104140 has_accessed_initial_document_ = true;
4141
[email protected]d1371bf8e2014-04-19 03:26:244142 // We may have left a failed browser-initiated navigation in the address bar
4143 // to let the user edit it and try again. Clear it now that content might
4144 // show up underneath it.
4145 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454146 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244147
[email protected]59167c22013-06-03 18:07:324148 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504149 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324150}
4151
alexmosbe2f4c32015-03-10 02:30:234152void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4153 const std::string& name) {
4154 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4155 FrameNameChanged(render_frame_host, name));
4156}
4157
[email protected]39f2f9252014-05-03 00:54:014158void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294159 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094160 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294161 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094162
4163 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214164 NotificationService::current()->Notify(
4165 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4166 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294167 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084168}
4169
creis8eb8ef22015-11-04 22:51:384170void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4171 const PageState& page_state) {
4172 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4173
4174 // The state update affects the last NavigationEntry associated with the given
4175 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4176 // in the case of an UpdateState from a frame being swapped out). We track
4177 // which entry this is in the RenderFrameHost's nav_entry_id.
4178 RenderFrameHostImpl* rfhi =
4179 static_cast<RenderFrameHostImpl*>(render_frame_host);
4180 NavigationEntryImpl* entry =
4181 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4182 if (!entry)
4183 return;
4184
4185 FrameNavigationEntry* frame_entry =
4186 entry->GetFrameEntry(rfhi->frame_tree_node());
4187 if (!frame_entry)
4188 return;
4189
creisd06a9422015-11-11 03:08:454190 // The SiteInstance might not match if we do a cross-process navigation with
4191 // replacement (e.g., auto-subframe), in which case the swap out of the old
4192 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4193 // has already been replaced and destroyed.
4194 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4195 return;
4196
creis8eb8ef22015-11-04 22:51:384197 if (page_state == frame_entry->page_state())
4198 return; // Nothing to update.
4199
4200 frame_entry->set_page_state(page_state);
4201 controller_.NotifyEntryChanged(entry);
4202}
4203
[email protected]ef3adfc2014-05-11 00:04:544204void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104205 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544206 const base::string16& title,
4207 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544208 // If we have a title, that's a pretty good indication that we've started
4209 // getting useful data.
4210 SetNotWaitingForResponse();
4211
4212 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584213 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544214 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584215 render_frame_host->GetSiteInstance(), page_id);
4216
creisd63f6c4a2015-11-06 19:05:534217 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4218 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
4219 DCHECK_EQ(entry, new_entry);
[email protected]ef3adfc2014-05-11 00:04:544220
4221 // We can handle title updates when we don't have an entry in
4222 // UpdateTitleForEntry, but only if the update is from the current RVH.
4223 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584224 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544225 return;
4226
4227 // TODO(evan): make use of title_direction.
4228 // http://code.google.com/p/chromium/issues/detail?id=27094
4229 if (!UpdateTitleForEntry(entry, title))
4230 return;
4231
4232 // Broadcast notifications when the UI should be updated.
4233 if (entry == controller_.GetEntryAtOffset(0))
4234 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4235}
4236
4237void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4238 const std::string& encoding) {
4239 SetEncoding(encoding);
4240}
4241
[email protected]39f2f9252014-05-03 00:54:014242void WebContentsImpl::DocumentAvailableInMainFrame(
4243 RenderViewHost* render_view_host) {
4244 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4245 DocumentAvailableInMainFrame());
4246}
naskoc0fceff2015-04-30 15:53:524247
[email protected]e1c3a552012-05-04 20:51:324248void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4249 // Tell the active RenderViewHost to run unload handlers and close, as long
4250 // as the request came from a RenderViewHost in the same BrowsingInstance.
4251 // In most cases, we receive this from a swapped out RenderViewHost.
4252 // It is possible to receive it from one that has just been swapped in,
4253 // in which case we might as well deliver the message anyway.
4254 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524255 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324256}
4257
alexmose7da5a12015-04-09 02:22:164258bool WebContentsImpl::ShouldRouteMessageEvent(
4259 RenderFrameHost* target_rfh,
4260 SiteInstance* source_site_instance) const {
4261 // Allow the message if this WebContents is dedicated to a browser plugin
4262 // guest.
[email protected]0eba810b2012-10-18 03:19:364263 // Note: This check means that an embedder could theoretically receive a
4264 // postMessage from anyone (not just its own guests). However, this is
4265 // probably not a risk for apps since other pages won't have references
4266 // to App windows.
alexmose7da5a12015-04-09 02:22:164267 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4268}
[email protected]f546640b2012-05-15 00:03:494269
alexmos58729042015-06-18 23:20:004270void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164271 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4272 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494273
alexmose7da5a12015-04-09 02:22:164274 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144275 // If this message is going to outer WebContents from inner WebContents,
4276 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4277 // already created a RenderFrameProxyHost for that purpose.
4278 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084279 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144280 return;
4281 }
4282
lfg812874d2016-02-09 22:26:134283 if (this != source_web_contents && GetBrowserPluginGuest()) {
nasko5fb985b2015-08-20 17:28:164284 // We create a swapped out RenderView or RenderFrameProxyHost for the
4285 // embedder in the guest's render process but we intentionally do not
4286 // expose the embedder's opener chain to it.
4287 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
4288 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4289 GetSiteInstance());
4290 } else {
4291 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance());
4292 }
[email protected]f546640b2012-05-15 00:03:494293 } else {
alexmos58729042015-06-18 23:20:004294 RenderFrameHostImpl* source_rfhi =
4295 static_cast<RenderFrameHostImpl*>(source_rfh);
4296 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394297 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494298 }
4299 }
[email protected]f546640b2012-05-15 00:03:494300}
4301
avib7348942015-12-25 20:57:104302bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264303 const base::string16& message,
avib7348942015-12-25 20:57:104304 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264305 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254306 if (!delegate_)
4307 return false;
4308 return delegate_->AddMessageToConsole(this, level, message, line_no,
4309 source_id);
4310}
4311
[email protected]0eba810b2012-10-18 03:19:364312int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214313 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294314 int render_view_routing_id = MSG_ROUTING_NONE;
nickac60e75472015-07-31 00:44:354315 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
nasko4c0feb62015-06-05 18:37:064316 GetRenderManager()->CreateRenderFrameProxy(instance);
4317 } else {
4318 GetRenderManager()->CreateRenderFrame(
carlosk35f35af2015-12-01 10:55:404319 instance, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN,
nasko4c0feb62015-06-05 18:37:064320 &render_view_routing_id);
4321 }
carlosk37f793792014-11-27 15:08:294322 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364323}
4324
avic3aa8422015-11-09 20:57:224325void WebContentsImpl::OnUserGesture(RenderWidgetHostImpl* render_widget_host) {
4326 if (render_widget_host != GetRenderViewHost()->GetWidget())
4327 return;
4328
[email protected]ddb85052011-05-18 14:40:274329 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254330 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224331
[email protected]ea114722012-03-12 01:11:254332 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174333 if (rdh) // NULL in unittests.
4334 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254335}
4336
dominickn2dd142dd2015-10-29 05:30:504337void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) {
4338 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4339 DidGetUserInteraction(type));
4340}
4341
[email protected]b172aee2012-04-10 17:05:264342void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444343 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254344 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444345}
4346
avic3aa8422015-11-09 20:57:224347void WebContentsImpl::RendererUnresponsive(
4348 RenderWidgetHostImpl* render_widget_host) {
[email protected]992db4c2011-05-12 15:37:154349 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224350 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154351 return;
4352
creiscce56cd2014-09-29 22:45:224353 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224354 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584355
[email protected]e5fc1632011-08-08 07:51:534356 // Ignore renderer unresponsive event if debugger is attached to the tab
4357 // since the event may be a result of the renderer sitting on a breakpoint.
4358 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364359 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534360 return;
4361
clamy226727e2015-06-29 10:28:474362 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224363 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324364 // Hang occurred while firing the beforeunload/unload handler.
4365 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224366 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324367
[email protected]fa944cb82013-11-15 17:51:214368 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324369 return;
4370
4371 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564372 // nothing we can do to recover. If the hang is in the beforeunload handler,
4373 // pretend the beforeunload listeners have all fired and allow the delegate
4374 // to continue closing; the user will not have the option of cancelling the
4375 // close. Otherwise, pretend the unload listeners have all fired and close
4376 // the tab.
4377 bool close = true;
clamy226727e2015-06-29 10:28:474378 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564379 delegate_->BeforeUnloadFired(this, true, &close);
4380 }
4381 if (close)
avic3aa8422015-11-09 20:57:224382 Close();
[email protected]420ae012009-04-24 05:16:324383 return;
4384 }
4385
creisc014b402015-04-23 16:41:454386 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474387 return;
4388
[email protected]6934a702011-12-20 00:04:514389 if (delegate_)
4390 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324391}
4392
avic3aa8422015-11-09 20:57:224393void WebContentsImpl::RendererResponsive(
4394 RenderWidgetHostImpl* render_widget_host) {
4395 if (render_widget_host != GetRenderViewHost()->GetWidget())
4396 return;
4397
[email protected]6934a702011-12-20 00:04:514398 if (delegate_)
4399 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324400}
4401
[email protected]b172aee2012-04-10 17:05:264402void WebContentsImpl::LoadStateChanged(
4403 const GURL& url,
4404 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104405 uint64_t upload_position,
4406 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544407 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4408 // is fixed.
4409 tracked_objects::ScopedTracker tracking_profile1(
4410 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4411 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324412 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564413 upload_position_ = upload_position;
4414 upload_size_ = upload_size;
rsleevi24f64dc22015-08-07 21:39:214415 load_state_host_ = url_formatter::IDNToUnicode(
4416 url.host(),
4417 GetContentClient()->browser()->GetAcceptLangs(GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214418 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324419 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464420 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224421 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4422 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464423 }
[email protected]420ae012009-04-24 05:16:324424}
4425
[email protected]b172aee2012-04-10 17:05:264426void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554427 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324428 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124429 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4430 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514431 if (delegate_)
4432 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094433 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324434}
4435
[email protected]58d5cfe2013-07-10 02:40:524436void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544437 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234438 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224439 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544440}
4441
[email protected]b172aee2012-04-10 17:05:264442void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104443 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214444 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264445 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4446 // here during container initialization and normal window size will be set
4447 // later. In case of tab duplication this resizing to 0x0 prevents setting
4448 // normal size later so just ignore it.
4449 if (!size.IsEmpty())
4450 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324451}
4452
[email protected]af905902013-10-01 21:38:514453void WebContentsImpl::CancelModalDialogsForRenderManager() {
4454 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544455 // deferrer would prevent us from swapping out. We also clear the state
4456 // because this is a cross-process navigation, which means that it's a new
4457 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174458 //
4459 // Note that we don't bother telling browser_plugin_embedder_ because the
4460 // cross-process navigation will either destroy the browser plugins or not
4461 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514462 if (dialog_manager_)
avi2460c762015-04-17 15:21:544463 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514464}
4465
[email protected]02d7b6e2014-06-24 21:01:504466void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4467 RenderFrameHost* new_host,
4468 bool is_main_frame) {
4469 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054470 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504471 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084472
[email protected]02d7b6e2014-06-24 21:01:504473 // Make sure the visible RVH reflects the new delegate's preferences.
4474 if (delegate_)
4475 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394476
[email protected]02d7b6e2014-06-24 21:01:504477 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4478 }
4479
4480 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544481}
4482
naskof5940b9f2015-03-02 23:04:054483void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4484 RenderViewHost* old_host,
4485 RenderViewHost* new_host) {
4486 NotifyViewSwapped(old_host, new_host);
4487}
4488
[email protected]b172aee2012-04-10 17:05:264489NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194490 return GetController();
[email protected]3a3d47472010-07-15 21:03:544491}
4492
carlosk35f35af2015-12-01 10:55:404493scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294494 const GURL& url) {
dbeama1b926a2015-08-31 23:17:514495 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(
4496 url, std::string())));
[email protected]420ae012009-04-24 05:16:324497}
4498
[email protected]10f417c52011-12-28 21:04:234499NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264500 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324501 return controller_.GetLastCommittedEntry();
4502}
4503
lfgbede6392015-09-11 21:54:064504void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4505 RenderViewHost* render_view_host) {
4506 RenderWidgetHostViewBase* rwh_view = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:144507 bool is_guest_in_site_per_process =
4508 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084509 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lfgbede6392015-09-11 21:54:064510 if (is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164511 RenderWidgetHostViewChildFrame* rwh_view_child =
avif9ab5d942015-10-15 14:05:444512 new RenderWidgetHostViewChildFrame(render_view_host->GetWidget());
[email protected]bffc8302014-01-23 20:52:164513 rwh_view = rwh_view_child;
4514 } else {
avif9ab5d942015-10-15 14:05:444515 rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]bffc8302014-01-23 20:52:164516 }
[email protected]1a98a932009-11-17 00:12:524517
[email protected]420ae012009-04-24 05:16:324518 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444519 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214520 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064521}
4522
4523bool WebContentsImpl::CreateRenderViewForRenderManager(
4524 RenderViewHost* render_view_host,
4525 int opener_frame_routing_id,
4526 int proxy_routing_id,
4527 const FrameReplicationState& replicated_frame_state) {
4528 TRACE_EVENT0("browser,navigation",
4529 "WebContentsImpl::CreateRenderViewForRenderManager");
4530
4531 if (proxy_routing_id == MSG_ROUTING_NONE)
4532 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324533
[email protected]74ce1ad2011-12-16 21:51:464534 // Make sure we use the correct starting page_id in the new RenderView.
4535 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104536 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584537 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464538
alexmos5ac402d2015-07-09 07:51:104539 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4540 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4541 max_page_id, replicated_frame_state,
4542 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524543 return false;
[email protected]14392a52012-05-02 20:28:444544 }
[email protected]a4127722011-04-27 23:13:524545
avi2b177592014-12-10 02:08:024546 SetHistoryOffsetAndLengthForView(render_view_host,
4547 controller_.GetLastCommittedEntryIndex(),
4548 controller_.GetEntryCount());
4549
[email protected]a220b5932013-09-21 03:47:444550#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504551 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4552 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444553 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444554 if (rwh_view) {
4555 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4556 render_widget_host->WasResized();
4557 }
[email protected]f8233cc2011-05-31 20:24:504558#endif
4559
[email protected]420ae012009-04-24 05:16:324560 return true;
4561}
4562
[email protected]82307f6b2014-08-07 03:30:124563bool WebContentsImpl::CreateRenderFrameForRenderManager(
4564 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044565 int proxy_routing_id,
4566 int opener_routing_id,
japhete6adf142014-10-31 00:01:494567 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044568 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434569 TRACE_EVENT0("browser,navigation",
4570 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124571
4572 RenderFrameHostImpl* rfh =
4573 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044574 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4575 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124576 return false;
4577
4578 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4579 // RenderFrameHost will have to be associated with the appropriate
4580 // RenderWidgetHostView or a new one should be created here.
4581
4582 return true;
4583}
4584
mfomitchev2b8b066a2016-01-28 19:23:154585#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454586
[email protected]155c7f22013-12-09 17:07:184587base::android::ScopedJavaLocalRef<jobject>
4588WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404589 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564590 return GetWebContentsAndroid()->GetJavaObject();
4591}
[email protected]155c7f22013-12-09 17:07:184592
[email protected]0e813a52014-08-13 10:34:564593WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184594 WebContentsAndroid* web_contents_android =
4595 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4596 if (!web_contents_android) {
4597 web_contents_android = new WebContentsAndroid(this);
4598 SetUserData(kWebContentsAndroidKey, web_contents_android);
4599 }
[email protected]0e813a52014-08-13 10:34:564600 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184601}
4602
[email protected]7d244f12013-08-22 21:41:514603bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064604 return CreateRenderViewForRenderManager(
4605 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064606 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514607}
[email protected]fc2b46b2014-05-03 16:33:454608
4609#elif defined(OS_MACOSX)
4610
[email protected]75f4df72014-07-16 22:39:424611void WebContentsImpl::SetAllowOtherViews(bool allow) {
4612 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454613}
4614
[email protected]75f4df72014-07-16 22:39:424615bool WebContentsImpl::GetAllowOtherViews() {
4616 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454617}
4618
[email protected]7d244f12013-08-22 21:41:514619#endif
4620
[email protected]6fba26d2014-04-29 09:38:284621void WebContentsImpl::OnDialogClosed(int render_process_id,
4622 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264623 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494624 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264625 bool success,
[email protected]fcf75d42013-12-03 20:11:264626 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284627 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4628 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494629 last_dialog_suppressed_ = dialog_was_suppressed;
4630
[email protected]beb440c2009-11-06 04:08:544631 if (is_showing_before_unload_dialog_ && !success) {
waffles1c12bf402016-02-10 17:45:484632 // If a beforeunload dialog is canceled, we need to stop the throbber from
4633 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284634 if (rfh)
waffles1c12bf402016-02-10 17:45:484635 DidStopLoading();
[email protected]15d160c02012-07-04 10:52:354636 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104637
[email protected]6d65a462013-06-21 21:29:124638 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4639 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544640 }
[email protected]87de04b02014-04-08 22:14:494641
[email protected]beb440c2009-11-06 04:08:544642 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284643 if (rfh) {
4644 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4645 dialog_was_suppressed);
4646 } else {
4647 // Don't leak the sync IPC reply if the RFH or process is gone.
4648 delete reply_msg;
4649 }
[email protected]beb440c2009-11-06 04:08:544650}
4651
[email protected]b172aee2012-04-10 17:05:264652void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544653 if (encoding == last_reported_encoding_)
4654 return;
4655 last_reported_encoding_ = encoding;
4656
4657 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124658 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104659}
[email protected]f45d2a72010-03-08 23:28:354660
[email protected]1ac10dca2013-08-20 20:47:044661bool WebContentsImpl::IsHidden() {
4662 return capturer_count_ == 0 && !should_normally_be_visible_;
4663}
4664
rob97250742015-12-10 17:45:154665int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144666 if (node_ && node_->outer_web_contents())
4667 return node_->outer_contents_frame_tree_node_id();
4668
nick2482a2d2015-12-18 01:39:374669 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144670}
4671
[email protected]b0936d22013-11-28 06:47:364672RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214673 return frame_tree_.root()->render_manager();
4674}
4675
lazyboy8e16ddfd2015-09-28 03:41:564676WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4677 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4678 if (node_)
4679 return node_->outer_web_contents();
4680 } else {
4681 if (GetBrowserPluginGuest())
4682 return GetBrowserPluginGuest()->embedder_web_contents();
4683 }
4684 return nullptr;
4685}
4686
[email protected]f8497342013-02-05 22:15:024687BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394688 return browser_plugin_guest_.get();
4689}
4690
[email protected]738f57a2013-06-29 21:06:544691void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4692 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144693 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544694 browser_plugin_guest_.reset(guest);
4695}
4696
[email protected]f8497342013-02-05 22:15:024697BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394698 return browser_plugin_embedder_.get();
4699}
[email protected]8ff00d72012-10-23 19:12:214700
fsamuel60b42282015-03-10 03:29:144701void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4702 if (browser_plugin_embedder_)
4703 return;
4704 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4705}
4706
[email protected]fc2b46b2014-05-03 16:33:454707gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214708 gfx::Size size;
4709 if (delegate_)
4710 size = delegate_->GetSizeForNewRenderView(this);
4711 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454712 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214713 return size;
4714}
4715
[email protected]ae7eeda2014-07-04 01:53:264716void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4717 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024718 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554719}
4720
[email protected]222f5822014-02-05 23:40:494721void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4722 if (!delegate_)
4723 return;
4724 const gfx::Size new_size = GetPreferredSize();
4725 if (new_size != old_size)
4726 delegate_->UpdatePreferredSize(this, new_size);
4727}
4728
dbeama1b926a2015-08-31 23:17:514729WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4730 const std::string& frame_name) {
4731 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4732 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4733 CreateWebUIControllerForURL(web_ui, url);
4734 if (controller) {
4735 web_ui->AddMessageHandler(new GenericHandler());
4736 web_ui->SetController(controller);
4737 return web_ui;
4738 }
4739
4740 delete web_ui;
4741 return NULL;
4742}
4743
[email protected]34ff1cfc2014-08-20 06:16:054744void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4745 force_disable_overscroll_content_ = force_disable;
4746 if (view_)
4747 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4748}
4749
dalecurtis88c240072015-12-09 02:11:184750void WebContentsImpl::MediaStartedPlaying(
4751 const WebContentsObserver::MediaPlayerId& id) {
4752 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4753}
4754
4755void WebContentsImpl::MediaStoppedPlaying(
4756 const WebContentsObserver::MediaPlayerId& id) {
4757 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4758}
4759
[email protected]8ff00d72012-10-23 19:12:214760} // namespace content