blob: a6a7c488357c29203be043f2c9003eb563eb9353 [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]1ae93fb2013-06-14 03:38:56900std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-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]1ae93fb2013-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;
naskoa7064ad6e2015-01-15 18:44:562763 rfh->frame_tree_node()->set_is_loading(false);
creis1163acf2014-12-19 21:18:472764 }
2765
[email protected]960b0372014-05-19 18:01:002766 // It is possible to get multiple calls to OnDidStartLoading that don't have
2767 // corresponding calls to OnDidStopLoading:
2768 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2769 // out for a cross-process navigation, and it turns into a placeholder for
2770 // one being rendered in a different process.
2771 // - Also, there might be more than one RenderFrameHost sharing the same
2772 // FrameTreeNode (and thus sharing its ID) each sending a start.
2773 // - But in the future, once clamy@ moves navigation network requests to the
2774 // browser process, there's a good chance that callbacks about starting and
2775 // stopping will all be handled by the browser. When that happens, there
2776 // should no longer be a start/stop call imbalance. TODO(avi): When this
2777 // future arrives, update this code to not allow this case.
naskoa7064ad6e2015-01-15 18:44:562778 if (rfh->frame_tree_node()->is_loading())
2779 return;
2780
[email protected]960b0372014-05-19 18:01:002781 DCHECK_GE(loading_frames_in_progress_, 0);
naskoa7064ad6e2015-01-15 18:44:562782 if (loading_frames_in_progress_ == 0)
2783 DidStartLoading(rfh, to_different_document);
2784
2785 ++loading_frames_in_progress_;
2786 rfh->frame_tree_node()->set_is_loading(true);
[email protected]960b0372014-05-19 18:01:002787
nasko3e8c20e2014-12-18 06:54:562788 // Notify the RenderFrameHostManager of the event.
2789 rfh->frame_tree_node()->render_manager()->OnDidStartLoading();
2790
[email protected]960b0372014-05-19 18:01:002791 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2792 SendLoadProgressChanged();
2793}
2794
2795void WebContentsImpl::OnDidStopLoading() {
2796 RenderFrameHostImpl* rfh =
2797 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2798 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
naskoa7064ad6e2015-01-15 18:44:562799 rfh->frame_tree_node()->set_is_loading(false);
[email protected]960b0372014-05-19 18:01:002800
2801 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2802 // Load stopped while we were still tracking load. Make sure we update
2803 // progress based on this frame's completion.
2804 loading_progresses_[render_frame_id] = 1.0;
2805 SendLoadProgressChanged();
2806 // Then we clean-up our states.
2807 if (loading_total_progress_ == 1.0)
2808 ResetLoadProgressState();
2809 }
2810
nasko3e8c20e2014-12-18 06:54:562811 // Notify the RenderFrameHostManager of the event.
2812 rfh->frame_tree_node()->render_manager()->OnDidStopLoading();
2813
[email protected]960b0372014-05-19 18:01:002814 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2815 // calls DidStopLoading() without a matching DidStartLoading().
2816 if (loading_frames_in_progress_ == 0)
2817 return;
2818 --loading_frames_in_progress_;
2819 if (loading_frames_in_progress_ == 0)
2820 DidStopLoading(rfh);
2821}
2822
2823void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2824 RenderFrameHostImpl* rfh =
2825 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2826 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2827
2828 loading_progresses_[render_frame_id] = load_progress;
2829
2830 // We notify progress change immediately for the first and last updates.
2831 // Also, since the message loop may be pretty busy when a page is loaded, it
2832 // might not execute a posted task in a timely manner so we make sure to
2833 // immediately send progress report if enough time has passed.
2834 base::TimeDelta min_delay =
2835 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2836 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2837 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2838 // If there is a pending task to send progress, it is now obsolete.
2839 loading_weak_factory_.InvalidateWeakPtrs();
2840 SendLoadProgressChanged();
2841 if (loading_total_progress_ == 1.0)
2842 ResetLoadProgressState();
2843 return;
2844 }
2845
2846 if (loading_weak_factory_.HasWeakPtrs())
2847 return;
2848
2849 base::MessageLoop::current()->PostDelayedTask(
2850 FROM_HERE,
2851 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2852 loading_weak_factory_.GetWeakPtr()),
2853 min_delay);
2854}
2855
[email protected]b172aee2012-04-10 17:05:262856void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222857 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2858 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262859}
2860
[email protected]b172aee2012-04-10 17:05:262861void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302862 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262863 minimum_zoom_percent_ = minimum_percent;
2864 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262865}
2866
[email protected]b172aee2012-04-10 17:05:262867void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342868 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432869 if (!delegate_)
2870 return;
2871
[email protected]b9535422012-02-09 01:47:592872 ChildProcessSecurityPolicyImpl* policy =
2873 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222874 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592875 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212876}
2877
[email protected]b172aee2012-04-10 17:05:262878void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2879 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262880 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362881 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432882 if (!delegate_)
2883 return;
2884
[email protected]b9535422012-02-09 01:47:592885 ChildProcessSecurityPolicyImpl* policy =
2886 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322887 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592888 return;
[email protected]8f810632013-06-06 22:33:322889
[email protected]c125e532014-05-10 20:39:062890 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202891}
2892
[email protected]f5273e52014-07-14 16:30:202893void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2894 const GURL& url,
2895 bool user_gesture) {
2896 if (!delegate_)
2897 return;
2898
2899 ChildProcessSecurityPolicyImpl* policy =
2900 ChildProcessSecurityPolicyImpl::GetInstance();
2901 if (policy->IsPseudoScheme(protocol))
2902 return;
2903
2904 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2905}
2906
[email protected]b172aee2012-04-10 17:05:262907void WebContentsImpl::OnFindReply(int request_id,
2908 int number_of_matches,
2909 const gfx::Rect& selection_rect,
2910 int active_match_ordinal,
2911 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432912 if (delegate_) {
2913 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2914 active_match_ordinal, final_update);
2915 }
[email protected]b888919c2011-09-02 00:32:162916}
2917
[email protected]59363fc92012-09-05 03:46:312918#if defined(OS_ANDROID)
2919void WebContentsImpl::OnFindMatchRectsReply(
2920 int version,
2921 const std::vector<gfx::RectF>& rects,
2922 const gfx::RectF& active_rect) {
2923 if (delegate_)
2924 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2925}
[email protected]583418cc2013-01-17 14:01:102926
[email protected]1ff427972013-02-07 21:14:072927void WebContentsImpl::OnOpenDateTimeDialog(
2928 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:172929 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:092930 GetRenderViewHost(),
2931 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132932 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092933 value.minimum,
2934 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172935 value.step,
2936 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102937}
[email protected]59363fc92012-09-05 03:46:312938#endif
2939
[email protected]cfa856d62014-02-22 07:58:402940void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2941 int automation_id) {
2942 DomOperationNotificationDetails details(json_string, automation_id);
2943 NotificationService::current()->Notify(
2944 NOTIFICATION_DOM_OPERATION_RESPONSE,
2945 Source<WebContents>(this),
2946 Details<DomOperationNotificationDetails>(&details));
2947}
2948
[email protected]b172aee2012-04-10 17:05:262949void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2950 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102951 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252952 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102953 AppCacheAccessed(manifest_url, blocked_by_policy));
2954}
2955
[email protected]8bc5ff02013-11-29 06:34:032956void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482957 int color_chooser_id,
2958 SkColor color,
2959 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462960 ColorChooser* new_color_chooser = delegate_ ?
2961 delegate_->OpenColorChooser(this, color, suggestions) :
2962 NULL;
[email protected]820957a2014-01-14 14:56:302963 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212964 return;
[email protected]8ed16472014-04-11 19:02:482965 if (color_chooser_info_.get())
2966 color_chooser_info_->chooser->End();
2967
2968 color_chooser_info_.reset(new ColorChooserInfo(
2969 render_frame_message_source_->GetProcess()->GetID(),
2970 render_frame_message_source_->GetRoutingID(),
2971 new_color_chooser,
2972 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202973}
2974
[email protected]b172aee2012-04-10 17:05:262975void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482976 if (color_chooser_info_ &&
2977 color_chooser_id == color_chooser_info_->identifier)
2978 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202979}
2980
[email protected]b172aee2012-04-10 17:05:262981void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322982 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482983 if (color_chooser_info_ &&
2984 color_chooser_id == color_chooser_info_->identifier)
2985 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202986}
2987
[email protected]d0759f492012-04-19 22:50:502988// This exists for render views that don't have a WebUI, but do have WebUI
2989// bindings enabled.
2990void WebContentsImpl::OnWebUISend(const GURL& source_url,
2991 const std::string& name,
2992 const base::ListValue& args) {
2993 if (delegate_)
2994 delegate_->WebUISend(this, source_url, name, args);
2995}
2996
thestigc4cac8f2014-09-04 21:17:502997#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:422998void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2999 const base::FilePath& path,
3000 bool is_hung) {
3001 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3002
3003 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3004 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3005}
3006
3007void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3008 base::ProcessId plugin_pid) {
3009 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3010 PluginCrashed(plugin_path, plugin_pid));
3011}
3012
[email protected]d8415ad92012-08-23 14:40:503013void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443014 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503015 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343016 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163017 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443018 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163019 return;
[email protected]d8415ad92012-08-23 14:40:503020 }
3021
[email protected]8c8fc292012-11-23 18:57:163022 if (!delegate_->RequestPpapiBrokerPermission(
3023 this, url, plugin_path,
3024 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443025 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163026 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443027 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163028 }
[email protected]d8415ad92012-08-23 14:40:503029}
3030
[email protected]ea0309c2013-08-06 19:35:443031void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503032 bool result) {
[email protected]ea0309c2013-08-06 19:35:443033 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503034}
3035
[email protected]c4538072013-03-18 02:17:553036void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:373037 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:083038 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:553039 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:393040 // For more info, see comment above classes BrowserPluginEmbedder and
3041 // BrowserPluginGuest.
3042 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:143043 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:083044 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:373045}
tommyclie6633ca72014-10-31 00:40:423046#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373047
[email protected]41225fe2013-03-29 05:32:023048void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393049 int id,
[email protected]749fadd2013-05-15 08:37:483050 int http_status_code,
[email protected]795c28972012-12-06 06:13:393051 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303052 const std::vector<SkBitmap>& bitmaps,
3053 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133054 if (bitmaps.size() != original_bitmap_sizes.size())
3055 return;
3056
[email protected]41225fe2013-03-29 05:32:023057 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3058 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393059 // Currently WebContents notifies us of ANY downloads so that it is
3060 // possible to get here.
3061 return;
3062 }
3063 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303064 iter->second.Run(
3065 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393066 }
[email protected]41225fe2013-03-29 05:32:023067 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393068}
3069
3070void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393071 const std::vector<FaviconURL>& candidates) {
3072 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293073 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393074}
3075
dalecurtisbc6572e12014-09-12 19:22:303076void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3077 // ChromeOS has its own way of handling power save blocks for media.
3078#if !defined(OS_CHROMEOS)
3079 DCHECK(!audio_power_save_blocker_);
3080 audio_power_save_blocker_ = PowerSaveBlocker::Create(
3081 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing Audio");
3082#endif
3083}
3084
3085void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3086 // ChromeOS has its own way of handling power save blocks for media.
3087#if !defined(OS_CHROMEOS)
3088 DCHECK(!video_power_save_blocker_);
3089 DCHECK(!active_video_players_.empty());
3090 video_power_save_blocker_ = PowerSaveBlocker::Create(
3091 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing Video");
3092#if defined(OS_ANDROID)
3093 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3094 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3095#endif
3096#endif
3097}
3098
3099void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3100 // If there are no more audio players and we don't have audio stream
3101 // monitoring, release the audio power save blocker here instead of during
3102 // NotifyNavigationStateChanged().
3103 if (active_audio_players_.empty() &&
3104 !AudioStreamMonitor::monitoring_available()) {
3105 audio_power_save_blocker_.reset();
3106 }
3107
3108 // If there are no more video players, clear the video power save blocker.
3109 if (active_video_players_.empty())
3110 video_power_save_blocker_.reset();
3111}
3112
[email protected]1dd0bb752014-02-01 01:16:263113void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3114 bool has_video,
avayvod68017be2014-10-10 18:02:433115 bool has_audio,
3116 bool is_remote) {
3117 // Ignore the videos playing remotely and don't hold the wake lock for the
3118 // screen.
3119 if (is_remote) return;
3120
dalecurtisbc6572e12014-09-12 19:22:303121 if (has_audio) {
3122 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3123
3124 // If we don't have audio stream monitoring, allocate the audio power save
3125 // blocker here instead of during NotifyNavigationStateChanged().
3126 if (!audio_power_save_blocker_ &&
3127 !AudioStreamMonitor::monitoring_available()) {
3128 CreateAudioPowerSaveBlocker();
3129 }
[email protected]1dd0bb752014-02-01 01:16:263130 }
loislo0381a742014-09-11 10:58:113131
dalecurtisbc6572e12014-09-12 19:22:303132 if (has_video) {
3133 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3134
3135 // If we're not hidden and have just created a player, create a blocker.
3136 if (!video_power_save_blocker_ && !IsHidden())
3137 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113138 }
[email protected]1dd0bb752014-02-01 01:16:263139}
3140
3141void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303142 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3143 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3144 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063145}
3146
[email protected]50279492014-05-05 23:24:293147void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153148 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293149 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153150}
[email protected]d9030b82013-07-19 08:26:063151
[email protected]e67ebf32013-02-13 11:07:193152void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073153 if (delegate_)
3154 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193155}
3156
[email protected]17e286e2013-03-01 23:29:393157void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3158 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3159 BeforeFormRepostWarningShow());
3160}
3161
[email protected]ec6c05f2013-10-23 18:41:573162void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3163 Activate();
3164 if (delegate_)
3165 delegate_->ShowRepostFormWarningDialog(this);
3166}
3167
[email protected]b4c84012014-04-28 19:51:103168bool WebContentsImpl::HasAccessedInitialDocument() {
3169 return has_accessed_initial_document_;
3170}
3171
[email protected]96d185d2009-04-24 03:28:543172// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593173// loading, or done loading.
3174void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3175 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093176 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263177 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543178 if (is_loading == is_loading_)
3179 return;
3180
3181 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263182 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3183 base::string16());
[email protected]96d185d2009-04-24 03:28:543184 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563185 upload_size_ = 0;
3186 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543187 }
3188
[email protected]fa944cb82013-11-15 17:51:213189 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543190
3191 is_loading_ = is_loading;
3192 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033193 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543194
[email protected]6ebdc9b2010-09-27 16:55:573195 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093196 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213197 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543198
[email protected]eab61442013-11-14 18:35:483199 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593200 if (is_loading) {
naskob8744d22014-08-28 17:07:433201 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3202 this, "URL", url);
[email protected]91621872013-10-08 04:04:593203 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3204 DidStartLoading(render_view_host));
3205 } else {
naskob8744d22014-08-28 17:07:433206 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3207 this, "URL", url);
[email protected]91621872013-10-08 04:04:593208 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3209 DidStopLoading(render_view_host));
3210 }
[email protected]66798902013-10-01 18:40:163211
3212 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213213 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3214 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543215 if (details)
[email protected]8ff00d72012-10-23 19:12:213216 det = Details<LoadNotificationDetails>(details);
3217 NotificationService::current()->Notify(
3218 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543219}
3220
christiankaeed9862014-11-05 10:49:143221void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
3222 RenderFrameHost* focused_frame = GetFocusedFrame();
3223 if (!focused_frame)
3224 return;
3225
3226 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
3227 focused_frame->GetRoutingID(), extent));
3228}
3229
3230void WebContentsImpl::SelectRange(const gfx::Point& base,
3231 const gfx::Point& extent) {
[email protected]959be4c2014-04-08 15:01:333232 RenderFrameHost* focused_frame = GetFocusedFrame();
3233 if (!focused_frame)
3234 return;
3235
3236 focused_frame->Send(
christiankaeed9862014-11-05 10:49:143237 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
[email protected]959be4c2014-04-08 15:01:333238}
3239
[email protected]b172aee2012-04-10 17:05:263240void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463241 // If we are creating a RVH for a restored controller, then we need to make
3242 // sure the RenderView starts with a next_page_id_ larger than the number
3243 // of restored entries. This must be called before the RenderView starts
3244 // navigating (to avoid a race between the browser updating max_page_id and
3245 // the renderer updating next_page_id_). Because of this, we only call this
3246 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563247 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583248 if (max_restored_page_id >
3249 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3250 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3251 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323252}
3253
[email protected]b172aee2012-04-10 17:05:263254bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263255 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323256 // For file URLs without a title, use the pathname instead. In the case of a
3257 // synthesized title, we don't want the update to count toward the "one set
3258 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263259 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323260 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513261 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243262 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323263 explicit_set = false; // Don't count synthetic titles toward the set limit.
3264 } else {
[email protected]8af69c6c2014-03-03 19:05:313265 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323266 explicit_set = true;
3267 }
3268
[email protected]987fc3a2011-05-26 14:18:093269 // If a page is created via window.open and never navigated,
3270 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553271 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093272 if (entry) {
[email protected]36fc0392011-12-25 03:59:513273 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093274 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323275
[email protected]36fc0392011-12-25 03:59:513276 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093277 } else {
3278 if (page_title_when_no_navigation_entry_ == final_title)
3279 return false; // Nothing changed, don't bother.
3280
3281 page_title_when_no_navigation_entry_ = final_title;
3282 }
[email protected]420ae012009-04-24 05:16:323283
[email protected]420ae012009-04-24 05:16:323284 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233285 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323286
[email protected]66798902013-10-01 18:40:163287 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533288 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163289
3290 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213291 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463292 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213293 NotificationService::current()->Notify(
3294 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3295 Source<WebContents>(this),
3296 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043297
[email protected]420ae012009-04-24 05:16:323298 return true;
3299}
3300
[email protected]960b0372014-05-19 18:01:003301void WebContentsImpl::SendLoadProgressChanged() {
3302 loading_last_progress_update_ = base::TimeTicks::Now();
3303 double progress = 0.0;
3304 int frame_count = 0;
3305
3306 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3307 it != loading_progresses_.end();
3308 ++it) {
3309 progress += it->second;
3310 ++frame_count;
3311 }
3312 if (frame_count == 0)
3313 return;
3314 progress /= frame_count;
3315 DCHECK(progress <= 1.0);
3316
3317 if (progress <= loading_total_progress_)
3318 return;
3319 loading_total_progress_ = progress;
3320
3321 if (delegate_)
3322 delegate_->LoadProgressChanged(this, progress);
3323}
3324
3325void WebContentsImpl::ResetLoadProgressState() {
3326 loading_progresses_.clear();
3327 loading_total_progress_ = 0.0;
3328 loading_weak_factory_.InvalidateWeakPtrs();
3329 loading_last_progress_update_ = base::TimeTicks();
3330}
3331
[email protected]02d7b6e2014-06-24 21:01:503332void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3333 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323334 // After sending out a swap notification, we need to send a disconnect
3335 // notification so that clients that pick up a pointer to |this| can NULL the
3336 // pointer. See Bug 1230284.
3337 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113338 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283339 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113340
3341 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283342 std::pair<RenderViewHost*, RenderViewHost*> details =
3343 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213344 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283345 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213346 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283347 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393348
3349 // Ensure that the associated embedder gets cleared after a RenderViewHost
3350 // gets swapped, so we don't reuse the same embedder next time a
3351 // RenderViewHost is attached to this WebContents.
3352 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323353}
3354
[email protected]02d7b6e2014-06-24 21:01:503355void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3356 RenderFrameHost* new_host) {
3357 FOR_EACH_OBSERVER(WebContentsObserver,
3358 observers_,
3359 RenderFrameHostChanged(old_host, new_host));
3360}
3361
[email protected]da7a7182013-09-06 08:11:113362// TODO(avi): Remove this entire function because this notification is already
3363// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263364void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323365 if (!notify_disconnection_)
3366 return;
3367
3368 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213369 NotificationService::current()->Notify(
3370 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3371 Source<WebContents>(this),
3372 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323373}
3374
[email protected]cbb1ef592013-06-05 19:49:463375void WebContentsImpl::NotifyNavigationEntryCommitted(
3376 const LoadCommittedDetails& load_details) {
3377 FOR_EACH_OBSERVER(
3378 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3379}
3380
[email protected]f114fa42013-12-06 17:06:443381bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3382 const IPC::Message& message) {
3383 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313384}
3385
[email protected]c31a84802014-04-03 15:55:493386const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3387 return GetLastCommittedURL();
3388}
3389
[email protected]b849847b2013-12-10 21:57:583390void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3391 // Note this is only for subframes, the notification for the main frame
3392 // happens in RenderViewCreated.
3393 FOR_EACH_OBSERVER(WebContentsObserver,
3394 observers_,
3395 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303396 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583397}
3398
3399void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193400 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583401 FOR_EACH_OBSERVER(WebContentsObserver,
3402 observers_,
3403 RenderFrameDeleted(render_frame_host));
3404}
3405
[email protected]a09d53ce2014-01-31 00:46:423406void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303407 if (delegate_)
3408 delegate_->WorkerCrashed(this);
3409}
3410
[email protected]a09d53ce2014-01-31 00:46:423411void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3412 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103413 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423414 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103415 if (GetBrowserPluginGuest()) {
3416 WebContentsViewGuest* view_guest =
3417 static_cast<WebContentsViewGuest*>(GetView());
3418 context_menu_params = view_guest->ConvertContextMenuParams(params);
3419 }
3420 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423421 return;
3422
[email protected]077e704b2014-05-23 19:24:103423 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3424 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423425}
3426
[email protected]87de04b02014-04-08 22:14:493427void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013428 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493429 const base::string16& message,
3430 const base::string16& default_prompt,
3431 const GURL& frame_url,
3432 JavaScriptMessageType javascript_message_type,
3433 IPC::Message* reply_msg) {
3434 // Suppress JavaScript dialogs when requested. Also suppress messages when
3435 // showing an interstitial as it's shown over the previous page and we don't
3436 // want the hidden page's dialogs to interfere with the interstitial.
3437 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223438 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503439 ShowingInterstitialPage() || !delegate_ ||
3440 delegate_->ShouldSuppressDialogs(this) ||
3441 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493442
3443 if (!suppress_this_message) {
3444 std::string accept_lang = GetContentClient()->browser()->
3445 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503446 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493447 dialog_manager_->RunJavaScriptDialog(
3448 this,
3449 frame_url.GetOrigin(),
3450 accept_lang,
3451 javascript_message_type,
3452 message,
3453 default_prompt,
3454 base::Bind(&WebContentsImpl::OnDialogClosed,
3455 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013456 render_frame_host->GetProcess()->GetID(),
3457 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493458 reply_msg,
3459 false),
3460 &suppress_this_message);
3461 }
3462
3463 if (suppress_this_message) {
3464 // If we are suppressing messages, just reply as if the user immediately
3465 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013466 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3467 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283468 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493469 }
3470
3471 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3472 // http://crbug.com/288961 ). The only safe thing to do here is return.
3473}
3474
3475void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013476 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493477 const base::string16& message,
3478 bool is_reload,
3479 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013480 RenderFrameHostImpl* rfhi =
3481 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493482 if (delegate_)
3483 delegate_->WillRunBeforeUnloadConfirm();
3484
3485 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503486 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT || !delegate_ ||
3487 delegate_->ShouldSuppressDialogs(this) ||
3488 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493489 if (suppress_this_message) {
3490 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3491 return;
3492 }
3493
3494 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503495 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493496 dialog_manager_->RunBeforeUnloadDialog(
3497 this, message, is_reload,
3498 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013499 render_frame_host->GetProcess()->GetID(),
3500 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283501 false));
[email protected]87de04b02014-04-08 22:14:493502}
3503
[email protected]a86c0e962013-12-17 17:10:393504WebContents* WebContentsImpl::GetAsWebContents() {
3505 return this;
3506}
3507
[email protected]7912e822014-04-16 02:37:033508bool WebContentsImpl::IsNeverVisible() {
3509 if (!delegate_)
3510 return false;
3511 return delegate_->IsNeverVisible(this);
3512}
3513
[email protected]95640212014-07-26 18:14:303514#if defined(OS_WIN)
3515gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3516 return accessible_parent_;
3517}
3518#endif
3519
[email protected]5a3bdf52012-05-24 15:12:573520RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3521 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323522}
3523
[email protected]8ff00d72012-10-23 19:12:213524RendererPreferences WebContentsImpl::GetRendererPrefs(
3525 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463526 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513527}
3528
[email protected]b172aee2012-04-10 17:05:263529gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173530 if (delegate_)
3531 return delegate_->GetRootWindowResizerRect();
3532 return gfx::Rect();
3533}
3534
[email protected]7a846df2012-09-20 19:17:393535void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273536 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393537 browser_plugin_embedder_.reset();
3538}
3539
[email protected]b172aee2012-04-10 17:05:263540void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443541 // Don't send notifications if we are just creating a swapped-out RVH for
3542 // the opener chain. These won't be used for view-source or WebUI, so it's
3543 // ok to return early.
creiscce56cd2014-09-29 22:45:223544 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443545 return;
3546
[email protected]86f98a22013-03-20 14:35:003547 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313548 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083549
[email protected]8ff00d72012-10-23 19:12:213550 NotificationService::current()->Notify(
3551 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3552 Source<WebContents>(this),
3553 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323554
3555 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353556 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213557 if (GetRenderManager()->pending_web_ui())
3558 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323559
[email protected]6286a372013-10-09 04:03:273560 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333561 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323562 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183563 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583564 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323565 }
[email protected]0666aef2009-05-13 19:48:083566
[email protected]60780f412013-02-25 16:34:103567 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263568
3569 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253570 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583571
3572 // We tell the observers now instead of when the main RenderFrameHostImpl is
3573 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3574 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363575 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583576 FOR_EACH_OBSERVER(
3577 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303578 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
dgozman24bfc912014-09-29 11:04:183579
3580 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:323581}
3582
[email protected]b172aee2012-04-10 17:05:263583void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523584 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323585 // Don't notify the world, since this came from a renderer in the
3586 // background.
3587 return;
3588 }
3589
[email protected]da7a7182013-09-06 08:11:113590 notify_disconnection_ = true;
3591 // TODO(avi): Remove. http://crbug.com/170921
3592 NotificationService::current()->Notify(
3593 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3594 Source<WebContents>(this),
3595 NotificationService::NoDetails());
3596
[email protected]be1f56ab2011-12-22 06:55:313597 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233598 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303599
3600 // Restore the focus to the tab (otherwise the focus will be on the top
3601 // window).
[email protected]484ae5912010-09-29 19:16:143602 if (was_crashed && !FocusLocationBarByDefault() &&
3603 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063604 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143605 }
[email protected]32ded2212011-11-10 18:51:433606
[email protected]d8c660432011-12-22 20:51:253607 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323608}
3609
[email protected]ec6a7eb2013-04-22 17:34:223610void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3611 base::TerminationStatus status,
3612 int error_code) {
[email protected]151a63d2011-12-20 22:32:523613 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323614 // The pending page's RenderViewHost is gone.
3615 return;
3616 }
3617
[email protected]2fcdcc32014-03-05 02:14:073618 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3619 // renderer may not have made a clean exit.
3620 if (IsFullscreenForCurrentTab())
3621 ToggleFullscreenMode(false);
3622
[email protected]698191dc2014-02-25 01:06:133623 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3624 if (dialog_manager_)
3625 dialog_manager_->CancelActiveAndPendingDialogs(this);
3626
[email protected]f738bdcb2014-07-11 20:40:443627 if (delegate_)
3628 delegate_->HideValidationMessage(this);
3629
[email protected]e3b10d12014-03-28 16:06:093630 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323631 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233632 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453633
[email protected]960b0372014-05-19 18:01:003634 // Reset the loading progress. TODO(avi): What does it mean to have a
3635 // "renderer crash" when there is more than one renderer process serving a
3636 // webpage? Once this function is called at a more granular frame level, we
3637 // probably will need to more granularly reset the state here.
3638 ResetLoadProgressState();
3639 loading_frames_in_progress_ = 0;
3640
[email protected]d8c660432011-12-22 20:51:253641 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273642 observers_,
[email protected]58d5cfe2013-07-10 02:40:523643 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323644}
3645
[email protected]b172aee2012-04-10 17:05:263646void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253647 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063648}
3649
[email protected]b172aee2012-04-10 17:05:263650void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3651 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043652 const PageState& page_state) {
creise1d3e5b2014-12-01 18:21:573653 // Ensure that this state update comes from a RenderViewHost that belongs to
3654 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413655 // TODO(nasko): This should go through RenderFrameHost.
3656 // TODO(creis): We can't update state for cross-process subframes until we
3657 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
creise1d3e5b2014-12-01 18:21:573658 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413659 return;
[email protected]420ae012009-04-24 05:16:323660
3661 // We must be prepared to handle state updates for any page, these occur
3662 // when the user is scrolling and entering form data, as well as when we're
3663 // leaving a page, in which case our state may have already been moved to
3664 // the next page. The navigation controller will look up the appropriate
3665 // NavigationEntry and update it when it is notified via the delegate.
3666
3667 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583668 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323669 if (entry_index < 0)
3670 return;
[email protected]10f417c52011-12-28 21:04:233671 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323672
[email protected]691aa2f2013-05-28 22:52:043673 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323674 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043675 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323676 controller_.NotifyEntryChanged(entry, entry_index);
3677}
3678
sky8b00392d2015-01-10 00:30:283679void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
3680 const GURL& url) {
3681 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
3682 // If we're fullscreen only update the url if it's from the fullscreen
3683 // renderer.
3684 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
3685 if (fs && fs->GetRenderWidgetHost() != render_view_host)
3686 return;
3687 }
[email protected]6934a702011-12-20 00:04:513688 if (delegate_)
avi450ce00e2014-09-24 01:58:523689 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323690}
3691
[email protected]b172aee2012-04-10 17:05:263692void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103693#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293694 // The UI may be in an event-tracking loop, such as between the
3695 // mouse-down and mouse-up in text selection or a button click.
3696 // Defer the close until after tracking is complete, so that we
3697 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293698 // TODO(shess): This could get more fine-grained. For instance,
3699 // closing a tab in another window while selecting text in the
3700 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103701 if (view_->IsEventTracking()) {
3702 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293703 return;
3704 }
[email protected]60780f412013-02-25 16:34:103705#endif
[email protected]07707302009-11-06 00:50:293706
[email protected]420ae012009-04-24 05:16:323707 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523708 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513709 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323710}
3711
[email protected]66bbadaf2014-03-28 16:25:543712void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573713 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3714 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573715}
3716
[email protected]6f2ac772014-07-24 22:22:083717void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253718 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173719#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563720 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173721#endif
3722}
3723
3724bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3725#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563726 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173727#else
3728 return false;
3729#endif
3730}
3731
[email protected]b172aee2012-04-10 17:05:263732void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513733 if (delegate_ && delegate_->IsPopupOrPanel(this))
3734 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323735}
3736
[email protected]e3b10d12014-03-28 16:06:093737void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3738 bool to_different_document) {
3739 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3740 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323741}
3742
[email protected]723971b2014-02-12 11:08:253743void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323744 scoped_ptr<LoadNotificationDetails> details;
3745
[email protected]9595fd82013-04-19 21:28:493746 // Use the last committed entry rather than the active one, in case a
3747 // pending entry has been created.
3748 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203749 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493750
[email protected]420ae012009-04-24 05:16:323751 // An entry may not exist for a stop when loading an initial blank page or
3752 // if an iframe injected by script into a blank page finishes loading.
3753 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203754 base::TimeDelta elapsed =
3755 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323756
3757 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513758 entry->GetVirtualURL(),
3759 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323760 elapsed,
3761 &controller_,
3762 controller_.GetCurrentEntryIndex()));
3763 }
3764
[email protected]e3b10d12014-03-28 16:06:093765 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3766 details.get());
[email protected]420ae012009-04-24 05:16:323767}
3768
[email protected]b172aee2012-04-10 17:05:263769void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163770 controller_.DiscardNonCommittedEntries();
3771
3772 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213773 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163774}
3775
[email protected]59167c22013-06-03 18:07:323776void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103777 has_accessed_initial_document_ = true;
3778
[email protected]d1371bf8e2014-04-19 03:26:243779 // We may have left a failed browser-initiated navigation in the address bar
3780 // to let the user edit it and try again. Clear it now that content might
3781 // show up underneath it.
3782 if (!IsLoading() && controller_.GetPendingEntry())
3783 controller_.DiscardPendingEntry();
3784
[email protected]59167c22013-06-03 18:07:323785 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503786 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323787}
3788
[email protected]3f19f1a2014-05-02 05:23:273789void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473790 // No action is necessary if the opener has already been cleared.
3791 if (!opener_)
3792 return;
3793
3794 // Clear our opener so that future cross-process navigations don't have an
3795 // opener assigned.
3796 RemoveDestructionObserver(opener_);
3797 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273798
3799 // Notify all swapped out RenderViewHosts for this tab. This is important
3800 // in case we go back to them, or if another window in those processes tries
3801 // to access window.opener.
creisbbbeb062014-08-25 18:20:313802 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273803}
3804
[email protected]39f2f9252014-05-03 00:54:013805void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293806 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093807 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293808 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093809
3810 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213811 NotificationService::current()->Notify(
3812 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3813 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293814 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083815}
3816
[email protected]ef3adfc2014-05-11 00:04:543817void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3818 int32 page_id,
3819 const base::string16& title,
3820 base::i18n::TextDirection title_direction) {
3821 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3822
3823 // If we have a title, that's a pretty good indication that we've started
3824 // getting useful data.
3825 SetNotWaitingForResponse();
3826
3827 // Try to find the navigation entry, which might not be the current one.
3828 // For example, it might be from a pending RVH for the pending entry.
3829 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3830 rvh->GetSiteInstance(), page_id);
3831
3832 // We can handle title updates when we don't have an entry in
3833 // UpdateTitleForEntry, but only if the update is from the current RVH.
3834 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3835 if (!entry && rvh != GetRenderViewHost())
3836 return;
3837
3838 // TODO(evan): make use of title_direction.
3839 // http://code.google.com/p/chromium/issues/detail?id=27094
3840 if (!UpdateTitleForEntry(entry, title))
3841 return;
3842
3843 // Broadcast notifications when the UI should be updated.
3844 if (entry == controller_.GetEntryAtOffset(0))
3845 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3846}
3847
3848void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3849 const std::string& encoding) {
3850 SetEncoding(encoding);
3851}
3852
[email protected]39f2f9252014-05-03 00:54:013853void WebContentsImpl::DocumentAvailableInMainFrame(
3854 RenderViewHost* render_view_host) {
3855 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3856 DocumentAvailableInMainFrame());
3857}
[email protected]e1c3a552012-05-04 20:51:323858void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3859 // Tell the active RenderViewHost to run unload handlers and close, as long
3860 // as the request came from a RenderViewHost in the same BrowsingInstance.
3861 // In most cases, we receive this from a swapped out RenderViewHost.
3862 // It is possible to receive it from one that has just been swapped in,
3863 // in which case we might as well deliver the message anyway.
3864 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3865 GetRenderViewHost()->ClosePage();
3866}
3867
[email protected]f546640b2012-05-15 00:03:493868void WebContentsImpl::RouteMessageEvent(
3869 RenderViewHost* rvh,
3870 const ViewMsg_PostMessage_Params& params) {
3871 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363872 // came from a RenderViewHost in the same BrowsingInstance or if this
3873 // WebContents is dedicated to a browser plugin guest.
3874 // Note: This check means that an embedder could theoretically receive a
3875 // postMessage from anyone (not just its own guests). However, this is
3876 // probably not a risk for apps since other pages won't have references
3877 // to App windows.
3878 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3879 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493880 return;
3881
3882 ViewMsg_PostMessage_Params new_params(params);
3883
[email protected]0bc7f3542013-10-21 15:05:533884 if (!params.message_port_ids.empty()) {
3885 MessagePortMessageFilter* message_port_message_filter =
3886 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3887 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093888 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3889 params.message_port_ids,
3890 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533891 }
3892
[email protected]f546640b2012-05-15 00:03:493893 // If there is a source_routing_id, translate it to the routing ID for
3894 // the equivalent swapped out RVH in the target process. If we need
3895 // to create a swapped out RVH for the source tab, we create its opener
3896 // chain as well, since those will also be accessible to the target page.
3897 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3898 // Try to look up the WebContents for the source page.
3899 WebContentsImpl* source_contents = NULL;
3900 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3901 rvh->GetProcess()->GetID(), params.source_routing_id);
3902 if (source_rvh) {
3903 source_contents = static_cast<WebContentsImpl*>(
3904 source_rvh->GetDelegate()->GetAsWebContents());
3905 }
3906
3907 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363908 if (GetBrowserPluginGuest()) {
3909 // We create a swapped out RenderView for the embedder in the guest's
3910 // render process but we intentionally do not expose the embedder's
3911 // opener chain to it.
3912 new_params.source_routing_id =
3913 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3914 } else {
3915 new_params.source_routing_id =
3916 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3917 }
[email protected]f546640b2012-05-15 00:03:493918 } else {
3919 // We couldn't find it, so don't pass a source frame.
3920 new_params.source_routing_id = MSG_ROUTING_NONE;
3921 }
3922 }
3923
3924 // In most cases, we receive this from a swapped out RenderViewHost.
3925 // It is possible to receive it from one that has just been swapped in,
3926 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183927 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493928}
3929
[email protected]a796f202012-05-30 14:14:253930bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263931 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253932 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263933 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253934 if (!delegate_)
3935 return false;
3936 return delegate_->AddMessageToConsole(this, level, message, line_no,
3937 source_id);
3938}
3939
[email protected]9e797d22014-08-08 21:31:303940WebPreferences WebContentsImpl::ComputeWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273941 // We want to base the page config off of the actual URL, rather than the
3942 // virtual URL.
3943 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3944 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003945 GURL url = controller_.GetActiveEntry()
3946 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153947
[email protected]9e797d22014-08-08 21:31:303948 return GetRenderManager()->current_host()->ComputeWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323949}
3950
[email protected]0eba810b2012-10-18 03:19:363951int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213952 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:293953 int render_view_routing_id = MSG_ROUTING_NONE;
3954 GetRenderManager()->CreateRenderFrame(
3955 instance, nullptr, MSG_ROUTING_NONE,
3956 CREATE_RF_SWAPPED_OUT | CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
3957 CREATE_RF_HIDDEN,
3958 &render_view_routing_id);
3959 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:363960}
3961
[email protected]b172aee2012-04-10 17:05:263962void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273963 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253964 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223965
[email protected]ea114722012-03-12 01:11:253966 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173967 if (rdh) // NULL in unittests.
3968 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253969}
3970
[email protected]b172aee2012-04-10 17:05:263971void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443972 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253973 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443974}
3975
creiscce56cd2014-09-29 22:45:223976void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:153977 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:223978 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153979 return;
3980
creiscce56cd2014-09-29 22:45:223981 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
3982 RenderFrameHostImpl* rfhi =
3983 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:583984
[email protected]e5fc1632011-08-08 07:51:533985 // Ignore renderer unresponsive event if debugger is attached to the tab
3986 // since the event may be a result of the renderer sitting on a breakpoint.
3987 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363988 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533989 return;
3990
creiscce56cd2014-09-29 22:45:223991 if (rfhi->is_waiting_for_beforeunload_ack() ||
3992 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:323993 // Hang occurred while firing the beforeunload/unload handler.
3994 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583995 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323996
[email protected]fa944cb82013-11-15 17:51:213997 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323998 return;
3999
4000 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564001 // nothing we can do to recover. If the hang is in the beforeunload handler,
4002 // pretend the beforeunload listeners have all fired and allow the delegate
4003 // to continue closing; the user will not have the option of cancelling the
4004 // close. Otherwise, pretend the unload listeners have all fired and close
4005 // the tab.
4006 bool close = true;
creiscce56cd2014-09-29 22:45:224007 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564008 delegate_->BeforeUnloadFired(this, true, &close);
4009 }
4010 if (close)
creiscce56cd2014-09-29 22:45:224011 Close(rvhi);
[email protected]420ae012009-04-24 05:16:324012 return;
4013 }
4014
[email protected]9f76c1e2012-03-05 15:15:584015 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474016 return;
4017
[email protected]6934a702011-12-20 00:04:514018 if (delegate_)
4019 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324020}
4021
[email protected]b172aee2012-04-10 17:05:264022void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:514023 if (delegate_)
4024 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324025}
4026
[email protected]b172aee2012-04-10 17:05:264027void WebContentsImpl::LoadStateChanged(
4028 const GURL& url,
4029 const net::LoadStateWithParam& load_state,
4030 uint64 upload_position,
4031 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:324032 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564033 upload_position_ = upload_position;
4034 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:504035 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:214036 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:304037 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214038 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324039 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464040 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224041 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4042 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464043 }
[email protected]420ae012009-04-24 05:16:324044}
4045
[email protected]b172aee2012-04-10 17:05:264046void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554047 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324048 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124049 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4050 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514051 if (delegate_)
4052 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094053 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324054}
4055
[email protected]58d5cfe2013-07-10 02:40:524056void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544057 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234058 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224059 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544060}
4061
[email protected]b172aee2012-04-10 17:05:264062void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104063 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214064 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264065 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4066 // here during container initialization and normal window size will be set
4067 // later. In case of tab duplication this resizing to 0x0 prevents setting
4068 // normal size later so just ignore it.
4069 if (!size.IsEmpty())
4070 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324071}
4072
[email protected]af905902013-10-01 21:38:514073void WebContentsImpl::CancelModalDialogsForRenderManager() {
4074 // We need to cancel modal dialogs when doing a process swap, since the load
4075 // deferrer would prevent us from swapping out.
4076 if (dialog_manager_)
4077 dialog_manager_->CancelActiveAndPendingDialogs(this);
4078}
4079
[email protected]02d7b6e2014-06-24 21:01:504080void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4081 RenderFrameHost* new_host,
4082 bool is_main_frame) {
4083 if (is_main_frame) {
4084 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4085 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084086
[email protected]02d7b6e2014-06-24 21:01:504087 // Make sure the visible RVH reflects the new delegate's preferences.
4088 if (delegate_)
4089 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394090
[email protected]02d7b6e2014-06-24 21:01:504091 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4092 }
4093
4094 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544095}
4096
[email protected]14392a52012-05-02 20:28:444097int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4098 SiteInstance* instance) {
4099 if (!opener_)
4100 return MSG_ROUTING_NONE;
4101
4102 // Recursively create RenderViews for anything else in the opener chain.
4103 return opener_->CreateOpenerRenderViews(instance);
4104}
4105
4106int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4107 int opener_route_id = MSG_ROUTING_NONE;
4108
4109 // If this tab has an opener, ensure it has a RenderView in the given
4110 // SiteInstance as well.
4111 if (opener_)
4112 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4113
[email protected]45a22ad2013-02-21 03:25:004114 // If any of the renderers (current, pending, or swapped out) for this
4115 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214116 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4117 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374118
[email protected]fa944cb82013-11-15 17:51:214119 if (GetRenderManager()->pending_render_view_host() &&
4120 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4121 instance)
4122 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004123
[email protected]fa944cb82013-11-15 17:51:214124 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374125 instance);
4126 if (rvh)
4127 return rvh->GetRoutingID();
4128
[email protected]14392a52012-05-02 20:28:444129 // Create a swapped out RenderView in the given SiteInstance if none exists,
4130 // setting its opener to the given route_id. Return the new view's route_id.
carlosk37f793792014-11-27 15:08:294131 int render_view_routing_id = MSG_ROUTING_NONE;
4132 GetRenderManager()->CreateRenderFrame(instance, nullptr, opener_route_id,
4133 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4134 CREATE_RF_SWAPPED_OUT |
4135 CREATE_RF_HIDDEN,
4136 &render_view_routing_id);
4137 return render_view_routing_id;
[email protected]14392a52012-05-02 20:28:444138}
4139
[email protected]b172aee2012-04-10 17:05:264140NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194141 return GetController();
[email protected]3a3d47472010-07-15 21:03:544142}
4143
carlosk37f793792014-11-27 15:08:294144scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderManager(
4145 const GURL& url) {
4146 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(url)));
[email protected]420ae012009-04-24 05:16:324147}
4148
[email protected]10f417c52011-12-28 21:04:234149NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264150 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324151 return controller_.GetLastCommittedEntry();
4152}
4153
[email protected]b172aee2012-04-10 17:05:264154bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164155 RenderViewHost* render_view_host,
4156 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044157 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124158 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434159 TRACE_EVENT0("browser,navigation",
4160 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444161 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484162 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164163 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4164 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4165 // case this because RWH is still a base class of RenderViewHost, and child
4166 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124167 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164168 RenderWidgetHostViewChildFrame* rwh_view_child =
4169 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164170 rwh_view = rwh_view_child;
4171 } else {
lazyboy549b3b42014-10-20 17:16:044172 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164173 }
[email protected]1a98a932009-11-17 00:12:524174
[email protected]420ae012009-04-24 05:16:324175 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444176 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214177 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324178
[email protected]74ce1ad2011-12-16 21:51:464179 // Make sure we use the correct starting page_id in the new RenderView.
4180 UpdateMaxPageIDIfNecessary(render_view_host);
4181 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584182 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464183
[email protected]9f76c1e2012-03-05 15:15:584184 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264185 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494186 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044187 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494188 max_page_id,
4189 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524190 return false;
[email protected]14392a52012-05-02 20:28:444191 }
[email protected]a4127722011-04-27 23:13:524192
avi2b177592014-12-10 02:08:024193 SetHistoryOffsetAndLengthForView(render_view_host,
4194 controller_.GetLastCommittedEntryIndex(),
4195 controller_.GetEntryCount());
4196
[email protected]a220b5932013-09-21 03:47:444197#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504198 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4199 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444200 if (rwh_view) {
4201 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4202 render_widget_host->WasResized();
4203 }
[email protected]f8233cc2011-05-31 20:24:504204#endif
4205
[email protected]420ae012009-04-24 05:16:324206 return true;
4207}
4208
[email protected]82307f6b2014-08-07 03:30:124209bool WebContentsImpl::CreateRenderFrameForRenderManager(
4210 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494211 int parent_routing_id,
4212 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434213 TRACE_EVENT0("browser,navigation",
4214 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124215
4216 RenderFrameHostImpl* rfh =
4217 static_cast<RenderFrameHostImpl*>(render_frame_host);
japhete6adf142014-10-31 00:01:494218 if (!rfh->CreateRenderFrame(parent_routing_id, proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124219 return false;
4220
4221 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4222 // RenderFrameHost will have to be associated with the appropriate
4223 // RenderWidgetHostView or a new one should be created here.
4224
4225 return true;
4226}
4227
[email protected]7d244f12013-08-22 21:41:514228#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454229
[email protected]155c7f22013-12-09 17:07:184230base::android::ScopedJavaLocalRef<jobject>
4231WebContentsImpl::GetJavaWebContents() {
4232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564233 return GetWebContentsAndroid()->GetJavaObject();
4234}
[email protected]155c7f22013-12-09 17:07:184235
[email protected]0e813a52014-08-13 10:34:564236WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184237 WebContentsAndroid* web_contents_android =
4238 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4239 if (!web_contents_android) {
4240 web_contents_android = new WebContentsAndroid(this);
4241 SetUserData(kWebContentsAndroidKey, web_contents_android);
4242 }
[email protected]0e813a52014-08-13 10:34:564243 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184244}
4245
[email protected]7d244f12013-08-22 21:41:514246bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4247 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164248 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044249 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594250 true);
[email protected]7d244f12013-08-22 21:41:514251}
[email protected]fc2b46b2014-05-03 16:33:454252
4253#elif defined(OS_MACOSX)
4254
[email protected]75f4df72014-07-16 22:39:424255void WebContentsImpl::SetAllowOtherViews(bool allow) {
4256 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454257}
4258
[email protected]75f4df72014-07-16 22:39:424259bool WebContentsImpl::GetAllowOtherViews() {
4260 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454261}
4262
[email protected]7d244f12013-08-22 21:41:514263#endif
4264
[email protected]6fba26d2014-04-29 09:38:284265void WebContentsImpl::OnDialogClosed(int render_process_id,
4266 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264267 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494268 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264269 bool success,
[email protected]fcf75d42013-12-03 20:11:264270 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284271 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4272 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494273 last_dialog_suppressed_ = dialog_was_suppressed;
4274
[email protected]beb440c2009-11-06 04:08:544275 if (is_showing_before_unload_dialog_ && !success) {
4276 // If a beforeunload dialog is canceled, we need to stop the throbber from
4277 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284278 if (rfh)
4279 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354280 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104281
[email protected]6d65a462013-06-21 21:29:124282 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4283 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544284 }
[email protected]87de04b02014-04-08 22:14:494285
[email protected]beb440c2009-11-06 04:08:544286 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284287 if (rfh) {
4288 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4289 dialog_was_suppressed);
4290 } else {
4291 // Don't leak the sync IPC reply if the RFH or process is gone.
4292 delete reply_msg;
4293 }
[email protected]beb440c2009-11-06 04:08:544294}
4295
[email protected]b172aee2012-04-10 17:05:264296void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544297 if (encoding == last_reported_encoding_)
4298 return;
4299 last_reported_encoding_ = encoding;
4300
4301 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124302 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104303}
[email protected]f45d2a72010-03-08 23:28:354304
[email protected]1ac10dca2013-08-20 20:47:044305bool WebContentsImpl::IsHidden() {
4306 return capturer_count_ == 0 && !should_normally_be_visible_;
4307}
4308
[email protected]b0936d22013-11-28 06:47:364309RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214310 return frame_tree_.root()->render_manager();
4311}
4312
[email protected]b172aee2012-04-10 17:05:264313RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584314 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4315}
[email protected]7900bfdb2012-05-24 19:31:244316
[email protected]f8497342013-02-05 22:15:024317BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394318 return browser_plugin_guest_.get();
4319}
4320
[email protected]738f57a2013-06-29 21:06:544321void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4322 CHECK(!browser_plugin_guest_);
4323 browser_plugin_guest_.reset(guest);
4324}
4325
[email protected]f8497342013-02-05 22:15:024326BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394327 return browser_plugin_embedder_.get();
4328}
[email protected]8ff00d72012-10-23 19:12:214329
[email protected]d9030b82013-07-19 08:26:064330void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194331 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304332 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4333 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4334 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064335}
4336
4337void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304338 active_audio_players_.clear();
4339 active_video_players_.clear();
4340 audio_power_save_blocker_.reset();
4341 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064342}
4343
[email protected]fc2b46b2014-05-03 16:33:454344gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214345 gfx::Size size;
4346 if (delegate_)
4347 size = delegate_->GetSizeForNewRenderView(this);
4348 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454349 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214350 return size;
4351}
4352
[email protected]ae7eeda2014-07-04 01:53:264353void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4354 FOR_EACH_OBSERVER(
4355 WebContentsObserver, observers_, FrameDetached(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554356}
4357
[email protected]222f5822014-02-05 23:40:494358void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4359 if (!delegate_)
4360 return;
4361 const gfx::Size new_size = GetPreferredSize();
4362 if (new_size != old_size)
4363 delegate_->UpdatePreferredSize(this, new_size);
4364}
4365
dalecurtisbc6572e12014-09-12 19:22:304366void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4367 ActiveMediaPlayerMap* player_map) {
4368 const uintptr_t key =
4369 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4370 DCHECK(std::find((*player_map)[key].begin(),
4371 (*player_map)[key].end(),
4372 player_cookie) == (*player_map)[key].end());
4373 (*player_map)[key].push_back(player_cookie);
4374}
4375
4376void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4377 ActiveMediaPlayerMap* player_map) {
4378 const uintptr_t key =
4379 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4380 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4381 if (it == player_map->end())
4382 return;
4383
4384 // Remove the player.
4385 PlayerList::iterator player_it =
4386 std::find(it->second.begin(), it->second.end(), player_cookie);
4387 if (player_it != it->second.end())
4388 it->second.erase(player_it);
4389
4390 // If there are no players left, remove the map entry.
4391 if (it->second.empty())
4392 player_map->erase(it);
4393}
4394
4395void WebContentsImpl::RemoveAllMediaPlayerEntries(
4396 RenderFrameHost* render_frame_host,
4397 ActiveMediaPlayerMap* player_map) {
4398 ActiveMediaPlayerMap::iterator it =
4399 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4400 if (it == player_map->end())
4401 return;
4402 player_map->erase(it);
4403}
4404
[email protected]23f41fd2014-06-21 05:29:174405void WebContentsImpl::ResumeResponseDeferredAtStart() {
4406 FrameTreeNode* node = frame_tree_.root();
4407 node->render_manager()->ResumeResponseDeferredAtStart();
4408}
4409
[email protected]34ff1cfc2014-08-20 06:16:054410void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4411 force_disable_overscroll_content_ = force_disable;
4412 if (view_)
4413 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4414}
4415
[email protected]8ff00d72012-10-23 19:12:214416} // namespace content