blob: f9ba939d844ad18acc9ababcfad18f576437144e [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]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]95640212014-07-26 18:14:3021#include "content/browser/accessibility/accessibility_mode_helper.h"
22#include "content/browser/accessibility/browser_accessibility_state_impl.h"
[email protected]7a846df2012-09-20 19:17:3923#include "content/browser/browser_plugin/browser_plugin_embedder.h"
24#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5925#include "content/browser/child_process_security_policy_impl.h"
dgozman24bfc912014-09-29 11:04:1826#include "content/browser/devtools/devtools_manager.h"
[email protected]5f2aa722013-08-07 16:59:4127#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0428#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4629#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1230#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1631#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1632#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4033#include "content/browser/frame_host/interstitial_page_impl.h"
34#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0135#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1836#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1637#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5738#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0539#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4440#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4041#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3042#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5243#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]0bc7f3542013-10-21 15:05:5344#include "content/browser/message_port_message_filter.h"
45#include "content/browser/message_port_service.h"
tommyclieb25b2a2014-11-03 19:45:0946#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]d9030b82013-07-19 08:26:0647#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3048#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5049#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3250#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5051#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4852#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0953#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3354#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1155#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5856#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0357#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5658#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1459#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4260#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4461#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0262#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1763#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5164#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0265#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3666#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1167#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2868#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4469#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3670#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1771#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1472#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4673#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1574#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0075#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2776#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0077#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3778#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1479#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3080#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3281#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0982#include "content/public/browser/screen_orientation_dispatcher_host.h"
[email protected]4c3a23582012-08-18 08:54:3483#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3884#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4285#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2586#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2187#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4888#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5489#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4990#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2091#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0392#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5793#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:0594#include "content/public/common/web_preferences.h"
[email protected]a53209b2012-01-20 16:48:1695#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2996#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5397#include "net/http/http_cache.h"
98#include "net/http/http_transaction_factory.h"
99#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34100#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:56101#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01102#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41103#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52104#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31105
qinmin58567c82015-01-07 21:00:20106#if defined(ENABLE_BROWSER_CDMS)
107#include "content/browser/media/media_web_contents_observer.h"
108#endif
109
[email protected]583418cc2013-01-17 14:01:10110#if defined(OS_ANDROID)
111#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
[email protected]420ae012009-04-24 05:16:32204} // namespace
205
[email protected]54944cde2012-12-09 09:24:59206WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15207 return WebContentsImpl::CreateWithOpener(
208 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19209}
210
211WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59212 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30213 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59214 WebContentsImpl* new_contents = new WebContentsImpl(
215 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30216
217 for (SessionStorageNamespaceMap::const_iterator it =
218 session_storage_namespace_map.begin();
219 it != session_storage_namespace_map.end();
220 ++it) {
221 new_contents->GetController()
222 .SetSessionStorageNamespace(it->first, it->second.get());
223 }
224
[email protected]54944cde2012-12-09 09:24:59225 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19226 return new_contents;
[email protected]a81343d232011-12-27 07:39:20227}
[email protected]746d3052012-05-22 15:15:47228
nickf9acfbe2014-12-23 19:12:37229void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
230 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46231 g_created_callbacks.Get().push_back(callback);
232}
233
nickf9acfbe2014-12-23 19:12:37234void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
235 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46236 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
237 if (g_created_callbacks.Get().at(i).Equals(callback)) {
238 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
239 return;
240 }
241 }
242}
243
[email protected]299d7f12012-05-23 05:31:15244WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47245 return rvh->GetDelegate()->GetAsWebContents();
246}
247
[email protected]a86c0e962013-12-17 17:10:39248WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
249 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
250 if (!rfh_impl)
251 return NULL;
252 return rfh_impl->delegate()->GetAsWebContents();
253}
254
[email protected]7fff43e2013-05-21 20:21:10255// WebContentsImpl::DestructionObserver ----------------------------------------
256
257class WebContentsImpl::DestructionObserver : public WebContentsObserver {
258 public:
259 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
260 : WebContentsObserver(watched_contents),
261 owner_(owner) {
262 }
263
264 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58265 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58266 owner_->OnWebContentsDestroyed(
267 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10268 }
269
270 private:
271 WebContentsImpl* owner_;
272
273 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
274};
275
[email protected]8ed16472014-04-11 19:02:48276WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
277 int render_frame_id,
278 ColorChooser* chooser,
279 int identifier)
280 : render_process_id(render_process_id),
281 render_frame_id(render_frame_id),
282 chooser(chooser),
283 identifier(identifier) {
284}
285
286WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
287}
288
[email protected]b172aee2012-04-10 17:05:26289// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32290
blundellc57b93f2014-10-29 13:19:57291WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
292 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42293 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22294 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57295 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44296 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49297 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08298#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41299 accessible_parent_(NULL),
300#endif
[email protected]6ea6bdf2013-12-06 13:35:01301 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57302 this,
303 this,
304 this,
305 this),
[email protected]d5f942ba2008-09-26 19:30:34306 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03307 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23308 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
309 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34310 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26311 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00312 loading_total_progress_(0.0),
[email protected]960b0372014-05-19 18:01:00313 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56314 upload_size_(0),
315 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47316 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10317 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55318 capturer_count_(0),
319 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57320 is_being_destroyed_(false),
321 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15322 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01323 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02324 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38325 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21326 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
327 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29328 totalPinchGestureAmount_(0),
329 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44330 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42331 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03332 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49333 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05334 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30335 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57336 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30337 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30338 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddy371ad9142014-09-17 08:01:46339 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50340 virtual_keyboard_requested_(false),
mohan.reddy371ad9142014-09-17 08:01:46341 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55342 frame_tree_.SetFrameRemoveListener(
343 base::Bind(&WebContentsImpl::OnFrameRemoved,
344 base::Unretained(this)));
qinmin58567c82015-01-07 21:00:20345#if defined(ENABLE_BROWSER_CDMS)
346 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
347#endif
[email protected]332af7732009-03-11 13:21:35348}
initial.commit09911bf2008-07-26 23:55:29349
[email protected]b172aee2012-04-10 17:05:26350WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32351 is_being_destroyed_ = true;
352
[email protected]21b41c7e892014-02-28 01:52:24353 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
354 // shutdown and be deleted as well.
355 frame_tree_.ForEach(
356 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
357
[email protected]d9030b82013-07-19 08:26:06358 ClearAllPowerSaveBlockers();
359
[email protected]b24b68a2012-09-24 21:57:26360 for (std::set<RenderWidgetHostImpl*>::iterator iter =
361 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
362 (*iter)->DetachDelegate();
363 }
364 created_widgets_.clear();
365
[email protected]3ab9cb82011-06-03 18:02:07366 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15367 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11368 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07369
[email protected]8ed16472014-04-11 19:02:48370 if (color_chooser_info_.get())
371 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20372
[email protected]420ae012009-04-24 05:16:32373 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32374
[email protected]ca13a442012-04-17 14:00:12375 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21376 NotificationService::current()->Notify(
377 NOTIFICATION_WEB_CONTENTS_DESTROYED,
378 Source<WebContents>(this),
379 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32380
[email protected]df0c843f2014-05-23 20:37:23381 // Destroy all frame tree nodes except for the root; this notifies observers.
382 frame_tree_.ResetForMainFrameSwap();
383 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59384
[email protected]df0c843f2014-05-23 20:37:23385 // Manually call the observer methods for the root frame tree node.
386 RenderFrameHostManager* root = GetRenderManager();
387 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27388 FOR_EACH_OBSERVER(WebContentsObserver,
389 observers_,
[email protected]df0c843f2014-05-23 20:37:23390 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27391 }
[email protected]df0c843f2014-05-23 20:37:23392 FOR_EACH_OBSERVER(WebContentsObserver,
393 observers_,
394 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27395
[email protected]df0c843f2014-05-23 20:37:23396 if (root->pending_render_view_host()) {
397 FOR_EACH_OBSERVER(WebContentsObserver,
398 observers_,
399 RenderViewDeleted(root->pending_render_view_host()));
400 }
[email protected]c06c58c2014-03-12 20:31:59401
[email protected]f273ee52013-10-18 16:05:27402 FOR_EACH_OBSERVER(WebContentsObserver,
403 observers_,
[email protected]df0c843f2014-05-23 20:37:23404 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27405
[email protected]2db9bd72012-04-13 20:20:56406 FOR_EACH_OBSERVER(WebContentsObserver,
407 observers_,
[email protected]12a46832014-05-09 13:35:58408 WebContentsDestroyed());
409
410 FOR_EACH_OBSERVER(WebContentsObserver,
411 observers_,
412 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08413
[email protected]6934a702011-12-20 00:04:51414 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10415
416 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
417 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42418}
419
[email protected]d1198fd2012-08-13 22:50:19420WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59421 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19422 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03423 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59424 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06425 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19426
[email protected]4858e432014-06-23 18:14:17427 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06428 // This makes |new_contents| act as a guest.
429 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16430 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06431 // We are instantiating a WebContents for browser plugin. Set its subframe
432 // bit to true.
433 new_contents->is_subframe_ = true;
434 }
[email protected]54944cde2012-12-09 09:24:59435 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19436 return new_contents;
437}
438
[email protected]95640212014-07-26 18:14:30439// static
440std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
441 std::vector<WebContentsImpl*> result;
442 scoped_ptr<RenderWidgetHostIterator> widgets(
443 RenderWidgetHostImpl::GetRenderWidgetHosts());
444 std::set<WebContentsImpl*> web_contents_set;
445 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
446 if (!rwh->IsRenderView())
447 continue;
448 RenderViewHost* rvh = RenderViewHost::From(rwh);
449 if (!rvh)
450 continue;
451 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
452 if (!web_contents)
453 continue;
454 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
455 if (web_contents_set.find(wci) == web_contents_set.end()) {
456 web_contents_set.insert(wci);
457 result.push_back(wci);
458 }
459 }
460 return result;
461}
462
[email protected]b0936d22013-11-28 06:47:36463RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21464 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28465}
466
[email protected]7bb761892012-07-20 09:32:47467bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
468 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44469 return OnMessageReceived(render_view_host, NULL, message);
470}
471
472bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
473 RenderFrameHost* render_frame_host,
474 const IPC::Message& message) {
475 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56476 if (GetWebUI() &&
477 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17478 return true;
[email protected]d2353452012-01-19 19:53:56479 }
[email protected]f82d57b52011-04-27 19:13:17480
[email protected]d8c660432011-12-22 20:51:25481 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
482 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33483 if (render_frame_host) {
484 while ((observer = it.GetNext()) != NULL)
485 if (observer->OnMessageReceived(message, render_frame_host))
486 return true;
487 } else {
488 while ((observer = it.GetNext()) != NULL)
489 if (observer->OnMessageReceived(message))
490 return true;
491 }
[email protected]403415a2011-01-10 18:57:53492
[email protected]1d62cf72014-02-07 21:31:57493 // Message handlers should be aware of which
494 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
495 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02496 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57497 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02498 else
[email protected]1d62cf72014-02-07 21:31:57499 render_view_message_source_ = render_view_host;
500
[email protected]724159a2010-12-30 01:11:18501 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33502 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40503 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
504 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05505 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
506 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48507 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
508 OnDocumentLoadedInFrame)
509 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00510 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
511 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
512 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
513 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48514 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
515 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
516 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
517 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19518 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
519 OnMediaPlayingNotification)
520 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
521 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11522 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
523 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18524 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
525 OnDidLoadResourceFromMemoryCache)
526 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
527 OnDidDisplayInsecureContent)
528 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
529 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25530 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26531 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21532 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20533 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
534 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20535 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
536 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16537 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10538 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50539 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50540#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:42541 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
542 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50543 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
544 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55545 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
546 OnBrowserPluginMessage(message))
thestigc4cac8f2014-09-04 21:17:50547#endif
[email protected]41225fe2013-03-29 05:32:02548 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
549 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07550 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
551 OnShowValidationMessage)
552 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
553 OnHideValidationMessage)
554 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
555 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48556#if defined(OS_ANDROID)
557 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
558 OnFindMatchRectsReply)
559 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
560 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48561#endif
[email protected]724159a2010-12-30 01:11:18562 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33563 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44564 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57565 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18566
[email protected]724159a2010-12-30 01:11:18567 return handled;
568}
569
[email protected]b172aee2012-04-10 17:05:26570void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18571 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21572 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43573 if (delegate_)
574 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18575}
576
[email protected]d1198fd2012-08-13 22:50:19577NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56578 return controller_;
579}
580
[email protected]d1198fd2012-08-13 22:50:19581const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56582 return controller_;
583}
584
[email protected]8ff00d72012-10-23 19:12:21585BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55586 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30587}
588
[email protected]b172aee2012-04-10 17:05:26589const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24590 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32591 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51592 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31593}
594
[email protected]a093ce02013-07-22 20:53:14595const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24596 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32597 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24598 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
599}
600
601const GURL& WebContentsImpl::GetLastCommittedURL() const {
602 // We may not have a navigation entry yet.
603 NavigationEntry* entry = controller_.GetLastCommittedEntry();
604 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
605}
606
[email protected]8ff00d72012-10-23 19:12:21607WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31608 return delegate_;
609}
610
[email protected]8ff00d72012-10-23 19:12:21611void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31612 // TODO(cbentzel): remove this debugging code?
613 if (delegate == delegate_)
614 return;
615 if (delegate_)
616 delegate_->Detach(this);
617 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08618 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31619 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08620 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00621 if (view_)
[email protected]e85165c642014-06-10 14:34:31622 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08623 }
[email protected]be1f56ab2011-12-22 06:55:31624}
625
[email protected]8ff00d72012-10-23 19:12:21626RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21627 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41628 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16629}
630
[email protected]60eca4eb2013-12-06 00:02:16631RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41632 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16633}
634
[email protected]9c9343b2014-03-08 02:56:07635RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
636 if (!frame_tree_.GetFocusedFrame())
637 return NULL;
638 return frame_tree_.GetFocusedFrame()->current_frame_host();
639}
640
[email protected]a86c0e962013-12-17 17:10:39641void WebContentsImpl::ForEachFrame(
642 const base::Callback<void(RenderFrameHost*)>& on_frame) {
643 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
644}
645
646void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
647 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
648 delete message;
649}
650
[email protected]b172aee2012-04-10 17:05:26651RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21652 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31653}
654
[email protected]6b618e62012-08-16 12:59:18655int WebContentsImpl::GetRoutingID() const {
656 if (!GetRenderViewHost())
657 return MSG_ROUTING_NONE;
658
659 return GetRenderViewHost()->GetRoutingID();
660}
661
[email protected]44470a22013-01-24 01:21:54662int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
663 return fullscreen_widget_routing_id_;
664}
665
[email protected]b172aee2012-04-10 17:05:26666RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21667 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31668}
669
[email protected]4aebbca2013-09-17 22:26:49670RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
671 const {
672 RenderWidgetHost* const widget_host =
673 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
674 GetFullscreenWidgetRoutingID());
675 return widget_host ? widget_host->GetView() : NULL;
676}
677
[email protected]8ff00d72012-10-23 19:12:21678WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31679 return view_.get();
680}
681
[email protected]95640212014-07-26 18:14:30682void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
683 if (mode == accessibility_mode_)
684 return;
685
686 accessibility_mode_ = mode;
687 frame_tree_.ForEach(
688 base::Bind(&ForEachFrameInternal,
689 base::Bind(&SetAccessibilityModeOnFrame, mode)));
690 frame_tree_.ForEach(
691 base::Bind(&ForEachPendingFrameInternal,
692 base::Bind(&SetAccessibilityModeOnFrame, mode)));
693}
694
695void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50696 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30697}
698
699void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50700 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30701}
702
zhenw1f790352014-10-30 00:06:04703void WebContentsImpl::ClearNavigationTransitionData() {
704 FrameTreeNode* node = frame_tree_.root();
705 node->render_manager()->ClearNavigationTransitionData();
706}
707
[email protected]8ff00d72012-10-23 19:12:21708WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56709 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03710 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
711 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22712 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58713 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22714 web_ui->SetController(controller);
715 return web_ui;
716 }
717
718 delete web_ui;
719 return NULL;
720}
721
[email protected]8ff00d72012-10-23 19:12:21722WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21723 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
724 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31725}
726
[email protected]8ff00d72012-10-23 19:12:21727WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21728 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34729}
730
[email protected]86ef6a392012-05-11 22:03:11731void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22732 if (GetUserAgentOverride() == override)
733 return;
734
735 renderer_preferences_.user_agent_override = override;
736
737 // Send the new override string to the renderer.
738 RenderViewHost* host = GetRenderViewHost();
739 if (host)
740 host->SyncRendererPrefs();
741
742 // Reload the page if a load is currently in progress to avoid having
743 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27744 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22745 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
746 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53747
748 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
749 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11750}
751
752const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22753 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11754}
755
[email protected]95640212014-07-26 18:14:30756void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
757 AddAccessibilityMode(AccessibilityModeTreeOnly);
758}
759
760bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
761 return accessibility_mode_ == AccessibilityModeTreeOnly;
762}
763
764bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
765 return accessibility_mode_ == AccessibilityModeComplete;
766}
767
[email protected]2ceee8f2014-01-14 18:02:08768#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41769void WebContentsImpl::SetParentNativeViewAccessible(
770gfx::NativeViewAccessible accessible_parent) {
771 accessible_parent_ = accessible_parent;
[email protected]95640212014-07-26 18:14:30772 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
773 if (rfh)
774 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41775}
776#endif
777
[email protected]fcf75d42013-12-03 20:11:26778const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55779 // Transient entries take precedence. They are used for interstitial pages
780 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23781 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08782 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21783 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30784 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23785 if (entry) {
[email protected]b5cca982011-05-26 04:42:08786 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23787 }
[email protected]fa944cb82013-11-15 17:51:21788 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
789 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58790 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54791 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32792 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54793 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35794 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26795 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54796 if (!title.empty())
797 return title;
798 }
799 }
800
801 // We use the title for the last committed entry rather than a pending
802 // navigation entry. For example, when the user types in a URL, we want to
803 // keep the old page's title until the new load has committed and we get a new
804 // title.
[email protected]96d185d2009-04-24 03:28:54805 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32806
[email protected]9eeafc012013-11-25 23:49:47807 // We make an exception for initial navigations.
808 if (controller_.IsInitialNavigation()) {
809 // We only want to use the title from the visible entry in one of two cases:
810 // 1. There's already a committed entry for an initial navigation, in which
811 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
812 // 2. The pending entry has been explicitly assigned a title to display.
813 //
814 // If there's no last committed entry and no assigned title, we should fall
815 // back to |page_title_when_no_navigation_entry_| rather than showing the
816 // URL.
817 if (entry ||
818 (controller_.GetVisibleEntry() &&
819 !controller_.GetVisibleEntry()->GetTitle().empty())) {
820 entry = controller_.GetVisibleEntry();
821 }
822 }
[email protected]59167c22013-06-03 18:07:32823
[email protected]45d0ef7f2011-01-05 13:46:23824 if (entry) {
[email protected]b5cca982011-05-26 04:42:08825 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23826 }
[email protected]987fc3a2011-05-26 14:18:09827
828 // |page_title_when_no_navigation_entry_| is finally used
829 // if no title cannot be retrieved.
830 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54831}
832
[email protected]b172aee2012-04-10 17:05:26833int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46834 return GetMaxPageIDForSiteInstance(GetSiteInstance());
835}
836
[email protected]b172aee2012-04-10 17:05:26837int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
838 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33839 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
840 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46841
[email protected]b6583592012-01-25 19:52:33842 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34843}
844
[email protected]b172aee2012-04-10 17:05:26845void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46846 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
847}
848
[email protected]b172aee2012-04-10 17:05:26849void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33850 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46851 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33852 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34853}
854
[email protected]ec6c05f2013-10-23 18:41:57855void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
856 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
857 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57858}
859
creiscce56cd2014-09-29 22:45:22860SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21861 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54862}
863
creiscce56cd2014-09-29 22:45:22864SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
865 RenderViewHostImpl* dest_rvh =
866 GetRenderManager()->pending_render_view_host() ?
867 GetRenderManager()->pending_render_view_host() :
868 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58869 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38870}
871
[email protected]b172aee2012-04-10 17:05:26872bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31873 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49874}
875
[email protected]6dfed692014-05-22 04:18:03876bool WebContentsImpl::IsLoadingToDifferentDocument() const {
877 return is_loading_ && is_load_to_different_document_;
878}
879
[email protected]b172aee2012-04-10 17:05:26880bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03881 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31882}
883
[email protected]b172aee2012-04-10 17:05:26884const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31885 return load_state_;
886}
887
[email protected]fcf75d42013-12-03 20:11:26888const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31889 return load_state_host_;
890}
891
[email protected]b172aee2012-04-10 17:05:26892uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31893 return upload_size_;
894}
895
[email protected]b172aee2012-04-10 17:05:26896uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31897 return upload_position_;
898}
899
[email protected]1ae93fb12013-06-14 03:38:56900std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb12013-06-14 03:38:56901 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39902 frame_tree_.ForEach(base::Bind(&CollectSites,
903 base::Unretained(GetBrowserContext()),
904 base::Unretained(&sites)));
[email protected]1ae93fb12013-06-14 03:38:56905 return sites;
906}
907
[email protected]b172aee2012-04-10 17:05:26908const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54909 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31910}
911
[email protected]b172aee2012-04-10 17:05:26912bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31913 return displayed_insecure_content_;
914}
915
[email protected]222f5822014-02-05 23:40:49916void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25917 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55918 ++capturer_count_;
919 DVLOG(1) << "There are now " << capturer_count_
920 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49921
922 // Note: This provides a hint to upstream code to size the views optimally
923 // for quality (e.g., to avoid scaling).
924 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
925 preferred_size_for_capture_ = capture_size;
926 OnPreferredSizeChanged(preferred_size_);
927 }
[email protected]54597982013-02-06 01:59:55928}
929
930void WebContentsImpl::DecrementCapturerCount() {
931 --capturer_count_;
932 DVLOG(1) << "There are now " << capturer_count_
933 << " capturing(s) of WebContentsImpl@" << this;
934 DCHECK_LE(0, capturer_count_);
935
[email protected]5a652232013-02-12 06:15:25936 if (is_being_destroyed_)
937 return;
938
[email protected]222f5822014-02-05 23:40:49939 if (capturer_count_ == 0) {
940 const gfx::Size old_size = preferred_size_for_capture_;
941 preferred_size_for_capture_ = gfx::Size();
942 OnPreferredSizeChanged(old_size);
943 }
944
[email protected]1ac10dca2013-08-20 20:47:04945 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55946 DVLOG(1) << "Executing delayed WasHidden().";
947 WasHidden();
948 }
[email protected]be1f56ab2011-12-22 06:55:31949}
950
[email protected]f2bd40812013-07-20 04:30:44951int WebContentsImpl::GetCapturerCount() const {
952 return capturer_count_;
953}
954
miu50f97892014-09-22 22:49:52955bool WebContentsImpl::IsAudioMuted() const {
956 return audio_muter_.get() && audio_muter_->is_muting();
957}
958
959void WebContentsImpl::SetAudioMuted(bool mute) {
960 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
961 << " for WebContentsImpl@" << this;
962
963 if (mute == IsAudioMuted())
964 return;
965
966 if (mute) {
967 if (!audio_muter_)
968 audio_muter_.reset(new WebContentsAudioMuter(this));
969 audio_muter_->StartMuting();
970 } else {
971 DCHECK(audio_muter_);
972 audio_muter_->StopMuting();
973 }
974
975 // Notification for UI updates in response to the changed muting state.
976 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
977}
978
[email protected]b172aee2012-04-10 17:05:26979bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31980 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
981 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
982 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49983}
984
[email protected]b172aee2012-04-10 17:05:26985void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
986 int error_code) {
[email protected]443b80e2010-12-14 00:42:23987 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34988 return;
989
[email protected]443b80e2010-12-14 00:42:23990 crashed_status_ = status;
991 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21992 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34993}
994
[email protected]b172aee2012-04-10 17:05:26995base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31996 return crashed_status_;
997}
998
[email protected]b172aee2012-04-10 17:05:26999bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311000 return is_being_destroyed_;
1001}
1002
[email protected]7f924832014-08-09 05:57:221003void WebContentsImpl::NotifyNavigationStateChanged(
1004 InvalidateTypes changed_flags) {
dalecurtisbc6572e12014-09-12 19:22:301005 // Create and release the audio power save blocker depending on whether the
1006 // tab is actively producing audio or not.
dalecurtis27011852015-01-06 19:52:341007 if ((changed_flags & INVALIDATE_TYPE_TAB) &&
dalecurtisbc6572e12014-09-12 19:22:301008 AudioStreamMonitor::monitoring_available()) {
1009 if (WasRecentlyAudible()) {
1010 if (!audio_power_save_blocker_)
1011 CreateAudioPowerSaveBlocker();
1012 } else {
1013 audio_power_save_blocker_.reset();
1014 }
1015 }
1016
[email protected]d5f942ba2008-09-26 19:30:341017 if (delegate_)
1018 delegate_->NavigationStateChanged(this, changed_flags);
1019}
1020
[email protected]9a890452014-02-13 22:21:021021base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1022 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331023}
1024
[email protected]9e2e4632012-07-27 16:38:411025void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541026 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591027
[email protected]948481d2014-06-11 18:32:221028 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1029 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591030 iter != widgets.end();
1031 iter++) {
[email protected]948481d2014-06-11 18:32:221032 if (*iter) {
1033 (*iter)->Show();
[email protected]789e9152009-08-04 21:59:431034#if defined(OS_MACOSX)
[email protected]948481d2014-06-11 18:32:221035 (*iter)->SetActive(true);
[email protected]789e9152009-08-04 21:59:431036#endif
[email protected]de3c5d82014-05-28 22:12:591037 }
[email protected]789e9152009-08-04 21:59:431038 }
[email protected]96d185d2009-04-24 03:28:541039
[email protected]9a890452014-02-13 22:21:021040 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381041
[email protected]b9769d82012-02-10 00:23:591042 // The resize rect might have changed while this was inactive -- send the new
1043 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581044 RenderViewHostImpl* rvh =
1045 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591046 if (rvh) {
1047 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1048 }
[email protected]96d185d2009-04-24 03:28:541049
dalecurtisbc6572e12014-09-12 19:22:301050 // Restore power save blocker if there are active video players running.
1051 if (!active_video_players_.empty() && !video_power_save_blocker_)
1052 CreateVideoPowerSaveBlocker();
1053
[email protected]c0d9d5672013-10-09 07:38:031054 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1055
[email protected]54597982013-02-06 01:59:551056 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311057}
1058
[email protected]b172aee2012-04-10 17:05:261059void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551060 // If there are entities capturing screenshots or video (e.g., mirroring),
1061 // don't activate the "disable rendering" optimization.
1062 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521063 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551064 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261065 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521066 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331067 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521068 // calls us).
[email protected]948481d2014-06-11 18:32:221069 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1070 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591071 iter != widgets.end();
1072 iter++) {
[email protected]948481d2014-06-11 18:32:221073 if (*iter)
1074 (*iter)->Hide();
[email protected]de3c5d82014-05-28 22:12:591075 }
dalecurtisbc6572e12014-09-12 19:22:301076
1077 // Release any video power save blockers held as video is not visible.
1078 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541079 }
1080
[email protected]c0d9d5672013-10-09 07:38:031081 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1082
[email protected]54597982013-02-06 01:59:551083 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371084}
1085
[email protected]b172aee2012-04-10 17:05:261086bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311087 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271088 return WillNotifyDisconnection() &&
1089 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581090 !static_cast<RenderViewHostImpl*>(
1091 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311092}
1093
[email protected]1c3f80bd2014-04-08 23:02:061094void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1095 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1096 for_cross_site_transition);
1097}
1098
[email protected]b172aee2012-04-10 17:05:261099void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211100 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401101 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271102}
1103
[email protected]b172aee2012-04-10 17:05:261104WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441105 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451106 // We pass our own opener so that the cloned page can access it if it was
1107 // before.
[email protected]54944cde2012-12-09 09:24:591108 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451109 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591110 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191111 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221112 FOR_EACH_OBSERVER(WebContentsObserver,
1113 observers_,
1114 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271115 return tc;
1116}
1117
[email protected]14392a52012-05-02 20:28:441118void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211119 const NotificationSource& source,
1120 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441121 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211122 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1123 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031124 RenderWidgetHostView* view = host->GetView();
1125 if (view == GetFullscreenRenderWidgetHostView()) {
1126 // We cannot just call view_->RestoreFocus() here. On some platforms,
1127 // attempting to focus the currently-invisible WebContentsView will be
1128 // flat-out ignored. Therefore, this boolean is used to track whether
1129 // we will request focus after the fullscreen widget has been
1130 // destroyed.
1131 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1132 } else {
1133 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1134 i != pending_widget_views_.end(); ++i) {
1135 if (host->GetView() == i->second) {
1136 pending_widget_views_.erase(i);
1137 break;
1138 }
[email protected]bafe6cd2012-05-23 23:09:501139 }
1140 }
1141 break;
1142 }
[email protected]14392a52012-05-02 20:28:441143 default:
1144 NOTREACHED();
1145 }
1146}
1147
[email protected]ec6c05f2013-10-23 18:41:571148WebContents* WebContentsImpl::GetWebContents() {
1149 return this;
1150}
1151
[email protected]54944cde2012-12-09 09:24:591152void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211153 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361154 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211155 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431156 should_normally_be_visible_ = !params.initially_hidden;
1157
avic2c29d782014-12-12 00:23:541158 // Either both routing ids can be given, or neither can be.
1159 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
1160 params.main_frame_routing_id == MSG_ROUTING_NONE) ||
1161 (params.routing_id != MSG_ROUTING_NONE &&
1162 params.main_frame_routing_id != MSG_ROUTING_NONE));
[email protected]fa944cb82013-11-15 17:51:211163 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041164 params.browser_context, params.site_instance, params.routing_id,
1165 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191166
[email protected]fc2b46b2014-05-03 16:33:451167 WebContentsViewDelegate* delegate =
1168 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1169
1170 if (browser_plugin_guest_) {
1171 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1172 this, delegate, &render_view_host_delegate_view_));
1173
1174 WebContentsViewGuest* rv = new WebContentsViewGuest(
1175 this, browser_plugin_guest_.get(), platform_view.Pass(),
1176 render_view_host_delegate_view_);
1177 render_view_host_delegate_view_ = rv;
1178 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191179 } else {
[email protected]fc2b46b2014-05-03 16:33:451180 // Regular WebContentsView.
1181 view_.reset(CreateWebContentsView(
1182 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191183 }
[email protected]fc2b46b2014-05-03 16:33:451184 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191185 CHECK(view_.get());
1186
[email protected]ed245db2012-12-18 08:00:451187 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591188 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191189
1190 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101191 if (opener_)
1192 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191193
tommyclieb25b2a2014-11-03 19:45:091194#if defined(ENABLE_PLUGINS)
1195 plugin_content_origin_whitelist_.reset(
1196 new PluginContentOriginWhitelist(this));
1197#endif
1198
[email protected]d1198fd2012-08-13 22:50:191199 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211200 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1201 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101202
[email protected]01f83f92014-06-17 14:41:541203 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091204 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541205
mlamouriefdca9d2014-09-16 16:55:401206 manifest_manager_host_.reset(new ManifestManagerHost(this));
1207
[email protected]c7654a232013-06-12 21:04:441208#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101209 date_time_chooser_.reset(new DateTimeChooserAndroid());
1210#endif
fsamuel7310a4262014-12-05 05:06:441211
1212 // BrowserPluginGuest::Init needs to be called after this WebContents has
1213 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1214 if (browser_plugin_guest_)
1215 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371216
1217 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1218 g_created_callbacks.Get().at(i).Run(this);
[email protected]d1198fd2012-08-13 22:50:191219}
1220
[email protected]7fff43e2013-05-21 20:21:101221void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1222 RemoveDestructionObserver(web_contents);
1223
[email protected]14392a52012-05-02 20:28:441224 // Clear the opener if it has been closed.
1225 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441226 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511227 return;
[email protected]14392a52012-05-02 20:28:441228 }
[email protected]ceee8cd2013-03-08 04:59:511229 // Clear a pending contents that has been closed before being shown.
1230 for (PendingContents::iterator iter = pending_contents_.begin();
1231 iter != pending_contents_.end();
1232 ++iter) {
1233 if (iter->second != web_contents)
1234 continue;
1235 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511236 return;
1237 }
1238 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441239}
1240
[email protected]7fff43e2013-05-21 20:21:101241void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1242 if (!ContainsKey(destruction_observers_, web_contents)) {
1243 destruction_observers_[web_contents] =
1244 new DestructionObserver(this, web_contents);
1245 }
1246}
1247
1248void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1249 DestructionObservers::iterator iter =
1250 destruction_observers_.find(web_contents);
1251 if (iter != destruction_observers_.end()) {
1252 delete destruction_observers_[web_contents];
1253 destruction_observers_.erase(iter);
1254 }
1255}
1256
[email protected]b172aee2012-04-10 17:05:261257void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311258 observers_.AddObserver(observer);
1259}
1260
[email protected]b172aee2012-04-10 17:05:261261void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311262 observers_.RemoveObserver(observer);
1263}
1264
[email protected]948481d2014-06-11 18:32:221265std::set<RenderWidgetHostView*>
1266WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1267 std::set<RenderWidgetHostView*> set;
1268 if (ShowingInterstitialPage()) {
1269 set.insert(GetRenderWidgetHostView());
1270 } else {
1271 ForEachFrame(
1272 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1273 }
[email protected]de3c5d82014-05-28 22:12:591274 return set;
1275}
1276
[email protected]b172aee2012-04-10 17:05:261277void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341278 if (delegate_)
1279 delegate_->ActivateContents(this);
1280}
1281
[email protected]b172aee2012-04-10 17:05:261282void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121283 if (delegate_)
1284 delegate_->DeactivateContents(this);
1285}
1286
[email protected]b172aee2012-04-10 17:05:261287void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481288 if (delegate_)
1289 delegate_->LostCapture();
1290}
1291
[email protected]b24b68a2012-09-24 21:57:261292void WebContentsImpl::RenderWidgetDeleted(
1293 RenderWidgetHostImpl* render_widget_host) {
1294 if (is_being_destroyed_) {
1295 // |created_widgets_| might have been destroyed.
1296 return;
1297 }
1298
1299 std::set<RenderWidgetHostImpl*>::iterator iter =
1300 created_widgets_.find(render_widget_host);
1301 if (iter != created_widgets_.end())
1302 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541303
1304 if (render_widget_host &&
1305 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491306 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1307 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541308 FOR_EACH_OBSERVER(WebContentsObserver,
1309 observers_,
1310 DidDestroyFullscreenWidget(
1311 fullscreen_widget_routing_id_));
1312 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031313 if (fullscreen_widget_had_focus_at_shutdown_)
1314 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541315 }
[email protected]b24b68a2012-09-24 21:57:261316}
1317
miu9e14e492014-10-25 02:39:041318void WebContentsImpl::RenderWidgetGotFocus(
1319 RenderWidgetHostImpl* render_widget_host) {
1320 // Notify the delegate if an embedded fullscreen widget was focused.
1321 if (delegate_ && render_widget_host &&
1322 delegate_->EmbedsFullscreenWidget() &&
1323 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1324 delegate_->WebContentsFocused(this);
1325}
1326
[email protected]b172aee2012-04-10 17:05:261327bool WebContentsImpl::PreHandleKeyboardEvent(
1328 const NativeWebKeyboardEvent& event,
1329 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481330 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131331 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481332}
1333
[email protected]b172aee2012-04-10 17:05:261334void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101335 if (browser_plugin_embedder_ &&
1336 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1337 return;
1338 }
[email protected]63954792011-07-11 04:17:481339 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131340 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481341}
1342
[email protected]d92026ef2014-03-03 21:04:131343bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461344 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191345#if !defined(OS_MACOSX)
yutakf3990fd2014-12-23 03:52:381346 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1347 // isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191348 // -the OS already has a gesture to do this through pinch-zoom
1349 // -if a user starts an inertial scroll, let's go, and presses control
1350 // (i.e. control+tab) then the OS's buffered scroll events will come in
1351 // with control key set which isn't what the user wants
yutakf3990fd2014-12-23 03:52:381352 if (delegate_ &&
1353 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551354 (event.modifiers & blink::WebInputEvent::ControlKey) &&
yutakf3990fd2014-12-23 03:52:381355 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1356 // gestures, which are regrettably easy to trigger accidentally.
1357 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521358 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1359 return true;
1360 }
[email protected]bccc4472013-04-18 16:37:191361#endif
[email protected]fb3f066e2013-02-12 19:12:521362 return false;
1363}
1364
[email protected]04bce562014-01-30 05:34:541365bool WebContentsImpl::PreHandleGestureEvent(
1366 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031367 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541368}
1369
[email protected]bab38af2014-03-30 17:37:291370bool WebContentsImpl::HandleGestureEvent(
1371 const blink::WebGestureEvent& event) {
1372 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1373 // Use them to implement browser zoom, as for HandleWheelEvent above.
1374 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331375 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291376 // The scale difference necessary to trigger a zoom action. Derived from
1377 // experimentation to find a value that feels reasonable.
1378 const float kZoomStepValue = 0.6f;
1379
1380 // Find the (absolute) thresholds on either side of the current zoom factor,
1381 // then convert those to actual numbers to trigger a zoom in or out.
1382 // This logic deliberately makes the range around the starting zoom value
1383 // for the gesture twice as large as the other ranges (i.e., the notches are
1384 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1385 // so that it's easier to get back to your starting point than it is to
1386 // overshoot.
1387 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1388 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1389 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1390 : -backStep;
1391 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1392 : backStep;
1393
[email protected]fb546cb2014-04-28 14:09:371394 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291395 if (totalPinchGestureAmount_ > zoomInThreshold) {
1396 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461397 if (delegate_)
1398 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291399 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1400 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461401 if (delegate_)
1402 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291403 }
1404 return true;
1405 }
1406
1407 return false;
1408}
1409
[email protected]b172aee2012-04-10 17:05:261410void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431411 if (delegate_)
1412 delegate_->HandleMouseDown();
1413}
1414
[email protected]b172aee2012-04-10 17:05:261415void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481416 if (delegate_)
1417 delegate_->HandleMouseUp();
1418}
1419
[email protected]590a634e2012-07-19 16:38:231420void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481421 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231422 delegate_->HandlePointerActivate();
1423}
1424
1425void WebContentsImpl::HandleGestureBegin() {
1426 if (delegate_)
1427 delegate_->HandleGestureBegin();
1428}
1429
1430void WebContentsImpl::HandleGestureEnd() {
1431 if (delegate_)
1432 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481433}
1434
[email protected]b172aee2012-04-10 17:05:261435void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491436 // This method is being called to enter or leave renderer-initiated fullscreen
1437 // mode. Either way, make sure any existing fullscreen widget is shut down
1438 // first.
1439 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1440 if (widget_view)
1441 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1442
[email protected]8a5e0ca2011-08-25 06:30:471443 if (delegate_)
1444 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371445
1446 FOR_EACH_OBSERVER(WebContentsObserver,
1447 observers_,
1448 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471449}
1450
[email protected]b172aee2012-04-10 17:05:261451bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381452 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121453}
1454
[email protected]a9c81f02012-06-01 00:15:441455void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1456 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371457 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441458 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371459 } else {
1460 GotResponseToLockMouseRequest(false);
1461 }
1462}
1463
[email protected]b172aee2012-04-10 17:05:261464void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371465 if (delegate_)
1466 delegate_->LostMouseLock();
1467}
1468
[email protected]bafe6cd2012-05-23 23:09:501469void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201470 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501471 int route_id,
[email protected]227692c52013-05-31 22:43:041472 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131473 const ViewHostMsg_CreateWindow_Params& params,
1474 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501475 // We usually create the new window in the same BrowsingInstance (group of
1476 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551477 // if the opener is being suppressed (in a non-guest), we create a new
1478 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251479 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551480
[email protected]04cbd3d2013-12-04 04:58:201481 // If the opener is to be suppressed, the new window can be in any process.
1482 // Since routing ids are process specific, we must not have one passed in
1483 // as argument here.
1484 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1485
[email protected]bafe6cd2012-05-23 23:09:501486 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551487 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571488 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501489 GetSiteInstance();
1490
[email protected]04cbd3d2013-12-04 04:58:201491 // A message to create a new window can only come from the active process for
1492 // this WebContentsImpl instance. If any other process sends the request,
1493 // it is invalid and the process must be terminated.
1494 if (GetRenderProcessHost()->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351495 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1496 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201497 if (process_handle != base::kNullProcessHandle) {
1498 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391499 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351500 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201501 }
1502 return;
1503 }
1504
[email protected]d1198fd2012-08-13 22:50:191505 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341506 //
1507 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301508 const std::string& partition_id =
1509 GetContentClient()->browser()->
1510 GetStoragePartitionIdForSite(GetBrowserContext(),
1511 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461512 StoragePartition* partition = BrowserContext::GetStoragePartition(
1513 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411514 DOMStorageContextWrapper* dom_storage_context =
1515 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191516 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1517 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1518 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371519
1520 if (delegate_ &&
1521 !delegate_->ShouldCreateWebContents(this,
1522 route_id,
avic2c29d782014-12-12 00:23:541523 main_frame_route_id,
[email protected]dd6730412013-08-14 15:03:371524 params.window_container_type,
1525 params.frame_name,
1526 params.target_url,
1527 partition_id,
1528 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011529 if (route_id != MSG_ROUTING_NONE &&
1530 !RenderViewHost::FromID(render_process_id, route_id)) {
1531 // If the embedder didn't create a WebContents for this route, we need to
1532 // delete the RenderView that had already been created.
1533 Send(new ViewMsg_Close(route_id));
1534 }
[email protected]dd6730412013-08-14 15:03:371535 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1536 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1537 main_frame_route_id);
1538 return;
1539 }
1540
1541 // Create the new web contents. This will automatically create the new
1542 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461543 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591544 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041545 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061546 create_params.opener = this;
1547 create_params.opener_suppressed = params.opener_suppressed;
1548 if (params.disposition == NEW_BACKGROUND_TAB)
1549 create_params.initially_hidden = true;
1550
[email protected]4858e432014-06-23 18:14:171551 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551552 if (!is_guest) {
1553 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451554 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171555 new_contents = static_cast<WebContentsImpl*>(
1556 WebContents::Create(create_params));
1557 } else {
1558 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551559 }
[email protected]50d326e2014-05-20 17:59:061560 new_contents->GetController().SetSessionStorageNamespace(
1561 partition_id,
1562 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261563 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191564
[email protected]c4538072013-03-18 02:17:551565 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341566 // will be shown immediately).
1567 if (!params.opener_suppressed) {
1568 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451569 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501570
[email protected]d70bea92013-04-05 04:23:341571 // TODO(brettw): It seems bogus that we have to call this function on the
1572 // newly created object and give it one of its own member variables.
lazyboy549b3b42014-10-20 17:16:041573 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false);
[email protected]d70bea92013-04-05 04:23:341574 }
[email protected]bafe6cd2012-05-23 23:09:501575 // Save the created window associated with the route so we can show it
1576 // later.
1577 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1578 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101579 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501580 }
1581
1582 if (delegate_) {
1583 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071584 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131585 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501586 }
1587
1588 if (params.opener_suppressed) {
1589 // When the opener is suppressed, the original renderer cannot access the
1590 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001591 bool was_blocked = false;
1592 if (delegate_) {
1593 gfx::Rect initial_pos;
1594 delegate_->AddNewContents(
1595 this, new_contents, params.disposition, initial_pos,
1596 params.user_gesture, &was_blocked);
1597 }
1598 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211599 OpenURLParams open_params(params.target_url,
1600 Referrer(),
1601 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351602 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211603 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301604 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001605 new_contents->OpenURL(open_params);
1606 }
[email protected]bafe6cd2012-05-23 23:09:501607 }
1608}
1609
[email protected]a8504022013-12-04 20:23:511610void WebContentsImpl::CreateNewWidget(int render_process_id,
1611 int route_id,
[email protected]180ef242013-11-07 06:50:461612 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511613 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501614}
1615
[email protected]a8504022013-12-04 20:23:511616void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1617 int route_id) {
1618 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501619}
1620
[email protected]a8504022013-12-04 20:23:511621void WebContentsImpl::CreateNewWidget(int render_process_id,
1622 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501623 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461624 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211625 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511626 // A message to create a new widget can only come from the active process for
1627 // this WebContentsImpl instance. If any other process sends the request,
1628 // it is invalid and the process must be terminated.
1629 if (process->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351630 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1631 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511632 if (process_handle != base::kNullProcessHandle) {
1633 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391634 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351635 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511636 }
1637 return;
1638 }
1639
[email protected]bafe6cd2012-05-23 23:09:501640 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041641 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261642 created_widgets_.insert(widget_host);
1643
[email protected]cfd80b02014-05-01 17:46:481644 RenderWidgetHostViewBase* widget_view =
1645 static_cast<RenderWidgetHostViewBase*>(
1646 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191647 if (!widget_view)
1648 return;
[email protected]bafe6cd2012-05-23 23:09:501649 if (!is_fullscreen) {
1650 // Popups should not get activated.
1651 widget_view->SetPopupType(popup_type);
1652 }
1653 // Save the created widget associated with the route so we can show it later.
1654 pending_widget_views_[route_id] = widget_view;
1655
1656#if defined(OS_MACOSX)
1657 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1658 // to allow it to survive the trip without being hosted.
1659 base::mac::NSObjectRetain(widget_view->GetNativeView());
1660#endif
1661}
1662
1663void WebContentsImpl::ShowCreatedWindow(int route_id,
1664 WindowOpenDisposition disposition,
1665 const gfx::Rect& initial_pos,
1666 bool user_gesture) {
1667 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001668 if (contents) {
1669 WebContentsDelegate* delegate = GetDelegate();
1670 if (delegate) {
1671 delegate->AddNewContents(
1672 this, contents, disposition, initial_pos, user_gesture, NULL);
1673 }
1674 }
[email protected]bafe6cd2012-05-23 23:09:501675}
1676
1677void WebContentsImpl::ShowCreatedWidget(int route_id,
1678 const gfx::Rect& initial_pos) {
1679 ShowCreatedWidget(route_id, false, initial_pos);
1680}
1681
1682void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1683 ShowCreatedWidget(route_id, true, gfx::Rect());
1684}
1685
1686void WebContentsImpl::ShowCreatedWidget(int route_id,
1687 bool is_fullscreen,
1688 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481689 RenderWidgetHostViewBase* widget_host_view =
1690 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501691 if (!widget_host_view)
1692 return;
[email protected]cfd80b02014-05-01 17:46:481693
1694 RenderWidgetHostView* view = NULL;
1695 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1696 if (guest && guest->embedder_web_contents()) {
1697 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1698 } else {
1699 view = GetRenderWidgetHostView();
1700 }
1701
[email protected]4aebbca2013-09-17 22:26:491702 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311703 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031704 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311705 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491706 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1707 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1708 delegate_->ToggleFullscreenModeForTab(this, true);
1709 } else {
[email protected]cfd80b02014-05-01 17:46:481710 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491711 }
[email protected]4aebbca2013-09-17 22:26:491712 FOR_EACH_OBSERVER(WebContentsObserver,
1713 observers_,
1714 DidShowFullscreenWidget(route_id));
1715 if (!widget_host_view->HasFocus())
1716 widget_host_view->Focus();
1717 } else {
[email protected]cfd80b02014-05-01 17:46:481718 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491719 }
[email protected]89054502012-06-03 10:29:241720
1721 RenderWidgetHostImpl* render_widget_host_impl =
1722 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1723 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311724 // Only allow privileged mouse lock for fullscreen render widget, which is
1725 // used to implement Pepper Flash fullscreen.
1726 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501727
1728#if defined(OS_MACOSX)
1729 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1730 // properly embedded (or purposefully ignored) we can release the retain we
1731 // took in CreateNewWidget().
1732 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1733#endif
1734}
1735
1736WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1737 PendingContents::iterator iter = pending_contents_.find(route_id);
1738
1739 // Certain systems can block the creation of new windows. If we didn't succeed
1740 // in creating one, just return NULL.
1741 if (iter == pending_contents_.end()) {
1742 return NULL;
1743 }
1744
1745 WebContentsImpl* new_contents = iter->second;
1746 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101747 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501748
[email protected]d70bea92013-04-05 04:23:341749 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251750 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341751 return new_contents;
1752
[email protected]bafe6cd2012-05-23 23:09:501753 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1754 !new_contents->GetRenderViewHost()->GetView())
1755 return NULL;
1756
creis82dd6af2014-09-17 16:30:451757 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501758 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1759 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
creis82dd6af2014-09-17 16:30:451760 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
1761
[email protected]bafe6cd2012-05-23 23:09:501762 return new_contents;
1763}
1764
1765RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1766 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1767 if (iter == pending_widget_views_.end()) {
1768 DCHECK(false);
1769 return NULL;
1770 }
1771
1772 RenderWidgetHostView* widget_host_view = iter->second;
1773 pending_widget_views_.erase(route_id);
1774
1775 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1776 if (!widget_host->GetProcess()->HasConnection()) {
1777 // The view has gone away or the renderer crashed. Nothing to do.
1778 return NULL;
1779 }
1780
1781 return widget_host_view;
1782}
1783
[email protected]f13b4202012-06-12 23:53:231784void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091785 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211786 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371787 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231788 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371789 } else {
1790 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041791 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371792 scoped_ptr<MediaStreamUI>());
1793 }
[email protected]f13b4202012-06-12 23:53:231794}
1795
grunell657d4d82014-09-18 00:09:431796bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1797 MediaStreamType type) {
1798 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1799 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1800 return delegate_ &&
1801 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1802}
1803
[email protected]cc9200432013-07-23 23:02:401804SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1805 SiteInstance* instance) {
1806 return controller_.GetSessionStorageNamespace(instance);
1807}
1808
[email protected]6de7fc482014-06-06 10:46:441809SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1810 return controller_.GetSessionStorageNamespaceMap();
1811}
1812
[email protected]9b159a52013-10-03 17:24:551813FrameTree* WebContentsImpl::GetFrameTree() {
1814 return &frame_tree_;
1815}
1816
lukendc35e7f2014-11-10 19:06:141817void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
1818 virtual_keyboard_requested_ = requested;
1819}
1820
1821bool WebContentsImpl::IsVirtualKeyboardRequested() {
1822 return virtual_keyboard_requested_;
1823}
1824
[email protected]95640212014-07-26 18:14:301825AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1826 return accessibility_mode_;
1827}
1828
[email protected]31a71eaf2014-03-13 01:47:361829void WebContentsImpl::AccessibilityEventReceived(
1830 const std::vector<AXEventNotificationDetails>& details) {
1831 FOR_EACH_OBSERVER(
1832 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1833}
1834
dmazzonia656928e2014-09-15 20:28:541835RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
1836 int browser_plugin_instance_id) {
1837 BrowserPluginGuestManager* guest_manager =
1838 GetBrowserContext()->GetGuestManager();
1839 WebContents* guest = guest_manager->GetGuestByInstanceID(
1840 this, browser_plugin_instance_id);
1841 if (!guest)
1842 return NULL;
1843 return guest->GetMainFrame();
1844}
1845
blundellc57b93f2014-10-29 13:19:571846GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
1847 return geolocation_service_context_.get();
1848}
1849
[email protected]edc3af82013-12-12 21:24:071850void WebContentsImpl::OnShowValidationMessage(
1851 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291852 const base::string16& main_text,
1853 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071854 if (delegate_)
1855 delegate_->ShowValidationMessage(
1856 this, anchor_in_root_view, main_text, sub_text);
1857}
1858
1859void WebContentsImpl::OnHideValidationMessage() {
1860 if (delegate_)
1861 delegate_->HideValidationMessage(this);
1862}
1863
1864void WebContentsImpl::OnMoveValidationMessage(
1865 const gfx::Rect& anchor_in_root_view) {
1866 if (delegate_)
1867 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1868}
1869
[email protected]32deec62013-05-15 23:55:041870void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1871 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441872 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041873}
1874
[email protected]95640212014-07-26 18:14:301875BrowserAccessibilityManager*
1876 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1877 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1878 return rfh ? rfh->browser_accessibility_manager() : NULL;
1879}
1880
1881BrowserAccessibilityManager*
1882 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1883 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1884 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1885}
1886
[email protected]b172aee2012-04-10 17:05:261887void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491888 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231889 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491890 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331891}
1892
[email protected]b172aee2012-04-10 17:05:261893void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341894 if (delegate_)
1895 delegate_->ResizeDueToAutoResize(this, new_size);
1896}
1897
[email protected]b172aee2012-04-10 17:05:261898WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201899 if (!delegate_)
1900 return NULL;
[email protected]00c37fc2011-08-02 00:22:501901
[email protected]e5d549d2011-12-28 01:29:201902 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201903 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341904}
1905
[email protected]6b618e62012-08-16 12:59:181906bool WebContentsImpl::Send(IPC::Message* message) {
1907 if (!GetRenderViewHost()) {
1908 delete message;
1909 return false;
1910 }
1911
1912 return GetRenderViewHost()->Send(message);
1913}
1914
[email protected]b172aee2012-04-10 17:05:261915bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501916 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261917 FrameTreeNode* node = frame_tree_.root();
1918
creise42f2a52014-09-18 18:14:571919 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
1920 // is currently only used in --site-per-process and tests.
[email protected]61ac9e242014-03-21 20:55:261921 NavigationEntryImpl* pending_entry =
1922 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
creise42f2a52014-09-18 18:14:571923 if (pending_entry->frame_tree_node_id() != -1) {
1924 FrameTreeNode* subframe =
1925 frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1926 DCHECK(subframe);
1927 if (subframe)
1928 node = subframe;
[email protected]61ac9e242014-03-21 20:55:261929 }
1930
1931 return node->navigator()->NavigateToPendingEntry(
1932 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541933}
[email protected]96d185d2009-04-24 03:28:541934
[email protected]a86c0e962013-12-17 17:10:391935void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1936 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441937 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391938 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441939}
1940
[email protected]20ca0382013-02-28 19:50:071941void WebContentsImpl::AttachInterstitialPage(
1942 InterstitialPageImpl* interstitial_page) {
1943 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211944 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291945
1946 // Cancel any visible dialogs so that they don't interfere with the
1947 // interstitial.
1948 if (dialog_manager_)
1949 dialog_manager_->CancelActiveAndPendingDialogs(this);
1950
[email protected]20ca0382013-02-28 19:50:071951 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1952 DidAttachInterstitialPage());
1953}
1954
1955void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571956 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211957 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071958 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1959 DidDetachInterstitialPage());
1960}
1961
avi2b177592014-12-10 02:08:021962void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
1963 int history_length) {
1964 SetHistoryOffsetAndLengthForView(
1965 GetRenderViewHost(), history_offset, history_length);
1966}
1967
1968void WebContentsImpl::SetHistoryOffsetAndLengthForView(
1969 RenderViewHost* render_view_host,
1970 int history_offset,
1971 int history_length) {
1972 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
1973 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:141974}
1975
[email protected]4fed3702014-04-01 09:08:001976void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171977 RenderFrameHost* focused_frame = GetFocusedFrame();
1978 if (!focused_frame)
1979 return;
1980
[email protected]959be4c2014-04-08 15:01:331981 focused_frame->Send(new FrameMsg_Reload(
1982 focused_frame->GetRoutingID(), ignore_cache));
1983}
1984
1985void WebContentsImpl::Undo() {
1986 RenderFrameHost* focused_frame = GetFocusedFrame();
1987 if (!focused_frame)
1988 return;
1989
1990 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1991 RecordAction(base::UserMetricsAction("Undo"));
1992}
1993
1994void WebContentsImpl::Redo() {
1995 RenderFrameHost* focused_frame = GetFocusedFrame();
1996 if (!focused_frame)
1997 return;
1998 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1999 RecordAction(base::UserMetricsAction("Redo"));
2000}
2001
2002void WebContentsImpl::Cut() {
2003 RenderFrameHost* focused_frame = GetFocusedFrame();
2004 if (!focused_frame)
2005 return;
2006
2007 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2008 RecordAction(base::UserMetricsAction("Cut"));
2009}
2010
2011void WebContentsImpl::Copy() {
2012 RenderFrameHost* focused_frame = GetFocusedFrame();
2013 if (!focused_frame)
2014 return;
2015
2016 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2017 RecordAction(base::UserMetricsAction("Copy"));
2018}
2019
2020void WebContentsImpl::CopyToFindPboard() {
2021#if defined(OS_MACOSX)
2022 RenderFrameHost* focused_frame = GetFocusedFrame();
2023 if (!focused_frame)
2024 return;
2025
2026 // Windows/Linux don't have the concept of a find pasteboard.
2027 focused_frame->Send(
2028 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2029 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2030#endif
2031}
2032
2033void WebContentsImpl::Paste() {
2034 RenderFrameHost* focused_frame = GetFocusedFrame();
2035 if (!focused_frame)
2036 return;
2037
2038 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2039 RecordAction(base::UserMetricsAction("Paste"));
2040}
2041
2042void WebContentsImpl::PasteAndMatchStyle() {
2043 RenderFrameHost* focused_frame = GetFocusedFrame();
2044 if (!focused_frame)
2045 return;
2046
2047 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2048 focused_frame->GetRoutingID()));
2049 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2050}
2051
2052void WebContentsImpl::Delete() {
2053 RenderFrameHost* focused_frame = GetFocusedFrame();
2054 if (!focused_frame)
2055 return;
2056
2057 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2058 RecordAction(base::UserMetricsAction("DeleteSelection"));
2059}
2060
2061void WebContentsImpl::SelectAll() {
2062 RenderFrameHost* focused_frame = GetFocusedFrame();
2063 if (!focused_frame)
2064 return;
2065
2066 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2067 RecordAction(base::UserMetricsAction("SelectAll"));
2068}
2069
2070void WebContentsImpl::Unselect() {
2071 RenderFrameHost* focused_frame = GetFocusedFrame();
2072 if (!focused_frame)
2073 return;
2074
2075 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2076 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172077}
2078
2079void WebContentsImpl::Replace(const base::string16& word) {
2080 RenderFrameHost* focused_frame = GetFocusedFrame();
2081 if (!focused_frame)
2082 return;
2083
[email protected]959be4c2014-04-08 15:01:332084 focused_frame->Send(new InputMsg_Replace(
2085 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172086}
2087
2088void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2089 RenderFrameHost* focused_frame = GetFocusedFrame();
2090 if (!focused_frame)
2091 return;
2092
[email protected]959be4c2014-04-08 15:01:332093 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2094 focused_frame->GetRoutingID(), word));
2095}
2096
2097void WebContentsImpl::NotifyContextMenuClosed(
2098 const CustomContextMenuContext& context) {
2099 RenderFrameHost* focused_frame = GetFocusedFrame();
2100 if (!focused_frame)
2101 return;
2102
2103 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2104 focused_frame->GetRoutingID(), context));
2105}
2106
2107void WebContentsImpl::ExecuteCustomContextMenuCommand(
2108 int action, const CustomContextMenuContext& context) {
2109 RenderFrameHost* focused_frame = GetFocusedFrame();
2110 if (!focused_frame)
2111 return;
2112
2113 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2114 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002115}
2116
[email protected]fc2b46b2014-05-03 16:33:452117gfx::NativeView WebContentsImpl::GetNativeView() {
2118 return view_->GetNativeView();
2119}
2120
2121gfx::NativeView WebContentsImpl::GetContentNativeView() {
2122 return view_->GetContentNativeView();
2123}
2124
2125gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2126 return view_->GetTopLevelNativeWindow();
2127}
2128
2129gfx::Rect WebContentsImpl::GetViewBounds() {
2130 return view_->GetViewBounds();
2131}
2132
2133gfx::Rect WebContentsImpl::GetContainerBounds() {
2134 gfx::Rect rv;
2135 view_->GetContainerBounds(&rv);
2136 return rv;
2137}
2138
2139DropData* WebContentsImpl::GetDropData() {
2140 return view_->GetDropData();
2141}
2142
2143void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042144 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452145}
2146
2147void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042148 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452149}
2150
2151void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042152 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452153}
2154
2155void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042156 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452157}
2158
[email protected]b172aee2012-04-10 17:05:262159void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272160 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212161 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542162 return;
2163 }
[email protected]0b431992014-06-24 00:08:032164 RenderWidgetHostView* const fullscreen_view =
2165 GetFullscreenRenderWidgetHostView();
2166 if (fullscreen_view) {
2167 fullscreen_view->Focus();
2168 return;
2169 }
[email protected]9f76c1e2012-03-05 15:15:582170 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542171}
2172
[email protected]b172aee2012-04-10 17:05:262173bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212174 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542175}
2176
[email protected]b172aee2012-04-10 17:05:262177InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212178 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222179}
2180
[email protected]b172aee2012-04-10 17:05:262181bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162182 // WebKit creates Document object when MIME type is application/xhtml+xml,
2183 // so we also support this MIME type.
2184 return contents_mime_type_ == "text/html" ||
2185 contents_mime_type_ == "text/xml" ||
2186 contents_mime_type_ == "application/xhtml+xml" ||
2187 contents_mime_type_ == "text/plain" ||
2188 contents_mime_type_ == "text/css" ||
2189 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2190}
2191
[email protected]b172aee2012-04-10 17:05:262192void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592193 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162194 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552195 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012196 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142197 return;
[email protected]c7dd2f62011-07-18 15:57:592198 }
2199
2200 Stop();
2201
2202 // Create the save package and possibly prompt the user for the name to save
2203 // the page as. The user prompt is an asynchronous operation that runs on
2204 // another thread.
2205 save_package_ = new SavePackage(this);
2206 save_package_->GetSaveInfo();
2207}
2208
2209// Used in automated testing to bypass prompting the user for file names.
2210// Instead, the names and paths are hard coded rather than running them through
2211// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342212bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2213 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212214 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592215 // Stop the page from navigating.
2216 Stop();
2217
2218 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212219 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592220}
2221
[email protected]3c71576ce2013-07-23 02:00:012222void WebContentsImpl::SaveFrame(const GURL& url,
2223 const Referrer& referrer) {
2224 if (!GetURL().is_valid())
2225 return;
sammc92af61552014-11-19 23:27:402226 if (delegate_ && delegate_->SaveFrame(url, referrer))
2227 return;
2228
[email protected]3c71576ce2013-07-23 02:00:012229 bool is_main_frame = (url == GetURL());
2230
2231 DownloadManager* dlm =
2232 BrowserContext::GetDownloadManager(GetBrowserContext());
2233 if (!dlm)
2234 return;
2235 int64 post_id = -1;
2236 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272237 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012238 if (entry)
2239 post_id = entry->GetPostID();
2240 }
2241 scoped_ptr<DownloadUrlParameters> params(
2242 DownloadUrlParameters::FromWebContents(this, url));
2243 params->set_referrer(referrer);
2244 params->set_post_id(post_id);
2245 params->set_prefer_cache(true);
2246 if (post_id >= 0)
2247 params->set_method("POST");
2248 params->set_prompt(true);
2249 dlm->DownloadUrl(params.Pass());
2250}
2251
[email protected]b172aee2012-04-10 17:05:262252void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342253 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482254 const base::Callback<void(int64)>& callback) {
2255 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122256}
2257
[email protected]b172aee2012-04-10 17:05:262258const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272259 return contents_mime_type_;
2260}
2261
[email protected]b172aee2012-04-10 17:05:262262bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272263 return notify_disconnection_;
2264}
2265
[email protected]b172aee2012-04-10 17:05:262266void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312267 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182268 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162269}
2270
[email protected]b172aee2012-04-10 17:05:262271void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542272 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182273 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162274}
2275
[email protected]8ff00d72012-10-23 19:12:212276RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272277 return &renderer_preferences_;
2278}
2279
[email protected]e35ccd52012-05-23 16:22:472280void WebContentsImpl::Close() {
2281 Close(GetRenderViewHost());
2282}
2283
[email protected]cf200a562013-05-03 16:24:292284void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462285 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292286 if (browser_plugin_embedder_.get())
2287 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2288 screen_x, screen_y, operation);
2289 if (GetRenderViewHost())
2290 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2291 screen_x, screen_y, operation);
2292}
2293
[email protected]d60f3702013-12-26 16:30:242294void WebContentsImpl::DidGetResourceResponseStart(
2295 const ResourceRequestDetails& details) {
2296 controller_.ssl_manager()->DidStartResourceResponse(details);
2297
2298 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2299 DidGetResourceResponseStart(details));
2300
2301 // TODO(avi): Remove. http://crbug.com/170921
2302 NotificationService::current()->Notify(
2303 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2304 Source<WebContents>(this),
2305 Details<const ResourceRequestDetails>(&details));
2306}
2307
2308void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462309 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242310 const ResourceRedirectDetails& details) {
2311 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2312
2313 FOR_EACH_OBSERVER(
2314 WebContentsObserver,
2315 observers_,
creis114ca1b2014-11-13 23:51:462316 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242317
2318 // TODO(avi): Remove. http://crbug.com/170921
2319 NotificationService::current()->Notify(
2320 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2321 Source<WebContents>(this),
2322 Details<const ResourceRedirectDetails>(&details));
2323}
2324
[email protected]b172aee2012-04-10 17:05:262325void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522326 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582327 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512328 if (delegate_)
2329 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292330 if (browser_plugin_embedder_.get())
2331 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342332}
2333
[email protected]e35ccd52012-05-23 16:22:472334void WebContentsImpl::UserGestureDone() {
2335 OnUserGesture();
2336}
2337
[email protected]b172aee2012-04-10 17:05:262338void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272339 closed_by_user_gesture_ = value;
2340}
2341
[email protected]b172aee2012-04-10 17:05:262342bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272343 return closed_by_user_gesture_;
2344}
2345
[email protected]b172aee2012-04-10 17:05:262346void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502347 if (!delegate_)
2348 return;
2349
[email protected]6286a372013-10-09 04:03:272350 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2351 if (!entry)
[email protected]1788e772010-12-15 16:40:502352 return;
2353
[email protected]6286a372013-10-09 04:03:272354 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122355}
2356
[email protected]b172aee2012-04-10 17:05:262357void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042358 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272359 if (!delegate_)
2360 return;
2361
[email protected]691aa2f2013-05-28 22:52:042362 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272363}
2364
[email protected]b172aee2012-04-10 17:05:262365int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272366 return minimum_zoom_percent_;
2367}
2368
[email protected]b172aee2012-04-10 17:05:262369int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272370 return maximum_zoom_percent_;
2371}
2372
[email protected]b172aee2012-04-10 17:05:262373gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492374 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232375}
2376
[email protected]b172aee2012-04-10 17:05:262377bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052378 if (GetBrowserPluginGuest())
2379 return GetBrowserPluginGuest()->LockMouse(allowed);
2380
[email protected]0bfbf882011-12-22 18:19:272381 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582382 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272383}
2384
[email protected]b172aee2012-04-10 17:05:262385bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442386 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502387}
2388
jochen55ff3502014-12-18 20:52:572389WebContents* WebContentsImpl::GetOpener() const {
2390 return static_cast<WebContents*>(opener_);
2391}
2392
[email protected]cb805452013-05-22 15:16:212393void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482394 if (!color_chooser_info_.get())
2395 return;
2396 RenderFrameHost* rfh = RenderFrameHost::FromID(
2397 color_chooser_info_->render_process_id,
2398 color_chooser_info_->render_frame_id);
2399 if (!rfh)
2400 return;
2401
2402 rfh->Send(new FrameMsg_DidChooseColorResponse(
2403 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202404}
2405
[email protected]cb805452013-05-22 15:16:212406void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482407 if (!color_chooser_info_.get())
2408 return;
2409 RenderFrameHost* rfh = RenderFrameHost::FromID(
2410 color_chooser_info_->render_process_id,
2411 color_chooser_info_->render_frame_id);
2412 if (!rfh)
2413 return;
2414
2415 rfh->Send(new FrameMsg_DidEndColorChooser(
2416 rfh->GetRoutingID(), color_chooser_info_->identifier));
2417 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202418}
2419
[email protected]41225fe2013-03-29 05:32:022420int WebContentsImpl::DownloadImage(const GURL& url,
2421 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302422 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022423 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582424 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022425 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392426 return id;
2427}
2428
[email protected]5dcaf8e2013-12-28 01:31:422429bool WebContentsImpl::IsSubframe() const {
2430 return is_subframe_;
2431}
2432
[email protected]36ec24f2014-01-09 00:32:082433void WebContentsImpl::Find(int request_id,
2434 const base::string16& search_text,
2435 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092436 // See if a top level browser plugin handles the find request first.
2437 if (browser_plugin_embedder_ &&
2438 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2439 return;
2440 }
[email protected]36ec24f2014-01-09 00:32:082441 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2442}
2443
2444void WebContentsImpl::StopFinding(StopFindAction action) {
2445 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2446}
2447
[email protected]4fe53add2014-04-08 19:53:362448void WebContentsImpl::InsertCSS(const std::string& css) {
2449 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2450 GetMainFrame()->GetRoutingID(), css));
2451}
2452
dalecurtisbc6572e12014-09-12 19:22:302453bool WebContentsImpl::WasRecentlyAudible() {
2454 return audio_stream_monitor_.WasRecentlyAudible();
2455}
2456
mlamouriefdca9d2014-09-16 16:55:402457void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2458 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2459}
2460
[email protected]b172aee2012-04-10 17:05:262461bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272462 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172463 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332464 return true;
2465 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272466}
2467
[email protected]b172aee2012-04-10 17:05:262468void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272469 if (delegate_)
2470 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212471}
2472
[email protected]52913802013-12-10 05:52:182473void WebContentsImpl::DidStartProvisionalLoad(
2474 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182475 const GURL& validated_url,
2476 bool is_error_page,
2477 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102478 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482479 FOR_EACH_OBSERVER(
2480 WebContentsObserver,
2481 observers_,
2482 DidStartProvisionalLoadForFrame(
2483 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
[email protected]400992b2012-06-14 00:03:542484}
2485
[email protected]0c3c54f2014-07-31 01:29:002486void WebContentsImpl::DidStartNavigationTransition(
morritaffb82612014-10-31 18:26:592487 RenderFrameHostImpl* render_frame_host) {
[email protected]0c3c54f2014-07-31 01:29:002488#if defined(OS_ANDROID)
2489 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562490 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
morritaffb82612014-10-31 18:26:592491 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002492#endif
2493}
2494
[email protected]3109fbb72014-01-06 23:57:152495void WebContentsImpl::DidFailProvisionalLoadWithError(
2496 RenderFrameHostImpl* render_frame_host,
2497 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2498 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312499 FOR_EACH_OBSERVER(WebContentsObserver,
2500 observers_,
2501 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312502 validated_url,
2503 params.error_code,
2504 params.error_description));
[email protected]3109fbb72014-01-06 23:57:152505}
2506
[email protected]b80624c2014-02-09 02:46:552507void WebContentsImpl::DidFailLoadWithError(
2508 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552509 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552510 int error_code,
2511 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142512 FOR_EACH_OBSERVER(
2513 WebContentsObserver,
2514 observers_,
2515 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552516}
2517
[email protected]52913802013-12-10 05:52:182518void WebContentsImpl::NotifyChangedNavigationState(
2519 InvalidateTypes changed_flags) {
2520 NotifyNavigationStateChanged(changed_flags);
2521}
2522
[email protected]3691e5cf2014-01-22 10:16:202523void WebContentsImpl::AboutToNavigateRenderFrame(
2524 RenderFrameHostImpl* render_frame_host) {
creis114ca1b2014-11-13 23:51:462525 // Notify observers that we will navigate in this RenderFrame.
[email protected]3691e5cf2014-01-22 10:16:202526 FOR_EACH_OBSERVER(
2527 WebContentsObserver,
2528 observers_,
creis114ca1b2014-11-13 23:51:462529 AboutToNavigateRenderFrame(render_frame_host));
[email protected]3691e5cf2014-01-22 10:16:202530}
2531
2532void WebContentsImpl::DidStartNavigationToPendingEntry(
2533 RenderFrameHostImpl* render_frame_host,
2534 const GURL& url,
2535 NavigationController::ReloadType reload_type) {
2536 // Notify observers about navigation.
2537 FOR_EACH_OBSERVER(
2538 WebContentsObserver,
2539 observers_,
2540 DidStartNavigationToPendingEntry(url, reload_type));
2541}
2542
[email protected]8cb834e2014-03-06 14:23:232543void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2544 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:502545 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
2546 // weak pointer of sorts.
2547 const int32_t process_id = render_frame_host->GetProcess()->GetID();
2548 const int32_t frame_id = render_frame_host->GetRoutingID();
2549
[email protected]65920f332014-03-04 21:14:182550 WebContents* new_contents = OpenURL(params);
2551
dchengb907f7332015-01-07 20:35:502552 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:182553 // Notify observers.
2554 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2555 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:462556 render_frame_host,
[email protected]65920f332014-03-04 21:14:182557 params.url,
2558 params.referrer,
2559 params.disposition,
creis114ca1b2014-11-13 23:51:462560 params.transition));
[email protected]65920f332014-03-04 21:14:182561 }
2562}
2563
[email protected]aa62afd2014-04-22 19:22:462564bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2565 if (!delegate_)
2566 return false;
2567 return delegate_->ShouldPreserveAbortedURLs(this);
2568}
2569
[email protected]37567b432014-02-12 01:12:222570void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432571 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222572 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352573 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222574 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482575 FOR_EACH_OBSERVER(WebContentsObserver,
2576 observers_,
2577 DidCommitProvisionalLoadForFrame(
2578 render_frame_host, url, transition_type));
[email protected]37567b432014-02-12 01:12:222579}
2580
[email protected]0d0f4c492014-04-02 06:42:572581void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232582 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572583 // Ensure fullscreen mode is exited before committing the navigation to a
2584 // different page. The next page will not start out assuming it is in
2585 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232586 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192587 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572588 return;
2589 }
2590 if (IsFullscreenForCurrentTab())
2591 GetRenderViewHost()->ExitFullscreen();
2592 DCHECK(!IsFullscreenForCurrentTab());
2593}
2594
[email protected]37567b432014-02-12 01:12:222595void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:282596 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222597 const LoadCommittedDetails& details,
2598 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2599 if (details.is_navigation_to_different_page()) {
2600 // Clear the status bubble. This is a workaround for a bug where WebKit
2601 // doesn't let us know that the cursor left an element during a
2602 // transition (this is also why the mouse cursor remains as a hand after
2603 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2604 // clear the bubble when a user navigates to a named anchor in the same
2605 // page.
sky8b00392d2015-01-10 00:30:282606 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
[email protected]37567b432014-02-12 01:12:222607 }
2608
2609 if (!details.is_in_page) {
2610 // Once the main frame is navigated, we're no longer considered to have
2611 // displayed insecure content.
2612 displayed_insecure_content_ = false;
2613 SSLManager::NotifySSLInternalStateChanged(
2614 GetController().GetBrowserContext());
2615 }
2616
2617 // Notify observers about navigation.
2618 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2619 DidNavigateMainFrame(details, params));
2620
[email protected]e85165c642014-06-10 14:34:312621 if (delegate_)
[email protected]37567b432014-02-12 01:12:222622 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312623 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222624}
2625
2626void WebContentsImpl::DidNavigateAnyFramePostCommit(
2627 RenderFrameHostImpl* render_frame_host,
2628 const LoadCommittedDetails& details,
2629 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102630 // Now that something has committed, we don't need to track whether the
2631 // initial page has been accessed.
2632 has_accessed_initial_document_ = false;
2633
[email protected]37567b432014-02-12 01:12:222634 // If we navigate off the page, close all JavaScript dialogs.
2635 if (dialog_manager_ && !details.is_in_page)
2636 dialog_manager_->CancelActiveAndPendingDialogs(this);
2637
2638 // Notify observers about navigation.
2639 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:092640 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:222641}
2642
2643void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2644 contents_mime_type_ = mime_type;
2645}
2646
[email protected]277857a2014-06-03 10:38:012647bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312648 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052649 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312650 return false;
2651
[email protected]37567b432014-02-12 01:12:222652 if (delegate_)
2653 return delegate_->CanOverscrollContent();
2654
2655 return false;
2656}
2657
[email protected]37b64c52014-07-11 21:14:052658void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252659 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052660 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252661}
2662
[email protected]b172aee2012-04-10 17:05:262663void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182664 const GURL& url,
[email protected]70435962011-08-02 20:13:282665 const std::string& security_info,
2666 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182667 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402668 ResourceType resource_type) {
[email protected]28620862011-03-22 23:07:192669 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182670 cache.Increment();
2671
2672 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082673 int cert_id = 0;
2674 net::CertStatus cert_status = 0;
2675 int security_bits = -1;
2676 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122677 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212678 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122679 &security_bits, &connection_status,
2680 &signed_certificate_timestamp_ids);
2681 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212682 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002683 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2684 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182685
[email protected]b0f724c2013-09-05 04:21:132686 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2687
2688 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2689 DidLoadResourceFromMemoryCache(details));
2690
[email protected]8bfc8272013-09-09 20:10:532691 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2692 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402693 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532694 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2695 GetRenderProcessHost()->GetID()) :
2696 GetBrowserContext()->GetRequestContextForRenderProcess(
2697 GetRenderProcessHost()->GetID()));
2698 BrowserThread::PostTask(
2699 BrowserThread::IO,
2700 FROM_HERE,
2701 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2702 }
[email protected]724159a2010-12-30 01:11:182703}
2704
[email protected]b172aee2012-04-10 17:05:262705void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392706 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182707 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192708 SSLManager::NotifySSLInternalStateChanged(
2709 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182710}
2711
[email protected]b172aee2012-04-10 17:05:262712void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022713 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582714 LOG(WARNING) << security_origin << " ran insecure content from "
2715 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392716 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412717 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392718 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182719 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412720 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192721 SSLManager::NotifySSLInternalStateChanged(
2722 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182723}
2724
[email protected]501052ff2014-02-21 22:19:072725void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572726 CHECK(render_frame_message_source_);
2727 CHECK(!render_view_message_source_);
2728 RenderFrameHostImpl* rfh =
2729 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142730 FOR_EACH_OBSERVER(
2731 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182732}
2733
[email protected]b172aee2012-04-10 17:05:262734void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262735 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372736 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122737 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2738 GetRenderProcessHost()->ReceivedBadMessage();
2739 return;
2740 }
[email protected]a1b99262013-12-27 21:56:222741
[email protected]8b3af1e2014-01-24 13:29:122742 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442743 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372744 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422745 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372746
[email protected]61ac9e242014-03-21 20:55:262747 RenderFrameHostImpl* rfh =
2748 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142749 FOR_EACH_OBSERVER(
2750 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312751}
2752
[email protected]960b0372014-05-19 18:01:002753void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2754 RenderFrameHostImpl* rfh =
2755 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2756 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2757
creis1163acf2014-12-19 21:18:472758 // Any main frame load to a new document should reset the load progress, since
2759 // it will replace the current page and any frames.
2760 if (to_different_document && !rfh->GetParent()) {
2761 ResetLoadProgressState();
2762 loading_frames_in_progress_ = 0;
2763 }
2764
[email protected]960b0372014-05-19 18:01:002765 // It is possible to get multiple calls to OnDidStartLoading that don't have
2766 // corresponding calls to OnDidStopLoading:
2767 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2768 // out for a cross-process navigation, and it turns into a placeholder for
2769 // one being rendered in a different process.
2770 // - Also, there might be more than one RenderFrameHost sharing the same
2771 // FrameTreeNode (and thus sharing its ID) each sending a start.
2772 // - But in the future, once clamy@ moves navigation network requests to the
2773 // browser process, there's a good chance that callbacks about starting and
2774 // stopping will all be handled by the browser. When that happens, there
2775 // should no longer be a start/stop call imbalance. TODO(avi): When this
2776 // future arrives, update this code to not allow this case.
2777 DCHECK_GE(loading_frames_in_progress_, 0);
2778 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2779 if (loading_frames_in_progress_ == 0)
2780 DidStartLoading(rfh, to_different_document);
2781 ++loading_frames_in_progress_;
2782 }
2783
nasko3e8c20e2014-12-18 06:54:562784 // Notify the RenderFrameHostManager of the event.
2785 rfh->frame_tree_node()->render_manager()->OnDidStartLoading();
2786
[email protected]960b0372014-05-19 18:01:002787 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2788 SendLoadProgressChanged();
2789}
2790
2791void WebContentsImpl::OnDidStopLoading() {
2792 RenderFrameHostImpl* rfh =
2793 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2794 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2795
2796 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2797 // Load stopped while we were still tracking load. Make sure we update
2798 // progress based on this frame's completion.
2799 loading_progresses_[render_frame_id] = 1.0;
2800 SendLoadProgressChanged();
2801 // Then we clean-up our states.
2802 if (loading_total_progress_ == 1.0)
2803 ResetLoadProgressState();
2804 }
2805
nasko3e8c20e2014-12-18 06:54:562806 // Notify the RenderFrameHostManager of the event.
2807 rfh->frame_tree_node()->render_manager()->OnDidStopLoading();
2808
[email protected]960b0372014-05-19 18:01:002809 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2810 // calls DidStopLoading() without a matching DidStartLoading().
2811 if (loading_frames_in_progress_ == 0)
2812 return;
2813 --loading_frames_in_progress_;
2814 if (loading_frames_in_progress_ == 0)
2815 DidStopLoading(rfh);
2816}
2817
2818void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2819 RenderFrameHostImpl* rfh =
2820 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2821 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2822
2823 loading_progresses_[render_frame_id] = load_progress;
2824
2825 // We notify progress change immediately for the first and last updates.
2826 // Also, since the message loop may be pretty busy when a page is loaded, it
2827 // might not execute a posted task in a timely manner so we make sure to
2828 // immediately send progress report if enough time has passed.
2829 base::TimeDelta min_delay =
2830 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2831 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2832 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2833 // If there is a pending task to send progress, it is now obsolete.
2834 loading_weak_factory_.InvalidateWeakPtrs();
2835 SendLoadProgressChanged();
2836 if (loading_total_progress_ == 1.0)
2837 ResetLoadProgressState();
2838 return;
2839 }
2840
2841 if (loading_weak_factory_.HasWeakPtrs())
2842 return;
2843
2844 base::MessageLoop::current()->PostDelayedTask(
2845 FROM_HERE,
2846 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2847 loading_weak_factory_.GetWeakPtr()),
2848 min_delay);
2849}
2850
[email protected]b172aee2012-04-10 17:05:262851void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222852 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2853 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262854}
2855
[email protected]b172aee2012-04-10 17:05:262856void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302857 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262858 minimum_zoom_percent_ = minimum_percent;
2859 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262860}
2861
[email protected]b172aee2012-04-10 17:05:262862void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342863 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432864 if (!delegate_)
2865 return;
2866
[email protected]b9535422012-02-09 01:47:592867 ChildProcessSecurityPolicyImpl* policy =
2868 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222869 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592870 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212871}
2872
[email protected]b172aee2012-04-10 17:05:262873void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2874 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262875 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362876 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432877 if (!delegate_)
2878 return;
2879
[email protected]b9535422012-02-09 01:47:592880 ChildProcessSecurityPolicyImpl* policy =
2881 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322882 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592883 return;
[email protected]8f810632013-06-06 22:33:322884
[email protected]c125e532014-05-10 20:39:062885 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202886}
2887
[email protected]f5273e52014-07-14 16:30:202888void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2889 const GURL& url,
2890 bool user_gesture) {
2891 if (!delegate_)
2892 return;
2893
2894 ChildProcessSecurityPolicyImpl* policy =
2895 ChildProcessSecurityPolicyImpl::GetInstance();
2896 if (policy->IsPseudoScheme(protocol))
2897 return;
2898
2899 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2900}
2901
[email protected]b172aee2012-04-10 17:05:262902void WebContentsImpl::OnFindReply(int request_id,
2903 int number_of_matches,
2904 const gfx::Rect& selection_rect,
2905 int active_match_ordinal,
2906 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432907 if (delegate_) {
2908 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2909 active_match_ordinal, final_update);
2910 }
[email protected]b888919c2011-09-02 00:32:162911}
2912
[email protected]59363fc92012-09-05 03:46:312913#if defined(OS_ANDROID)
2914void WebContentsImpl::OnFindMatchRectsReply(
2915 int version,
2916 const std::vector<gfx::RectF>& rects,
2917 const gfx::RectF& active_rect) {
2918 if (delegate_)
2919 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2920}
[email protected]583418cc2013-01-17 14:01:102921
[email protected]1ff427972013-02-07 21:14:072922void WebContentsImpl::OnOpenDateTimeDialog(
2923 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:172924 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:092925 GetRenderViewHost(),
2926 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132927 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092928 value.minimum,
2929 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172930 value.step,
2931 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102932}
[email protected]59363fc92012-09-05 03:46:312933#endif
2934
[email protected]cfa856d62014-02-22 07:58:402935void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2936 int automation_id) {
2937 DomOperationNotificationDetails details(json_string, automation_id);
2938 NotificationService::current()->Notify(
2939 NOTIFICATION_DOM_OPERATION_RESPONSE,
2940 Source<WebContents>(this),
2941 Details<DomOperationNotificationDetails>(&details));
2942}
2943
[email protected]b172aee2012-04-10 17:05:262944void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2945 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102946 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252947 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102948 AppCacheAccessed(manifest_url, blocked_by_policy));
2949}
2950
[email protected]8bc5ff02013-11-29 06:34:032951void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482952 int color_chooser_id,
2953 SkColor color,
2954 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462955 ColorChooser* new_color_chooser = delegate_ ?
2956 delegate_->OpenColorChooser(this, color, suggestions) :
2957 NULL;
[email protected]820957a2014-01-14 14:56:302958 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212959 return;
[email protected]8ed16472014-04-11 19:02:482960 if (color_chooser_info_.get())
2961 color_chooser_info_->chooser->End();
2962
2963 color_chooser_info_.reset(new ColorChooserInfo(
2964 render_frame_message_source_->GetProcess()->GetID(),
2965 render_frame_message_source_->GetRoutingID(),
2966 new_color_chooser,
2967 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202968}
2969
[email protected]b172aee2012-04-10 17:05:262970void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482971 if (color_chooser_info_ &&
2972 color_chooser_id == color_chooser_info_->identifier)
2973 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202974}
2975
[email protected]b172aee2012-04-10 17:05:262976void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322977 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482978 if (color_chooser_info_ &&
2979 color_chooser_id == color_chooser_info_->identifier)
2980 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202981}
2982
[email protected]d0759f492012-04-19 22:50:502983// This exists for render views that don't have a WebUI, but do have WebUI
2984// bindings enabled.
2985void WebContentsImpl::OnWebUISend(const GURL& source_url,
2986 const std::string& name,
2987 const base::ListValue& args) {
2988 if (delegate_)
2989 delegate_->WebUISend(this, source_url, name, args);
2990}
2991
thestigc4cac8f2014-09-04 21:17:502992#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:422993void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2994 const base::FilePath& path,
2995 bool is_hung) {
2996 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2997
2998 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2999 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3000}
3001
3002void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3003 base::ProcessId plugin_pid) {
3004 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3005 PluginCrashed(plugin_path, plugin_pid));
3006}
3007
[email protected]d8415ad92012-08-23 14:40:503008void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443009 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503010 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343011 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163012 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443013 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163014 return;
[email protected]d8415ad92012-08-23 14:40:503015 }
3016
[email protected]8c8fc292012-11-23 18:57:163017 if (!delegate_->RequestPpapiBrokerPermission(
3018 this, url, plugin_path,
3019 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443020 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163021 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443022 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163023 }
[email protected]d8415ad92012-08-23 14:40:503024}
3025
[email protected]ea0309c2013-08-06 19:35:443026void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503027 bool result) {
[email protected]ea0309c2013-08-06 19:35:443028 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503029}
3030
[email protected]c4538072013-03-18 02:17:553031void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:373032 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:083033 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:553034 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:393035 // For more info, see comment above classes BrowserPluginEmbedder and
3036 // BrowserPluginGuest.
3037 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:143038 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:083039 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:373040}
tommyclie6633ca72014-10-31 00:40:423041#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373042
[email protected]41225fe2013-03-29 05:32:023043void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393044 int id,
[email protected]749fadd2013-05-15 08:37:483045 int http_status_code,
[email protected]795c28972012-12-06 06:13:393046 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303047 const std::vector<SkBitmap>& bitmaps,
3048 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133049 if (bitmaps.size() != original_bitmap_sizes.size())
3050 return;
3051
[email protected]41225fe2013-03-29 05:32:023052 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3053 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393054 // Currently WebContents notifies us of ANY downloads so that it is
3055 // possible to get here.
3056 return;
3057 }
3058 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303059 iter->second.Run(
3060 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393061 }
[email protected]41225fe2013-03-29 05:32:023062 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393063}
3064
3065void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393066 const std::vector<FaviconURL>& candidates) {
3067 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293068 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393069}
3070
dalecurtisbc6572e12014-09-12 19:22:303071void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3072 // ChromeOS has its own way of handling power save blocks for media.
3073#if !defined(OS_CHROMEOS)
3074 DCHECK(!audio_power_save_blocker_);
3075 audio_power_save_blocker_ = PowerSaveBlocker::Create(
3076 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing Audio");
3077#endif
3078}
3079
3080void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3081 // ChromeOS has its own way of handling power save blocks for media.
3082#if !defined(OS_CHROMEOS)
3083 DCHECK(!video_power_save_blocker_);
3084 DCHECK(!active_video_players_.empty());
3085 video_power_save_blocker_ = PowerSaveBlocker::Create(
3086 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing Video");
3087#if defined(OS_ANDROID)
3088 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3089 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3090#endif
3091#endif
3092}
3093
3094void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3095 // If there are no more audio players and we don't have audio stream
3096 // monitoring, release the audio power save blocker here instead of during
3097 // NotifyNavigationStateChanged().
3098 if (active_audio_players_.empty() &&
3099 !AudioStreamMonitor::monitoring_available()) {
3100 audio_power_save_blocker_.reset();
3101 }
3102
3103 // If there are no more video players, clear the video power save blocker.
3104 if (active_video_players_.empty())
3105 video_power_save_blocker_.reset();
3106}
3107
[email protected]1dd0bb752014-02-01 01:16:263108void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3109 bool has_video,
avayvod68017be2014-10-10 18:02:433110 bool has_audio,
3111 bool is_remote) {
3112 // Ignore the videos playing remotely and don't hold the wake lock for the
3113 // screen.
3114 if (is_remote) return;
3115
dalecurtisbc6572e12014-09-12 19:22:303116 if (has_audio) {
3117 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3118
3119 // If we don't have audio stream monitoring, allocate the audio power save
3120 // blocker here instead of during NotifyNavigationStateChanged().
3121 if (!audio_power_save_blocker_ &&
3122 !AudioStreamMonitor::monitoring_available()) {
3123 CreateAudioPowerSaveBlocker();
3124 }
[email protected]1dd0bb752014-02-01 01:16:263125 }
loislo0381a742014-09-11 10:58:113126
dalecurtisbc6572e12014-09-12 19:22:303127 if (has_video) {
3128 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3129
3130 // If we're not hidden and have just created a player, create a blocker.
3131 if (!video_power_save_blocker_ && !IsHidden())
3132 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113133 }
[email protected]1dd0bb752014-02-01 01:16:263134}
3135
3136void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303137 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3138 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3139 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063140}
3141
[email protected]50279492014-05-05 23:24:293142void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153143 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293144 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153145}
[email protected]d9030b82013-07-19 08:26:063146
[email protected]e67ebf32013-02-13 11:07:193147void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073148 if (delegate_)
3149 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193150}
3151
[email protected]17e286e2013-03-01 23:29:393152void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3153 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3154 BeforeFormRepostWarningShow());
3155}
3156
[email protected]ec6c05f2013-10-23 18:41:573157void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3158 Activate();
3159 if (delegate_)
3160 delegate_->ShowRepostFormWarningDialog(this);
3161}
3162
[email protected]b4c84012014-04-28 19:51:103163bool WebContentsImpl::HasAccessedInitialDocument() {
3164 return has_accessed_initial_document_;
3165}
3166
[email protected]96d185d2009-04-24 03:28:543167// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593168// loading, or done loading.
3169void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3170 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093171 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263172 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543173 if (is_loading == is_loading_)
3174 return;
3175
3176 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263177 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3178 base::string16());
[email protected]96d185d2009-04-24 03:28:543179 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563180 upload_size_ = 0;
3181 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543182 }
3183
[email protected]fa944cb82013-11-15 17:51:213184 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543185
3186 is_loading_ = is_loading;
3187 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033188 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543189
[email protected]6ebdc9b2010-09-27 16:55:573190 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093191 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213192 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543193
[email protected]eab61442013-11-14 18:35:483194 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593195 if (is_loading) {
naskob8744d22014-08-28 17:07:433196 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3197 this, "URL", url);
[email protected]91621872013-10-08 04:04:593198 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3199 DidStartLoading(render_view_host));
3200 } else {
naskob8744d22014-08-28 17:07:433201 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3202 this, "URL", url);
[email protected]91621872013-10-08 04:04:593203 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3204 DidStopLoading(render_view_host));
3205 }
[email protected]66798902013-10-01 18:40:163206
3207 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213208 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3209 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543210 if (details)
[email protected]8ff00d72012-10-23 19:12:213211 det = Details<LoadNotificationDetails>(details);
3212 NotificationService::current()->Notify(
3213 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543214}
3215
christiankaeed9862014-11-05 10:49:143216void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
3217 RenderFrameHost* focused_frame = GetFocusedFrame();
3218 if (!focused_frame)
3219 return;
3220
3221 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
3222 focused_frame->GetRoutingID(), extent));
3223}
3224
3225void WebContentsImpl::SelectRange(const gfx::Point& base,
3226 const gfx::Point& extent) {
[email protected]959be4c2014-04-08 15:01:333227 RenderFrameHost* focused_frame = GetFocusedFrame();
3228 if (!focused_frame)
3229 return;
3230
3231 focused_frame->Send(
christiankaeed9862014-11-05 10:49:143232 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
[email protected]959be4c2014-04-08 15:01:333233}
3234
[email protected]b172aee2012-04-10 17:05:263235void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463236 // If we are creating a RVH for a restored controller, then we need to make
3237 // sure the RenderView starts with a next_page_id_ larger than the number
3238 // of restored entries. This must be called before the RenderView starts
3239 // navigating (to avoid a race between the browser updating max_page_id and
3240 // the renderer updating next_page_id_). Because of this, we only call this
3241 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563242 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583243 if (max_restored_page_id >
3244 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3245 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3246 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323247}
3248
[email protected]b172aee2012-04-10 17:05:263249bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263250 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323251 // For file URLs without a title, use the pathname instead. In the case of a
3252 // synthesized title, we don't want the update to count toward the "one set
3253 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263254 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323255 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513256 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243257 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323258 explicit_set = false; // Don't count synthetic titles toward the set limit.
3259 } else {
[email protected]8af69c6c2014-03-03 19:05:313260 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323261 explicit_set = true;
3262 }
3263
[email protected]987fc3a2011-05-26 14:18:093264 // If a page is created via window.open and never navigated,
3265 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553266 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093267 if (entry) {
[email protected]36fc0392011-12-25 03:59:513268 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093269 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323270
[email protected]36fc0392011-12-25 03:59:513271 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093272 } else {
3273 if (page_title_when_no_navigation_entry_ == final_title)
3274 return false; // Nothing changed, don't bother.
3275
3276 page_title_when_no_navigation_entry_ = final_title;
3277 }
[email protected]420ae012009-04-24 05:16:323278
[email protected]420ae012009-04-24 05:16:323279 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233280 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323281
[email protected]66798902013-10-01 18:40:163282 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533283 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163284
3285 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213286 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463287 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213288 NotificationService::current()->Notify(
3289 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3290 Source<WebContents>(this),
3291 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043292
[email protected]420ae012009-04-24 05:16:323293 return true;
3294}
3295
[email protected]960b0372014-05-19 18:01:003296void WebContentsImpl::SendLoadProgressChanged() {
3297 loading_last_progress_update_ = base::TimeTicks::Now();
3298 double progress = 0.0;
3299 int frame_count = 0;
3300
3301 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3302 it != loading_progresses_.end();
3303 ++it) {
3304 progress += it->second;
3305 ++frame_count;
3306 }
3307 if (frame_count == 0)
3308 return;
3309 progress /= frame_count;
3310 DCHECK(progress <= 1.0);
3311
3312 if (progress <= loading_total_progress_)
3313 return;
3314 loading_total_progress_ = progress;
3315
3316 if (delegate_)
3317 delegate_->LoadProgressChanged(this, progress);
3318}
3319
3320void WebContentsImpl::ResetLoadProgressState() {
3321 loading_progresses_.clear();
3322 loading_total_progress_ = 0.0;
3323 loading_weak_factory_.InvalidateWeakPtrs();
3324 loading_last_progress_update_ = base::TimeTicks();
3325}
3326
[email protected]02d7b6e2014-06-24 21:01:503327void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3328 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323329 // After sending out a swap notification, we need to send a disconnect
3330 // notification so that clients that pick up a pointer to |this| can NULL the
3331 // pointer. See Bug 1230284.
3332 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113333 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283334 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113335
3336 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283337 std::pair<RenderViewHost*, RenderViewHost*> details =
3338 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213339 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283340 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213341 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283342 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393343
3344 // Ensure that the associated embedder gets cleared after a RenderViewHost
3345 // gets swapped, so we don't reuse the same embedder next time a
3346 // RenderViewHost is attached to this WebContents.
3347 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323348}
3349
[email protected]02d7b6e2014-06-24 21:01:503350void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3351 RenderFrameHost* new_host) {
3352 FOR_EACH_OBSERVER(WebContentsObserver,
3353 observers_,
3354 RenderFrameHostChanged(old_host, new_host));
3355}
3356
[email protected]da7a7182013-09-06 08:11:113357// TODO(avi): Remove this entire function because this notification is already
3358// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263359void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323360 if (!notify_disconnection_)
3361 return;
3362
3363 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213364 NotificationService::current()->Notify(
3365 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3366 Source<WebContents>(this),
3367 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323368}
3369
[email protected]cbb1ef592013-06-05 19:49:463370void WebContentsImpl::NotifyNavigationEntryCommitted(
3371 const LoadCommittedDetails& load_details) {
3372 FOR_EACH_OBSERVER(
3373 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3374}
3375
[email protected]f114fa42013-12-06 17:06:443376bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3377 const IPC::Message& message) {
3378 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313379}
3380
[email protected]c31a84802014-04-03 15:55:493381const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3382 return GetLastCommittedURL();
3383}
3384
[email protected]b849847b2013-12-10 21:57:583385void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3386 // Note this is only for subframes, the notification for the main frame
3387 // happens in RenderViewCreated.
3388 FOR_EACH_OBSERVER(WebContentsObserver,
3389 observers_,
3390 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303391 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583392}
3393
3394void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193395 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583396 FOR_EACH_OBSERVER(WebContentsObserver,
3397 observers_,
3398 RenderFrameDeleted(render_frame_host));
3399}
3400
[email protected]a09d53ce2014-01-31 00:46:423401void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303402 if (delegate_)
3403 delegate_->WorkerCrashed(this);
3404}
3405
[email protected]a09d53ce2014-01-31 00:46:423406void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3407 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103408 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423409 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103410 if (GetBrowserPluginGuest()) {
3411 WebContentsViewGuest* view_guest =
3412 static_cast<WebContentsViewGuest*>(GetView());
3413 context_menu_params = view_guest->ConvertContextMenuParams(params);
3414 }
3415 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423416 return;
3417
[email protected]077e704b2014-05-23 19:24:103418 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3419 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423420}
3421
[email protected]87de04b02014-04-08 22:14:493422void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013423 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493424 const base::string16& message,
3425 const base::string16& default_prompt,
3426 const GURL& frame_url,
3427 JavaScriptMessageType javascript_message_type,
3428 IPC::Message* reply_msg) {
3429 // Suppress JavaScript dialogs when requested. Also suppress messages when
3430 // showing an interstitial as it's shown over the previous page and we don't
3431 // want the hidden page's dialogs to interfere with the interstitial.
3432 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223433 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503434 ShowingInterstitialPage() || !delegate_ ||
3435 delegate_->ShouldSuppressDialogs(this) ||
3436 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493437
3438 if (!suppress_this_message) {
3439 std::string accept_lang = GetContentClient()->browser()->
3440 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503441 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493442 dialog_manager_->RunJavaScriptDialog(
3443 this,
3444 frame_url.GetOrigin(),
3445 accept_lang,
3446 javascript_message_type,
3447 message,
3448 default_prompt,
3449 base::Bind(&WebContentsImpl::OnDialogClosed,
3450 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013451 render_frame_host->GetProcess()->GetID(),
3452 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493453 reply_msg,
3454 false),
3455 &suppress_this_message);
3456 }
3457
3458 if (suppress_this_message) {
3459 // If we are suppressing messages, just reply as if the user immediately
3460 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013461 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3462 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283463 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493464 }
3465
3466 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3467 // http://crbug.com/288961 ). The only safe thing to do here is return.
3468}
3469
3470void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013471 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493472 const base::string16& message,
3473 bool is_reload,
3474 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013475 RenderFrameHostImpl* rfhi =
3476 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493477 if (delegate_)
3478 delegate_->WillRunBeforeUnloadConfirm();
3479
3480 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503481 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT || !delegate_ ||
3482 delegate_->ShouldSuppressDialogs(this) ||
3483 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493484 if (suppress_this_message) {
3485 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3486 return;
3487 }
3488
3489 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503490 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493491 dialog_manager_->RunBeforeUnloadDialog(
3492 this, message, is_reload,
3493 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013494 render_frame_host->GetProcess()->GetID(),
3495 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283496 false));
[email protected]87de04b02014-04-08 22:14:493497}
3498
[email protected]a86c0e962013-12-17 17:10:393499WebContents* WebContentsImpl::GetAsWebContents() {
3500 return this;
3501}
3502
[email protected]7912e822014-04-16 02:37:033503bool WebContentsImpl::IsNeverVisible() {
3504 if (!delegate_)
3505 return false;
3506 return delegate_->IsNeverVisible(this);
3507}
3508
[email protected]95640212014-07-26 18:14:303509#if defined(OS_WIN)
3510gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3511 return accessible_parent_;
3512}
3513#endif
3514
[email protected]5a3bdf52012-05-24 15:12:573515RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3516 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323517}
3518
[email protected]8ff00d72012-10-23 19:12:213519RendererPreferences WebContentsImpl::GetRendererPrefs(
3520 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463521 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513522}
3523
[email protected]b172aee2012-04-10 17:05:263524gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173525 if (delegate_)
3526 return delegate_->GetRootWindowResizerRect();
3527 return gfx::Rect();
3528}
3529
[email protected]7a846df2012-09-20 19:17:393530void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273531 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393532 browser_plugin_embedder_.reset();
3533}
3534
[email protected]b172aee2012-04-10 17:05:263535void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443536 // Don't send notifications if we are just creating a swapped-out RVH for
3537 // the opener chain. These won't be used for view-source or WebUI, so it's
3538 // ok to return early.
creiscce56cd2014-09-29 22:45:223539 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443540 return;
3541
[email protected]86f98a22013-03-20 14:35:003542 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313543 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083544
[email protected]8ff00d72012-10-23 19:12:213545 NotificationService::current()->Notify(
3546 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3547 Source<WebContents>(this),
3548 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323549
3550 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353551 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213552 if (GetRenderManager()->pending_web_ui())
3553 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323554
[email protected]6286a372013-10-09 04:03:273555 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333556 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323557 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183558 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583559 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323560 }
[email protected]0666aef2009-05-13 19:48:083561
[email protected]60780f412013-02-25 16:34:103562 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263563
3564 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253565 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583566
3567 // We tell the observers now instead of when the main RenderFrameHostImpl is
3568 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3569 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363570 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583571 FOR_EACH_OBSERVER(
3572 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303573 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
dgozman24bfc912014-09-29 11:04:183574
3575 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:323576}
3577
[email protected]b172aee2012-04-10 17:05:263578void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523579 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323580 // Don't notify the world, since this came from a renderer in the
3581 // background.
3582 return;
3583 }
3584
[email protected]da7a7182013-09-06 08:11:113585 notify_disconnection_ = true;
3586 // TODO(avi): Remove. http://crbug.com/170921
3587 NotificationService::current()->Notify(
3588 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3589 Source<WebContents>(this),
3590 NotificationService::NoDetails());
3591
[email protected]be1f56ab2011-12-22 06:55:313592 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233593 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303594
3595 // Restore the focus to the tab (otherwise the focus will be on the top
3596 // window).
[email protected]484ae5912010-09-29 19:16:143597 if (was_crashed && !FocusLocationBarByDefault() &&
3598 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063599 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143600 }
[email protected]32ded2212011-11-10 18:51:433601
[email protected]d8c660432011-12-22 20:51:253602 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323603}
3604
[email protected]ec6a7eb2013-04-22 17:34:223605void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3606 base::TerminationStatus status,
3607 int error_code) {
[email protected]151a63d2011-12-20 22:32:523608 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323609 // The pending page's RenderViewHost is gone.
3610 return;
3611 }
3612
[email protected]2fcdcc32014-03-05 02:14:073613 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3614 // renderer may not have made a clean exit.
3615 if (IsFullscreenForCurrentTab())
3616 ToggleFullscreenMode(false);
3617
[email protected]698191dc2014-02-25 01:06:133618 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3619 if (dialog_manager_)
3620 dialog_manager_->CancelActiveAndPendingDialogs(this);
3621
[email protected]f738bdcb2014-07-11 20:40:443622 if (delegate_)
3623 delegate_->HideValidationMessage(this);
3624
[email protected]e3b10d12014-03-28 16:06:093625 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323626 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233627 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453628
[email protected]960b0372014-05-19 18:01:003629 // Reset the loading progress. TODO(avi): What does it mean to have a
3630 // "renderer crash" when there is more than one renderer process serving a
3631 // webpage? Once this function is called at a more granular frame level, we
3632 // probably will need to more granularly reset the state here.
3633 ResetLoadProgressState();
3634 loading_frames_in_progress_ = 0;
3635
[email protected]d8c660432011-12-22 20:51:253636 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273637 observers_,
[email protected]58d5cfe2013-07-10 02:40:523638 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323639}
3640
[email protected]b172aee2012-04-10 17:05:263641void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253642 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063643}
3644
[email protected]b172aee2012-04-10 17:05:263645void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3646 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043647 const PageState& page_state) {
creise1d3e5b2014-12-01 18:21:573648 // Ensure that this state update comes from a RenderViewHost that belongs to
3649 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413650 // TODO(nasko): This should go through RenderFrameHost.
3651 // TODO(creis): We can't update state for cross-process subframes until we
3652 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
creise1d3e5b2014-12-01 18:21:573653 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413654 return;
[email protected]420ae012009-04-24 05:16:323655
3656 // We must be prepared to handle state updates for any page, these occur
3657 // when the user is scrolling and entering form data, as well as when we're
3658 // leaving a page, in which case our state may have already been moved to
3659 // the next page. The navigation controller will look up the appropriate
3660 // NavigationEntry and update it when it is notified via the delegate.
3661
3662 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583663 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323664 if (entry_index < 0)
3665 return;
[email protected]10f417c52011-12-28 21:04:233666 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323667
[email protected]691aa2f2013-05-28 22:52:043668 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323669 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043670 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323671 controller_.NotifyEntryChanged(entry, entry_index);
3672}
3673
sky8b00392d2015-01-10 00:30:283674void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
3675 const GURL& url) {
3676 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
3677 // If we're fullscreen only update the url if it's from the fullscreen
3678 // renderer.
3679 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
3680 if (fs && fs->GetRenderWidgetHost() != render_view_host)
3681 return;
3682 }
[email protected]6934a702011-12-20 00:04:513683 if (delegate_)
avi450ce00e2014-09-24 01:58:523684 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323685}
3686
[email protected]b172aee2012-04-10 17:05:263687void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103688#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293689 // The UI may be in an event-tracking loop, such as between the
3690 // mouse-down and mouse-up in text selection or a button click.
3691 // Defer the close until after tracking is complete, so that we
3692 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293693 // TODO(shess): This could get more fine-grained. For instance,
3694 // closing a tab in another window while selecting text in the
3695 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103696 if (view_->IsEventTracking()) {
3697 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293698 return;
3699 }
[email protected]60780f412013-02-25 16:34:103700#endif
[email protected]07707302009-11-06 00:50:293701
[email protected]420ae012009-04-24 05:16:323702 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523703 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513704 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323705}
3706
[email protected]66bbadaf2014-03-28 16:25:543707void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573708 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3709 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573710}
3711
[email protected]6f2ac772014-07-24 22:22:083712void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253713 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173714#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563715 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173716#endif
3717}
3718
3719bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3720#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563721 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173722#else
3723 return false;
3724#endif
3725}
3726
[email protected]b172aee2012-04-10 17:05:263727void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513728 if (delegate_ && delegate_->IsPopupOrPanel(this))
3729 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323730}
3731
[email protected]e3b10d12014-03-28 16:06:093732void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3733 bool to_different_document) {
3734 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3735 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323736}
3737
[email protected]723971b2014-02-12 11:08:253738void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323739 scoped_ptr<LoadNotificationDetails> details;
3740
[email protected]9595fd82013-04-19 21:28:493741 // Use the last committed entry rather than the active one, in case a
3742 // pending entry has been created.
3743 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203744 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493745
[email protected]420ae012009-04-24 05:16:323746 // An entry may not exist for a stop when loading an initial blank page or
3747 // if an iframe injected by script into a blank page finishes loading.
3748 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203749 base::TimeDelta elapsed =
3750 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323751
3752 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513753 entry->GetVirtualURL(),
3754 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323755 elapsed,
3756 &controller_,
3757 controller_.GetCurrentEntryIndex()));
3758 }
3759
[email protected]e3b10d12014-03-28 16:06:093760 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3761 details.get());
[email protected]420ae012009-04-24 05:16:323762}
3763
[email protected]b172aee2012-04-10 17:05:263764void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163765 controller_.DiscardNonCommittedEntries();
3766
3767 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213768 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163769}
3770
[email protected]59167c22013-06-03 18:07:323771void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103772 has_accessed_initial_document_ = true;
3773
[email protected]d1371bf8e2014-04-19 03:26:243774 // We may have left a failed browser-initiated navigation in the address bar
3775 // to let the user edit it and try again. Clear it now that content might
3776 // show up underneath it.
3777 if (!IsLoading() && controller_.GetPendingEntry())
3778 controller_.DiscardPendingEntry();
3779
[email protected]59167c22013-06-03 18:07:323780 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503781 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323782}
3783
[email protected]3f19f1a2014-05-02 05:23:273784void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473785 // No action is necessary if the opener has already been cleared.
3786 if (!opener_)
3787 return;
3788
3789 // Clear our opener so that future cross-process navigations don't have an
3790 // opener assigned.
3791 RemoveDestructionObserver(opener_);
3792 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273793
3794 // Notify all swapped out RenderViewHosts for this tab. This is important
3795 // in case we go back to them, or if another window in those processes tries
3796 // to access window.opener.
creisbbbeb062014-08-25 18:20:313797 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273798}
3799
[email protected]39f2f9252014-05-03 00:54:013800void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293801 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093802 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293803 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093804
3805 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213806 NotificationService::current()->Notify(
3807 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3808 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293809 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083810}
3811
[email protected]ef3adfc2014-05-11 00:04:543812void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3813 int32 page_id,
3814 const base::string16& title,
3815 base::i18n::TextDirection title_direction) {
3816 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3817
3818 // If we have a title, that's a pretty good indication that we've started
3819 // getting useful data.
3820 SetNotWaitingForResponse();
3821
3822 // Try to find the navigation entry, which might not be the current one.
3823 // For example, it might be from a pending RVH for the pending entry.
3824 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3825 rvh->GetSiteInstance(), page_id);
3826
3827 // We can handle title updates when we don't have an entry in
3828 // UpdateTitleForEntry, but only if the update is from the current RVH.
3829 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3830 if (!entry && rvh != GetRenderViewHost())
3831 return;
3832
3833 // TODO(evan): make use of title_direction.
3834 // http://code.google.com/p/chromium/issues/detail?id=27094
3835 if (!UpdateTitleForEntry(entry, title))
3836 return;
3837
3838 // Broadcast notifications when the UI should be updated.
3839 if (entry == controller_.GetEntryAtOffset(0))
3840 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3841}
3842
3843void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3844 const std::string& encoding) {
3845 SetEncoding(encoding);
3846}
3847
[email protected]39f2f9252014-05-03 00:54:013848void WebContentsImpl::DocumentAvailableInMainFrame(
3849 RenderViewHost* render_view_host) {
3850 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3851 DocumentAvailableInMainFrame());
3852}
[email protected]e1c3a552012-05-04 20:51:323853void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3854 // Tell the active RenderViewHost to run unload handlers and close, as long
3855 // as the request came from a RenderViewHost in the same BrowsingInstance.
3856 // In most cases, we receive this from a swapped out RenderViewHost.
3857 // It is possible to receive it from one that has just been swapped in,
3858 // in which case we might as well deliver the message anyway.
3859 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3860 GetRenderViewHost()->ClosePage();
3861}
3862
[email protected]f546640b2012-05-15 00:03:493863void WebContentsImpl::RouteMessageEvent(
3864 RenderViewHost* rvh,
3865 const ViewMsg_PostMessage_Params& params) {
3866 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363867 // came from a RenderViewHost in the same BrowsingInstance or if this
3868 // WebContents is dedicated to a browser plugin guest.
3869 // Note: This check means that an embedder could theoretically receive a
3870 // postMessage from anyone (not just its own guests). However, this is
3871 // probably not a risk for apps since other pages won't have references
3872 // to App windows.
3873 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3874 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493875 return;
3876
3877 ViewMsg_PostMessage_Params new_params(params);
3878
[email protected]0bc7f3542013-10-21 15:05:533879 if (!params.message_port_ids.empty()) {
3880 MessagePortMessageFilter* message_port_message_filter =
3881 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3882 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093883 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3884 params.message_port_ids,
3885 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533886 }
3887
[email protected]f546640b2012-05-15 00:03:493888 // If there is a source_routing_id, translate it to the routing ID for
3889 // the equivalent swapped out RVH in the target process. If we need
3890 // to create a swapped out RVH for the source tab, we create its opener
3891 // chain as well, since those will also be accessible to the target page.
3892 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3893 // Try to look up the WebContents for the source page.
3894 WebContentsImpl* source_contents = NULL;
3895 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3896 rvh->GetProcess()->GetID(), params.source_routing_id);
3897 if (source_rvh) {
3898 source_contents = static_cast<WebContentsImpl*>(
3899 source_rvh->GetDelegate()->GetAsWebContents());
3900 }
3901
3902 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363903 if (GetBrowserPluginGuest()) {
3904 // We create a swapped out RenderView for the embedder in the guest's
3905 // render process but we intentionally do not expose the embedder's
3906 // opener chain to it.
3907 new_params.source_routing_id =
3908 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3909 } else {
3910 new_params.source_routing_id =
3911 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3912 }
[email protected]f546640b2012-05-15 00:03:493913 } else {
3914 // We couldn't find it, so don't pass a source frame.
3915 new_params.source_routing_id = MSG_ROUTING_NONE;
3916 }
3917 }
3918
3919 // In most cases, we receive this from a swapped out RenderViewHost.
3920 // It is possible to receive it from one that has just been swapped in,
3921 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183922 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493923}
3924
[email protected]a796f202012-05-30 14:14:253925bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263926 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253927 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263928 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253929 if (!delegate_)
3930 return false;
3931 return delegate_->AddMessageToConsole(this, level, message, line_no,
3932 source_id);
3933}
3934
[email protected]9e797d22014-08-08 21:31:303935WebPreferences WebContentsImpl::ComputeWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273936 // We want to base the page config off of the actual URL, rather than the
3937 // virtual URL.
3938 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3939 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003940 GURL url = controller_.GetActiveEntry()
3941 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153942
[email protected]9e797d22014-08-08 21:31:303943 return GetRenderManager()->current_host()->ComputeWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323944}
3945
[email protected]0eba810b2012-10-18 03:19:363946int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213947 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:293948 int render_view_routing_id = MSG_ROUTING_NONE;
3949 GetRenderManager()->CreateRenderFrame(
3950 instance, nullptr, MSG_ROUTING_NONE,
3951 CREATE_RF_SWAPPED_OUT | CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
3952 CREATE_RF_HIDDEN,
3953 &render_view_routing_id);
3954 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:363955}
3956
[email protected]b172aee2012-04-10 17:05:263957void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273958 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253959 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223960
[email protected]ea114722012-03-12 01:11:253961 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173962 if (rdh) // NULL in unittests.
3963 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253964}
3965
[email protected]b172aee2012-04-10 17:05:263966void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443967 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253968 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443969}
3970
creiscce56cd2014-09-29 22:45:223971void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:153972 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:223973 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153974 return;
3975
creiscce56cd2014-09-29 22:45:223976 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
3977 RenderFrameHostImpl* rfhi =
3978 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:583979
[email protected]e5fc1632011-08-08 07:51:533980 // Ignore renderer unresponsive event if debugger is attached to the tab
3981 // since the event may be a result of the renderer sitting on a breakpoint.
3982 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363983 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533984 return;
3985
creiscce56cd2014-09-29 22:45:223986 if (rfhi->is_waiting_for_beforeunload_ack() ||
3987 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:323988 // Hang occurred while firing the beforeunload/unload handler.
3989 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583990 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323991
[email protected]fa944cb82013-11-15 17:51:213992 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323993 return;
3994
3995 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563996 // nothing we can do to recover. If the hang is in the beforeunload handler,
3997 // pretend the beforeunload listeners have all fired and allow the delegate
3998 // to continue closing; the user will not have the option of cancelling the
3999 // close. Otherwise, pretend the unload listeners have all fired and close
4000 // the tab.
4001 bool close = true;
creiscce56cd2014-09-29 22:45:224002 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564003 delegate_->BeforeUnloadFired(this, true, &close);
4004 }
4005 if (close)
creiscce56cd2014-09-29 22:45:224006 Close(rvhi);
[email protected]420ae012009-04-24 05:16:324007 return;
4008 }
4009
[email protected]9f76c1e2012-03-05 15:15:584010 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474011 return;
4012
[email protected]6934a702011-12-20 00:04:514013 if (delegate_)
4014 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324015}
4016
[email protected]b172aee2012-04-10 17:05:264017void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:514018 if (delegate_)
4019 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324020}
4021
[email protected]b172aee2012-04-10 17:05:264022void WebContentsImpl::LoadStateChanged(
4023 const GURL& url,
4024 const net::LoadStateWithParam& load_state,
4025 uint64 upload_position,
4026 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:324027 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564028 upload_position_ = upload_position;
4029 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:504030 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:214031 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:304032 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214033 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324034 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464035 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224036 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4037 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464038 }
[email protected]420ae012009-04-24 05:16:324039}
4040
[email protected]b172aee2012-04-10 17:05:264041void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554042 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324043 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124044 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4045 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514046 if (delegate_)
4047 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094048 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324049}
4050
[email protected]58d5cfe2013-07-10 02:40:524051void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544052 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234053 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224054 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544055}
4056
[email protected]b172aee2012-04-10 17:05:264057void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104058 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214059 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264060 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4061 // here during container initialization and normal window size will be set
4062 // later. In case of tab duplication this resizing to 0x0 prevents setting
4063 // normal size later so just ignore it.
4064 if (!size.IsEmpty())
4065 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324066}
4067
[email protected]af905902013-10-01 21:38:514068void WebContentsImpl::CancelModalDialogsForRenderManager() {
4069 // We need to cancel modal dialogs when doing a process swap, since the load
4070 // deferrer would prevent us from swapping out.
4071 if (dialog_manager_)
4072 dialog_manager_->CancelActiveAndPendingDialogs(this);
4073}
4074
[email protected]02d7b6e2014-06-24 21:01:504075void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4076 RenderFrameHost* new_host,
4077 bool is_main_frame) {
4078 if (is_main_frame) {
4079 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4080 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084081
[email protected]02d7b6e2014-06-24 21:01:504082 // Make sure the visible RVH reflects the new delegate's preferences.
4083 if (delegate_)
4084 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394085
[email protected]02d7b6e2014-06-24 21:01:504086 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4087 }
4088
4089 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544090}
4091
[email protected]14392a52012-05-02 20:28:444092int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4093 SiteInstance* instance) {
4094 if (!opener_)
4095 return MSG_ROUTING_NONE;
4096
4097 // Recursively create RenderViews for anything else in the opener chain.
4098 return opener_->CreateOpenerRenderViews(instance);
4099}
4100
4101int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4102 int opener_route_id = MSG_ROUTING_NONE;
4103
4104 // If this tab has an opener, ensure it has a RenderView in the given
4105 // SiteInstance as well.
4106 if (opener_)
4107 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4108
[email protected]45a22ad2013-02-21 03:25:004109 // If any of the renderers (current, pending, or swapped out) for this
4110 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214111 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4112 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374113
[email protected]fa944cb82013-11-15 17:51:214114 if (GetRenderManager()->pending_render_view_host() &&
4115 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4116 instance)
4117 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004118
[email protected]fa944cb82013-11-15 17:51:214119 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374120 instance);
4121 if (rvh)
4122 return rvh->GetRoutingID();
4123
[email protected]14392a52012-05-02 20:28:444124 // Create a swapped out RenderView in the given SiteInstance if none exists,
4125 // setting its opener to the given route_id. Return the new view's route_id.
carlosk37f793792014-11-27 15:08:294126 int render_view_routing_id = MSG_ROUTING_NONE;
4127 GetRenderManager()->CreateRenderFrame(instance, nullptr, opener_route_id,
4128 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4129 CREATE_RF_SWAPPED_OUT |
4130 CREATE_RF_HIDDEN,
4131 &render_view_routing_id);
4132 return render_view_routing_id;
[email protected]14392a52012-05-02 20:28:444133}
4134
[email protected]b172aee2012-04-10 17:05:264135NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194136 return GetController();
[email protected]3a3d47472010-07-15 21:03:544137}
4138
carlosk37f793792014-11-27 15:08:294139scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderManager(
4140 const GURL& url) {
4141 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(url)));
[email protected]420ae012009-04-24 05:16:324142}
4143
[email protected]10f417c52011-12-28 21:04:234144NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264145 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324146 return controller_.GetLastCommittedEntry();
4147}
4148
[email protected]b172aee2012-04-10 17:05:264149bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164150 RenderViewHost* render_view_host,
4151 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044152 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124153 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434154 TRACE_EVENT0("browser,navigation",
4155 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444156 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484157 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164158 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4159 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4160 // case this because RWH is still a base class of RenderViewHost, and child
4161 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124162 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164163 RenderWidgetHostViewChildFrame* rwh_view_child =
4164 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164165 rwh_view = rwh_view_child;
4166 } else {
lazyboy549b3b42014-10-20 17:16:044167 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164168 }
[email protected]1a98a932009-11-17 00:12:524169
[email protected]420ae012009-04-24 05:16:324170 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444171 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214172 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324173
[email protected]74ce1ad2011-12-16 21:51:464174 // Make sure we use the correct starting page_id in the new RenderView.
4175 UpdateMaxPageIDIfNecessary(render_view_host);
4176 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584177 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464178
[email protected]9f76c1e2012-03-05 15:15:584179 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264180 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494181 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044182 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494183 max_page_id,
4184 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524185 return false;
[email protected]14392a52012-05-02 20:28:444186 }
[email protected]a4127722011-04-27 23:13:524187
avi2b177592014-12-10 02:08:024188 SetHistoryOffsetAndLengthForView(render_view_host,
4189 controller_.GetLastCommittedEntryIndex(),
4190 controller_.GetEntryCount());
4191
[email protected]a220b5932013-09-21 03:47:444192#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504193 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4194 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444195 if (rwh_view) {
4196 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4197 render_widget_host->WasResized();
4198 }
[email protected]f8233cc2011-05-31 20:24:504199#endif
4200
[email protected]420ae012009-04-24 05:16:324201 return true;
4202}
4203
[email protected]82307f6b2014-08-07 03:30:124204bool WebContentsImpl::CreateRenderFrameForRenderManager(
4205 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494206 int parent_routing_id,
4207 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434208 TRACE_EVENT0("browser,navigation",
4209 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124210
4211 RenderFrameHostImpl* rfh =
4212 static_cast<RenderFrameHostImpl*>(render_frame_host);
japhete6adf142014-10-31 00:01:494213 if (!rfh->CreateRenderFrame(parent_routing_id, proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124214 return false;
4215
4216 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4217 // RenderFrameHost will have to be associated with the appropriate
4218 // RenderWidgetHostView or a new one should be created here.
4219
4220 return true;
4221}
4222
[email protected]7d244f12013-08-22 21:41:514223#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454224
[email protected]155c7f22013-12-09 17:07:184225base::android::ScopedJavaLocalRef<jobject>
4226WebContentsImpl::GetJavaWebContents() {
4227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564228 return GetWebContentsAndroid()->GetJavaObject();
4229}
[email protected]155c7f22013-12-09 17:07:184230
[email protected]0e813a52014-08-13 10:34:564231WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184232 WebContentsAndroid* web_contents_android =
4233 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4234 if (!web_contents_android) {
4235 web_contents_android = new WebContentsAndroid(this);
4236 SetUserData(kWebContentsAndroidKey, web_contents_android);
4237 }
[email protected]0e813a52014-08-13 10:34:564238 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184239}
4240
[email protected]7d244f12013-08-22 21:41:514241bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4242 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164243 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044244 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594245 true);
[email protected]7d244f12013-08-22 21:41:514246}
[email protected]fc2b46b2014-05-03 16:33:454247
4248#elif defined(OS_MACOSX)
4249
[email protected]75f4df72014-07-16 22:39:424250void WebContentsImpl::SetAllowOtherViews(bool allow) {
4251 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454252}
4253
[email protected]75f4df72014-07-16 22:39:424254bool WebContentsImpl::GetAllowOtherViews() {
4255 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454256}
4257
[email protected]7d244f12013-08-22 21:41:514258#endif
4259
[email protected]6fba26d2014-04-29 09:38:284260void WebContentsImpl::OnDialogClosed(int render_process_id,
4261 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264262 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494263 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264264 bool success,
[email protected]fcf75d42013-12-03 20:11:264265 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284266 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4267 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494268 last_dialog_suppressed_ = dialog_was_suppressed;
4269
[email protected]beb440c2009-11-06 04:08:544270 if (is_showing_before_unload_dialog_ && !success) {
4271 // If a beforeunload dialog is canceled, we need to stop the throbber from
4272 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284273 if (rfh)
4274 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354275 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104276
[email protected]6d65a462013-06-21 21:29:124277 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4278 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544279 }
[email protected]87de04b02014-04-08 22:14:494280
[email protected]beb440c2009-11-06 04:08:544281 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284282 if (rfh) {
4283 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4284 dialog_was_suppressed);
4285 } else {
4286 // Don't leak the sync IPC reply if the RFH or process is gone.
4287 delete reply_msg;
4288 }
[email protected]beb440c2009-11-06 04:08:544289}
4290
[email protected]b172aee2012-04-10 17:05:264291void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544292 if (encoding == last_reported_encoding_)
4293 return;
4294 last_reported_encoding_ = encoding;
4295
4296 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124297 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104298}
[email protected]f45d2a72010-03-08 23:28:354299
[email protected]1ac10dca2013-08-20 20:47:044300bool WebContentsImpl::IsHidden() {
4301 return capturer_count_ == 0 && !should_normally_be_visible_;
4302}
4303
[email protected]b0936d22013-11-28 06:47:364304RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214305 return frame_tree_.root()->render_manager();
4306}
4307
[email protected]b172aee2012-04-10 17:05:264308RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584309 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4310}
[email protected]7900bfdb2012-05-24 19:31:244311
[email protected]f8497342013-02-05 22:15:024312BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394313 return browser_plugin_guest_.get();
4314}
4315
[email protected]738f57a2013-06-29 21:06:544316void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4317 CHECK(!browser_plugin_guest_);
4318 browser_plugin_guest_.reset(guest);
4319}
4320
[email protected]f8497342013-02-05 22:15:024321BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394322 return browser_plugin_embedder_.get();
4323}
[email protected]8ff00d72012-10-23 19:12:214324
[email protected]d9030b82013-07-19 08:26:064325void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194326 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304327 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4328 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4329 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064330}
4331
4332void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304333 active_audio_players_.clear();
4334 active_video_players_.clear();
4335 audio_power_save_blocker_.reset();
4336 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064337}
4338
[email protected]fc2b46b2014-05-03 16:33:454339gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214340 gfx::Size size;
4341 if (delegate_)
4342 size = delegate_->GetSizeForNewRenderView(this);
4343 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454344 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214345 return size;
4346}
4347
[email protected]ae7eeda2014-07-04 01:53:264348void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4349 FOR_EACH_OBSERVER(
4350 WebContentsObserver, observers_, FrameDetached(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554351}
4352
[email protected]222f5822014-02-05 23:40:494353void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4354 if (!delegate_)
4355 return;
4356 const gfx::Size new_size = GetPreferredSize();
4357 if (new_size != old_size)
4358 delegate_->UpdatePreferredSize(this, new_size);
4359}
4360
dalecurtisbc6572e12014-09-12 19:22:304361void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4362 ActiveMediaPlayerMap* player_map) {
4363 const uintptr_t key =
4364 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4365 DCHECK(std::find((*player_map)[key].begin(),
4366 (*player_map)[key].end(),
4367 player_cookie) == (*player_map)[key].end());
4368 (*player_map)[key].push_back(player_cookie);
4369}
4370
4371void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4372 ActiveMediaPlayerMap* player_map) {
4373 const uintptr_t key =
4374 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4375 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4376 if (it == player_map->end())
4377 return;
4378
4379 // Remove the player.
4380 PlayerList::iterator player_it =
4381 std::find(it->second.begin(), it->second.end(), player_cookie);
4382 if (player_it != it->second.end())
4383 it->second.erase(player_it);
4384
4385 // If there are no players left, remove the map entry.
4386 if (it->second.empty())
4387 player_map->erase(it);
4388}
4389
4390void WebContentsImpl::RemoveAllMediaPlayerEntries(
4391 RenderFrameHost* render_frame_host,
4392 ActiveMediaPlayerMap* player_map) {
4393 ActiveMediaPlayerMap::iterator it =
4394 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4395 if (it == player_map->end())
4396 return;
4397 player_map->erase(it);
4398}
4399
[email protected]23f41fd2014-06-21 05:29:174400void WebContentsImpl::ResumeResponseDeferredAtStart() {
4401 FrameTreeNode* node = frame_tree_.root();
4402 node->render_manager()->ResumeResponseDeferredAtStart();
4403}
4404
[email protected]34ff1cfc2014-08-20 06:16:054405void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4406 force_disable_overscroll_content_ = force_disable;
4407 if (view_)
4408 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4409}
4410
[email protected]8ff00d72012-10-23 19:12:214411} // namespace content