blob: 3c46724086182f256112f0cb2c3841faf15eb3fa [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
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]cbb1ef592013-06-05 19:49:4610#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5611#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2013#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5114#include "base/strings/string16.h"
15#include "base/strings/string_number_conversions.h"
16#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0017#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3718#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4219#include "base/trace_event/trace_event.h"
[email protected]95640212014-07-26 18:14:3020#include "content/browser/accessibility/accessibility_mode_helper.h"
21#include "content/browser/accessibility/browser_accessibility_state_impl.h"
[email protected]7a846df2012-09-20 19:17:3922#include "content/browser/browser_plugin/browser_plugin_embedder.h"
23#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5924#include "content/browser/child_process_security_policy_impl.h"
dgozman24bfc912014-09-29 11:04:1825#include "content/browser/devtools/devtools_manager.h"
[email protected]5f2aa722013-08-07 16:59:4126#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0427#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4628#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1229#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1630#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1631#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4032#include "content/browser/frame_host/interstitial_page_impl.h"
33#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0134#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1835#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1636#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5737#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0538#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4439#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4040#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3041#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5242#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]0bc7f3542013-10-21 15:05:5343#include "content/browser/message_port_message_filter.h"
44#include "content/browser/message_port_service.h"
tommyclieb25b2a2014-11-03 19:45:0945#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]d9030b82013-07-19 08:26:0646#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3047#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5048#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3249#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5050#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4851#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0952#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3353#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1154#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5855#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0356#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5657#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1458#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4259#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4460#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0261#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1762#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5163#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0264#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3665#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1166#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2867#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4468#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3669#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1770#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1471#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4672#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1573#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0074#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2775#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0076#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3777#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1478#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3079#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3280#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0981#include "content/public/browser/screen_orientation_dispatcher_host.h"
[email protected]4c3a23582012-08-18 08:54:3482#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3883#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4284#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2585#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2186#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4887#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5488#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4989#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2090#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0391#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5792#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:0593#include "content/public/common/web_preferences.h"
[email protected]a53209b2012-01-20 16:48:1694#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2995#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5396#include "net/http/http_cache.h"
97#include "net/http/http_transaction_factory.h"
98#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3499#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:56100#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01101#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41102#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52103#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31104
qinmin58567c82015-01-07 21:00:20105#if defined(ENABLE_BROWSER_CDMS)
106#include "content/browser/media/media_web_contents_observer.h"
107#endif
108
[email protected]583418cc2013-01-17 14:01:10109#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40110#include "content/browser/android/content_video_view.h"
[email protected]583418cc2013-01-17 14:01:10111#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:45112#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18113#include "content/browser/web_contents/web_contents_android.h"
[email protected]583418cc2013-01-17 14:01:10114#endif
115
[email protected]f66df822012-05-18 16:52:17116#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50117#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57118#endif
[email protected]3e45ba92009-02-20 21:09:00119
[email protected]8ff00d72012-10-23 19:12:21120namespace content {
[email protected]420ae012009-04-24 05:16:32121namespace {
122
[email protected]960b0372014-05-19 18:01:00123const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
124
125// This matches what Blink's ProgressTracker has traditionally used for a
126// minimum progress value.
127const double kMinimumLoadingProgress = 0.1;
128
[email protected]82114f52012-03-20 22:53:41129const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05130
[email protected]155c7f22013-12-09 17:07:18131#if defined(OS_ANDROID)
132const char kWebContentsAndroidKey[] = "web_contents_android";
133#endif // OS_ANDROID
134
[email protected]e4abd3b42013-11-12 18:28:47135base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46136g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
137
thestigc4cac8f2014-09-04 21:17:50138static int StartDownload(RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39139 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29140 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30141 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02142 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58143 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02144 ++g_next_image_download_id,
145 url,
146 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30147 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02148 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39149}
150
[email protected]8bfc8272013-09-09 20:10:53151void NotifyCacheOnIO(
152 scoped_refptr<net::URLRequestContextGetter> request_context,
153 const GURL& url,
154 const std::string& http_method) {
155 request_context->GetURLRequestContext()->http_transaction_factory()->
156 GetCache()->OnExternalCacheHit(url, http_method);
157}
158
[email protected]9b159a52013-10-03 17:24:55159// Helper function for retrieving all the sites in a frame tree.
160bool CollectSites(BrowserContext* context,
161 std::set<GURL>* sites,
162 FrameTreeNode* node) {
163 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
164 return true;
165}
166
[email protected]a86c0e962013-12-17 17:10:39167bool ForEachFrameInternal(
168 const base::Callback<void(RenderFrameHost*)>& on_frame,
169 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41170 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39171 return true;
172}
173
[email protected]95640212014-07-26 18:14:30174bool ForEachPendingFrameInternal(
175 const base::Callback<void(RenderFrameHost*)>& on_frame,
176 FrameTreeNode* node) {
177 RenderFrameHost* pending_frame_host =
178 node->render_manager()->pending_frame_host();
179 if (pending_frame_host)
180 on_frame.Run(pending_frame_host);
181 return true;
182}
183
[email protected]a86c0e962013-12-17 17:10:39184void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
185 IPC::Message* message_copy = new IPC::Message(*message);
186 message_copy->set_routing_id(rfh->GetRoutingID());
187 rfh->Send(message_copy);
188}
189
[email protected]948481d2014-06-11 18:32:22190void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
191 RenderFrameHost* rfh) {
192 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
193 ->frame_tree_node()
194 ->render_manager()
195 ->GetRenderWidgetHostView();
196 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59197}
198
[email protected]95640212014-07-26 18:14:30199void SetAccessibilityModeOnFrame(AccessibilityMode mode,
200 RenderFrameHost* frame_host) {
201 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
202}
203
clamydf1975e2015-02-05 19:12:24204// Enable sudden termination for the current RenderFrameHost of
205// |frame_tree_node| if the ID of its SiteInstance is |site_instance_id|. Used
206// with FrameTree::ForEach.
207bool EnableSuddenTermination(int32 site_instance_id,
208 FrameTreeNode* frame_tree_node) {
209 if (frame_tree_node->current_frame_host()->GetSiteInstance()->GetId()
210 == site_instance_id) {
211 frame_tree_node->current_frame_host()
212 ->set_override_sudden_termination_status(true);
213 }
214 return true;
215}
216
217// Returns false and sets |sudden_termination_allowed| to false if sudden
218// termination is not allowed for the current RenderFrameHost of
219// |frame_tree_node|. Used with FrameTree::ForEach.
220bool SuddenTerminationAllowed(bool* sudden_termination_allowed,
221 FrameTreeNode* frame_tree_node) {
222 if (frame_tree_node->current_frame_host()->SuddenTerminationAllowed())
223 return true;
224 *sudden_termination_allowed = false;
225 return false;
226}
227
[email protected]420ae012009-04-24 05:16:32228} // namespace
229
[email protected]54944cde2012-12-09 09:24:59230WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15231 return WebContentsImpl::CreateWithOpener(
232 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19233}
234
235WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59236 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30237 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59238 WebContentsImpl* new_contents = new WebContentsImpl(
239 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30240
241 for (SessionStorageNamespaceMap::const_iterator it =
242 session_storage_namespace_map.begin();
243 it != session_storage_namespace_map.end();
244 ++it) {
245 new_contents->GetController()
246 .SetSessionStorageNamespace(it->first, it->second.get());
247 }
248
[email protected]54944cde2012-12-09 09:24:59249 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19250 return new_contents;
[email protected]a81343d232011-12-27 07:39:20251}
[email protected]746d3052012-05-22 15:15:47252
nickf9acfbe2014-12-23 19:12:37253void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
254 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46255 g_created_callbacks.Get().push_back(callback);
256}
257
nickf9acfbe2014-12-23 19:12:37258void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
259 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46260 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
261 if (g_created_callbacks.Get().at(i).Equals(callback)) {
262 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
263 return;
264 }
265 }
266}
267
[email protected]299d7f12012-05-23 05:31:15268WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47269 return rvh->GetDelegate()->GetAsWebContents();
270}
271
[email protected]a86c0e962013-12-17 17:10:39272WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
273 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
274 if (!rfh_impl)
275 return NULL;
276 return rfh_impl->delegate()->GetAsWebContents();
277}
278
[email protected]7fff43e2013-05-21 20:21:10279// WebContentsImpl::DestructionObserver ----------------------------------------
280
281class WebContentsImpl::DestructionObserver : public WebContentsObserver {
282 public:
283 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
284 : WebContentsObserver(watched_contents),
285 owner_(owner) {
286 }
287
288 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58289 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58290 owner_->OnWebContentsDestroyed(
291 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10292 }
293
294 private:
295 WebContentsImpl* owner_;
296
297 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
298};
299
[email protected]8ed16472014-04-11 19:02:48300WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
301 int render_frame_id,
302 ColorChooser* chooser,
303 int identifier)
304 : render_process_id(render_process_id),
305 render_frame_id(render_frame_id),
306 chooser(chooser),
307 identifier(identifier) {
308}
309
310WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
311}
312
[email protected]b172aee2012-04-10 17:05:26313// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32314
blundellc57b93f2014-10-29 13:19:57315WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
316 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42317 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22318 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57319 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44320 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49321 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08322#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41323 accessible_parent_(NULL),
324#endif
[email protected]6ea6bdf2013-12-06 13:35:01325 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57326 this,
327 this,
328 this,
329 this),
[email protected]d5f942ba2008-09-26 19:30:34330 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03331 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23332 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
333 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34334 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26335 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00336 loading_total_progress_(0.0),
[email protected]960b0372014-05-19 18:01:00337 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56338 upload_size_(0),
339 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47340 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10341 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55342 capturer_count_(0),
343 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57344 is_being_destroyed_(false),
345 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15346 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01347 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02348 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38349 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21350 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
351 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]f114fa42013-12-06 17:06:44352 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55353 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42354 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03355 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49356 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05357 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30358 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57359 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30360 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30361 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddy371ad9142014-09-17 08:01:46362 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50363 virtual_keyboard_requested_(false),
mohan.reddy371ad9142014-09-17 08:01:46364 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55365 frame_tree_.SetFrameRemoveListener(
366 base::Bind(&WebContentsImpl::OnFrameRemoved,
367 base::Unretained(this)));
qinmin58567c82015-01-07 21:00:20368#if defined(ENABLE_BROWSER_CDMS)
369 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
370#endif
[email protected]332af7732009-03-11 13:21:35371}
initial.commit09911bf2008-07-26 23:55:29372
[email protected]b172aee2012-04-10 17:05:26373WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32374 is_being_destroyed_ = true;
375
[email protected]21b41c7e892014-02-28 01:52:24376 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
377 // shutdown and be deleted as well.
378 frame_tree_.ForEach(
379 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
380
[email protected]d9030b82013-07-19 08:26:06381 ClearAllPowerSaveBlockers();
382
[email protected]b24b68a2012-09-24 21:57:26383 for (std::set<RenderWidgetHostImpl*>::iterator iter =
384 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
385 (*iter)->DetachDelegate();
386 }
387 created_widgets_.clear();
388
[email protected]3ab9cb82011-06-03 18:02:07389 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15390 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11391 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07392
[email protected]8ed16472014-04-11 19:02:48393 if (color_chooser_info_.get())
394 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20395
[email protected]420ae012009-04-24 05:16:32396 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32397
[email protected]ca13a442012-04-17 14:00:12398 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21399 NotificationService::current()->Notify(
400 NOTIFICATION_WEB_CONTENTS_DESTROYED,
401 Source<WebContents>(this),
402 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32403
[email protected]df0c843f2014-05-23 20:37:23404 // Destroy all frame tree nodes except for the root; this notifies observers.
405 frame_tree_.ResetForMainFrameSwap();
406 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59407
[email protected]df0c843f2014-05-23 20:37:23408 // Manually call the observer methods for the root frame tree node.
409 RenderFrameHostManager* root = GetRenderManager();
410 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27411 FOR_EACH_OBSERVER(WebContentsObserver,
412 observers_,
[email protected]df0c843f2014-05-23 20:37:23413 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27414 }
[email protected]df0c843f2014-05-23 20:37:23415 FOR_EACH_OBSERVER(WebContentsObserver,
416 observers_,
417 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27418
[email protected]df0c843f2014-05-23 20:37:23419 if (root->pending_render_view_host()) {
420 FOR_EACH_OBSERVER(WebContentsObserver,
421 observers_,
422 RenderViewDeleted(root->pending_render_view_host()));
423 }
[email protected]c06c58c2014-03-12 20:31:59424
[email protected]f273ee52013-10-18 16:05:27425 FOR_EACH_OBSERVER(WebContentsObserver,
426 observers_,
[email protected]df0c843f2014-05-23 20:37:23427 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27428
[email protected]2db9bd72012-04-13 20:20:56429 FOR_EACH_OBSERVER(WebContentsObserver,
430 observers_,
[email protected]12a46832014-05-09 13:35:58431 WebContentsDestroyed());
432
433 FOR_EACH_OBSERVER(WebContentsObserver,
434 observers_,
435 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08436
[email protected]6934a702011-12-20 00:04:51437 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10438
439 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
440 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42441}
442
[email protected]d1198fd2012-08-13 22:50:19443WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59444 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19445 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03446 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59447 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06448 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19449
[email protected]4858e432014-06-23 18:14:17450 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06451 // This makes |new_contents| act as a guest.
452 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16453 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06454 // We are instantiating a WebContents for browser plugin. Set its subframe
455 // bit to true.
456 new_contents->is_subframe_ = true;
457 }
[email protected]54944cde2012-12-09 09:24:59458 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19459 return new_contents;
460}
461
[email protected]95640212014-07-26 18:14:30462// static
463std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
464 std::vector<WebContentsImpl*> result;
465 scoped_ptr<RenderWidgetHostIterator> widgets(
466 RenderWidgetHostImpl::GetRenderWidgetHosts());
467 std::set<WebContentsImpl*> web_contents_set;
468 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
469 if (!rwh->IsRenderView())
470 continue;
471 RenderViewHost* rvh = RenderViewHost::From(rwh);
472 if (!rvh)
473 continue;
474 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
475 if (!web_contents)
476 continue;
477 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
478 if (web_contents_set.find(wci) == web_contents_set.end()) {
479 web_contents_set.insert(wci);
480 result.push_back(wci);
481 }
482 }
483 return result;
484}
485
[email protected]b0936d22013-11-28 06:47:36486RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21487 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28488}
489
[email protected]7bb761892012-07-20 09:32:47490bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
491 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44492 return OnMessageReceived(render_view_host, NULL, message);
493}
494
495bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
496 RenderFrameHost* render_frame_host,
497 const IPC::Message& message) {
498 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56499 if (GetWebUI() &&
500 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17501 return true;
[email protected]d2353452012-01-19 19:53:56502 }
[email protected]f82d57b52011-04-27 19:13:17503
[email protected]d8c660432011-12-22 20:51:25504 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
505 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33506 if (render_frame_host) {
507 while ((observer = it.GetNext()) != NULL)
508 if (observer->OnMessageReceived(message, render_frame_host))
509 return true;
510 } else {
511 while ((observer = it.GetNext()) != NULL)
512 if (observer->OnMessageReceived(message))
513 return true;
514 }
[email protected]403415a2011-01-10 18:57:53515
[email protected]1d62cf72014-02-07 21:31:57516 // Message handlers should be aware of which
517 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
518 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02519 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57520 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02521 else
[email protected]1d62cf72014-02-07 21:31:57522 render_view_message_source_ = render_view_host;
523
[email protected]724159a2010-12-30 01:11:18524 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33525 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40526 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
527 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05528 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
529 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48530 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
531 OnDocumentLoadedInFrame)
532 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00533 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
534 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
535 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
536 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48537 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
538 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
539 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
540 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19541 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
542 OnMediaPlayingNotification)
543 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
544 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11545 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
546 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18547 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
548 OnDidLoadResourceFromMemoryCache)
549 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
550 OnDidDisplayInsecureContent)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
552 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25553 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26554 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21555 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20556 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
557 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20558 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
559 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16560 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10561 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50562 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50563#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:42564 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
565 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50566 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
567 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55568 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40569 OnBrowserPluginMessage(render_frame_host,
570 message))
thestigc4cac8f2014-09-04 21:17:50571#endif
[email protected]41225fe2013-03-29 05:32:02572 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
573 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07574 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
575 OnShowValidationMessage)
576 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
577 OnHideValidationMessage)
578 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
579 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48580#if defined(OS_ANDROID)
581 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
582 OnFindMatchRectsReply)
583 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
584 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48585#endif
[email protected]724159a2010-12-30 01:11:18586 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33587 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44588 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57589 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18590
[email protected]724159a2010-12-30 01:11:18591 return handled;
592}
593
nasko907fcb62015-01-28 04:24:11594bool WebContentsImpl::HasValidFrameSource() {
595 if (!render_frame_message_source_) {
596 DCHECK(render_view_message_source_);
597 RecordAction(base::UserMetricsAction("BadMessageTerminate_WC"));
598 GetRenderProcessHost()->ReceivedBadMessage();
599 return false;
600 }
601
602 return true;
603}
604
[email protected]b172aee2012-04-10 17:05:26605void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18606 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21607 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43608 if (delegate_)
609 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18610}
611
[email protected]d1198fd2012-08-13 22:50:19612NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56613 return controller_;
614}
615
[email protected]d1198fd2012-08-13 22:50:19616const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56617 return controller_;
618}
619
[email protected]8ff00d72012-10-23 19:12:21620BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55621 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30622}
623
[email protected]b172aee2012-04-10 17:05:26624const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24625 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32626 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51627 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31628}
629
[email protected]a093ce02013-07-22 20:53:14630const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24631 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32632 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24633 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
634}
635
636const GURL& WebContentsImpl::GetLastCommittedURL() const {
637 // We may not have a navigation entry yet.
638 NavigationEntry* entry = controller_.GetLastCommittedEntry();
639 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
640}
641
[email protected]8ff00d72012-10-23 19:12:21642WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31643 return delegate_;
644}
645
[email protected]8ff00d72012-10-23 19:12:21646void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31647 // TODO(cbentzel): remove this debugging code?
648 if (delegate == delegate_)
649 return;
650 if (delegate_)
651 delegate_->Detach(this);
652 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08653 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31654 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08655 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00656 if (view_)
[email protected]e85165c642014-06-10 14:34:31657 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08658 }
[email protected]be1f56ab2011-12-22 06:55:31659}
660
[email protected]8ff00d72012-10-23 19:12:21661RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21662 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41663 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16664}
665
clamydf1975e2015-02-05 19:12:24666RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41667 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16668}
669
[email protected]9c9343b2014-03-08 02:56:07670RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
671 if (!frame_tree_.GetFocusedFrame())
672 return NULL;
673 return frame_tree_.GetFocusedFrame()->current_frame_host();
674}
675
[email protected]a86c0e962013-12-17 17:10:39676void WebContentsImpl::ForEachFrame(
677 const base::Callback<void(RenderFrameHost*)>& on_frame) {
678 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
679}
680
681void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
682 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
683 delete message;
684}
685
[email protected]b172aee2012-04-10 17:05:26686RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21687 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31688}
689
[email protected]6b618e62012-08-16 12:59:18690int WebContentsImpl::GetRoutingID() const {
691 if (!GetRenderViewHost())
692 return MSG_ROUTING_NONE;
693
694 return GetRenderViewHost()->GetRoutingID();
695}
696
[email protected]44470a22013-01-24 01:21:54697int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
698 return fullscreen_widget_routing_id_;
699}
700
[email protected]b172aee2012-04-10 17:05:26701RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21702 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31703}
704
[email protected]4aebbca2013-09-17 22:26:49705RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
706 const {
707 RenderWidgetHost* const widget_host =
708 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
709 GetFullscreenWidgetRoutingID());
710 return widget_host ? widget_host->GetView() : NULL;
711}
712
[email protected]8ff00d72012-10-23 19:12:21713WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31714 return view_.get();
715}
716
[email protected]95640212014-07-26 18:14:30717void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
718 if (mode == accessibility_mode_)
719 return;
720
721 accessibility_mode_ = mode;
722 frame_tree_.ForEach(
723 base::Bind(&ForEachFrameInternal,
724 base::Bind(&SetAccessibilityModeOnFrame, mode)));
725 frame_tree_.ForEach(
726 base::Bind(&ForEachPendingFrameInternal,
727 base::Bind(&SetAccessibilityModeOnFrame, mode)));
728}
729
730void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50731 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30732}
733
734void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50735 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30736}
737
zhenw1f790352014-10-30 00:06:04738void WebContentsImpl::ClearNavigationTransitionData() {
739 FrameTreeNode* node = frame_tree_.root();
740 node->render_manager()->ClearNavigationTransitionData();
741}
742
[email protected]8ff00d72012-10-23 19:12:21743WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56744 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03745 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
746 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22747 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58748 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22749 web_ui->SetController(controller);
750 return web_ui;
751 }
752
753 delete web_ui;
754 return NULL;
755}
756
[email protected]8ff00d72012-10-23 19:12:21757WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21758 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
759 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31760}
761
[email protected]8ff00d72012-10-23 19:12:21762WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21763 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34764}
765
[email protected]86ef6a392012-05-11 22:03:11766void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22767 if (GetUserAgentOverride() == override)
768 return;
769
770 renderer_preferences_.user_agent_override = override;
771
772 // Send the new override string to the renderer.
773 RenderViewHost* host = GetRenderViewHost();
774 if (host)
775 host->SyncRendererPrefs();
776
777 // Reload the page if a load is currently in progress to avoid having
778 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27779 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22780 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
781 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53782
783 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
784 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11785}
786
787const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22788 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11789}
790
[email protected]95640212014-07-26 18:14:30791void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
792 AddAccessibilityMode(AccessibilityModeTreeOnly);
793}
794
795bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
796 return accessibility_mode_ == AccessibilityModeTreeOnly;
797}
798
799bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
800 return accessibility_mode_ == AccessibilityModeComplete;
801}
802
[email protected]2ceee8f2014-01-14 18:02:08803#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41804void WebContentsImpl::SetParentNativeViewAccessible(
805gfx::NativeViewAccessible accessible_parent) {
806 accessible_parent_ = accessible_parent;
clamydf1975e2015-02-05 19:12:24807 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:30808 if (rfh)
809 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41810}
811#endif
812
[email protected]fcf75d42013-12-03 20:11:26813const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55814 // Transient entries take precedence. They are used for interstitial pages
815 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23816 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08817 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21818 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30819 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23820 if (entry) {
[email protected]b5cca982011-05-26 04:42:08821 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23822 }
[email protected]fa944cb82013-11-15 17:51:21823 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
824 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58825 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54826 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32827 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54828 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35829 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26830 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54831 if (!title.empty())
832 return title;
833 }
834 }
835
836 // We use the title for the last committed entry rather than a pending
837 // navigation entry. For example, when the user types in a URL, we want to
838 // keep the old page's title until the new load has committed and we get a new
839 // title.
[email protected]96d185d2009-04-24 03:28:54840 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32841
[email protected]9eeafc012013-11-25 23:49:47842 // We make an exception for initial navigations.
843 if (controller_.IsInitialNavigation()) {
844 // We only want to use the title from the visible entry in one of two cases:
845 // 1. There's already a committed entry for an initial navigation, in which
846 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
847 // 2. The pending entry has been explicitly assigned a title to display.
848 //
849 // If there's no last committed entry and no assigned title, we should fall
850 // back to |page_title_when_no_navigation_entry_| rather than showing the
851 // URL.
852 if (entry ||
853 (controller_.GetVisibleEntry() &&
854 !controller_.GetVisibleEntry()->GetTitle().empty())) {
855 entry = controller_.GetVisibleEntry();
856 }
857 }
[email protected]59167c22013-06-03 18:07:32858
[email protected]45d0ef7f2011-01-05 13:46:23859 if (entry) {
[email protected]b5cca982011-05-26 04:42:08860 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23861 }
[email protected]987fc3a2011-05-26 14:18:09862
863 // |page_title_when_no_navigation_entry_| is finally used
864 // if no title cannot be retrieved.
865 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54866}
867
[email protected]b172aee2012-04-10 17:05:26868int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46869 return GetMaxPageIDForSiteInstance(GetSiteInstance());
870}
871
[email protected]b172aee2012-04-10 17:05:26872int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
873 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33874 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
875 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46876
[email protected]b6583592012-01-25 19:52:33877 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34878}
879
[email protected]b172aee2012-04-10 17:05:26880void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46881 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
882}
883
[email protected]b172aee2012-04-10 17:05:26884void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33885 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46886 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33887 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34888}
889
[email protected]ec6c05f2013-10-23 18:41:57890void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
891 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
892 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57893}
894
creiscce56cd2014-09-29 22:45:22895SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21896 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54897}
898
creiscce56cd2014-09-29 22:45:22899SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
900 RenderViewHostImpl* dest_rvh =
901 GetRenderManager()->pending_render_view_host() ?
902 GetRenderManager()->pending_render_view_host() :
903 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58904 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38905}
906
[email protected]b172aee2012-04-10 17:05:26907bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31908 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49909}
910
[email protected]6dfed692014-05-22 04:18:03911bool WebContentsImpl::IsLoadingToDifferentDocument() const {
912 return is_loading_ && is_load_to_different_document_;
913}
914
[email protected]b172aee2012-04-10 17:05:26915bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03916 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31917}
918
[email protected]b172aee2012-04-10 17:05:26919const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31920 return load_state_;
921}
922
[email protected]fcf75d42013-12-03 20:11:26923const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31924 return load_state_host_;
925}
926
[email protected]b172aee2012-04-10 17:05:26927uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31928 return upload_size_;
929}
930
[email protected]b172aee2012-04-10 17:05:26931uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31932 return upload_position_;
933}
934
[email protected]1ae93fb2013-06-14 03:38:56935std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56936 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39937 frame_tree_.ForEach(base::Bind(&CollectSites,
938 base::Unretained(GetBrowserContext()),
939 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56940 return sites;
941}
942
[email protected]b172aee2012-04-10 17:05:26943const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54944 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31945}
946
[email protected]b172aee2012-04-10 17:05:26947bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31948 return displayed_insecure_content_;
949}
950
[email protected]222f5822014-02-05 23:40:49951void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25952 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55953 ++capturer_count_;
954 DVLOG(1) << "There are now " << capturer_count_
955 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49956
957 // Note: This provides a hint to upstream code to size the views optimally
958 // for quality (e.g., to avoid scaling).
959 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
960 preferred_size_for_capture_ = capture_size;
961 OnPreferredSizeChanged(preferred_size_);
962 }
ccameron8807c38f2015-01-17 00:29:19963
964 // Ensure that all views are un-occluded before capture begins.
965 WasUnOccluded();
[email protected]54597982013-02-06 01:59:55966}
967
968void WebContentsImpl::DecrementCapturerCount() {
969 --capturer_count_;
970 DVLOG(1) << "There are now " << capturer_count_
971 << " capturing(s) of WebContentsImpl@" << this;
972 DCHECK_LE(0, capturer_count_);
973
[email protected]5a652232013-02-12 06:15:25974 if (is_being_destroyed_)
975 return;
976
[email protected]222f5822014-02-05 23:40:49977 if (capturer_count_ == 0) {
978 const gfx::Size old_size = preferred_size_for_capture_;
979 preferred_size_for_capture_ = gfx::Size();
980 OnPreferredSizeChanged(old_size);
981 }
982
[email protected]1ac10dca2013-08-20 20:47:04983 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55984 DVLOG(1) << "Executing delayed WasHidden().";
985 WasHidden();
986 }
[email protected]be1f56ab2011-12-22 06:55:31987}
988
[email protected]f2bd40812013-07-20 04:30:44989int WebContentsImpl::GetCapturerCount() const {
990 return capturer_count_;
991}
992
miu50f97892014-09-22 22:49:52993bool WebContentsImpl::IsAudioMuted() const {
994 return audio_muter_.get() && audio_muter_->is_muting();
995}
996
997void WebContentsImpl::SetAudioMuted(bool mute) {
998 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
999 << " for WebContentsImpl@" << this;
1000
1001 if (mute == IsAudioMuted())
1002 return;
1003
1004 if (mute) {
1005 if (!audio_muter_)
1006 audio_muter_.reset(new WebContentsAudioMuter(this));
1007 audio_muter_->StartMuting();
1008 } else {
1009 DCHECK(audio_muter_);
1010 audio_muter_->StopMuting();
1011 }
1012
1013 // Notification for UI updates in response to the changed muting state.
1014 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1015}
1016
[email protected]b172aee2012-04-10 17:05:261017bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311018 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1019 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
1020 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:491021}
1022
[email protected]b172aee2012-04-10 17:05:261023void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1024 int error_code) {
[email protected]443b80e2010-12-14 00:42:231025 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341026 return;
1027
[email protected]443b80e2010-12-14 00:42:231028 crashed_status_ = status;
1029 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211030 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341031}
1032
[email protected]b172aee2012-04-10 17:05:261033base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311034 return crashed_status_;
1035}
1036
[email protected]b172aee2012-04-10 17:05:261037bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311038 return is_being_destroyed_;
1039}
1040
[email protected]7f924832014-08-09 05:57:221041void WebContentsImpl::NotifyNavigationStateChanged(
1042 InvalidateTypes changed_flags) {
dalecurtisbc6572e12014-09-12 19:22:301043 // Create and release the audio power save blocker depending on whether the
1044 // tab is actively producing audio or not.
dalecurtis27011852015-01-06 19:52:341045 if ((changed_flags & INVALIDATE_TYPE_TAB) &&
dalecurtisbc6572e12014-09-12 19:22:301046 AudioStreamMonitor::monitoring_available()) {
1047 if (WasRecentlyAudible()) {
1048 if (!audio_power_save_blocker_)
1049 CreateAudioPowerSaveBlocker();
1050 } else {
1051 audio_power_save_blocker_.reset();
1052 }
1053 }
1054
[email protected]d5f942ba2008-09-26 19:30:341055 if (delegate_)
1056 delegate_->NavigationStateChanged(this, changed_flags);
1057}
1058
[email protected]9a890452014-02-13 22:21:021059base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1060 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331061}
1062
[email protected]9e2e4632012-07-27 16:38:411063void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541064 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591065
ccameron8807c38f2015-01-17 00:29:191066 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1067 if (view) {
1068 view->Show();
[email protected]789e9152009-08-04 21:59:431069#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191070 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431071#endif
[email protected]de3c5d82014-05-28 22:12:591072 }
[email protected]789e9152009-08-04 21:59:431073 }
[email protected]96d185d2009-04-24 03:28:541074
[email protected]9a890452014-02-13 22:21:021075 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381076
[email protected]b9769d82012-02-10 00:23:591077 // The resize rect might have changed while this was inactive -- send the new
1078 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581079 RenderViewHostImpl* rvh =
1080 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591081 if (rvh) {
1082 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1083 }
[email protected]96d185d2009-04-24 03:28:541084
dalecurtisbc6572e12014-09-12 19:22:301085 // Restore power save blocker if there are active video players running.
1086 if (!active_video_players_.empty() && !video_power_save_blocker_)
1087 CreateVideoPowerSaveBlocker();
1088
[email protected]c0d9d5672013-10-09 07:38:031089 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1090
[email protected]54597982013-02-06 01:59:551091 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311092}
1093
[email protected]b172aee2012-04-10 17:05:261094void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551095 // If there are entities capturing screenshots or video (e.g., mirroring),
1096 // don't activate the "disable rendering" optimization.
1097 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521098 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551099 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261100 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521101 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331102 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521103 // calls us).
ccameron8807c38f2015-01-17 00:29:191104 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1105 if (view)
1106 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591107 }
dalecurtisbc6572e12014-09-12 19:22:301108
1109 // Release any video power save blockers held as video is not visible.
1110 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541111 }
1112
[email protected]c0d9d5672013-10-09 07:38:031113 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1114
[email protected]54597982013-02-06 01:59:551115 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371116}
1117
ccameron8807c38f2015-01-17 00:29:191118void WebContentsImpl::WasOccluded() {
1119 if (capturer_count_ > 0)
1120 return;
1121
1122 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1123 if (view)
1124 view->WasOccluded();
1125 }
1126}
1127
1128void WebContentsImpl::WasUnOccluded() {
1129 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1130 if (view)
1131 view->WasUnOccluded();
1132 }
1133}
1134
[email protected]b172aee2012-04-10 17:05:261135bool WebContentsImpl::NeedToFireBeforeUnload() {
clamydf1975e2015-02-05 19:12:241136 bool sudden_termination_allowed = true;
1137 frame_tree_.ForEach(base::Bind(
1138 &SuddenTerminationAllowed, &sudden_termination_allowed));
[email protected]be1f56ab2011-12-22 06:55:311139 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271140 return WillNotifyDisconnection() &&
1141 !ShowingInterstitialPage() &&
clamydf1975e2015-02-05 19:12:241142 !sudden_termination_allowed;
[email protected]be1f56ab2011-12-22 06:55:311143}
1144
[email protected]1c3f80bd2014-04-08 23:02:061145void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
clamydf1975e2015-02-05 19:12:241146 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061147}
1148
[email protected]b172aee2012-04-10 17:05:261149void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211150 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401151 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271152}
1153
[email protected]b172aee2012-04-10 17:05:261154WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441155 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451156 // We pass our own opener so that the cloned page can access it if it was
1157 // before.
[email protected]54944cde2012-12-09 09:24:591158 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451159 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591160 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191161 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221162 FOR_EACH_OBSERVER(WebContentsObserver,
1163 observers_,
1164 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271165 return tc;
1166}
1167
[email protected]14392a52012-05-02 20:28:441168void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211169 const NotificationSource& source,
1170 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441171 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211172 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1173 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031174 RenderWidgetHostView* view = host->GetView();
1175 if (view == GetFullscreenRenderWidgetHostView()) {
1176 // We cannot just call view_->RestoreFocus() here. On some platforms,
1177 // attempting to focus the currently-invisible WebContentsView will be
1178 // flat-out ignored. Therefore, this boolean is used to track whether
1179 // we will request focus after the fullscreen widget has been
1180 // destroyed.
1181 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1182 } else {
1183 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1184 i != pending_widget_views_.end(); ++i) {
1185 if (host->GetView() == i->second) {
1186 pending_widget_views_.erase(i);
1187 break;
1188 }
[email protected]bafe6cd2012-05-23 23:09:501189 }
1190 }
1191 break;
1192 }
[email protected]14392a52012-05-02 20:28:441193 default:
1194 NOTREACHED();
1195 }
1196}
1197
[email protected]ec6c05f2013-10-23 18:41:571198WebContents* WebContentsImpl::GetWebContents() {
1199 return this;
1200}
1201
[email protected]54944cde2012-12-09 09:24:591202void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211203 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361204 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211205 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431206 should_normally_be_visible_ = !params.initially_hidden;
1207
avic2c29d782014-12-12 00:23:541208 // Either both routing ids can be given, or neither can be.
1209 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
1210 params.main_frame_routing_id == MSG_ROUTING_NONE) ||
1211 (params.routing_id != MSG_ROUTING_NONE &&
1212 params.main_frame_routing_id != MSG_ROUTING_NONE));
[email protected]fa944cb82013-11-15 17:51:211213 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041214 params.browser_context, params.site_instance, params.routing_id,
1215 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191216
[email protected]fc2b46b2014-05-03 16:33:451217 WebContentsViewDelegate* delegate =
1218 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1219
1220 if (browser_plugin_guest_) {
1221 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1222 this, delegate, &render_view_host_delegate_view_));
1223
1224 WebContentsViewGuest* rv = new WebContentsViewGuest(
1225 this, browser_plugin_guest_.get(), platform_view.Pass(),
1226 render_view_host_delegate_view_);
1227 render_view_host_delegate_view_ = rv;
1228 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191229 } else {
[email protected]fc2b46b2014-05-03 16:33:451230 // Regular WebContentsView.
1231 view_.reset(CreateWebContentsView(
1232 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191233 }
[email protected]fc2b46b2014-05-03 16:33:451234 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191235 CHECK(view_.get());
1236
[email protected]ed245db2012-12-18 08:00:451237 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591238 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191239
1240 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101241 if (opener_)
1242 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191243
tommyclieb25b2a2014-11-03 19:45:091244#if defined(ENABLE_PLUGINS)
1245 plugin_content_origin_whitelist_.reset(
1246 new PluginContentOriginWhitelist(this));
1247#endif
1248
[email protected]d1198fd2012-08-13 22:50:191249 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211250 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1251 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101252
[email protected]01f83f92014-06-17 14:41:541253 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091254 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541255
mlamouriefdca9d2014-09-16 16:55:401256 manifest_manager_host_.reset(new ManifestManagerHost(this));
1257
[email protected]c7654a232013-06-12 21:04:441258#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101259 date_time_chooser_.reset(new DateTimeChooserAndroid());
1260#endif
fsamuel7310a4262014-12-05 05:06:441261
1262 // BrowserPluginGuest::Init needs to be called after this WebContents has
1263 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1264 if (browser_plugin_guest_)
1265 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371266
1267 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1268 g_created_callbacks.Get().at(i).Run(this);
[email protected]d1198fd2012-08-13 22:50:191269}
1270
[email protected]7fff43e2013-05-21 20:21:101271void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1272 RemoveDestructionObserver(web_contents);
1273
[email protected]14392a52012-05-02 20:28:441274 // Clear the opener if it has been closed.
1275 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441276 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511277 return;
[email protected]14392a52012-05-02 20:28:441278 }
[email protected]ceee8cd2013-03-08 04:59:511279 // Clear a pending contents that has been closed before being shown.
1280 for (PendingContents::iterator iter = pending_contents_.begin();
1281 iter != pending_contents_.end();
1282 ++iter) {
1283 if (iter->second != web_contents)
1284 continue;
1285 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511286 return;
1287 }
1288 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441289}
1290
[email protected]7fff43e2013-05-21 20:21:101291void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1292 if (!ContainsKey(destruction_observers_, web_contents)) {
1293 destruction_observers_[web_contents] =
1294 new DestructionObserver(this, web_contents);
1295 }
1296}
1297
1298void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1299 DestructionObservers::iterator iter =
1300 destruction_observers_.find(web_contents);
1301 if (iter != destruction_observers_.end()) {
1302 delete destruction_observers_[web_contents];
1303 destruction_observers_.erase(iter);
1304 }
1305}
1306
[email protected]b172aee2012-04-10 17:05:261307void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311308 observers_.AddObserver(observer);
1309}
1310
[email protected]b172aee2012-04-10 17:05:261311void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311312 observers_.RemoveObserver(observer);
1313}
1314
[email protected]948481d2014-06-11 18:32:221315std::set<RenderWidgetHostView*>
1316WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1317 std::set<RenderWidgetHostView*> set;
1318 if (ShowingInterstitialPage()) {
1319 set.insert(GetRenderWidgetHostView());
1320 } else {
1321 ForEachFrame(
1322 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1323 }
[email protected]de3c5d82014-05-28 22:12:591324 return set;
1325}
1326
[email protected]b172aee2012-04-10 17:05:261327void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341328 if (delegate_)
1329 delegate_->ActivateContents(this);
1330}
1331
[email protected]b172aee2012-04-10 17:05:261332void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121333 if (delegate_)
1334 delegate_->DeactivateContents(this);
1335}
1336
[email protected]b172aee2012-04-10 17:05:261337void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481338 if (delegate_)
1339 delegate_->LostCapture();
1340}
1341
[email protected]b24b68a2012-09-24 21:57:261342void WebContentsImpl::RenderWidgetDeleted(
1343 RenderWidgetHostImpl* render_widget_host) {
1344 if (is_being_destroyed_) {
1345 // |created_widgets_| might have been destroyed.
1346 return;
1347 }
1348
1349 std::set<RenderWidgetHostImpl*>::iterator iter =
1350 created_widgets_.find(render_widget_host);
1351 if (iter != created_widgets_.end())
1352 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541353
1354 if (render_widget_host &&
1355 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491356 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531357 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541358 FOR_EACH_OBSERVER(WebContentsObserver,
1359 observers_,
1360 DidDestroyFullscreenWidget(
1361 fullscreen_widget_routing_id_));
1362 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031363 if (fullscreen_widget_had_focus_at_shutdown_)
1364 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541365 }
[email protected]b24b68a2012-09-24 21:57:261366}
1367
miu9e14e492014-10-25 02:39:041368void WebContentsImpl::RenderWidgetGotFocus(
1369 RenderWidgetHostImpl* render_widget_host) {
1370 // Notify the delegate if an embedded fullscreen widget was focused.
1371 if (delegate_ && render_widget_host &&
1372 delegate_->EmbedsFullscreenWidget() &&
1373 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1374 delegate_->WebContentsFocused(this);
1375}
1376
estaded0a0c992015-01-21 14:12:061377void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311378 RenderWidgetHostImpl* render_widget_host,
1379 bool width_changed) {
clamydf1975e2015-02-05 19:12:241380 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291381 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061382 return;
estaded0a0c992015-01-21 14:12:061383
rouslan2f5993f2015-01-29 00:18:311384 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1385 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061386}
1387
[email protected]b172aee2012-04-10 17:05:261388bool WebContentsImpl::PreHandleKeyboardEvent(
1389 const NativeWebKeyboardEvent& event,
1390 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481391 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131392 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481393}
1394
[email protected]b172aee2012-04-10 17:05:261395void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101396 if (browser_plugin_embedder_ &&
1397 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1398 return;
1399 }
[email protected]63954792011-07-11 04:17:481400 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131401 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481402}
1403
[email protected]d92026ef2014-03-03 21:04:131404bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461405 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191406#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331407 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1408 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191409 // -the OS already has a gesture to do this through pinch-zoom
1410 // -if a user starts an inertial scroll, let's go, and presses control
1411 // (i.e. control+tab) then the OS's buffered scroll events will come in
1412 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331413 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551414 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331415 !event.canScroll) {
[email protected]fb3f066e2013-02-12 19:12:521416 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1417 return true;
1418 }
[email protected]bccc4472013-04-18 16:37:191419#endif
[email protected]fb3f066e2013-02-12 19:12:521420 return false;
1421}
1422
[email protected]04bce562014-01-30 05:34:541423bool WebContentsImpl::PreHandleGestureEvent(
1424 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031425 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541426}
1427
[email protected]b172aee2012-04-10 17:05:261428void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431429 if (delegate_)
1430 delegate_->HandleMouseDown();
1431}
1432
[email protected]b172aee2012-04-10 17:05:261433void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481434 if (delegate_)
1435 delegate_->HandleMouseUp();
1436}
1437
[email protected]590a634e2012-07-19 16:38:231438void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481439 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231440 delegate_->HandlePointerActivate();
1441}
1442
1443void WebContentsImpl::HandleGestureBegin() {
1444 if (delegate_)
1445 delegate_->HandleGestureBegin();
1446}
1447
1448void WebContentsImpl::HandleGestureEnd() {
1449 if (delegate_)
1450 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481451}
1452
mlamouri7a78d6fd2015-01-17 13:23:531453void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1454 // This method is being called to enter renderer-initiated fullscreen mode.
1455 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491456 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1457 if (widget_view)
1458 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1459
[email protected]8a5e0ca2011-08-25 06:30:471460 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531461 delegate_->EnterFullscreenModeForTab(this, origin);
1462
1463 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1464 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
1465}
1466
1467void WebContentsImpl::ExitFullscreenMode() {
1468 // This method is being called to leave renderer-initiated fullscreen mode.
1469 // Make sure any existing fullscreen widget is shut down first.
1470 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1471 if (widget_view)
1472 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1473
hugo.holgersson61288e6c2015-01-28 17:04:401474#if defined(OS_ANDROID)
1475 ContentVideoView* video_view = ContentVideoView::GetInstance();
1476 if (video_view != NULL)
1477 video_view->OnExitFullscreen();
1478#endif
1479
mlamouri7a78d6fd2015-01-17 13:23:531480 if (delegate_)
1481 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371482
1483 FOR_EACH_OBSERVER(WebContentsObserver,
1484 observers_,
1485 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471486}
1487
[email protected]b172aee2012-04-10 17:05:261488bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381489 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121490}
1491
[email protected]a9c81f02012-06-01 00:15:441492void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1493 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371494 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441495 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371496 } else {
1497 GotResponseToLockMouseRequest(false);
1498 }
1499}
1500
[email protected]b172aee2012-04-10 17:05:261501void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371502 if (delegate_)
1503 delegate_->LostMouseLock();
1504}
1505
[email protected]bafe6cd2012-05-23 23:09:501506void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201507 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501508 int route_id,
[email protected]227692c52013-05-31 22:43:041509 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131510 const ViewHostMsg_CreateWindow_Params& params,
1511 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501512 // We usually create the new window in the same BrowsingInstance (group of
1513 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551514 // if the opener is being suppressed (in a non-guest), we create a new
1515 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251516 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551517
[email protected]04cbd3d2013-12-04 04:58:201518 // If the opener is to be suppressed, the new window can be in any process.
1519 // Since routing ids are process specific, we must not have one passed in
1520 // as argument here.
1521 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1522
[email protected]bafe6cd2012-05-23 23:09:501523 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551524 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571525 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501526 GetSiteInstance();
1527
[email protected]04cbd3d2013-12-04 04:58:201528 // A message to create a new window can only come from the active process for
1529 // this WebContentsImpl instance. If any other process sends the request,
1530 // it is invalid and the process must be terminated.
1531 if (GetRenderProcessHost()->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351532 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1533 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201534 if (process_handle != base::kNullProcessHandle) {
1535 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391536 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351537 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201538 }
1539 return;
1540 }
1541
[email protected]d1198fd2012-08-13 22:50:191542 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341543 //
1544 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301545 const std::string& partition_id =
1546 GetContentClient()->browser()->
1547 GetStoragePartitionIdForSite(GetBrowserContext(),
1548 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461549 StoragePartition* partition = BrowserContext::GetStoragePartition(
1550 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411551 DOMStorageContextWrapper* dom_storage_context =
1552 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191553 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1554 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1555 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371556
1557 if (delegate_ &&
1558 !delegate_->ShouldCreateWebContents(this,
1559 route_id,
avic2c29d782014-12-12 00:23:541560 main_frame_route_id,
[email protected]dd6730412013-08-14 15:03:371561 params.window_container_type,
1562 params.frame_name,
1563 params.target_url,
1564 partition_id,
1565 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011566 if (route_id != MSG_ROUTING_NONE &&
1567 !RenderViewHost::FromID(render_process_id, route_id)) {
1568 // If the embedder didn't create a WebContents for this route, we need to
1569 // delete the RenderView that had already been created.
1570 Send(new ViewMsg_Close(route_id));
1571 }
[email protected]dd6730412013-08-14 15:03:371572 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1573 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1574 main_frame_route_id);
1575 return;
1576 }
1577
1578 // Create the new web contents. This will automatically create the new
1579 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461580 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591581 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041582 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061583 create_params.opener = this;
1584 create_params.opener_suppressed = params.opener_suppressed;
1585 if (params.disposition == NEW_BACKGROUND_TAB)
1586 create_params.initially_hidden = true;
1587
[email protected]4858e432014-06-23 18:14:171588 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551589 if (!is_guest) {
1590 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451591 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171592 new_contents = static_cast<WebContentsImpl*>(
1593 WebContents::Create(create_params));
1594 } else {
1595 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551596 }
[email protected]50d326e2014-05-20 17:59:061597 new_contents->GetController().SetSessionStorageNamespace(
1598 partition_id,
1599 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261600 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191601
[email protected]c4538072013-03-18 02:17:551602 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341603 // will be shown immediately).
1604 if (!params.opener_suppressed) {
1605 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451606 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501607
[email protected]d70bea92013-04-05 04:23:341608 // TODO(brettw): It seems bogus that we have to call this function on the
1609 // newly created object and give it one of its own member variables.
lazyboy549b3b42014-10-20 17:16:041610 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false);
[email protected]d70bea92013-04-05 04:23:341611 }
[email protected]bafe6cd2012-05-23 23:09:501612 // Save the created window associated with the route so we can show it
1613 // later.
1614 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1615 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101616 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501617 }
1618
1619 if (delegate_) {
1620 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071621 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131622 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501623 }
1624
1625 if (params.opener_suppressed) {
1626 // When the opener is suppressed, the original renderer cannot access the
1627 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001628 bool was_blocked = false;
1629 if (delegate_) {
bokan107a47f2015-02-03 23:23:391630 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001631 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391632 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001633 params.user_gesture, &was_blocked);
1634 }
1635 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211636 OpenURLParams open_params(params.target_url,
1637 Referrer(),
1638 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351639 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211640 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301641 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001642 new_contents->OpenURL(open_params);
1643 }
[email protected]bafe6cd2012-05-23 23:09:501644 }
1645}
1646
[email protected]a8504022013-12-04 20:23:511647void WebContentsImpl::CreateNewWidget(int render_process_id,
1648 int route_id,
[email protected]180ef242013-11-07 06:50:461649 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511650 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501651}
1652
[email protected]a8504022013-12-04 20:23:511653void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1654 int route_id) {
1655 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501656}
1657
[email protected]a8504022013-12-04 20:23:511658void WebContentsImpl::CreateNewWidget(int render_process_id,
1659 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501660 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461661 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211662 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511663 // A message to create a new widget can only come from the active process for
1664 // this WebContentsImpl instance. If any other process sends the request,
1665 // it is invalid and the process must be terminated.
1666 if (process->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351667 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1668 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511669 if (process_handle != base::kNullProcessHandle) {
1670 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391671 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351672 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511673 }
1674 return;
1675 }
1676
[email protected]bafe6cd2012-05-23 23:09:501677 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041678 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261679 created_widgets_.insert(widget_host);
1680
[email protected]cfd80b02014-05-01 17:46:481681 RenderWidgetHostViewBase* widget_view =
1682 static_cast<RenderWidgetHostViewBase*>(
1683 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191684 if (!widget_view)
1685 return;
[email protected]bafe6cd2012-05-23 23:09:501686 if (!is_fullscreen) {
1687 // Popups should not get activated.
1688 widget_view->SetPopupType(popup_type);
1689 }
1690 // Save the created widget associated with the route so we can show it later.
1691 pending_widget_views_[route_id] = widget_view;
1692
1693#if defined(OS_MACOSX)
1694 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1695 // to allow it to survive the trip without being hosted.
1696 base::mac::NSObjectRetain(widget_view->GetNativeView());
1697#endif
1698}
1699
1700void WebContentsImpl::ShowCreatedWindow(int route_id,
1701 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:391702 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:501703 bool user_gesture) {
1704 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001705 if (contents) {
1706 WebContentsDelegate* delegate = GetDelegate();
1707 if (delegate) {
1708 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:391709 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:001710 }
1711 }
[email protected]bafe6cd2012-05-23 23:09:501712}
1713
1714void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:391715 const gfx::Rect& initial_rect) {
1716 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:501717}
1718
1719void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1720 ShowCreatedWidget(route_id, true, gfx::Rect());
1721}
1722
1723void WebContentsImpl::ShowCreatedWidget(int route_id,
1724 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:391725 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:481726 RenderWidgetHostViewBase* widget_host_view =
1727 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501728 if (!widget_host_view)
1729 return;
[email protected]cfd80b02014-05-01 17:46:481730
1731 RenderWidgetHostView* view = NULL;
1732 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1733 if (guest && guest->embedder_web_contents()) {
1734 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1735 } else {
1736 view = GetRenderWidgetHostView();
1737 }
1738
[email protected]4aebbca2013-09-17 22:26:491739 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311740 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031741 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311742 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491743 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1744 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:531745 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:491746 } else {
[email protected]cfd80b02014-05-01 17:46:481747 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491748 }
[email protected]4aebbca2013-09-17 22:26:491749 FOR_EACH_OBSERVER(WebContentsObserver,
1750 observers_,
1751 DidShowFullscreenWidget(route_id));
1752 if (!widget_host_view->HasFocus())
1753 widget_host_view->Focus();
1754 } else {
bokan107a47f2015-02-03 23:23:391755 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:491756 }
[email protected]89054502012-06-03 10:29:241757
1758 RenderWidgetHostImpl* render_widget_host_impl =
1759 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1760 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311761 // Only allow privileged mouse lock for fullscreen render widget, which is
1762 // used to implement Pepper Flash fullscreen.
1763 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501764
1765#if defined(OS_MACOSX)
1766 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1767 // properly embedded (or purposefully ignored) we can release the retain we
1768 // took in CreateNewWidget().
1769 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1770#endif
1771}
1772
1773WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1774 PendingContents::iterator iter = pending_contents_.find(route_id);
1775
1776 // Certain systems can block the creation of new windows. If we didn't succeed
1777 // in creating one, just return NULL.
1778 if (iter == pending_contents_.end()) {
1779 return NULL;
1780 }
1781
1782 WebContentsImpl* new_contents = iter->second;
1783 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101784 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501785
[email protected]d70bea92013-04-05 04:23:341786 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251787 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341788 return new_contents;
1789
[email protected]bafe6cd2012-05-23 23:09:501790 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1791 !new_contents->GetRenderViewHost()->GetView())
1792 return NULL;
1793
creis82dd6af2014-09-17 16:30:451794 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501795 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1796 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
clamydf1975e2015-02-05 19:12:241797 new_contents->GetMainFrame()->Init();
creis82dd6af2014-09-17 16:30:451798
[email protected]bafe6cd2012-05-23 23:09:501799 return new_contents;
1800}
1801
1802RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1803 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1804 if (iter == pending_widget_views_.end()) {
1805 DCHECK(false);
1806 return NULL;
1807 }
1808
1809 RenderWidgetHostView* widget_host_view = iter->second;
1810 pending_widget_views_.erase(route_id);
1811
1812 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1813 if (!widget_host->GetProcess()->HasConnection()) {
1814 // The view has gone away or the renderer crashed. Nothing to do.
1815 return NULL;
1816 }
1817
1818 return widget_host_view;
1819}
1820
[email protected]f13b4202012-06-12 23:53:231821void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091822 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211823 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371824 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231825 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371826 } else {
1827 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041828 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371829 scoped_ptr<MediaStreamUI>());
1830 }
[email protected]f13b4202012-06-12 23:53:231831}
1832
grunell657d4d82014-09-18 00:09:431833bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1834 MediaStreamType type) {
1835 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1836 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1837 return delegate_ &&
1838 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1839}
1840
[email protected]cc9200432013-07-23 23:02:401841SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1842 SiteInstance* instance) {
1843 return controller_.GetSessionStorageNamespace(instance);
1844}
1845
[email protected]6de7fc482014-06-06 10:46:441846SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1847 return controller_.GetSessionStorageNamespaceMap();
1848}
1849
[email protected]9b159a52013-10-03 17:24:551850FrameTree* WebContentsImpl::GetFrameTree() {
1851 return &frame_tree_;
1852}
1853
lukendc35e7f2014-11-10 19:06:141854void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
1855 virtual_keyboard_requested_ = requested;
1856}
1857
1858bool WebContentsImpl::IsVirtualKeyboardRequested() {
1859 return virtual_keyboard_requested_;
1860}
1861
[email protected]95640212014-07-26 18:14:301862AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1863 return accessibility_mode_;
1864}
1865
[email protected]31a71eaf2014-03-13 01:47:361866void WebContentsImpl::AccessibilityEventReceived(
1867 const std::vector<AXEventNotificationDetails>& details) {
1868 FOR_EACH_OBSERVER(
1869 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1870}
1871
dmazzonia656928e2014-09-15 20:28:541872RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:401873 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:541874 int browser_plugin_instance_id) {
1875 BrowserPluginGuestManager* guest_manager =
1876 GetBrowserContext()->GetGuestManager();
fsamuel833ee7c2015-02-13 23:40:401877 // TODO(fsamuel): Change message routing to use the process ID of the
1878 // |render_frame_host| once BrowserPlugin IPCs get routed using the RFH
1879 // routing ID. See http://crbug.com/436339.
dmazzonia656928e2014-09-15 20:28:541880 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:401881 GetRenderProcessHost()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:541882 if (!guest)
1883 return NULL;
1884 return guest->GetMainFrame();
1885}
1886
blundellc57b93f2014-10-29 13:19:571887GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
1888 return geolocation_service_context_.get();
1889}
1890
[email protected]edc3af82013-12-12 21:24:071891void WebContentsImpl::OnShowValidationMessage(
1892 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291893 const base::string16& main_text,
1894 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071895 if (delegate_)
1896 delegate_->ShowValidationMessage(
1897 this, anchor_in_root_view, main_text, sub_text);
1898}
1899
1900void WebContentsImpl::OnHideValidationMessage() {
1901 if (delegate_)
1902 delegate_->HideValidationMessage(this);
1903}
1904
1905void WebContentsImpl::OnMoveValidationMessage(
1906 const gfx::Rect& anchor_in_root_view) {
1907 if (delegate_)
1908 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1909}
1910
[email protected]32deec62013-05-15 23:55:041911void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1912 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441913 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041914}
1915
[email protected]95640212014-07-26 18:14:301916BrowserAccessibilityManager*
1917 WebContentsImpl::GetRootBrowserAccessibilityManager() {
clamydf1975e2015-02-05 19:12:241918 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:301919 return rfh ? rfh->browser_accessibility_manager() : NULL;
1920}
1921
1922BrowserAccessibilityManager*
1923 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
clamydf1975e2015-02-05 19:12:241924 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:301925 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1926}
1927
[email protected]b172aee2012-04-10 17:05:261928void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491929 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231930 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491931 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331932}
1933
[email protected]b172aee2012-04-10 17:05:261934void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341935 if (delegate_)
1936 delegate_->ResizeDueToAutoResize(this, new_size);
1937}
1938
[email protected]b172aee2012-04-10 17:05:261939WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201940 if (!delegate_)
1941 return NULL;
[email protected]00c37fc2011-08-02 00:22:501942
[email protected]e5d549d2011-12-28 01:29:201943 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201944 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341945}
1946
[email protected]6b618e62012-08-16 12:59:181947bool WebContentsImpl::Send(IPC::Message* message) {
1948 if (!GetRenderViewHost()) {
1949 delete message;
1950 return false;
1951 }
1952
1953 return GetRenderViewHost()->Send(message);
1954}
1955
[email protected]b172aee2012-04-10 17:05:261956bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501957 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261958 FrameTreeNode* node = frame_tree_.root();
1959
creise42f2a52014-09-18 18:14:571960 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
1961 // is currently only used in --site-per-process and tests.
[email protected]61ac9e242014-03-21 20:55:261962 NavigationEntryImpl* pending_entry =
1963 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
creise42f2a52014-09-18 18:14:571964 if (pending_entry->frame_tree_node_id() != -1) {
1965 FrameTreeNode* subframe =
1966 frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1967 DCHECK(subframe);
1968 if (subframe)
1969 node = subframe;
[email protected]61ac9e242014-03-21 20:55:261970 }
1971
1972 return node->navigator()->NavigateToPendingEntry(
1973 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541974}
[email protected]96d185d2009-04-24 03:28:541975
[email protected]a86c0e962013-12-17 17:10:391976void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1977 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441978 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391979 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441980}
1981
[email protected]20ca0382013-02-28 19:50:071982void WebContentsImpl::AttachInterstitialPage(
1983 InterstitialPageImpl* interstitial_page) {
1984 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211985 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291986
1987 // Cancel any visible dialogs so that they don't interfere with the
1988 // interstitial.
1989 if (dialog_manager_)
1990 dialog_manager_->CancelActiveAndPendingDialogs(this);
1991
[email protected]20ca0382013-02-28 19:50:071992 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1993 DidAttachInterstitialPage());
1994}
1995
1996void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571997 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211998 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071999 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2000 DidDetachInterstitialPage());
2001}
2002
avi2b177592014-12-10 02:08:022003void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2004 int history_length) {
2005 SetHistoryOffsetAndLengthForView(
2006 GetRenderViewHost(), history_offset, history_length);
2007}
2008
2009void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2010 RenderViewHost* render_view_host,
2011 int history_offset,
2012 int history_length) {
2013 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2014 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142015}
2016
[email protected]4fed3702014-04-01 09:08:002017void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172018 RenderFrameHost* focused_frame = GetFocusedFrame();
2019 if (!focused_frame)
2020 return;
2021
[email protected]959be4c2014-04-08 15:01:332022 focused_frame->Send(new FrameMsg_Reload(
2023 focused_frame->GetRoutingID(), ignore_cache));
2024}
2025
2026void WebContentsImpl::Undo() {
2027 RenderFrameHost* focused_frame = GetFocusedFrame();
2028 if (!focused_frame)
2029 return;
2030
2031 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2032 RecordAction(base::UserMetricsAction("Undo"));
2033}
2034
2035void WebContentsImpl::Redo() {
2036 RenderFrameHost* focused_frame = GetFocusedFrame();
2037 if (!focused_frame)
2038 return;
2039 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2040 RecordAction(base::UserMetricsAction("Redo"));
2041}
2042
2043void WebContentsImpl::Cut() {
2044 RenderFrameHost* focused_frame = GetFocusedFrame();
2045 if (!focused_frame)
2046 return;
2047
2048 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2049 RecordAction(base::UserMetricsAction("Cut"));
2050}
2051
2052void WebContentsImpl::Copy() {
2053 RenderFrameHost* focused_frame = GetFocusedFrame();
2054 if (!focused_frame)
2055 return;
2056
2057 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2058 RecordAction(base::UserMetricsAction("Copy"));
2059}
2060
2061void WebContentsImpl::CopyToFindPboard() {
2062#if defined(OS_MACOSX)
2063 RenderFrameHost* focused_frame = GetFocusedFrame();
2064 if (!focused_frame)
2065 return;
2066
2067 // Windows/Linux don't have the concept of a find pasteboard.
2068 focused_frame->Send(
2069 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2070 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2071#endif
2072}
2073
2074void WebContentsImpl::Paste() {
2075 RenderFrameHost* focused_frame = GetFocusedFrame();
2076 if (!focused_frame)
2077 return;
2078
2079 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2080 RecordAction(base::UserMetricsAction("Paste"));
2081}
2082
2083void WebContentsImpl::PasteAndMatchStyle() {
2084 RenderFrameHost* focused_frame = GetFocusedFrame();
2085 if (!focused_frame)
2086 return;
2087
2088 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2089 focused_frame->GetRoutingID()));
2090 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2091}
2092
2093void WebContentsImpl::Delete() {
2094 RenderFrameHost* focused_frame = GetFocusedFrame();
2095 if (!focused_frame)
2096 return;
2097
2098 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2099 RecordAction(base::UserMetricsAction("DeleteSelection"));
2100}
2101
2102void WebContentsImpl::SelectAll() {
2103 RenderFrameHost* focused_frame = GetFocusedFrame();
2104 if (!focused_frame)
2105 return;
2106
2107 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2108 RecordAction(base::UserMetricsAction("SelectAll"));
2109}
2110
2111void WebContentsImpl::Unselect() {
2112 RenderFrameHost* focused_frame = GetFocusedFrame();
2113 if (!focused_frame)
2114 return;
2115
2116 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2117 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172118}
2119
2120void WebContentsImpl::Replace(const base::string16& word) {
2121 RenderFrameHost* focused_frame = GetFocusedFrame();
2122 if (!focused_frame)
2123 return;
2124
[email protected]959be4c2014-04-08 15:01:332125 focused_frame->Send(new InputMsg_Replace(
2126 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172127}
2128
2129void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2130 RenderFrameHost* focused_frame = GetFocusedFrame();
2131 if (!focused_frame)
2132 return;
2133
[email protected]959be4c2014-04-08 15:01:332134 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2135 focused_frame->GetRoutingID(), word));
2136}
2137
2138void WebContentsImpl::NotifyContextMenuClosed(
2139 const CustomContextMenuContext& context) {
2140 RenderFrameHost* focused_frame = GetFocusedFrame();
2141 if (!focused_frame)
2142 return;
2143
2144 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2145 focused_frame->GetRoutingID(), context));
2146}
2147
2148void WebContentsImpl::ExecuteCustomContextMenuCommand(
2149 int action, const CustomContextMenuContext& context) {
2150 RenderFrameHost* focused_frame = GetFocusedFrame();
2151 if (!focused_frame)
2152 return;
2153
2154 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2155 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002156}
2157
[email protected]fc2b46b2014-05-03 16:33:452158gfx::NativeView WebContentsImpl::GetNativeView() {
2159 return view_->GetNativeView();
2160}
2161
2162gfx::NativeView WebContentsImpl::GetContentNativeView() {
2163 return view_->GetContentNativeView();
2164}
2165
2166gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2167 return view_->GetTopLevelNativeWindow();
2168}
2169
2170gfx::Rect WebContentsImpl::GetViewBounds() {
2171 return view_->GetViewBounds();
2172}
2173
2174gfx::Rect WebContentsImpl::GetContainerBounds() {
2175 gfx::Rect rv;
2176 view_->GetContainerBounds(&rv);
2177 return rv;
2178}
2179
2180DropData* WebContentsImpl::GetDropData() {
2181 return view_->GetDropData();
2182}
2183
2184void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042185 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452186}
2187
2188void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042189 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452190}
2191
2192void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042193 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452194}
2195
2196void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042197 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452198}
2199
[email protected]b172aee2012-04-10 17:05:262200void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272201 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212202 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542203 return;
2204 }
[email protected]0b431992014-06-24 00:08:032205 RenderWidgetHostView* const fullscreen_view =
2206 GetFullscreenRenderWidgetHostView();
2207 if (fullscreen_view) {
2208 fullscreen_view->Focus();
2209 return;
2210 }
[email protected]9f76c1e2012-03-05 15:15:582211 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542212}
2213
[email protected]b172aee2012-04-10 17:05:262214bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212215 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542216}
2217
[email protected]b172aee2012-04-10 17:05:262218InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212219 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222220}
2221
[email protected]b172aee2012-04-10 17:05:262222bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162223 // WebKit creates Document object when MIME type is application/xhtml+xml,
2224 // so we also support this MIME type.
2225 return contents_mime_type_ == "text/html" ||
2226 contents_mime_type_ == "text/xml" ||
2227 contents_mime_type_ == "application/xhtml+xml" ||
2228 contents_mime_type_ == "text/plain" ||
2229 contents_mime_type_ == "text/css" ||
2230 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2231}
2232
[email protected]b172aee2012-04-10 17:05:262233void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592234 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162235 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552236 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012237 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142238 return;
[email protected]c7dd2f62011-07-18 15:57:592239 }
2240
2241 Stop();
2242
2243 // Create the save package and possibly prompt the user for the name to save
2244 // the page as. The user prompt is an asynchronous operation that runs on
2245 // another thread.
2246 save_package_ = new SavePackage(this);
2247 save_package_->GetSaveInfo();
2248}
2249
2250// Used in automated testing to bypass prompting the user for file names.
2251// Instead, the names and paths are hard coded rather than running them through
2252// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342253bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2254 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212255 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592256 // Stop the page from navigating.
2257 Stop();
2258
2259 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212260 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592261}
2262
[email protected]3c71576ce2013-07-23 02:00:012263void WebContentsImpl::SaveFrame(const GURL& url,
2264 const Referrer& referrer) {
2265 if (!GetURL().is_valid())
2266 return;
sammc92af61552014-11-19 23:27:402267 if (delegate_ && delegate_->SaveFrame(url, referrer))
2268 return;
2269
[email protected]3c71576ce2013-07-23 02:00:012270 bool is_main_frame = (url == GetURL());
2271
2272 DownloadManager* dlm =
2273 BrowserContext::GetDownloadManager(GetBrowserContext());
2274 if (!dlm)
2275 return;
2276 int64 post_id = -1;
2277 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272278 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012279 if (entry)
2280 post_id = entry->GetPostID();
2281 }
2282 scoped_ptr<DownloadUrlParameters> params(
2283 DownloadUrlParameters::FromWebContents(this, url));
2284 params->set_referrer(referrer);
2285 params->set_post_id(post_id);
2286 params->set_prefer_cache(true);
2287 if (post_id >= 0)
2288 params->set_method("POST");
2289 params->set_prompt(true);
2290 dlm->DownloadUrl(params.Pass());
2291}
2292
[email protected]b172aee2012-04-10 17:05:262293void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342294 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482295 const base::Callback<void(int64)>& callback) {
2296 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122297}
2298
[email protected]b172aee2012-04-10 17:05:262299const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272300 return contents_mime_type_;
2301}
2302
[email protected]b172aee2012-04-10 17:05:262303bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272304 return notify_disconnection_;
2305}
2306
[email protected]b172aee2012-04-10 17:05:262307void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312308 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182309 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162310}
2311
[email protected]b172aee2012-04-10 17:05:262312void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542313 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182314 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162315}
2316
[email protected]8ff00d72012-10-23 19:12:212317RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272318 return &renderer_preferences_;
2319}
2320
[email protected]e35ccd52012-05-23 16:22:472321void WebContentsImpl::Close() {
2322 Close(GetRenderViewHost());
2323}
2324
[email protected]cf200a562013-05-03 16:24:292325void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462326 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292327 if (browser_plugin_embedder_.get())
2328 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2329 screen_x, screen_y, operation);
2330 if (GetRenderViewHost())
2331 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2332 screen_x, screen_y, operation);
2333}
2334
[email protected]d60f3702013-12-26 16:30:242335void WebContentsImpl::DidGetResourceResponseStart(
2336 const ResourceRequestDetails& details) {
2337 controller_.ssl_manager()->DidStartResourceResponse(details);
2338
2339 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2340 DidGetResourceResponseStart(details));
2341
2342 // TODO(avi): Remove. http://crbug.com/170921
2343 NotificationService::current()->Notify(
2344 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2345 Source<WebContents>(this),
2346 Details<const ResourceRequestDetails>(&details));
2347}
2348
2349void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462350 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242351 const ResourceRedirectDetails& details) {
2352 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2353
2354 FOR_EACH_OBSERVER(
2355 WebContentsObserver,
2356 observers_,
creis114ca1b2014-11-13 23:51:462357 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242358
2359 // TODO(avi): Remove. http://crbug.com/170921
2360 NotificationService::current()->Notify(
2361 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2362 Source<WebContents>(this),
2363 Details<const ResourceRedirectDetails>(&details));
2364}
2365
[email protected]b172aee2012-04-10 17:05:262366void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522367 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582368 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512369 if (delegate_)
2370 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292371 if (browser_plugin_embedder_.get())
2372 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342373}
2374
[email protected]e35ccd52012-05-23 16:22:472375void WebContentsImpl::UserGestureDone() {
2376 OnUserGesture();
2377}
2378
[email protected]b172aee2012-04-10 17:05:262379void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272380 closed_by_user_gesture_ = value;
2381}
2382
[email protected]b172aee2012-04-10 17:05:262383bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272384 return closed_by_user_gesture_;
2385}
2386
[email protected]b172aee2012-04-10 17:05:262387void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502388 if (!delegate_)
2389 return;
2390
[email protected]6286a372013-10-09 04:03:272391 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2392 if (!entry)
[email protected]1788e772010-12-15 16:40:502393 return;
2394
[email protected]6286a372013-10-09 04:03:272395 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122396}
2397
[email protected]b172aee2012-04-10 17:05:262398void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042399 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272400 if (!delegate_)
2401 return;
2402
[email protected]691aa2f2013-05-28 22:52:042403 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272404}
2405
[email protected]b172aee2012-04-10 17:05:262406int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272407 return minimum_zoom_percent_;
2408}
2409
[email protected]b172aee2012-04-10 17:05:262410int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272411 return maximum_zoom_percent_;
2412}
2413
[email protected]b172aee2012-04-10 17:05:262414gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492415 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232416}
2417
[email protected]b172aee2012-04-10 17:05:262418bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052419 if (GetBrowserPluginGuest())
2420 return GetBrowserPluginGuest()->LockMouse(allowed);
2421
[email protected]0bfbf882011-12-22 18:19:272422 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582423 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272424}
2425
[email protected]b172aee2012-04-10 17:05:262426bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442427 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502428}
2429
jochen55ff3502014-12-18 20:52:572430WebContents* WebContentsImpl::GetOpener() const {
2431 return static_cast<WebContents*>(opener_);
2432}
2433
[email protected]cb805452013-05-22 15:16:212434void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482435 if (!color_chooser_info_.get())
2436 return;
2437 RenderFrameHost* rfh = RenderFrameHost::FromID(
2438 color_chooser_info_->render_process_id,
2439 color_chooser_info_->render_frame_id);
2440 if (!rfh)
2441 return;
2442
2443 rfh->Send(new FrameMsg_DidChooseColorResponse(
2444 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202445}
2446
[email protected]cb805452013-05-22 15:16:212447void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482448 if (!color_chooser_info_.get())
2449 return;
2450 RenderFrameHost* rfh = RenderFrameHost::FromID(
2451 color_chooser_info_->render_process_id,
2452 color_chooser_info_->render_frame_id);
2453 if (!rfh)
2454 return;
2455
2456 rfh->Send(new FrameMsg_DidEndColorChooser(
2457 rfh->GetRoutingID(), color_chooser_info_->identifier));
2458 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202459}
2460
[email protected]41225fe2013-03-29 05:32:022461int WebContentsImpl::DownloadImage(const GURL& url,
2462 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302463 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022464 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582465 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022466 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392467 return id;
2468}
2469
[email protected]5dcaf8e2013-12-28 01:31:422470bool WebContentsImpl::IsSubframe() const {
2471 return is_subframe_;
2472}
2473
[email protected]36ec24f2014-01-09 00:32:082474void WebContentsImpl::Find(int request_id,
2475 const base::string16& search_text,
2476 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092477 // See if a top level browser plugin handles the find request first.
2478 if (browser_plugin_embedder_ &&
2479 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2480 return;
2481 }
[email protected]36ec24f2014-01-09 00:32:082482 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2483}
2484
2485void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012486 // See if a top level browser plugin handles the stop finding request first.
2487 if (browser_plugin_embedder_ &&
2488 browser_plugin_embedder_->StopFinding(action)) {
2489 return;
2490 }
[email protected]36ec24f2014-01-09 00:32:082491 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2492}
2493
[email protected]4fe53add2014-04-08 19:53:362494void WebContentsImpl::InsertCSS(const std::string& css) {
2495 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2496 GetMainFrame()->GetRoutingID(), css));
2497}
2498
dalecurtisbc6572e12014-09-12 19:22:302499bool WebContentsImpl::WasRecentlyAudible() {
2500 return audio_stream_monitor_.WasRecentlyAudible();
2501}
2502
mlamouriefdca9d2014-09-16 16:55:402503void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2504 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2505}
2506
mlamouri7a78d6fd2015-01-17 13:23:532507void WebContentsImpl::ExitFullscreen() {
2508 // Clean up related state and initiate the fullscreen exit.
2509 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary();
2510 ExitFullscreenMode();
2511}
2512
[email protected]b172aee2012-04-10 17:05:262513bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272514 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172515 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332516 return true;
2517 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272518}
2519
[email protected]b172aee2012-04-10 17:05:262520void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272521 if (delegate_)
2522 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212523}
2524
[email protected]52913802013-12-10 05:52:182525void WebContentsImpl::DidStartProvisionalLoad(
2526 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182527 const GURL& validated_url,
2528 bool is_error_page,
2529 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102530 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482531 FOR_EACH_OBSERVER(
2532 WebContentsObserver,
2533 observers_,
2534 DidStartProvisionalLoadForFrame(
2535 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:082536
2537 // Notify accessibility if this is a reload.
2538 NavigationEntry* entry = controller_.GetVisibleEntry();
2539 if (entry && ui::PageTransitionCoreTypeIs(
2540 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
2541 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2542 BrowserAccessibilityManager* manager =
2543 ftn->current_frame_host()->browser_accessibility_manager();
2544 if (manager)
2545 manager->UserIsReloading();
2546 }
[email protected]400992b2012-06-14 00:03:542547}
2548
[email protected]0c3c54f2014-07-31 01:29:002549void WebContentsImpl::DidStartNavigationTransition(
morritaffb82612014-10-31 18:26:592550 RenderFrameHostImpl* render_frame_host) {
[email protected]0c3c54f2014-07-31 01:29:002551#if defined(OS_ANDROID)
2552 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562553 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
morritaffb82612014-10-31 18:26:592554 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002555#endif
2556}
2557
[email protected]3109fbb72014-01-06 23:57:152558void WebContentsImpl::DidFailProvisionalLoadWithError(
2559 RenderFrameHostImpl* render_frame_host,
2560 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2561 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312562 FOR_EACH_OBSERVER(WebContentsObserver,
2563 observers_,
2564 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312565 validated_url,
2566 params.error_code,
2567 params.error_description));
dmazzonibf8cec42015-02-08 08:28:082568
2569 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2570 BrowserAccessibilityManager* manager =
2571 ftn->current_frame_host()->browser_accessibility_manager();
2572 if (manager)
2573 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:152574}
2575
[email protected]b80624c2014-02-09 02:46:552576void WebContentsImpl::DidFailLoadWithError(
2577 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552578 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552579 int error_code,
2580 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142581 FOR_EACH_OBSERVER(
2582 WebContentsObserver,
2583 observers_,
2584 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552585}
2586
[email protected]52913802013-12-10 05:52:182587void WebContentsImpl::NotifyChangedNavigationState(
2588 InvalidateTypes changed_flags) {
2589 NotifyNavigationStateChanged(changed_flags);
2590}
2591
[email protected]3691e5cf2014-01-22 10:16:202592void WebContentsImpl::AboutToNavigateRenderFrame(
pfeldmanf87691a2015-01-23 16:58:172593 RenderFrameHostImpl* old_host,
2594 RenderFrameHostImpl* new_host) {
creis114ca1b2014-11-13 23:51:462595 // Notify observers that we will navigate in this RenderFrame.
[email protected]3691e5cf2014-01-22 10:16:202596 FOR_EACH_OBSERVER(
2597 WebContentsObserver,
2598 observers_,
pfeldmanf87691a2015-01-23 16:58:172599 AboutToNavigateRenderFrame(old_host, new_host));
[email protected]3691e5cf2014-01-22 10:16:202600}
2601
2602void WebContentsImpl::DidStartNavigationToPendingEntry(
2603 RenderFrameHostImpl* render_frame_host,
2604 const GURL& url,
2605 NavigationController::ReloadType reload_type) {
2606 // Notify observers about navigation.
2607 FOR_EACH_OBSERVER(
2608 WebContentsObserver,
2609 observers_,
2610 DidStartNavigationToPendingEntry(url, reload_type));
2611}
2612
[email protected]8cb834e2014-03-06 14:23:232613void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2614 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:502615 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
2616 // weak pointer of sorts.
2617 const int32_t process_id = render_frame_host->GetProcess()->GetID();
2618 const int32_t frame_id = render_frame_host->GetRoutingID();
2619
[email protected]65920f332014-03-04 21:14:182620 WebContents* new_contents = OpenURL(params);
2621
dchengb907f7332015-01-07 20:35:502622 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:182623 // Notify observers.
2624 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2625 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:462626 render_frame_host,
[email protected]65920f332014-03-04 21:14:182627 params.url,
2628 params.referrer,
2629 params.disposition,
creis114ca1b2014-11-13 23:51:462630 params.transition));
[email protected]65920f332014-03-04 21:14:182631 }
2632}
2633
[email protected]aa62afd2014-04-22 19:22:462634bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2635 if (!delegate_)
2636 return false;
2637 return delegate_->ShouldPreserveAbortedURLs(this);
2638}
2639
[email protected]37567b432014-02-12 01:12:222640void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432641 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222642 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352643 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222644 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482645 FOR_EACH_OBSERVER(WebContentsObserver,
2646 observers_,
2647 DidCommitProvisionalLoadForFrame(
2648 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:082649
2650 BrowserAccessibilityManager* manager =
2651 render_frame_host->browser_accessibility_manager();
2652 if (manager)
2653 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:222654}
2655
[email protected]0d0f4c492014-04-02 06:42:572656void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232657 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572658 // Ensure fullscreen mode is exited before committing the navigation to a
2659 // different page. The next page will not start out assuming it is in
2660 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232661 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192662 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572663 return;
2664 }
2665 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:532666 ExitFullscreen();
[email protected]0d0f4c492014-04-02 06:42:572667 DCHECK(!IsFullscreenForCurrentTab());
2668}
2669
[email protected]37567b432014-02-12 01:12:222670void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:282671 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222672 const LoadCommittedDetails& details,
2673 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2674 if (details.is_navigation_to_different_page()) {
2675 // Clear the status bubble. This is a workaround for a bug where WebKit
2676 // doesn't let us know that the cursor left an element during a
2677 // transition (this is also why the mouse cursor remains as a hand after
2678 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2679 // clear the bubble when a user navigates to a named anchor in the same
2680 // page.
sky8b00392d2015-01-10 00:30:282681 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:002682
2683 RenderWidgetHostViewBase* rwhvb =
2684 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2685 if (rwhvb)
2686 rwhvb->OnDidNavigateMainFrameToNewPage();
[email protected]37567b432014-02-12 01:12:222687 }
2688
2689 if (!details.is_in_page) {
2690 // Once the main frame is navigated, we're no longer considered to have
2691 // displayed insecure content.
2692 displayed_insecure_content_ = false;
2693 SSLManager::NotifySSLInternalStateChanged(
2694 GetController().GetBrowserContext());
2695 }
2696
2697 // Notify observers about navigation.
2698 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2699 DidNavigateMainFrame(details, params));
2700
[email protected]e85165c642014-06-10 14:34:312701 if (delegate_)
[email protected]37567b432014-02-12 01:12:222702 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312703 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222704}
2705
2706void WebContentsImpl::DidNavigateAnyFramePostCommit(
2707 RenderFrameHostImpl* render_frame_host,
2708 const LoadCommittedDetails& details,
2709 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102710 // Now that something has committed, we don't need to track whether the
2711 // initial page has been accessed.
2712 has_accessed_initial_document_ = false;
2713
[email protected]37567b432014-02-12 01:12:222714 // If we navigate off the page, close all JavaScript dialogs.
2715 if (dialog_manager_ && !details.is_in_page)
2716 dialog_manager_->CancelActiveAndPendingDialogs(this);
2717
2718 // Notify observers about navigation.
2719 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:092720 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:222721}
2722
2723void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2724 contents_mime_type_ = mime_type;
2725}
2726
[email protected]277857a2014-06-03 10:38:012727bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312728 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052729 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312730 return false;
2731
[email protected]37567b432014-02-12 01:12:222732 if (delegate_)
2733 return delegate_->CanOverscrollContent();
2734
2735 return false;
2736}
2737
[email protected]37b64c52014-07-11 21:14:052738void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252739 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052740 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252741}
2742
[email protected]b172aee2012-04-10 17:05:262743void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182744 const GURL& url,
[email protected]70435962011-08-02 20:13:282745 const std::string& security_info,
2746 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182747 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402748 ResourceType resource_type) {
[email protected]724159a2010-12-30 01:11:182749
2750 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082751 int cert_id = 0;
2752 net::CertStatus cert_status = 0;
2753 int security_bits = -1;
2754 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122755 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212756 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122757 &security_bits, &connection_status,
2758 &signed_certificate_timestamp_ids);
2759 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212760 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002761 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2762 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182763
[email protected]b0f724c2013-09-05 04:21:132764 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2765
2766 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2767 DidLoadResourceFromMemoryCache(details));
2768
[email protected]8bfc8272013-09-09 20:10:532769 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2770 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402771 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532772 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2773 GetRenderProcessHost()->GetID()) :
2774 GetBrowserContext()->GetRequestContextForRenderProcess(
2775 GetRenderProcessHost()->GetID()));
2776 BrowserThread::PostTask(
2777 BrowserThread::IO,
2778 FROM_HERE,
2779 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2780 }
[email protected]724159a2010-12-30 01:11:182781}
2782
[email protected]b172aee2012-04-10 17:05:262783void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392784 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182785 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192786 SSLManager::NotifySSLInternalStateChanged(
2787 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182788}
2789
[email protected]b172aee2012-04-10 17:05:262790void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022791 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582792 LOG(WARNING) << security_origin << " ran insecure content from "
2793 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392794 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412795 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392796 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182797 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412798 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192799 SSLManager::NotifySSLInternalStateChanged(
2800 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182801}
2802
[email protected]501052ff2014-02-21 22:19:072803void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:112804 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:472805 return;
naskofbd033392015-01-27 02:34:472806
[email protected]1d62cf72014-02-07 21:31:572807 RenderFrameHostImpl* rfh =
2808 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142809 FOR_EACH_OBSERVER(
2810 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182811}
2812
naskofbd033392015-01-27 02:34:472813void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:112814 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:122815 return;
[email protected]a1b99262013-12-27 21:56:222816
[email protected]8b3af1e2014-01-24 13:29:122817 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442818 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372819 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422820 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372821
[email protected]61ac9e242014-03-21 20:55:262822 RenderFrameHostImpl* rfh =
2823 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142824 FOR_EACH_OBSERVER(
2825 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312826}
2827
[email protected]960b0372014-05-19 18:01:002828void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
nasko907fcb62015-01-28 04:24:112829 if (!HasValidFrameSource())
2830 return;
2831
[email protected]960b0372014-05-19 18:01:002832 RenderFrameHostImpl* rfh =
2833 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2834 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2835
creis1163acf2014-12-19 21:18:472836 // Any main frame load to a new document should reset the load progress, since
2837 // it will replace the current page and any frames.
2838 if (to_different_document && !rfh->GetParent()) {
2839 ResetLoadProgressState();
2840 loading_frames_in_progress_ = 0;
naskoa7064ad6e2015-01-15 18:44:562841 rfh->frame_tree_node()->set_is_loading(false);
creis1163acf2014-12-19 21:18:472842 }
2843
[email protected]960b0372014-05-19 18:01:002844 // It is possible to get multiple calls to OnDidStartLoading that don't have
2845 // corresponding calls to OnDidStopLoading:
2846 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2847 // out for a cross-process navigation, and it turns into a placeholder for
2848 // one being rendered in a different process.
2849 // - Also, there might be more than one RenderFrameHost sharing the same
2850 // FrameTreeNode (and thus sharing its ID) each sending a start.
2851 // - But in the future, once clamy@ moves navigation network requests to the
2852 // browser process, there's a good chance that callbacks about starting and
2853 // stopping will all be handled by the browser. When that happens, there
2854 // should no longer be a start/stop call imbalance. TODO(avi): When this
2855 // future arrives, update this code to not allow this case.
naskoa7064ad6e2015-01-15 18:44:562856 if (rfh->frame_tree_node()->is_loading())
2857 return;
2858
[email protected]960b0372014-05-19 18:01:002859 DCHECK_GE(loading_frames_in_progress_, 0);
naskoa7064ad6e2015-01-15 18:44:562860 if (loading_frames_in_progress_ == 0)
2861 DidStartLoading(rfh, to_different_document);
2862
2863 ++loading_frames_in_progress_;
2864 rfh->frame_tree_node()->set_is_loading(true);
[email protected]960b0372014-05-19 18:01:002865
nasko3e8c20e2014-12-18 06:54:562866 // Notify the RenderFrameHostManager of the event.
2867 rfh->frame_tree_node()->render_manager()->OnDidStartLoading();
2868
[email protected]960b0372014-05-19 18:01:002869 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2870 SendLoadProgressChanged();
2871}
2872
2873void WebContentsImpl::OnDidStopLoading() {
nasko907fcb62015-01-28 04:24:112874 if (!HasValidFrameSource())
2875 return;
2876
[email protected]960b0372014-05-19 18:01:002877 RenderFrameHostImpl* rfh =
2878 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2879 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
naskoa7064ad6e2015-01-15 18:44:562880 rfh->frame_tree_node()->set_is_loading(false);
[email protected]960b0372014-05-19 18:01:002881
2882 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2883 // Load stopped while we were still tracking load. Make sure we update
2884 // progress based on this frame's completion.
2885 loading_progresses_[render_frame_id] = 1.0;
2886 SendLoadProgressChanged();
2887 // Then we clean-up our states.
2888 if (loading_total_progress_ == 1.0)
2889 ResetLoadProgressState();
2890 }
2891
nasko3e8c20e2014-12-18 06:54:562892 // Notify the RenderFrameHostManager of the event.
2893 rfh->frame_tree_node()->render_manager()->OnDidStopLoading();
2894
[email protected]960b0372014-05-19 18:01:002895 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2896 // calls DidStopLoading() without a matching DidStartLoading().
2897 if (loading_frames_in_progress_ == 0)
2898 return;
2899 --loading_frames_in_progress_;
2900 if (loading_frames_in_progress_ == 0)
2901 DidStopLoading(rfh);
2902}
2903
2904void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
nasko907fcb62015-01-28 04:24:112905 if (!HasValidFrameSource())
2906 return;
2907
[email protected]960b0372014-05-19 18:01:002908 RenderFrameHostImpl* rfh =
2909 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2910 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2911
2912 loading_progresses_[render_frame_id] = load_progress;
2913
2914 // We notify progress change immediately for the first and last updates.
2915 // Also, since the message loop may be pretty busy when a page is loaded, it
2916 // might not execute a posted task in a timely manner so we make sure to
2917 // immediately send progress report if enough time has passed.
2918 base::TimeDelta min_delay =
2919 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2920 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2921 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2922 // If there is a pending task to send progress, it is now obsolete.
2923 loading_weak_factory_.InvalidateWeakPtrs();
2924 SendLoadProgressChanged();
2925 if (loading_total_progress_ == 1.0)
2926 ResetLoadProgressState();
2927 return;
2928 }
2929
2930 if (loading_weak_factory_.HasWeakPtrs())
2931 return;
2932
2933 base::MessageLoop::current()->PostDelayedTask(
2934 FROM_HERE,
2935 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2936 loading_weak_factory_.GetWeakPtr()),
2937 min_delay);
2938}
2939
[email protected]b172aee2012-04-10 17:05:262940void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222941 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2942 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262943}
2944
[email protected]b172aee2012-04-10 17:05:262945void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302946 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262947 minimum_zoom_percent_ = minimum_percent;
2948 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262949}
2950
[email protected]b172aee2012-04-10 17:05:262951void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342952 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432953 if (!delegate_)
2954 return;
2955
[email protected]b9535422012-02-09 01:47:592956 ChildProcessSecurityPolicyImpl* policy =
2957 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222958 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592959 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212960}
2961
[email protected]b172aee2012-04-10 17:05:262962void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2963 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262964 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362965 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432966 if (!delegate_)
2967 return;
2968
[email protected]b9535422012-02-09 01:47:592969 ChildProcessSecurityPolicyImpl* policy =
2970 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322971 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592972 return;
[email protected]8f810632013-06-06 22:33:322973
[email protected]c125e532014-05-10 20:39:062974 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202975}
2976
[email protected]f5273e52014-07-14 16:30:202977void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2978 const GURL& url,
2979 bool user_gesture) {
2980 if (!delegate_)
2981 return;
2982
2983 ChildProcessSecurityPolicyImpl* policy =
2984 ChildProcessSecurityPolicyImpl::GetInstance();
2985 if (policy->IsPseudoScheme(protocol))
2986 return;
2987
2988 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2989}
2990
[email protected]b172aee2012-04-10 17:05:262991void WebContentsImpl::OnFindReply(int request_id,
2992 int number_of_matches,
2993 const gfx::Rect& selection_rect,
2994 int active_match_ordinal,
2995 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432996 if (delegate_) {
2997 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2998 active_match_ordinal, final_update);
2999 }
[email protected]b888919c2011-09-02 00:32:163000}
3001
[email protected]59363fc92012-09-05 03:46:313002#if defined(OS_ANDROID)
3003void WebContentsImpl::OnFindMatchRectsReply(
3004 int version,
3005 const std::vector<gfx::RectF>& rects,
3006 const gfx::RectF& active_rect) {
3007 if (delegate_)
3008 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3009}
[email protected]583418cc2013-01-17 14:01:103010
[email protected]1ff427972013-02-07 21:14:073011void WebContentsImpl::OnOpenDateTimeDialog(
3012 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173013 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093014 GetRenderViewHost(),
3015 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133016 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093017 value.minimum,
3018 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173019 value.step,
3020 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103021}
[email protected]59363fc92012-09-05 03:46:313022#endif
3023
[email protected]cfa856d62014-02-22 07:58:403024void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
3025 int automation_id) {
3026 DomOperationNotificationDetails details(json_string, automation_id);
3027 NotificationService::current()->Notify(
3028 NOTIFICATION_DOM_OPERATION_RESPONSE,
3029 Source<WebContents>(this),
3030 Details<DomOperationNotificationDetails>(&details));
3031}
3032
[email protected]b172aee2012-04-10 17:05:263033void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3034 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103035 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253036 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103037 AppCacheAccessed(manifest_url, blocked_by_policy));
3038}
3039
[email protected]8bc5ff02013-11-29 06:34:033040void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483041 int color_chooser_id,
3042 SkColor color,
3043 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113044 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003045 return;
nasko907fcb62015-01-28 04:24:113046
[email protected]aa62afd2014-04-22 19:22:463047 ColorChooser* new_color_chooser = delegate_ ?
3048 delegate_->OpenColorChooser(this, color, suggestions) :
3049 NULL;
[email protected]820957a2014-01-14 14:56:303050 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213051 return;
[email protected]8ed16472014-04-11 19:02:483052 if (color_chooser_info_.get())
3053 color_chooser_info_->chooser->End();
3054
3055 color_chooser_info_.reset(new ColorChooserInfo(
3056 render_frame_message_source_->GetProcess()->GetID(),
3057 render_frame_message_source_->GetRoutingID(),
3058 new_color_chooser,
3059 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203060}
3061
[email protected]b172aee2012-04-10 17:05:263062void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483063 if (color_chooser_info_ &&
3064 color_chooser_id == color_chooser_info_->identifier)
3065 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203066}
3067
[email protected]b172aee2012-04-10 17:05:263068void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323069 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483070 if (color_chooser_info_ &&
3071 color_chooser_id == color_chooser_info_->identifier)
3072 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203073}
3074
[email protected]d0759f492012-04-19 22:50:503075// This exists for render views that don't have a WebUI, but do have WebUI
3076// bindings enabled.
3077void WebContentsImpl::OnWebUISend(const GURL& source_url,
3078 const std::string& name,
3079 const base::ListValue& args) {
3080 if (delegate_)
3081 delegate_->WebUISend(this, source_url, name, args);
3082}
3083
thestigc4cac8f2014-09-04 21:17:503084#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:423085void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3086 const base::FilePath& path,
3087 bool is_hung) {
3088 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3089
3090 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3091 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3092}
3093
3094void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3095 base::ProcessId plugin_pid) {
3096 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3097 PluginCrashed(plugin_path, plugin_pid));
3098}
3099
[email protected]d8415ad92012-08-23 14:40:503100void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443101 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503102 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343103 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163104 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443105 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163106 return;
[email protected]d8415ad92012-08-23 14:40:503107 }
3108
[email protected]8c8fc292012-11-23 18:57:163109 if (!delegate_->RequestPpapiBrokerPermission(
3110 this, url, plugin_path,
3111 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443112 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163113 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443114 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163115 }
[email protected]d8415ad92012-08-23 14:40:503116}
3117
[email protected]ea0309c2013-08-06 19:35:443118void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503119 bool result) {
[email protected]ea0309c2013-08-06 19:35:443120 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503121}
3122
fsamuel833ee7c2015-02-13 23:40:403123void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3124 const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:373125 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:083126 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:553127 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:393128 // For more info, see comment above classes BrowserPluginEmbedder and
3129 // BrowserPluginGuest.
3130 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:143131 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
fsamuel833ee7c2015-02-13 23:40:403132 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373133}
tommyclie6633ca72014-10-31 00:40:423134#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373135
[email protected]41225fe2013-03-29 05:32:023136void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393137 int id,
[email protected]749fadd2013-05-15 08:37:483138 int http_status_code,
[email protected]795c28972012-12-06 06:13:393139 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303140 const std::vector<SkBitmap>& bitmaps,
3141 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133142 if (bitmaps.size() != original_bitmap_sizes.size())
3143 return;
3144
[email protected]41225fe2013-03-29 05:32:023145 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3146 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393147 // Currently WebContents notifies us of ANY downloads so that it is
3148 // possible to get here.
3149 return;
3150 }
3151 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303152 iter->second.Run(
3153 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393154 }
[email protected]41225fe2013-03-29 05:32:023155 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393156}
3157
3158void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393159 const std::vector<FaviconURL>& candidates) {
3160 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293161 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393162}
3163
dalecurtisbc6572e12014-09-12 19:22:303164void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3165 // ChromeOS has its own way of handling power save blocks for media.
3166#if !defined(OS_CHROMEOS)
3167 DCHECK(!audio_power_save_blocker_);
3168 audio_power_save_blocker_ = PowerSaveBlocker::Create(
3169 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing Audio");
3170#endif
3171}
3172
3173void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3174 // ChromeOS has its own way of handling power save blocks for media.
3175#if !defined(OS_CHROMEOS)
3176 DCHECK(!video_power_save_blocker_);
3177 DCHECK(!active_video_players_.empty());
3178 video_power_save_blocker_ = PowerSaveBlocker::Create(
3179 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing Video");
3180#if defined(OS_ANDROID)
3181 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3182 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3183#endif
3184#endif
3185}
3186
3187void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3188 // If there are no more audio players and we don't have audio stream
3189 // monitoring, release the audio power save blocker here instead of during
3190 // NotifyNavigationStateChanged().
3191 if (active_audio_players_.empty() &&
3192 !AudioStreamMonitor::monitoring_available()) {
3193 audio_power_save_blocker_.reset();
3194 }
3195
3196 // If there are no more video players, clear the video power save blocker.
3197 if (active_video_players_.empty())
3198 video_power_save_blocker_.reset();
3199}
3200
[email protected]1dd0bb752014-02-01 01:16:263201void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3202 bool has_video,
avayvod68017be2014-10-10 18:02:433203 bool has_audio,
3204 bool is_remote) {
3205 // Ignore the videos playing remotely and don't hold the wake lock for the
3206 // screen.
3207 if (is_remote) return;
3208
dalecurtisbc6572e12014-09-12 19:22:303209 if (has_audio) {
3210 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3211
3212 // If we don't have audio stream monitoring, allocate the audio power save
3213 // blocker here instead of during NotifyNavigationStateChanged().
3214 if (!audio_power_save_blocker_ &&
3215 !AudioStreamMonitor::monitoring_available()) {
3216 CreateAudioPowerSaveBlocker();
3217 }
[email protected]1dd0bb752014-02-01 01:16:263218 }
loislo0381a742014-09-11 10:58:113219
dalecurtisbc6572e12014-09-12 19:22:303220 if (has_video) {
3221 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3222
3223 // If we're not hidden and have just created a player, create a blocker.
3224 if (!video_power_save_blocker_ && !IsHidden())
3225 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113226 }
[email protected]1dd0bb752014-02-01 01:16:263227}
3228
3229void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303230 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3231 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3232 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063233}
3234
[email protected]50279492014-05-05 23:24:293235void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153236 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293237 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153238}
[email protected]d9030b82013-07-19 08:26:063239
[email protected]e67ebf32013-02-13 11:07:193240void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073241 if (delegate_)
3242 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193243}
3244
[email protected]17e286e2013-03-01 23:29:393245void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3246 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3247 BeforeFormRepostWarningShow());
3248}
3249
[email protected]ec6c05f2013-10-23 18:41:573250void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3251 Activate();
3252 if (delegate_)
3253 delegate_->ShowRepostFormWarningDialog(this);
3254}
3255
[email protected]b4c84012014-04-28 19:51:103256bool WebContentsImpl::HasAccessedInitialDocument() {
3257 return has_accessed_initial_document_;
3258}
3259
[email protected]96d185d2009-04-24 03:28:543260// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593261// loading, or done loading.
3262void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3263 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093264 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263265 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543266 if (is_loading == is_loading_)
3267 return;
3268
3269 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263270 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3271 base::string16());
[email protected]96d185d2009-04-24 03:28:543272 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563273 upload_size_ = 0;
3274 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543275 }
3276
[email protected]fa944cb82013-11-15 17:51:213277 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543278
3279 is_loading_ = is_loading;
3280 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033281 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543282
[email protected]6ebdc9b2010-09-27 16:55:573283 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093284 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213285 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543286
[email protected]eab61442013-11-14 18:35:483287 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593288 if (is_loading) {
naskob8744d22014-08-28 17:07:433289 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3290 this, "URL", url);
[email protected]91621872013-10-08 04:04:593291 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3292 DidStartLoading(render_view_host));
3293 } else {
naskob8744d22014-08-28 17:07:433294 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3295 this, "URL", url);
[email protected]91621872013-10-08 04:04:593296 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3297 DidStopLoading(render_view_host));
3298 }
[email protected]66798902013-10-01 18:40:163299
3300 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213301 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3302 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543303 if (details)
[email protected]8ff00d72012-10-23 19:12:213304 det = Details<LoadNotificationDetails>(details);
3305 NotificationService::current()->Notify(
3306 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543307}
3308
christiankaeed9862014-11-05 10:49:143309void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
3310 RenderFrameHost* focused_frame = GetFocusedFrame();
3311 if (!focused_frame)
3312 return;
3313
3314 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
3315 focused_frame->GetRoutingID(), extent));
3316}
3317
3318void WebContentsImpl::SelectRange(const gfx::Point& base,
3319 const gfx::Point& extent) {
[email protected]959be4c2014-04-08 15:01:333320 RenderFrameHost* focused_frame = GetFocusedFrame();
3321 if (!focused_frame)
3322 return;
3323
3324 focused_frame->Send(
christiankaeed9862014-11-05 10:49:143325 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
[email protected]959be4c2014-04-08 15:01:333326}
3327
[email protected]b172aee2012-04-10 17:05:263328void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463329 // If we are creating a RVH for a restored controller, then we need to make
3330 // sure the RenderView starts with a next_page_id_ larger than the number
3331 // of restored entries. This must be called before the RenderView starts
3332 // navigating (to avoid a race between the browser updating max_page_id and
3333 // the renderer updating next_page_id_). Because of this, we only call this
3334 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563335 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583336 if (max_restored_page_id >
3337 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3338 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3339 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323340}
3341
[email protected]b172aee2012-04-10 17:05:263342bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263343 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323344 // For file URLs without a title, use the pathname instead. In the case of a
3345 // synthesized title, we don't want the update to count toward the "one set
3346 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263347 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323348 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513349 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243350 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323351 explicit_set = false; // Don't count synthetic titles toward the set limit.
3352 } else {
[email protected]8af69c6c2014-03-03 19:05:313353 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323354 explicit_set = true;
3355 }
3356
[email protected]987fc3a2011-05-26 14:18:093357 // If a page is created via window.open and never navigated,
3358 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553359 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093360 if (entry) {
[email protected]36fc0392011-12-25 03:59:513361 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093362 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323363
[email protected]36fc0392011-12-25 03:59:513364 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093365 } else {
3366 if (page_title_when_no_navigation_entry_ == final_title)
3367 return false; // Nothing changed, don't bother.
3368
3369 page_title_when_no_navigation_entry_ = final_title;
3370 }
[email protected]420ae012009-04-24 05:16:323371
[email protected]420ae012009-04-24 05:16:323372 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233373 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323374
[email protected]66798902013-10-01 18:40:163375 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533376 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163377
3378 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213379 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463380 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213381 NotificationService::current()->Notify(
3382 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3383 Source<WebContents>(this),
3384 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043385
[email protected]420ae012009-04-24 05:16:323386 return true;
3387}
3388
[email protected]960b0372014-05-19 18:01:003389void WebContentsImpl::SendLoadProgressChanged() {
3390 loading_last_progress_update_ = base::TimeTicks::Now();
3391 double progress = 0.0;
3392 int frame_count = 0;
3393
3394 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3395 it != loading_progresses_.end();
3396 ++it) {
3397 progress += it->second;
3398 ++frame_count;
3399 }
3400 if (frame_count == 0)
3401 return;
3402 progress /= frame_count;
3403 DCHECK(progress <= 1.0);
3404
3405 if (progress <= loading_total_progress_)
3406 return;
3407 loading_total_progress_ = progress;
3408
3409 if (delegate_)
3410 delegate_->LoadProgressChanged(this, progress);
3411}
3412
3413void WebContentsImpl::ResetLoadProgressState() {
3414 loading_progresses_.clear();
3415 loading_total_progress_ = 0.0;
3416 loading_weak_factory_.InvalidateWeakPtrs();
3417 loading_last_progress_update_ = base::TimeTicks();
3418}
3419
[email protected]02d7b6e2014-06-24 21:01:503420void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3421 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323422 // After sending out a swap notification, we need to send a disconnect
3423 // notification so that clients that pick up a pointer to |this| can NULL the
3424 // pointer. See Bug 1230284.
3425 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113426 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283427 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113428
3429 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283430 std::pair<RenderViewHost*, RenderViewHost*> details =
3431 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213432 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283433 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213434 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283435 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393436
3437 // Ensure that the associated embedder gets cleared after a RenderViewHost
3438 // gets swapped, so we don't reuse the same embedder next time a
3439 // RenderViewHost is attached to this WebContents.
3440 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323441}
3442
[email protected]02d7b6e2014-06-24 21:01:503443void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3444 RenderFrameHost* new_host) {
3445 FOR_EACH_OBSERVER(WebContentsObserver,
3446 observers_,
3447 RenderFrameHostChanged(old_host, new_host));
3448}
3449
[email protected]da7a7182013-09-06 08:11:113450// TODO(avi): Remove this entire function because this notification is already
3451// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263452void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323453 if (!notify_disconnection_)
3454 return;
3455
3456 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213457 NotificationService::current()->Notify(
3458 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3459 Source<WebContents>(this),
3460 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323461}
3462
[email protected]cbb1ef592013-06-05 19:49:463463void WebContentsImpl::NotifyNavigationEntryCommitted(
3464 const LoadCommittedDetails& load_details) {
3465 FOR_EACH_OBSERVER(
3466 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3467}
3468
[email protected]f114fa42013-12-06 17:06:443469bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3470 const IPC::Message& message) {
3471 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313472}
3473
[email protected]c31a84802014-04-03 15:55:493474const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3475 return GetLastCommittedURL();
3476}
3477
[email protected]b849847b2013-12-10 21:57:583478void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3479 // Note this is only for subframes, the notification for the main frame
3480 // happens in RenderViewCreated.
3481 FOR_EACH_OBSERVER(WebContentsObserver,
3482 observers_,
3483 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303484 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583485}
3486
3487void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193488 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583489 FOR_EACH_OBSERVER(WebContentsObserver,
3490 observers_,
3491 RenderFrameDeleted(render_frame_host));
3492}
3493
[email protected]a09d53ce2014-01-31 00:46:423494void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303495 if (delegate_)
3496 delegate_->WorkerCrashed(this);
3497}
3498
[email protected]a09d53ce2014-01-31 00:46:423499void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3500 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103501 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423502 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103503 if (GetBrowserPluginGuest()) {
3504 WebContentsViewGuest* view_guest =
3505 static_cast<WebContentsViewGuest*>(GetView());
3506 context_menu_params = view_guest->ConvertContextMenuParams(params);
3507 }
3508 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423509 return;
3510
[email protected]077e704b2014-05-23 19:24:103511 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3512 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423513}
3514
[email protected]87de04b02014-04-08 22:14:493515void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013516 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493517 const base::string16& message,
3518 const base::string16& default_prompt,
3519 const GURL& frame_url,
3520 JavaScriptMessageType javascript_message_type,
3521 IPC::Message* reply_msg) {
3522 // Suppress JavaScript dialogs when requested. Also suppress messages when
3523 // showing an interstitial as it's shown over the previous page and we don't
3524 // want the hidden page's dialogs to interfere with the interstitial.
3525 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223526 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503527 ShowingInterstitialPage() || !delegate_ ||
3528 delegate_->ShouldSuppressDialogs(this) ||
3529 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493530
3531 if (!suppress_this_message) {
3532 std::string accept_lang = GetContentClient()->browser()->
3533 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503534 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493535 dialog_manager_->RunJavaScriptDialog(
3536 this,
3537 frame_url.GetOrigin(),
3538 accept_lang,
3539 javascript_message_type,
3540 message,
3541 default_prompt,
3542 base::Bind(&WebContentsImpl::OnDialogClosed,
3543 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013544 render_frame_host->GetProcess()->GetID(),
3545 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493546 reply_msg,
3547 false),
3548 &suppress_this_message);
3549 }
3550
3551 if (suppress_this_message) {
3552 // If we are suppressing messages, just reply as if the user immediately
3553 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013554 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3555 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283556 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493557 }
3558
3559 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3560 // http://crbug.com/288961 ). The only safe thing to do here is return.
3561}
3562
3563void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013564 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493565 const base::string16& message,
3566 bool is_reload,
3567 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013568 RenderFrameHostImpl* rfhi =
3569 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493570 if (delegate_)
3571 delegate_->WillRunBeforeUnloadConfirm();
3572
3573 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503574 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT || !delegate_ ||
3575 delegate_->ShouldSuppressDialogs(this) ||
3576 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493577 if (suppress_this_message) {
3578 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3579 return;
3580 }
3581
3582 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503583 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493584 dialog_manager_->RunBeforeUnloadDialog(
3585 this, message, is_reload,
3586 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013587 render_frame_host->GetProcess()->GetID(),
3588 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283589 false));
[email protected]87de04b02014-04-08 22:14:493590}
3591
[email protected]a86c0e962013-12-17 17:10:393592WebContents* WebContentsImpl::GetAsWebContents() {
3593 return this;
3594}
3595
[email protected]7912e822014-04-16 02:37:033596bool WebContentsImpl::IsNeverVisible() {
3597 if (!delegate_)
3598 return false;
3599 return delegate_->IsNeverVisible(this);
3600}
3601
[email protected]95640212014-07-26 18:14:303602#if defined(OS_WIN)
3603gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3604 return accessible_parent_;
3605}
3606#endif
3607
[email protected]5a3bdf52012-05-24 15:12:573608RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3609 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323610}
3611
[email protected]8ff00d72012-10-23 19:12:213612RendererPreferences WebContentsImpl::GetRendererPrefs(
3613 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463614 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513615}
3616
[email protected]b172aee2012-04-10 17:05:263617gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173618 if (delegate_)
3619 return delegate_->GetRootWindowResizerRect();
3620 return gfx::Rect();
3621}
3622
[email protected]7a846df2012-09-20 19:17:393623void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273624 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393625 browser_plugin_embedder_.reset();
3626}
3627
[email protected]b172aee2012-04-10 17:05:263628void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443629 // Don't send notifications if we are just creating a swapped-out RVH for
3630 // the opener chain. These won't be used for view-source or WebUI, so it's
3631 // ok to return early.
creiscce56cd2014-09-29 22:45:223632 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443633 return;
3634
[email protected]86f98a22013-03-20 14:35:003635 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313636 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083637
[email protected]8ff00d72012-10-23 19:12:213638 NotificationService::current()->Notify(
3639 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3640 Source<WebContents>(this),
3641 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323642
3643 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353644 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213645 if (GetRenderManager()->pending_web_ui())
3646 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323647
[email protected]6286a372013-10-09 04:03:273648 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333649 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323650 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183651 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583652 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323653 }
[email protected]0666aef2009-05-13 19:48:083654
[email protected]60780f412013-02-25 16:34:103655 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263656
3657 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253658 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583659
3660 // We tell the observers now instead of when the main RenderFrameHostImpl is
3661 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3662 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363663 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583664 FOR_EACH_OBSERVER(
3665 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303666 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
dgozman24bfc912014-09-29 11:04:183667
3668 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:323669}
3670
[email protected]b172aee2012-04-10 17:05:263671void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523672 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323673 // Don't notify the world, since this came from a renderer in the
3674 // background.
3675 return;
3676 }
3677
[email protected]da7a7182013-09-06 08:11:113678 notify_disconnection_ = true;
3679 // TODO(avi): Remove. http://crbug.com/170921
3680 NotificationService::current()->Notify(
3681 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3682 Source<WebContents>(this),
3683 NotificationService::NoDetails());
3684
[email protected]be1f56ab2011-12-22 06:55:313685 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233686 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303687
3688 // Restore the focus to the tab (otherwise the focus will be on the top
3689 // window).
[email protected]484ae5912010-09-29 19:16:143690 if (was_crashed && !FocusLocationBarByDefault() &&
3691 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063692 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143693 }
[email protected]32ded2212011-11-10 18:51:433694
[email protected]d8c660432011-12-22 20:51:253695 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323696}
3697
[email protected]ec6a7eb2013-04-22 17:34:223698void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3699 base::TerminationStatus status,
3700 int error_code) {
dalecurtis8fc7b4dd2015-02-06 01:05:333701 // TODO(nasko): This isn't ideal; the termination process should be handled by
3702 // RenderFrameDeleted(). See http://crbug.com/455943.
3703 ClearPowerSaveBlockers(rvh->GetMainFrame());
3704
[email protected]151a63d2011-12-20 22:32:523705 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323706 // The pending page's RenderViewHost is gone.
3707 return;
3708 }
3709
[email protected]2fcdcc32014-03-05 02:14:073710 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3711 // renderer may not have made a clean exit.
3712 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:533713 ExitFullscreenMode();
[email protected]2fcdcc32014-03-05 02:14:073714
[email protected]698191dc2014-02-25 01:06:133715 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3716 if (dialog_manager_)
3717 dialog_manager_->CancelActiveAndPendingDialogs(this);
3718
[email protected]f738bdcb2014-07-11 20:40:443719 if (delegate_)
3720 delegate_->HideValidationMessage(this);
3721
[email protected]e3b10d12014-03-28 16:06:093722 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323723 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233724 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453725
[email protected]960b0372014-05-19 18:01:003726 // Reset the loading progress. TODO(avi): What does it mean to have a
3727 // "renderer crash" when there is more than one renderer process serving a
3728 // webpage? Once this function is called at a more granular frame level, we
3729 // probably will need to more granularly reset the state here.
3730 ResetLoadProgressState();
3731 loading_frames_in_progress_ = 0;
3732
[email protected]d8c660432011-12-22 20:51:253733 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273734 observers_,
[email protected]58d5cfe2013-07-10 02:40:523735 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323736}
3737
[email protected]b172aee2012-04-10 17:05:263738void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253739 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063740}
3741
[email protected]b172aee2012-04-10 17:05:263742void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3743 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043744 const PageState& page_state) {
creise1d3e5b2014-12-01 18:21:573745 // Ensure that this state update comes from a RenderViewHost that belongs to
3746 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413747 // TODO(nasko): This should go through RenderFrameHost.
3748 // TODO(creis): We can't update state for cross-process subframes until we
3749 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
creise1d3e5b2014-12-01 18:21:573750 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413751 return;
[email protected]420ae012009-04-24 05:16:323752
3753 // We must be prepared to handle state updates for any page, these occur
3754 // when the user is scrolling and entering form data, as well as when we're
3755 // leaving a page, in which case our state may have already been moved to
3756 // the next page. The navigation controller will look up the appropriate
3757 // NavigationEntry and update it when it is notified via the delegate.
3758
3759 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583760 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323761 if (entry_index < 0)
3762 return;
[email protected]10f417c52011-12-28 21:04:233763 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323764
[email protected]691aa2f2013-05-28 22:52:043765 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323766 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043767 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323768 controller_.NotifyEntryChanged(entry, entry_index);
3769}
3770
sky8b00392d2015-01-10 00:30:283771void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
3772 const GURL& url) {
3773 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
3774 // If we're fullscreen only update the url if it's from the fullscreen
3775 // renderer.
3776 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
3777 if (fs && fs->GetRenderWidgetHost() != render_view_host)
3778 return;
3779 }
[email protected]6934a702011-12-20 00:04:513780 if (delegate_)
avi450ce00e2014-09-24 01:58:523781 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323782}
3783
[email protected]b172aee2012-04-10 17:05:263784void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103785#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293786 // The UI may be in an event-tracking loop, such as between the
3787 // mouse-down and mouse-up in text selection or a button click.
3788 // Defer the close until after tracking is complete, so that we
3789 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293790 // TODO(shess): This could get more fine-grained. For instance,
3791 // closing a tab in another window while selecting text in the
3792 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103793 if (view_->IsEventTracking()) {
3794 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293795 return;
3796 }
[email protected]60780f412013-02-25 16:34:103797#endif
[email protected]07707302009-11-06 00:50:293798
[email protected]420ae012009-04-24 05:16:323799 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523800 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513801 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323802}
3803
[email protected]66bbadaf2014-03-28 16:25:543804void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573805 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3806 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573807}
3808
[email protected]6f2ac772014-07-24 22:22:083809void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253810 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173811#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563812 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173813#endif
3814}
3815
3816bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3817#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563818 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173819#else
3820 return false;
3821#endif
3822}
3823
[email protected]b172aee2012-04-10 17:05:263824void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513825 if (delegate_ && delegate_->IsPopupOrPanel(this))
3826 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323827}
3828
[email protected]e3b10d12014-03-28 16:06:093829void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3830 bool to_different_document) {
3831 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3832 to_different_document, NULL);
dmazzonibf8cec42015-02-08 08:28:083833
3834 // Notify accessibility that the user is navigating away from the
3835 // current document.
3836 //
3837 // TODO(dmazzoni): do this using a WebContentsObserver.
3838 FrameTreeNode* ftn = static_cast<RenderFrameHostImpl*>(render_frame_host)->
3839 frame_tree_node();
3840 BrowserAccessibilityManager* manager =
3841 ftn->current_frame_host()->browser_accessibility_manager();
3842 if (manager)
3843 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:323844}
3845
[email protected]723971b2014-02-12 11:08:253846void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323847 scoped_ptr<LoadNotificationDetails> details;
3848
[email protected]9595fd82013-04-19 21:28:493849 // Use the last committed entry rather than the active one, in case a
3850 // pending entry has been created.
3851 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203852 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493853
[email protected]420ae012009-04-24 05:16:323854 // An entry may not exist for a stop when loading an initial blank page or
3855 // if an iframe injected by script into a blank page finishes loading.
3856 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203857 base::TimeDelta elapsed =
3858 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323859
3860 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513861 entry->GetVirtualURL(),
3862 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323863 elapsed,
3864 &controller_,
3865 controller_.GetCurrentEntryIndex()));
3866 }
3867
[email protected]e3b10d12014-03-28 16:06:093868 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3869 details.get());
[email protected]420ae012009-04-24 05:16:323870}
3871
[email protected]b172aee2012-04-10 17:05:263872void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163873 controller_.DiscardNonCommittedEntries();
3874
3875 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213876 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163877}
3878
[email protected]59167c22013-06-03 18:07:323879void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103880 has_accessed_initial_document_ = true;
3881
[email protected]d1371bf8e2014-04-19 03:26:243882 // We may have left a failed browser-initiated navigation in the address bar
3883 // to let the user edit it and try again. Clear it now that content might
3884 // show up underneath it.
3885 if (!IsLoading() && controller_.GetPendingEntry())
3886 controller_.DiscardPendingEntry();
3887
[email protected]59167c22013-06-03 18:07:323888 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503889 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323890}
3891
[email protected]3f19f1a2014-05-02 05:23:273892void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473893 // No action is necessary if the opener has already been cleared.
3894 if (!opener_)
3895 return;
3896
3897 // Clear our opener so that future cross-process navigations don't have an
3898 // opener assigned.
3899 RemoveDestructionObserver(opener_);
3900 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273901
3902 // Notify all swapped out RenderViewHosts for this tab. This is important
3903 // in case we go back to them, or if another window in those processes tries
3904 // to access window.opener.
creisbbbeb062014-08-25 18:20:313905 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273906}
3907
[email protected]39f2f9252014-05-03 00:54:013908void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293909 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093910 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293911 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093912
3913 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213914 NotificationService::current()->Notify(
3915 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3916 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293917 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083918}
3919
[email protected]ef3adfc2014-05-11 00:04:543920void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3921 int32 page_id,
3922 const base::string16& title,
3923 base::i18n::TextDirection title_direction) {
3924 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3925
3926 // If we have a title, that's a pretty good indication that we've started
3927 // getting useful data.
3928 SetNotWaitingForResponse();
3929
3930 // Try to find the navigation entry, which might not be the current one.
3931 // For example, it might be from a pending RVH for the pending entry.
3932 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3933 rvh->GetSiteInstance(), page_id);
3934
3935 // We can handle title updates when we don't have an entry in
3936 // UpdateTitleForEntry, but only if the update is from the current RVH.
3937 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3938 if (!entry && rvh != GetRenderViewHost())
3939 return;
3940
3941 // TODO(evan): make use of title_direction.
3942 // http://code.google.com/p/chromium/issues/detail?id=27094
3943 if (!UpdateTitleForEntry(entry, title))
3944 return;
3945
3946 // Broadcast notifications when the UI should be updated.
3947 if (entry == controller_.GetEntryAtOffset(0))
3948 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3949}
3950
3951void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3952 const std::string& encoding) {
3953 SetEncoding(encoding);
3954}
3955
[email protected]39f2f9252014-05-03 00:54:013956void WebContentsImpl::DocumentAvailableInMainFrame(
3957 RenderViewHost* render_view_host) {
3958 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3959 DocumentAvailableInMainFrame());
3960}
[email protected]e1c3a552012-05-04 20:51:323961void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3962 // Tell the active RenderViewHost to run unload handlers and close, as long
3963 // as the request came from a RenderViewHost in the same BrowsingInstance.
3964 // In most cases, we receive this from a swapped out RenderViewHost.
3965 // It is possible to receive it from one that has just been swapped in,
3966 // in which case we might as well deliver the message anyway.
3967 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3968 GetRenderViewHost()->ClosePage();
3969}
3970
[email protected]f546640b2012-05-15 00:03:493971void WebContentsImpl::RouteMessageEvent(
3972 RenderViewHost* rvh,
3973 const ViewMsg_PostMessage_Params& params) {
3974 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363975 // came from a RenderViewHost in the same BrowsingInstance or if this
3976 // WebContents is dedicated to a browser plugin guest.
3977 // Note: This check means that an embedder could theoretically receive a
3978 // postMessage from anyone (not just its own guests). However, this is
3979 // probably not a risk for apps since other pages won't have references
3980 // to App windows.
3981 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3982 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493983 return;
3984
3985 ViewMsg_PostMessage_Params new_params(params);
3986
[email protected]0bc7f3542013-10-21 15:05:533987 if (!params.message_port_ids.empty()) {
3988 MessagePortMessageFilter* message_port_message_filter =
3989 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3990 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093991 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3992 params.message_port_ids,
3993 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533994 }
3995
[email protected]f546640b2012-05-15 00:03:493996 // If there is a source_routing_id, translate it to the routing ID for
3997 // the equivalent swapped out RVH in the target process. If we need
3998 // to create a swapped out RVH for the source tab, we create its opener
3999 // chain as well, since those will also be accessible to the target page.
4000 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
4001 // Try to look up the WebContents for the source page.
4002 WebContentsImpl* source_contents = NULL;
4003 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
4004 rvh->GetProcess()->GetID(), params.source_routing_id);
4005 if (source_rvh) {
4006 source_contents = static_cast<WebContentsImpl*>(
4007 source_rvh->GetDelegate()->GetAsWebContents());
4008 }
4009
4010 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:364011 if (GetBrowserPluginGuest()) {
4012 // We create a swapped out RenderView for the embedder in the guest's
4013 // render process but we intentionally do not expose the embedder's
4014 // opener chain to it.
4015 new_params.source_routing_id =
4016 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
4017 } else {
4018 new_params.source_routing_id =
4019 source_contents->CreateOpenerRenderViews(GetSiteInstance());
4020 }
[email protected]f546640b2012-05-15 00:03:494021 } else {
4022 // We couldn't find it, so don't pass a source frame.
4023 new_params.source_routing_id = MSG_ROUTING_NONE;
4024 }
4025 }
4026
4027 // In most cases, we receive this from a swapped out RenderViewHost.
4028 // It is possible to receive it from one that has just been swapped in,
4029 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:184030 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:494031}
4032
[email protected]a796f202012-05-30 14:14:254033bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:264034 const base::string16& message,
[email protected]a796f202012-05-30 14:14:254035 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:264036 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254037 if (!delegate_)
4038 return false;
4039 return delegate_->AddMessageToConsole(this, level, message, line_no,
4040 source_id);
4041}
4042
[email protected]0eba810b2012-10-18 03:19:364043int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214044 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294045 int render_view_routing_id = MSG_ROUTING_NONE;
4046 GetRenderManager()->CreateRenderFrame(
4047 instance, nullptr, MSG_ROUTING_NONE,
4048 CREATE_RF_SWAPPED_OUT | CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4049 CREATE_RF_HIDDEN,
4050 &render_view_routing_id);
4051 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364052}
4053
[email protected]b172aee2012-04-10 17:05:264054void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:274055 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254056 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224057
[email protected]ea114722012-03-12 01:11:254058 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174059 if (rdh) // NULL in unittests.
4060 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254061}
4062
[email protected]b172aee2012-04-10 17:05:264063void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444064 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254065 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444066}
4067
creiscce56cd2014-09-29 22:45:224068void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:154069 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:224070 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:154071 return;
4072
creiscce56cd2014-09-29 22:45:224073 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
4074 RenderFrameHostImpl* rfhi =
4075 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584076
[email protected]e5fc1632011-08-08 07:51:534077 // Ignore renderer unresponsive event if debugger is attached to the tab
4078 // since the event may be a result of the renderer sitting on a breakpoint.
4079 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364080 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534081 return;
4082
clamyafbf7f02015-01-21 20:38:114083 if (rfhi->IsWaitingForBeforeUnloadACK() ||
creiscce56cd2014-09-29 22:45:224084 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324085 // Hang occurred while firing the beforeunload/unload handler.
4086 // Pretend the handler fired so tab closing continues as if it had.
clamydf1975e2015-02-05 19:12:244087 frame_tree_.ForEach(base::Bind(
4088 &EnableSuddenTermination, rvhi->GetSiteInstance()->GetId()));
[email protected]420ae012009-04-24 05:16:324089
[email protected]fa944cb82013-11-15 17:51:214090 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324091 return;
4092
4093 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564094 // nothing we can do to recover. If the hang is in the beforeunload handler,
4095 // pretend the beforeunload listeners have all fired and allow the delegate
4096 // to continue closing; the user will not have the option of cancelling the
4097 // close. Otherwise, pretend the unload listeners have all fired and close
4098 // the tab.
4099 bool close = true;
clamyafbf7f02015-01-21 20:38:114100 if (rfhi->IsWaitingForBeforeUnloadACK() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564101 delegate_->BeforeUnloadFired(this, true, &close);
4102 }
4103 if (close)
creiscce56cd2014-09-29 22:45:224104 Close(rvhi);
[email protected]420ae012009-04-24 05:16:324105 return;
4106 }
4107
[email protected]9f76c1e2012-03-05 15:15:584108 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474109 return;
4110
[email protected]6934a702011-12-20 00:04:514111 if (delegate_)
4112 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324113}
4114
[email protected]b172aee2012-04-10 17:05:264115void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:514116 if (delegate_)
4117 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324118}
4119
[email protected]b172aee2012-04-10 17:05:264120void WebContentsImpl::LoadStateChanged(
4121 const GURL& url,
4122 const net::LoadStateWithParam& load_state,
4123 uint64 upload_position,
4124 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:324125 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564126 upload_position_ = upload_position;
4127 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:504128 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:214129 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:304130 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214131 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324132 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464133 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224134 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4135 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464136 }
[email protected]420ae012009-04-24 05:16:324137}
4138
[email protected]b172aee2012-04-10 17:05:264139void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554140 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324141 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124142 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4143 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514144 if (delegate_)
4145 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094146 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324147}
4148
[email protected]58d5cfe2013-07-10 02:40:524149void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544150 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234151 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224152 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544153}
4154
[email protected]b172aee2012-04-10 17:05:264155void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104156 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214157 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264158 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4159 // here during container initialization and normal window size will be set
4160 // later. In case of tab duplication this resizing to 0x0 prevents setting
4161 // normal size later so just ignore it.
4162 if (!size.IsEmpty())
4163 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324164}
4165
[email protected]af905902013-10-01 21:38:514166void WebContentsImpl::CancelModalDialogsForRenderManager() {
4167 // We need to cancel modal dialogs when doing a process swap, since the load
4168 // deferrer would prevent us from swapping out.
4169 if (dialog_manager_)
4170 dialog_manager_->CancelActiveAndPendingDialogs(this);
4171}
4172
[email protected]02d7b6e2014-06-24 21:01:504173void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4174 RenderFrameHost* new_host,
4175 bool is_main_frame) {
4176 if (is_main_frame) {
4177 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4178 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084179
[email protected]02d7b6e2014-06-24 21:01:504180 // Make sure the visible RVH reflects the new delegate's preferences.
4181 if (delegate_)
4182 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394183
[email protected]02d7b6e2014-06-24 21:01:504184 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4185 }
4186
4187 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544188}
4189
[email protected]14392a52012-05-02 20:28:444190int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4191 SiteInstance* instance) {
4192 if (!opener_)
4193 return MSG_ROUTING_NONE;
4194
4195 // Recursively create RenderViews for anything else in the opener chain.
4196 return opener_->CreateOpenerRenderViews(instance);
4197}
4198
4199int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4200 int opener_route_id = MSG_ROUTING_NONE;
4201
4202 // If this tab has an opener, ensure it has a RenderView in the given
4203 // SiteInstance as well.
4204 if (opener_)
4205 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4206
[email protected]45a22ad2013-02-21 03:25:004207 // If any of the renderers (current, pending, or swapped out) for this
4208 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214209 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4210 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374211
[email protected]fa944cb82013-11-15 17:51:214212 if (GetRenderManager()->pending_render_view_host() &&
4213 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4214 instance)
4215 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004216
[email protected]fa944cb82013-11-15 17:51:214217 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374218 instance);
4219 if (rvh)
4220 return rvh->GetRoutingID();
4221
[email protected]14392a52012-05-02 20:28:444222 // Create a swapped out RenderView in the given SiteInstance if none exists,
4223 // setting its opener to the given route_id. Return the new view's route_id.
carlosk37f793792014-11-27 15:08:294224 int render_view_routing_id = MSG_ROUTING_NONE;
4225 GetRenderManager()->CreateRenderFrame(instance, nullptr, opener_route_id,
4226 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4227 CREATE_RF_SWAPPED_OUT |
4228 CREATE_RF_HIDDEN,
4229 &render_view_routing_id);
4230 return render_view_routing_id;
[email protected]14392a52012-05-02 20:28:444231}
4232
[email protected]b172aee2012-04-10 17:05:264233NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194234 return GetController();
[email protected]3a3d47472010-07-15 21:03:544235}
4236
carlosk37f793792014-11-27 15:08:294237scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderManager(
4238 const GURL& url) {
4239 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(url)));
[email protected]420ae012009-04-24 05:16:324240}
4241
[email protected]10f417c52011-12-28 21:04:234242NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264243 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324244 return controller_.GetLastCommittedEntry();
4245}
4246
[email protected]b172aee2012-04-10 17:05:264247bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164248 RenderViewHost* render_view_host,
4249 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044250 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124251 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434252 TRACE_EVENT0("browser,navigation",
4253 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444254 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484255 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164256 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4257 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4258 // case this because RWH is still a base class of RenderViewHost, and child
4259 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124260 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164261 RenderWidgetHostViewChildFrame* rwh_view_child =
4262 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164263 rwh_view = rwh_view_child;
4264 } else {
lazyboy549b3b42014-10-20 17:16:044265 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164266 }
[email protected]1a98a932009-11-17 00:12:524267
[email protected]420ae012009-04-24 05:16:324268 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444269 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214270 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324271
[email protected]74ce1ad2011-12-16 21:51:464272 // Make sure we use the correct starting page_id in the new RenderView.
4273 UpdateMaxPageIDIfNecessary(render_view_host);
4274 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584275 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464276
[email protected]9f76c1e2012-03-05 15:15:584277 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264278 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494279 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044280 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494281 max_page_id,
4282 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524283 return false;
[email protected]14392a52012-05-02 20:28:444284 }
[email protected]a4127722011-04-27 23:13:524285
avi2b177592014-12-10 02:08:024286 SetHistoryOffsetAndLengthForView(render_view_host,
4287 controller_.GetLastCommittedEntryIndex(),
4288 controller_.GetEntryCount());
4289
[email protected]a220b5932013-09-21 03:47:444290#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504291 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4292 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444293 if (rwh_view) {
4294 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4295 render_widget_host->WasResized();
4296 }
[email protected]f8233cc2011-05-31 20:24:504297#endif
4298
[email protected]420ae012009-04-24 05:16:324299 return true;
4300}
4301
[email protected]82307f6b2014-08-07 03:30:124302bool WebContentsImpl::CreateRenderFrameForRenderManager(
4303 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494304 int parent_routing_id,
4305 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434306 TRACE_EVENT0("browser,navigation",
4307 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124308
4309 RenderFrameHostImpl* rfh =
4310 static_cast<RenderFrameHostImpl*>(render_frame_host);
japhete6adf142014-10-31 00:01:494311 if (!rfh->CreateRenderFrame(parent_routing_id, proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124312 return false;
4313
4314 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4315 // RenderFrameHost will have to be associated with the appropriate
4316 // RenderWidgetHostView or a new one should be created here.
4317
4318 return true;
4319}
4320
[email protected]7d244f12013-08-22 21:41:514321#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454322
[email protected]155c7f22013-12-09 17:07:184323base::android::ScopedJavaLocalRef<jobject>
4324WebContentsImpl::GetJavaWebContents() {
4325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564326 return GetWebContentsAndroid()->GetJavaObject();
4327}
[email protected]155c7f22013-12-09 17:07:184328
[email protected]0e813a52014-08-13 10:34:564329WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184330 WebContentsAndroid* web_contents_android =
4331 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4332 if (!web_contents_android) {
4333 web_contents_android = new WebContentsAndroid(this);
4334 SetUserData(kWebContentsAndroidKey, web_contents_android);
4335 }
[email protected]0e813a52014-08-13 10:34:564336 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184337}
4338
[email protected]7d244f12013-08-22 21:41:514339bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4340 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164341 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044342 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594343 true);
[email protected]7d244f12013-08-22 21:41:514344}
[email protected]fc2b46b2014-05-03 16:33:454345
4346#elif defined(OS_MACOSX)
4347
[email protected]75f4df72014-07-16 22:39:424348void WebContentsImpl::SetAllowOtherViews(bool allow) {
4349 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454350}
4351
[email protected]75f4df72014-07-16 22:39:424352bool WebContentsImpl::GetAllowOtherViews() {
4353 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454354}
4355
[email protected]7d244f12013-08-22 21:41:514356#endif
4357
[email protected]6fba26d2014-04-29 09:38:284358void WebContentsImpl::OnDialogClosed(int render_process_id,
4359 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264360 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494361 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264362 bool success,
[email protected]fcf75d42013-12-03 20:11:264363 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284364 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4365 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494366 last_dialog_suppressed_ = dialog_was_suppressed;
4367
[email protected]beb440c2009-11-06 04:08:544368 if (is_showing_before_unload_dialog_ && !success) {
4369 // If a beforeunload dialog is canceled, we need to stop the throbber from
4370 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284371 if (rfh)
4372 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354373 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104374
[email protected]6d65a462013-06-21 21:29:124375 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4376 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544377 }
[email protected]87de04b02014-04-08 22:14:494378
[email protected]beb440c2009-11-06 04:08:544379 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284380 if (rfh) {
4381 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4382 dialog_was_suppressed);
4383 } else {
4384 // Don't leak the sync IPC reply if the RFH or process is gone.
4385 delete reply_msg;
4386 }
[email protected]beb440c2009-11-06 04:08:544387}
4388
[email protected]b172aee2012-04-10 17:05:264389void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544390 if (encoding == last_reported_encoding_)
4391 return;
4392 last_reported_encoding_ = encoding;
4393
4394 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124395 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104396}
[email protected]f45d2a72010-03-08 23:28:354397
[email protected]1ac10dca2013-08-20 20:47:044398bool WebContentsImpl::IsHidden() {
4399 return capturer_count_ == 0 && !should_normally_be_visible_;
4400}
4401
[email protected]b0936d22013-11-28 06:47:364402RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214403 return frame_tree_.root()->render_manager();
4404}
4405
[email protected]b172aee2012-04-10 17:05:264406RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584407 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4408}
[email protected]7900bfdb2012-05-24 19:31:244409
[email protected]f8497342013-02-05 22:15:024410BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394411 return browser_plugin_guest_.get();
4412}
4413
[email protected]738f57a2013-06-29 21:06:544414void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4415 CHECK(!browser_plugin_guest_);
4416 browser_plugin_guest_.reset(guest);
4417}
4418
[email protected]f8497342013-02-05 22:15:024419BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394420 return browser_plugin_embedder_.get();
4421}
[email protected]8ff00d72012-10-23 19:12:214422
[email protected]d9030b82013-07-19 08:26:064423void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194424 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304425 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4426 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4427 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064428}
4429
4430void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304431 active_audio_players_.clear();
4432 active_video_players_.clear();
4433 audio_power_save_blocker_.reset();
4434 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064435}
4436
[email protected]fc2b46b2014-05-03 16:33:454437gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214438 gfx::Size size;
4439 if (delegate_)
4440 size = delegate_->GetSizeForNewRenderView(this);
4441 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454442 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214443 return size;
4444}
4445
[email protected]ae7eeda2014-07-04 01:53:264446void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4447 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024448 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554449}
4450
[email protected]222f5822014-02-05 23:40:494451void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4452 if (!delegate_)
4453 return;
4454 const gfx::Size new_size = GetPreferredSize();
4455 if (new_size != old_size)
4456 delegate_->UpdatePreferredSize(this, new_size);
4457}
4458
dalecurtisbc6572e12014-09-12 19:22:304459void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4460 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114461 if (!HasValidFrameSource())
4462 return;
4463
dalecurtisbc6572e12014-09-12 19:22:304464 const uintptr_t key =
4465 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4466 DCHECK(std::find((*player_map)[key].begin(),
4467 (*player_map)[key].end(),
4468 player_cookie) == (*player_map)[key].end());
4469 (*player_map)[key].push_back(player_cookie);
4470}
4471
4472void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4473 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114474 if (!HasValidFrameSource())
4475 return;
4476
dalecurtisbc6572e12014-09-12 19:22:304477 const uintptr_t key =
4478 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4479 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4480 if (it == player_map->end())
4481 return;
4482
4483 // Remove the player.
4484 PlayerList::iterator player_it =
4485 std::find(it->second.begin(), it->second.end(), player_cookie);
4486 if (player_it != it->second.end())
4487 it->second.erase(player_it);
4488
4489 // If there are no players left, remove the map entry.
4490 if (it->second.empty())
4491 player_map->erase(it);
4492}
4493
4494void WebContentsImpl::RemoveAllMediaPlayerEntries(
4495 RenderFrameHost* render_frame_host,
4496 ActiveMediaPlayerMap* player_map) {
4497 ActiveMediaPlayerMap::iterator it =
4498 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4499 if (it == player_map->end())
4500 return;
4501 player_map->erase(it);
4502}
4503
[email protected]23f41fd2014-06-21 05:29:174504void WebContentsImpl::ResumeResponseDeferredAtStart() {
4505 FrameTreeNode* node = frame_tree_.root();
4506 node->render_manager()->ResumeResponseDeferredAtStart();
4507}
4508
[email protected]34ff1cfc2014-08-20 06:16:054509void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4510 force_disable_overscroll_content_ = force_disable;
4511 if (view_)
4512 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4513}
4514
[email protected]8ff00d72012-10-23 19:12:214515} // namespace content