blob: 094361dcfe9aff59aef949981b719341e54ee51b [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]cbb1ef592013-06-05 19:49:4610#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5611#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1813#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2014#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5115#include "base/strings/string16.h"
16#include "base/strings/string_number_conversions.h"
17#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0018#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3719#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4220#include "base/trace_event/trace_event.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)
hugo.holgersson61288e6c2015-01-28 17:04:40111#include "content/browser/android/content_video_view.h"
[email protected]583418cc2013-01-17 14:01:10112#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:45113#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18114#include "content/browser/web_contents/web_contents_android.h"
[email protected]583418cc2013-01-17 14:01:10115#endif
116
[email protected]f66df822012-05-18 16:52:17117#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50118#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57119#endif
[email protected]3e45ba92009-02-20 21:09:00120
[email protected]8ff00d72012-10-23 19:12:21121namespace content {
[email protected]420ae012009-04-24 05:16:32122namespace {
123
[email protected]960b0372014-05-19 18:01:00124const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
125
126// This matches what Blink's ProgressTracker has traditionally used for a
127// minimum progress value.
128const double kMinimumLoadingProgress = 0.1;
129
[email protected]82114f52012-03-20 22:53:41130const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05131
[email protected]155c7f22013-12-09 17:07:18132#if defined(OS_ANDROID)
133const char kWebContentsAndroidKey[] = "web_contents_android";
134#endif // OS_ANDROID
135
[email protected]e4abd3b42013-11-12 18:28:47136base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46137g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
138
thestigc4cac8f2014-09-04 21:17:50139static int StartDownload(RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39140 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29141 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30142 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02143 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58144 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02145 ++g_next_image_download_id,
146 url,
147 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30148 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02149 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39150}
151
[email protected]8bfc8272013-09-09 20:10:53152void NotifyCacheOnIO(
153 scoped_refptr<net::URLRequestContextGetter> request_context,
154 const GURL& url,
155 const std::string& http_method) {
156 request_context->GetURLRequestContext()->http_transaction_factory()->
157 GetCache()->OnExternalCacheHit(url, http_method);
158}
159
[email protected]9b159a52013-10-03 17:24:55160// Helper function for retrieving all the sites in a frame tree.
161bool CollectSites(BrowserContext* context,
162 std::set<GURL>* sites,
163 FrameTreeNode* node) {
164 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
165 return true;
166}
167
[email protected]a86c0e962013-12-17 17:10:39168bool ForEachFrameInternal(
169 const base::Callback<void(RenderFrameHost*)>& on_frame,
170 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41171 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39172 return true;
173}
174
[email protected]95640212014-07-26 18:14:30175bool ForEachPendingFrameInternal(
176 const base::Callback<void(RenderFrameHost*)>& on_frame,
177 FrameTreeNode* node) {
178 RenderFrameHost* pending_frame_host =
179 node->render_manager()->pending_frame_host();
180 if (pending_frame_host)
181 on_frame.Run(pending_frame_host);
182 return true;
183}
184
[email protected]a86c0e962013-12-17 17:10:39185void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
186 IPC::Message* message_copy = new IPC::Message(*message);
187 message_copy->set_routing_id(rfh->GetRoutingID());
188 rfh->Send(message_copy);
189}
190
[email protected]948481d2014-06-11 18:32:22191void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
192 RenderFrameHost* rfh) {
193 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
194 ->frame_tree_node()
195 ->render_manager()
196 ->GetRenderWidgetHostView();
197 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59198}
199
[email protected]95640212014-07-26 18:14:30200void SetAccessibilityModeOnFrame(AccessibilityMode mode,
201 RenderFrameHost* frame_host) {
202 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
203}
204
[email protected]420ae012009-04-24 05:16:32205} // namespace
206
[email protected]54944cde2012-12-09 09:24:59207WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15208 return WebContentsImpl::CreateWithOpener(
209 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19210}
211
212WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59213 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30214 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59215 WebContentsImpl* new_contents = new WebContentsImpl(
216 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30217
218 for (SessionStorageNamespaceMap::const_iterator it =
219 session_storage_namespace_map.begin();
220 it != session_storage_namespace_map.end();
221 ++it) {
222 new_contents->GetController()
223 .SetSessionStorageNamespace(it->first, it->second.get());
224 }
225
[email protected]54944cde2012-12-09 09:24:59226 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19227 return new_contents;
[email protected]a81343d232011-12-27 07:39:20228}
[email protected]746d3052012-05-22 15:15:47229
nickf9acfbe2014-12-23 19:12:37230void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
231 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46232 g_created_callbacks.Get().push_back(callback);
233}
234
nickf9acfbe2014-12-23 19:12:37235void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
236 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46237 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
238 if (g_created_callbacks.Get().at(i).Equals(callback)) {
239 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
240 return;
241 }
242 }
243}
244
[email protected]299d7f12012-05-23 05:31:15245WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47246 return rvh->GetDelegate()->GetAsWebContents();
247}
248
[email protected]a86c0e962013-12-17 17:10:39249WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
250 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
251 if (!rfh_impl)
252 return NULL;
253 return rfh_impl->delegate()->GetAsWebContents();
254}
255
[email protected]7fff43e2013-05-21 20:21:10256// WebContentsImpl::DestructionObserver ----------------------------------------
257
258class WebContentsImpl::DestructionObserver : public WebContentsObserver {
259 public:
260 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
261 : WebContentsObserver(watched_contents),
262 owner_(owner) {
263 }
264
265 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58266 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58267 owner_->OnWebContentsDestroyed(
268 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10269 }
270
271 private:
272 WebContentsImpl* owner_;
273
274 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
275};
276
[email protected]8ed16472014-04-11 19:02:48277WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
278 int render_frame_id,
279 ColorChooser* chooser,
280 int identifier)
281 : render_process_id(render_process_id),
282 render_frame_id(render_frame_id),
283 chooser(chooser),
284 identifier(identifier) {
285}
286
287WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
288}
289
[email protected]b172aee2012-04-10 17:05:26290// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32291
blundellc57b93f2014-10-29 13:19:57292WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
293 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42294 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22295 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57296 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44297 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49298 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08299#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41300 accessible_parent_(NULL),
301#endif
[email protected]6ea6bdf2013-12-06 13:35:01302 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57303 this,
304 this,
305 this,
306 this),
[email protected]d5f942ba2008-09-26 19:30:34307 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03308 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23309 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
310 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34311 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26312 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00313 loading_total_progress_(0.0),
[email protected]960b0372014-05-19 18:01:00314 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56315 upload_size_(0),
316 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47317 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10318 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55319 capturer_count_(0),
320 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57321 is_being_destroyed_(false),
322 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15323 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01324 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02325 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38326 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21327 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
328 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29329 totalPinchGestureAmount_(0),
330 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44331 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55332 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42333 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03334 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49335 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05336 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30337 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57338 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30339 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30340 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddy371ad9142014-09-17 08:01:46341 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50342 virtual_keyboard_requested_(false),
mohan.reddy371ad9142014-09-17 08:01:46343 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55344 frame_tree_.SetFrameRemoveListener(
345 base::Bind(&WebContentsImpl::OnFrameRemoved,
346 base::Unretained(this)));
qinmin58567c82015-01-07 21:00:20347#if defined(ENABLE_BROWSER_CDMS)
348 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
349#endif
[email protected]332af7732009-03-11 13:21:35350}
initial.commit09911bf2008-07-26 23:55:29351
[email protected]b172aee2012-04-10 17:05:26352WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32353 is_being_destroyed_ = true;
354
[email protected]21b41c7e892014-02-28 01:52:24355 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
356 // shutdown and be deleted as well.
357 frame_tree_.ForEach(
358 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
359
[email protected]d9030b82013-07-19 08:26:06360 ClearAllPowerSaveBlockers();
361
[email protected]b24b68a2012-09-24 21:57:26362 for (std::set<RenderWidgetHostImpl*>::iterator iter =
363 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
364 (*iter)->DetachDelegate();
365 }
366 created_widgets_.clear();
367
[email protected]3ab9cb82011-06-03 18:02:07368 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15369 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11370 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07371
[email protected]8ed16472014-04-11 19:02:48372 if (color_chooser_info_.get())
373 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20374
[email protected]420ae012009-04-24 05:16:32375 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32376
[email protected]ca13a442012-04-17 14:00:12377 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21378 NotificationService::current()->Notify(
379 NOTIFICATION_WEB_CONTENTS_DESTROYED,
380 Source<WebContents>(this),
381 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32382
[email protected]df0c843f2014-05-23 20:37:23383 // Destroy all frame tree nodes except for the root; this notifies observers.
384 frame_tree_.ResetForMainFrameSwap();
385 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59386
[email protected]df0c843f2014-05-23 20:37:23387 // Manually call the observer methods for the root frame tree node.
388 RenderFrameHostManager* root = GetRenderManager();
389 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27390 FOR_EACH_OBSERVER(WebContentsObserver,
391 observers_,
[email protected]df0c843f2014-05-23 20:37:23392 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27393 }
[email protected]df0c843f2014-05-23 20:37:23394 FOR_EACH_OBSERVER(WebContentsObserver,
395 observers_,
396 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27397
[email protected]df0c843f2014-05-23 20:37:23398 if (root->pending_render_view_host()) {
399 FOR_EACH_OBSERVER(WebContentsObserver,
400 observers_,
401 RenderViewDeleted(root->pending_render_view_host()));
402 }
[email protected]c06c58c2014-03-12 20:31:59403
[email protected]f273ee52013-10-18 16:05:27404 FOR_EACH_OBSERVER(WebContentsObserver,
405 observers_,
[email protected]df0c843f2014-05-23 20:37:23406 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27407
[email protected]2db9bd72012-04-13 20:20:56408 FOR_EACH_OBSERVER(WebContentsObserver,
409 observers_,
[email protected]12a46832014-05-09 13:35:58410 WebContentsDestroyed());
411
412 FOR_EACH_OBSERVER(WebContentsObserver,
413 observers_,
414 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08415
[email protected]6934a702011-12-20 00:04:51416 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10417
418 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
419 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42420}
421
[email protected]d1198fd2012-08-13 22:50:19422WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59423 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19424 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03425 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59426 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06427 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19428
[email protected]4858e432014-06-23 18:14:17429 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06430 // This makes |new_contents| act as a guest.
431 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16432 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06433 // We are instantiating a WebContents for browser plugin. Set its subframe
434 // bit to true.
435 new_contents->is_subframe_ = true;
436 }
[email protected]54944cde2012-12-09 09:24:59437 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19438 return new_contents;
439}
440
[email protected]95640212014-07-26 18:14:30441// static
442std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
443 std::vector<WebContentsImpl*> result;
444 scoped_ptr<RenderWidgetHostIterator> widgets(
445 RenderWidgetHostImpl::GetRenderWidgetHosts());
446 std::set<WebContentsImpl*> web_contents_set;
447 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
448 if (!rwh->IsRenderView())
449 continue;
450 RenderViewHost* rvh = RenderViewHost::From(rwh);
451 if (!rvh)
452 continue;
453 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
454 if (!web_contents)
455 continue;
456 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
457 if (web_contents_set.find(wci) == web_contents_set.end()) {
458 web_contents_set.insert(wci);
459 result.push_back(wci);
460 }
461 }
462 return result;
463}
464
[email protected]b0936d22013-11-28 06:47:36465RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21466 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28467}
468
[email protected]7bb761892012-07-20 09:32:47469bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
470 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44471 return OnMessageReceived(render_view_host, NULL, message);
472}
473
474bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
475 RenderFrameHost* render_frame_host,
476 const IPC::Message& message) {
477 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56478 if (GetWebUI() &&
479 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17480 return true;
[email protected]d2353452012-01-19 19:53:56481 }
[email protected]f82d57b52011-04-27 19:13:17482
[email protected]d8c660432011-12-22 20:51:25483 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
484 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33485 if (render_frame_host) {
486 while ((observer = it.GetNext()) != NULL)
487 if (observer->OnMessageReceived(message, render_frame_host))
488 return true;
489 } else {
490 while ((observer = it.GetNext()) != NULL)
491 if (observer->OnMessageReceived(message))
492 return true;
493 }
[email protected]403415a2011-01-10 18:57:53494
[email protected]1d62cf72014-02-07 21:31:57495 // Message handlers should be aware of which
496 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
497 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02498 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57499 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02500 else
[email protected]1d62cf72014-02-07 21:31:57501 render_view_message_source_ = render_view_host;
502
[email protected]724159a2010-12-30 01:11:18503 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33504 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40505 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
506 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05507 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
508 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48509 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
510 OnDocumentLoadedInFrame)
511 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00512 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
513 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
514 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
515 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48516 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
517 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
518 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
519 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19520 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
521 OnMediaPlayingNotification)
522 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
523 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11524 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
525 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18526 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
527 OnDidLoadResourceFromMemoryCache)
528 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
529 OnDidDisplayInsecureContent)
530 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
531 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25532 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26533 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21534 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20535 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
536 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20537 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
538 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16539 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10540 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50541 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50542#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:42543 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
544 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50545 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
546 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55547 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
548 OnBrowserPluginMessage(message))
thestigc4cac8f2014-09-04 21:17:50549#endif
[email protected]41225fe2013-03-29 05:32:02550 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07552 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
553 OnShowValidationMessage)
554 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
555 OnHideValidationMessage)
556 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
557 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48558#if defined(OS_ANDROID)
559 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
560 OnFindMatchRectsReply)
561 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
562 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48563#endif
[email protected]724159a2010-12-30 01:11:18564 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33565 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44566 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57567 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18568
[email protected]724159a2010-12-30 01:11:18569 return handled;
570}
571
nasko907fcb62015-01-28 04:24:11572bool WebContentsImpl::HasValidFrameSource() {
573 if (!render_frame_message_source_) {
574 DCHECK(render_view_message_source_);
575 RecordAction(base::UserMetricsAction("BadMessageTerminate_WC"));
576 GetRenderProcessHost()->ReceivedBadMessage();
577 return false;
578 }
579
580 return true;
581}
582
[email protected]b172aee2012-04-10 17:05:26583void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18584 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21585 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43586 if (delegate_)
587 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18588}
589
[email protected]d1198fd2012-08-13 22:50:19590NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56591 return controller_;
592}
593
[email protected]d1198fd2012-08-13 22:50:19594const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56595 return controller_;
596}
597
[email protected]8ff00d72012-10-23 19:12:21598BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55599 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30600}
601
[email protected]b172aee2012-04-10 17:05:26602const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24603 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32604 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51605 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31606}
607
[email protected]a093ce02013-07-22 20:53:14608const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24609 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32610 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24611 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
612}
613
614const GURL& WebContentsImpl::GetLastCommittedURL() const {
615 // We may not have a navigation entry yet.
616 NavigationEntry* entry = controller_.GetLastCommittedEntry();
617 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
618}
619
[email protected]8ff00d72012-10-23 19:12:21620WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31621 return delegate_;
622}
623
[email protected]8ff00d72012-10-23 19:12:21624void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31625 // TODO(cbentzel): remove this debugging code?
626 if (delegate == delegate_)
627 return;
628 if (delegate_)
629 delegate_->Detach(this);
630 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08631 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31632 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08633 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00634 if (view_)
[email protected]e85165c642014-06-10 14:34:31635 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08636 }
[email protected]be1f56ab2011-12-22 06:55:31637}
638
[email protected]8ff00d72012-10-23 19:12:21639RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21640 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41641 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16642}
643
[email protected]60eca4eb2013-12-06 00:02:16644RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41645 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16646}
647
[email protected]9c9343b2014-03-08 02:56:07648RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
649 if (!frame_tree_.GetFocusedFrame())
650 return NULL;
651 return frame_tree_.GetFocusedFrame()->current_frame_host();
652}
653
[email protected]a86c0e962013-12-17 17:10:39654void WebContentsImpl::ForEachFrame(
655 const base::Callback<void(RenderFrameHost*)>& on_frame) {
656 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
657}
658
659void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
660 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
661 delete message;
662}
663
[email protected]b172aee2012-04-10 17:05:26664RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21665 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31666}
667
[email protected]6b618e62012-08-16 12:59:18668int WebContentsImpl::GetRoutingID() const {
669 if (!GetRenderViewHost())
670 return MSG_ROUTING_NONE;
671
672 return GetRenderViewHost()->GetRoutingID();
673}
674
[email protected]44470a22013-01-24 01:21:54675int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
676 return fullscreen_widget_routing_id_;
677}
678
[email protected]b172aee2012-04-10 17:05:26679RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21680 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31681}
682
[email protected]4aebbca2013-09-17 22:26:49683RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
684 const {
685 RenderWidgetHost* const widget_host =
686 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
687 GetFullscreenWidgetRoutingID());
688 return widget_host ? widget_host->GetView() : NULL;
689}
690
[email protected]8ff00d72012-10-23 19:12:21691WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31692 return view_.get();
693}
694
[email protected]95640212014-07-26 18:14:30695void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
696 if (mode == accessibility_mode_)
697 return;
698
699 accessibility_mode_ = mode;
700 frame_tree_.ForEach(
701 base::Bind(&ForEachFrameInternal,
702 base::Bind(&SetAccessibilityModeOnFrame, mode)));
703 frame_tree_.ForEach(
704 base::Bind(&ForEachPendingFrameInternal,
705 base::Bind(&SetAccessibilityModeOnFrame, mode)));
706}
707
708void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50709 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30710}
711
712void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50713 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30714}
715
zhenw1f790352014-10-30 00:06:04716void WebContentsImpl::ClearNavigationTransitionData() {
717 FrameTreeNode* node = frame_tree_.root();
718 node->render_manager()->ClearNavigationTransitionData();
719}
720
[email protected]8ff00d72012-10-23 19:12:21721WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56722 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03723 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
724 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22725 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58726 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22727 web_ui->SetController(controller);
728 return web_ui;
729 }
730
731 delete web_ui;
732 return NULL;
733}
734
[email protected]8ff00d72012-10-23 19:12:21735WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21736 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
737 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31738}
739
[email protected]8ff00d72012-10-23 19:12:21740WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21741 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34742}
743
[email protected]86ef6a392012-05-11 22:03:11744void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22745 if (GetUserAgentOverride() == override)
746 return;
747
748 renderer_preferences_.user_agent_override = override;
749
750 // Send the new override string to the renderer.
751 RenderViewHost* host = GetRenderViewHost();
752 if (host)
753 host->SyncRendererPrefs();
754
755 // Reload the page if a load is currently in progress to avoid having
756 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27757 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22758 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
759 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53760
761 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
762 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11763}
764
765const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22766 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11767}
768
[email protected]95640212014-07-26 18:14:30769void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
770 AddAccessibilityMode(AccessibilityModeTreeOnly);
771}
772
773bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
774 return accessibility_mode_ == AccessibilityModeTreeOnly;
775}
776
777bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
778 return accessibility_mode_ == AccessibilityModeComplete;
779}
780
[email protected]2ceee8f2014-01-14 18:02:08781#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41782void WebContentsImpl::SetParentNativeViewAccessible(
783gfx::NativeViewAccessible accessible_parent) {
784 accessible_parent_ = accessible_parent;
[email protected]95640212014-07-26 18:14:30785 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
786 if (rfh)
787 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41788}
789#endif
790
[email protected]fcf75d42013-12-03 20:11:26791const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55792 // Transient entries take precedence. They are used for interstitial pages
793 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23794 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08795 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21796 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30797 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23798 if (entry) {
[email protected]b5cca982011-05-26 04:42:08799 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23800 }
[email protected]fa944cb82013-11-15 17:51:21801 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
802 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58803 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54804 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32805 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54806 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35807 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26808 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54809 if (!title.empty())
810 return title;
811 }
812 }
813
814 // We use the title for the last committed entry rather than a pending
815 // navigation entry. For example, when the user types in a URL, we want to
816 // keep the old page's title until the new load has committed and we get a new
817 // title.
[email protected]96d185d2009-04-24 03:28:54818 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32819
[email protected]9eeafc012013-11-25 23:49:47820 // We make an exception for initial navigations.
821 if (controller_.IsInitialNavigation()) {
822 // We only want to use the title from the visible entry in one of two cases:
823 // 1. There's already a committed entry for an initial navigation, in which
824 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
825 // 2. The pending entry has been explicitly assigned a title to display.
826 //
827 // If there's no last committed entry and no assigned title, we should fall
828 // back to |page_title_when_no_navigation_entry_| rather than showing the
829 // URL.
830 if (entry ||
831 (controller_.GetVisibleEntry() &&
832 !controller_.GetVisibleEntry()->GetTitle().empty())) {
833 entry = controller_.GetVisibleEntry();
834 }
835 }
[email protected]59167c22013-06-03 18:07:32836
[email protected]45d0ef7f2011-01-05 13:46:23837 if (entry) {
[email protected]b5cca982011-05-26 04:42:08838 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23839 }
[email protected]987fc3a2011-05-26 14:18:09840
841 // |page_title_when_no_navigation_entry_| is finally used
842 // if no title cannot be retrieved.
843 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54844}
845
[email protected]b172aee2012-04-10 17:05:26846int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46847 return GetMaxPageIDForSiteInstance(GetSiteInstance());
848}
849
[email protected]b172aee2012-04-10 17:05:26850int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
851 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33852 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
853 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46854
[email protected]b6583592012-01-25 19:52:33855 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34856}
857
[email protected]b172aee2012-04-10 17:05:26858void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46859 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
860}
861
[email protected]b172aee2012-04-10 17:05:26862void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33863 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46864 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33865 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34866}
867
[email protected]ec6c05f2013-10-23 18:41:57868void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
869 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
870 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57871}
872
creiscce56cd2014-09-29 22:45:22873SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21874 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54875}
876
creiscce56cd2014-09-29 22:45:22877SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
878 RenderViewHostImpl* dest_rvh =
879 GetRenderManager()->pending_render_view_host() ?
880 GetRenderManager()->pending_render_view_host() :
881 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58882 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38883}
884
[email protected]b172aee2012-04-10 17:05:26885bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31886 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49887}
888
[email protected]6dfed692014-05-22 04:18:03889bool WebContentsImpl::IsLoadingToDifferentDocument() const {
890 return is_loading_ && is_load_to_different_document_;
891}
892
[email protected]b172aee2012-04-10 17:05:26893bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03894 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31895}
896
[email protected]b172aee2012-04-10 17:05:26897const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31898 return load_state_;
899}
900
[email protected]fcf75d42013-12-03 20:11:26901const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31902 return load_state_host_;
903}
904
[email protected]b172aee2012-04-10 17:05:26905uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31906 return upload_size_;
907}
908
[email protected]b172aee2012-04-10 17:05:26909uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31910 return upload_position_;
911}
912
[email protected]1ae93fb2013-06-14 03:38:56913std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56914 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39915 frame_tree_.ForEach(base::Bind(&CollectSites,
916 base::Unretained(GetBrowserContext()),
917 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56918 return sites;
919}
920
[email protected]b172aee2012-04-10 17:05:26921const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54922 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31923}
924
[email protected]b172aee2012-04-10 17:05:26925bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31926 return displayed_insecure_content_;
927}
928
[email protected]222f5822014-02-05 23:40:49929void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25930 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55931 ++capturer_count_;
932 DVLOG(1) << "There are now " << capturer_count_
933 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49934
935 // Note: This provides a hint to upstream code to size the views optimally
936 // for quality (e.g., to avoid scaling).
937 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
938 preferred_size_for_capture_ = capture_size;
939 OnPreferredSizeChanged(preferred_size_);
940 }
ccameron8807c38f2015-01-17 00:29:19941
942 // Ensure that all views are un-occluded before capture begins.
943 WasUnOccluded();
[email protected]54597982013-02-06 01:59:55944}
945
946void WebContentsImpl::DecrementCapturerCount() {
947 --capturer_count_;
948 DVLOG(1) << "There are now " << capturer_count_
949 << " capturing(s) of WebContentsImpl@" << this;
950 DCHECK_LE(0, capturer_count_);
951
[email protected]5a652232013-02-12 06:15:25952 if (is_being_destroyed_)
953 return;
954
[email protected]222f5822014-02-05 23:40:49955 if (capturer_count_ == 0) {
956 const gfx::Size old_size = preferred_size_for_capture_;
957 preferred_size_for_capture_ = gfx::Size();
958 OnPreferredSizeChanged(old_size);
959 }
960
[email protected]1ac10dca2013-08-20 20:47:04961 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55962 DVLOG(1) << "Executing delayed WasHidden().";
963 WasHidden();
964 }
[email protected]be1f56ab2011-12-22 06:55:31965}
966
[email protected]f2bd40812013-07-20 04:30:44967int WebContentsImpl::GetCapturerCount() const {
968 return capturer_count_;
969}
970
miu50f97892014-09-22 22:49:52971bool WebContentsImpl::IsAudioMuted() const {
972 return audio_muter_.get() && audio_muter_->is_muting();
973}
974
975void WebContentsImpl::SetAudioMuted(bool mute) {
976 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
977 << " for WebContentsImpl@" << this;
978
979 if (mute == IsAudioMuted())
980 return;
981
982 if (mute) {
983 if (!audio_muter_)
984 audio_muter_.reset(new WebContentsAudioMuter(this));
985 audio_muter_->StartMuting();
986 } else {
987 DCHECK(audio_muter_);
988 audio_muter_->StopMuting();
989 }
990
991 // Notification for UI updates in response to the changed muting state.
992 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
993}
994
[email protected]b172aee2012-04-10 17:05:26995bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31996 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
997 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
998 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49999}
1000
[email protected]b172aee2012-04-10 17:05:261001void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1002 int error_code) {
[email protected]443b80e2010-12-14 00:42:231003 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341004 return;
1005
[email protected]443b80e2010-12-14 00:42:231006 crashed_status_ = status;
1007 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211008 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341009}
1010
[email protected]b172aee2012-04-10 17:05:261011base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311012 return crashed_status_;
1013}
1014
[email protected]b172aee2012-04-10 17:05:261015bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311016 return is_being_destroyed_;
1017}
1018
[email protected]7f924832014-08-09 05:57:221019void WebContentsImpl::NotifyNavigationStateChanged(
1020 InvalidateTypes changed_flags) {
dalecurtisbc6572e12014-09-12 19:22:301021 // Create and release the audio power save blocker depending on whether the
1022 // tab is actively producing audio or not.
dalecurtis27011852015-01-06 19:52:341023 if ((changed_flags & INVALIDATE_TYPE_TAB) &&
dalecurtisbc6572e12014-09-12 19:22:301024 AudioStreamMonitor::monitoring_available()) {
1025 if (WasRecentlyAudible()) {
1026 if (!audio_power_save_blocker_)
1027 CreateAudioPowerSaveBlocker();
1028 } else {
1029 audio_power_save_blocker_.reset();
1030 }
1031 }
1032
[email protected]d5f942ba2008-09-26 19:30:341033 if (delegate_)
1034 delegate_->NavigationStateChanged(this, changed_flags);
1035}
1036
[email protected]9a890452014-02-13 22:21:021037base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1038 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331039}
1040
[email protected]9e2e4632012-07-27 16:38:411041void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541042 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591043
ccameron8807c38f2015-01-17 00:29:191044 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1045 if (view) {
1046 view->Show();
[email protected]789e9152009-08-04 21:59:431047#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191048 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431049#endif
[email protected]de3c5d82014-05-28 22:12:591050 }
[email protected]789e9152009-08-04 21:59:431051 }
[email protected]96d185d2009-04-24 03:28:541052
[email protected]9a890452014-02-13 22:21:021053 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381054
[email protected]b9769d82012-02-10 00:23:591055 // The resize rect might have changed while this was inactive -- send the new
1056 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581057 RenderViewHostImpl* rvh =
1058 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591059 if (rvh) {
1060 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1061 }
[email protected]96d185d2009-04-24 03:28:541062
dalecurtisbc6572e12014-09-12 19:22:301063 // Restore power save blocker if there are active video players running.
1064 if (!active_video_players_.empty() && !video_power_save_blocker_)
1065 CreateVideoPowerSaveBlocker();
1066
[email protected]c0d9d5672013-10-09 07:38:031067 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1068
[email protected]54597982013-02-06 01:59:551069 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311070}
1071
[email protected]b172aee2012-04-10 17:05:261072void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551073 // If there are entities capturing screenshots or video (e.g., mirroring),
1074 // don't activate the "disable rendering" optimization.
1075 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521076 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551077 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261078 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521079 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331080 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521081 // calls us).
ccameron8807c38f2015-01-17 00:29:191082 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1083 if (view)
1084 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591085 }
dalecurtisbc6572e12014-09-12 19:22:301086
1087 // Release any video power save blockers held as video is not visible.
1088 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541089 }
1090
[email protected]c0d9d5672013-10-09 07:38:031091 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1092
[email protected]54597982013-02-06 01:59:551093 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371094}
1095
ccameron8807c38f2015-01-17 00:29:191096void WebContentsImpl::WasOccluded() {
1097 if (capturer_count_ > 0)
1098 return;
1099
1100 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1101 if (view)
1102 view->WasOccluded();
1103 }
1104}
1105
1106void WebContentsImpl::WasUnOccluded() {
1107 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1108 if (view)
1109 view->WasUnOccluded();
1110 }
1111}
1112
[email protected]b172aee2012-04-10 17:05:261113bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311114 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271115 return WillNotifyDisconnection() &&
1116 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581117 !static_cast<RenderViewHostImpl*>(
1118 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311119}
1120
[email protected]1c3f80bd2014-04-08 23:02:061121void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1122 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1123 for_cross_site_transition);
1124}
1125
[email protected]b172aee2012-04-10 17:05:261126void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211127 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401128 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271129}
1130
[email protected]b172aee2012-04-10 17:05:261131WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441132 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451133 // We pass our own opener so that the cloned page can access it if it was
1134 // before.
[email protected]54944cde2012-12-09 09:24:591135 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451136 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591137 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191138 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221139 FOR_EACH_OBSERVER(WebContentsObserver,
1140 observers_,
1141 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271142 return tc;
1143}
1144
[email protected]14392a52012-05-02 20:28:441145void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211146 const NotificationSource& source,
1147 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441148 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211149 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1150 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031151 RenderWidgetHostView* view = host->GetView();
1152 if (view == GetFullscreenRenderWidgetHostView()) {
1153 // We cannot just call view_->RestoreFocus() here. On some platforms,
1154 // attempting to focus the currently-invisible WebContentsView will be
1155 // flat-out ignored. Therefore, this boolean is used to track whether
1156 // we will request focus after the fullscreen widget has been
1157 // destroyed.
1158 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1159 } else {
1160 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1161 i != pending_widget_views_.end(); ++i) {
1162 if (host->GetView() == i->second) {
1163 pending_widget_views_.erase(i);
1164 break;
1165 }
[email protected]bafe6cd2012-05-23 23:09:501166 }
1167 }
1168 break;
1169 }
[email protected]14392a52012-05-02 20:28:441170 default:
1171 NOTREACHED();
1172 }
1173}
1174
[email protected]ec6c05f2013-10-23 18:41:571175WebContents* WebContentsImpl::GetWebContents() {
1176 return this;
1177}
1178
[email protected]54944cde2012-12-09 09:24:591179void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211180 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361181 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211182 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431183 should_normally_be_visible_ = !params.initially_hidden;
1184
avic2c29d782014-12-12 00:23:541185 // Either both routing ids can be given, or neither can be.
1186 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
1187 params.main_frame_routing_id == MSG_ROUTING_NONE) ||
1188 (params.routing_id != MSG_ROUTING_NONE &&
1189 params.main_frame_routing_id != MSG_ROUTING_NONE));
[email protected]fa944cb82013-11-15 17:51:211190 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041191 params.browser_context, params.site_instance, params.routing_id,
1192 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191193
[email protected]fc2b46b2014-05-03 16:33:451194 WebContentsViewDelegate* delegate =
1195 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1196
1197 if (browser_plugin_guest_) {
1198 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1199 this, delegate, &render_view_host_delegate_view_));
1200
1201 WebContentsViewGuest* rv = new WebContentsViewGuest(
1202 this, browser_plugin_guest_.get(), platform_view.Pass(),
1203 render_view_host_delegate_view_);
1204 render_view_host_delegate_view_ = rv;
1205 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191206 } else {
[email protected]fc2b46b2014-05-03 16:33:451207 // Regular WebContentsView.
1208 view_.reset(CreateWebContentsView(
1209 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191210 }
[email protected]fc2b46b2014-05-03 16:33:451211 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191212 CHECK(view_.get());
1213
[email protected]ed245db2012-12-18 08:00:451214 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591215 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191216
1217 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101218 if (opener_)
1219 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191220
tommyclieb25b2a2014-11-03 19:45:091221#if defined(ENABLE_PLUGINS)
1222 plugin_content_origin_whitelist_.reset(
1223 new PluginContentOriginWhitelist(this));
1224#endif
1225
[email protected]d1198fd2012-08-13 22:50:191226 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211227 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1228 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101229
[email protected]01f83f92014-06-17 14:41:541230 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091231 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541232
mlamouriefdca9d2014-09-16 16:55:401233 manifest_manager_host_.reset(new ManifestManagerHost(this));
1234
[email protected]c7654a232013-06-12 21:04:441235#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101236 date_time_chooser_.reset(new DateTimeChooserAndroid());
1237#endif
fsamuel7310a4262014-12-05 05:06:441238
1239 // BrowserPluginGuest::Init needs to be called after this WebContents has
1240 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1241 if (browser_plugin_guest_)
1242 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371243
1244 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1245 g_created_callbacks.Get().at(i).Run(this);
[email protected]d1198fd2012-08-13 22:50:191246}
1247
[email protected]7fff43e2013-05-21 20:21:101248void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1249 RemoveDestructionObserver(web_contents);
1250
[email protected]14392a52012-05-02 20:28:441251 // Clear the opener if it has been closed.
1252 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441253 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511254 return;
[email protected]14392a52012-05-02 20:28:441255 }
[email protected]ceee8cd2013-03-08 04:59:511256 // Clear a pending contents that has been closed before being shown.
1257 for (PendingContents::iterator iter = pending_contents_.begin();
1258 iter != pending_contents_.end();
1259 ++iter) {
1260 if (iter->second != web_contents)
1261 continue;
1262 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511263 return;
1264 }
1265 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441266}
1267
[email protected]7fff43e2013-05-21 20:21:101268void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1269 if (!ContainsKey(destruction_observers_, web_contents)) {
1270 destruction_observers_[web_contents] =
1271 new DestructionObserver(this, web_contents);
1272 }
1273}
1274
1275void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1276 DestructionObservers::iterator iter =
1277 destruction_observers_.find(web_contents);
1278 if (iter != destruction_observers_.end()) {
1279 delete destruction_observers_[web_contents];
1280 destruction_observers_.erase(iter);
1281 }
1282}
1283
[email protected]b172aee2012-04-10 17:05:261284void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311285 observers_.AddObserver(observer);
1286}
1287
[email protected]b172aee2012-04-10 17:05:261288void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311289 observers_.RemoveObserver(observer);
1290}
1291
[email protected]948481d2014-06-11 18:32:221292std::set<RenderWidgetHostView*>
1293WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1294 std::set<RenderWidgetHostView*> set;
1295 if (ShowingInterstitialPage()) {
1296 set.insert(GetRenderWidgetHostView());
1297 } else {
1298 ForEachFrame(
1299 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1300 }
[email protected]de3c5d82014-05-28 22:12:591301 return set;
1302}
1303
[email protected]b172aee2012-04-10 17:05:261304void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341305 if (delegate_)
1306 delegate_->ActivateContents(this);
1307}
1308
[email protected]b172aee2012-04-10 17:05:261309void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121310 if (delegate_)
1311 delegate_->DeactivateContents(this);
1312}
1313
[email protected]b172aee2012-04-10 17:05:261314void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481315 if (delegate_)
1316 delegate_->LostCapture();
1317}
1318
[email protected]b24b68a2012-09-24 21:57:261319void WebContentsImpl::RenderWidgetDeleted(
1320 RenderWidgetHostImpl* render_widget_host) {
1321 if (is_being_destroyed_) {
1322 // |created_widgets_| might have been destroyed.
1323 return;
1324 }
1325
1326 std::set<RenderWidgetHostImpl*>::iterator iter =
1327 created_widgets_.find(render_widget_host);
1328 if (iter != created_widgets_.end())
1329 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541330
1331 if (render_widget_host &&
1332 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491333 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531334 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541335 FOR_EACH_OBSERVER(WebContentsObserver,
1336 observers_,
1337 DidDestroyFullscreenWidget(
1338 fullscreen_widget_routing_id_));
1339 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031340 if (fullscreen_widget_had_focus_at_shutdown_)
1341 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541342 }
[email protected]b24b68a2012-09-24 21:57:261343}
1344
miu9e14e492014-10-25 02:39:041345void WebContentsImpl::RenderWidgetGotFocus(
1346 RenderWidgetHostImpl* render_widget_host) {
1347 // Notify the delegate if an embedded fullscreen widget was focused.
1348 if (delegate_ && render_widget_host &&
1349 delegate_->EmbedsFullscreenWidget() &&
1350 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1351 delegate_->WebContentsFocused(this);
1352}
1353
estaded0a0c992015-01-21 14:12:061354void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311355 RenderWidgetHostImpl* render_widget_host,
1356 bool width_changed) {
estadece344ec2015-01-23 00:12:291357 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1358 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061359 return;
estaded0a0c992015-01-21 14:12:061360
rouslan2f5993f2015-01-29 00:18:311361 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1362 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061363}
1364
[email protected]b172aee2012-04-10 17:05:261365bool WebContentsImpl::PreHandleKeyboardEvent(
1366 const NativeWebKeyboardEvent& event,
1367 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481368 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131369 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481370}
1371
[email protected]b172aee2012-04-10 17:05:261372void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101373 if (browser_plugin_embedder_ &&
1374 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1375 return;
1376 }
[email protected]63954792011-07-11 04:17:481377 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131378 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481379}
1380
[email protected]d92026ef2014-03-03 21:04:131381bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461382 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191383#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331384 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1385 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191386 // -the OS already has a gesture to do this through pinch-zoom
1387 // -if a user starts an inertial scroll, let's go, and presses control
1388 // (i.e. control+tab) then the OS's buffered scroll events will come in
1389 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331390 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551391 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331392 !event.canScroll) {
[email protected]fb3f066e2013-02-12 19:12:521393 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1394 return true;
1395 }
[email protected]bccc4472013-04-18 16:37:191396#endif
[email protected]fb3f066e2013-02-12 19:12:521397 return false;
1398}
1399
[email protected]04bce562014-01-30 05:34:541400bool WebContentsImpl::PreHandleGestureEvent(
1401 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031402 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541403}
1404
[email protected]bab38af2014-03-30 17:37:291405bool WebContentsImpl::HandleGestureEvent(
1406 const blink::WebGestureEvent& event) {
1407 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1408 // Use them to implement browser zoom, as for HandleWheelEvent above.
1409 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331410 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291411 // The scale difference necessary to trigger a zoom action. Derived from
1412 // experimentation to find a value that feels reasonable.
1413 const float kZoomStepValue = 0.6f;
1414
1415 // Find the (absolute) thresholds on either side of the current zoom factor,
1416 // then convert those to actual numbers to trigger a zoom in or out.
1417 // This logic deliberately makes the range around the starting zoom value
1418 // for the gesture twice as large as the other ranges (i.e., the notches are
1419 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1420 // so that it's easier to get back to your starting point than it is to
1421 // overshoot.
1422 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1423 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1424 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1425 : -backStep;
1426 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1427 : backStep;
1428
[email protected]fb546cb2014-04-28 14:09:371429 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291430 if (totalPinchGestureAmount_ > zoomInThreshold) {
1431 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461432 if (delegate_)
1433 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291434 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1435 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461436 if (delegate_)
1437 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291438 }
1439 return true;
1440 }
1441
1442 return false;
1443}
1444
[email protected]b172aee2012-04-10 17:05:261445void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431446 if (delegate_)
1447 delegate_->HandleMouseDown();
1448}
1449
[email protected]b172aee2012-04-10 17:05:261450void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481451 if (delegate_)
1452 delegate_->HandleMouseUp();
1453}
1454
[email protected]590a634e2012-07-19 16:38:231455void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481456 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231457 delegate_->HandlePointerActivate();
1458}
1459
1460void WebContentsImpl::HandleGestureBegin() {
1461 if (delegate_)
1462 delegate_->HandleGestureBegin();
1463}
1464
1465void WebContentsImpl::HandleGestureEnd() {
1466 if (delegate_)
1467 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481468}
1469
mlamouri7a78d6fd2015-01-17 13:23:531470void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1471 // This method is being called to enter renderer-initiated fullscreen mode.
1472 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491473 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1474 if (widget_view)
1475 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1476
[email protected]8a5e0ca2011-08-25 06:30:471477 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531478 delegate_->EnterFullscreenModeForTab(this, origin);
1479
1480 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1481 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
1482}
1483
1484void WebContentsImpl::ExitFullscreenMode() {
1485 // This method is being called to leave renderer-initiated fullscreen mode.
1486 // Make sure any existing fullscreen widget is shut down first.
1487 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1488 if (widget_view)
1489 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1490
hugo.holgersson61288e6c2015-01-28 17:04:401491#if defined(OS_ANDROID)
1492 ContentVideoView* video_view = ContentVideoView::GetInstance();
1493 if (video_view != NULL)
1494 video_view->OnExitFullscreen();
1495#endif
1496
mlamouri7a78d6fd2015-01-17 13:23:531497 if (delegate_)
1498 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371499
1500 FOR_EACH_OBSERVER(WebContentsObserver,
1501 observers_,
1502 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471503}
1504
[email protected]b172aee2012-04-10 17:05:261505bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381506 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121507}
1508
[email protected]a9c81f02012-06-01 00:15:441509void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1510 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371511 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441512 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371513 } else {
1514 GotResponseToLockMouseRequest(false);
1515 }
1516}
1517
[email protected]b172aee2012-04-10 17:05:261518void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371519 if (delegate_)
1520 delegate_->LostMouseLock();
1521}
1522
[email protected]bafe6cd2012-05-23 23:09:501523void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201524 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501525 int route_id,
[email protected]227692c52013-05-31 22:43:041526 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131527 const ViewHostMsg_CreateWindow_Params& params,
1528 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501529 // We usually create the new window in the same BrowsingInstance (group of
1530 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551531 // if the opener is being suppressed (in a non-guest), we create a new
1532 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251533 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551534
[email protected]04cbd3d2013-12-04 04:58:201535 // If the opener is to be suppressed, the new window can be in any process.
1536 // Since routing ids are process specific, we must not have one passed in
1537 // as argument here.
1538 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1539
[email protected]bafe6cd2012-05-23 23:09:501540 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551541 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571542 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501543 GetSiteInstance();
1544
[email protected]04cbd3d2013-12-04 04:58:201545 // A message to create a new window can only come from the active process for
1546 // this WebContentsImpl instance. If any other process sends the request,
1547 // it is invalid and the process must be terminated.
1548 if (GetRenderProcessHost()->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351549 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1550 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201551 if (process_handle != base::kNullProcessHandle) {
1552 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391553 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351554 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201555 }
1556 return;
1557 }
1558
[email protected]d1198fd2012-08-13 22:50:191559 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341560 //
1561 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301562 const std::string& partition_id =
1563 GetContentClient()->browser()->
1564 GetStoragePartitionIdForSite(GetBrowserContext(),
1565 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461566 StoragePartition* partition = BrowserContext::GetStoragePartition(
1567 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411568 DOMStorageContextWrapper* dom_storage_context =
1569 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191570 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1571 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1572 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371573
1574 if (delegate_ &&
1575 !delegate_->ShouldCreateWebContents(this,
1576 route_id,
avic2c29d782014-12-12 00:23:541577 main_frame_route_id,
[email protected]dd6730412013-08-14 15:03:371578 params.window_container_type,
1579 params.frame_name,
1580 params.target_url,
1581 partition_id,
1582 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011583 if (route_id != MSG_ROUTING_NONE &&
1584 !RenderViewHost::FromID(render_process_id, route_id)) {
1585 // If the embedder didn't create a WebContents for this route, we need to
1586 // delete the RenderView that had already been created.
1587 Send(new ViewMsg_Close(route_id));
1588 }
[email protected]dd6730412013-08-14 15:03:371589 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1590 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1591 main_frame_route_id);
1592 return;
1593 }
1594
1595 // Create the new web contents. This will automatically create the new
1596 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461597 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591598 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041599 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061600 create_params.opener = this;
1601 create_params.opener_suppressed = params.opener_suppressed;
1602 if (params.disposition == NEW_BACKGROUND_TAB)
1603 create_params.initially_hidden = true;
1604
[email protected]4858e432014-06-23 18:14:171605 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551606 if (!is_guest) {
1607 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451608 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171609 new_contents = static_cast<WebContentsImpl*>(
1610 WebContents::Create(create_params));
1611 } else {
1612 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551613 }
[email protected]50d326e2014-05-20 17:59:061614 new_contents->GetController().SetSessionStorageNamespace(
1615 partition_id,
1616 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261617 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191618
[email protected]c4538072013-03-18 02:17:551619 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341620 // will be shown immediately).
1621 if (!params.opener_suppressed) {
1622 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451623 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501624
[email protected]d70bea92013-04-05 04:23:341625 // TODO(brettw): It seems bogus that we have to call this function on the
1626 // newly created object and give it one of its own member variables.
lazyboy549b3b42014-10-20 17:16:041627 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false);
[email protected]d70bea92013-04-05 04:23:341628 }
[email protected]bafe6cd2012-05-23 23:09:501629 // Save the created window associated with the route so we can show it
1630 // later.
1631 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1632 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101633 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501634 }
1635
1636 if (delegate_) {
1637 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071638 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131639 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501640 }
1641
1642 if (params.opener_suppressed) {
1643 // When the opener is suppressed, the original renderer cannot access the
1644 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001645 bool was_blocked = false;
1646 if (delegate_) {
bokan107a47f2015-02-03 23:23:391647 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001648 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391649 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001650 params.user_gesture, &was_blocked);
1651 }
1652 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211653 OpenURLParams open_params(params.target_url,
1654 Referrer(),
1655 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351656 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211657 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301658 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001659 new_contents->OpenURL(open_params);
1660 }
[email protected]bafe6cd2012-05-23 23:09:501661 }
1662}
1663
[email protected]a8504022013-12-04 20:23:511664void WebContentsImpl::CreateNewWidget(int render_process_id,
1665 int route_id,
[email protected]180ef242013-11-07 06:50:461666 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511667 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501668}
1669
[email protected]a8504022013-12-04 20:23:511670void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1671 int route_id) {
1672 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501673}
1674
[email protected]a8504022013-12-04 20:23:511675void WebContentsImpl::CreateNewWidget(int render_process_id,
1676 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501677 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461678 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211679 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511680 // A message to create a new widget can only come from the active process for
1681 // this WebContentsImpl instance. If any other process sends the request,
1682 // it is invalid and the process must be terminated.
1683 if (process->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351684 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1685 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511686 if (process_handle != base::kNullProcessHandle) {
1687 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391688 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351689 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511690 }
1691 return;
1692 }
1693
[email protected]bafe6cd2012-05-23 23:09:501694 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041695 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261696 created_widgets_.insert(widget_host);
1697
[email protected]cfd80b02014-05-01 17:46:481698 RenderWidgetHostViewBase* widget_view =
1699 static_cast<RenderWidgetHostViewBase*>(
1700 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191701 if (!widget_view)
1702 return;
[email protected]bafe6cd2012-05-23 23:09:501703 if (!is_fullscreen) {
1704 // Popups should not get activated.
1705 widget_view->SetPopupType(popup_type);
1706 }
1707 // Save the created widget associated with the route so we can show it later.
1708 pending_widget_views_[route_id] = widget_view;
1709
1710#if defined(OS_MACOSX)
1711 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1712 // to allow it to survive the trip without being hosted.
1713 base::mac::NSObjectRetain(widget_view->GetNativeView());
1714#endif
1715}
1716
1717void WebContentsImpl::ShowCreatedWindow(int route_id,
1718 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:391719 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:501720 bool user_gesture) {
1721 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001722 if (contents) {
1723 WebContentsDelegate* delegate = GetDelegate();
1724 if (delegate) {
1725 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:391726 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:001727 }
1728 }
[email protected]bafe6cd2012-05-23 23:09:501729}
1730
1731void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:391732 const gfx::Rect& initial_rect) {
1733 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:501734}
1735
1736void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1737 ShowCreatedWidget(route_id, true, gfx::Rect());
1738}
1739
1740void WebContentsImpl::ShowCreatedWidget(int route_id,
1741 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:391742 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:481743 RenderWidgetHostViewBase* widget_host_view =
1744 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501745 if (!widget_host_view)
1746 return;
[email protected]cfd80b02014-05-01 17:46:481747
1748 RenderWidgetHostView* view = NULL;
1749 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1750 if (guest && guest->embedder_web_contents()) {
1751 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1752 } else {
1753 view = GetRenderWidgetHostView();
1754 }
1755
[email protected]4aebbca2013-09-17 22:26:491756 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311757 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031758 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311759 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491760 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1761 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:531762 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:491763 } else {
[email protected]cfd80b02014-05-01 17:46:481764 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491765 }
[email protected]4aebbca2013-09-17 22:26:491766 FOR_EACH_OBSERVER(WebContentsObserver,
1767 observers_,
1768 DidShowFullscreenWidget(route_id));
1769 if (!widget_host_view->HasFocus())
1770 widget_host_view->Focus();
1771 } else {
bokan107a47f2015-02-03 23:23:391772 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:491773 }
[email protected]89054502012-06-03 10:29:241774
1775 RenderWidgetHostImpl* render_widget_host_impl =
1776 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1777 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311778 // Only allow privileged mouse lock for fullscreen render widget, which is
1779 // used to implement Pepper Flash fullscreen.
1780 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501781
1782#if defined(OS_MACOSX)
1783 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1784 // properly embedded (or purposefully ignored) we can release the retain we
1785 // took in CreateNewWidget().
1786 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1787#endif
1788}
1789
1790WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1791 PendingContents::iterator iter = pending_contents_.find(route_id);
1792
1793 // Certain systems can block the creation of new windows. If we didn't succeed
1794 // in creating one, just return NULL.
1795 if (iter == pending_contents_.end()) {
1796 return NULL;
1797 }
1798
1799 WebContentsImpl* new_contents = iter->second;
1800 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101801 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501802
[email protected]d70bea92013-04-05 04:23:341803 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251804 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341805 return new_contents;
1806
[email protected]bafe6cd2012-05-23 23:09:501807 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1808 !new_contents->GetRenderViewHost()->GetView())
1809 return NULL;
1810
creis82dd6af2014-09-17 16:30:451811 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501812 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1813 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
creis82dd6af2014-09-17 16:30:451814 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
1815
[email protected]bafe6cd2012-05-23 23:09:501816 return new_contents;
1817}
1818
1819RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1820 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1821 if (iter == pending_widget_views_.end()) {
1822 DCHECK(false);
1823 return NULL;
1824 }
1825
1826 RenderWidgetHostView* widget_host_view = iter->second;
1827 pending_widget_views_.erase(route_id);
1828
1829 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1830 if (!widget_host->GetProcess()->HasConnection()) {
1831 // The view has gone away or the renderer crashed. Nothing to do.
1832 return NULL;
1833 }
1834
1835 return widget_host_view;
1836}
1837
[email protected]f13b4202012-06-12 23:53:231838void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091839 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211840 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371841 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231842 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371843 } else {
1844 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041845 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371846 scoped_ptr<MediaStreamUI>());
1847 }
[email protected]f13b4202012-06-12 23:53:231848}
1849
grunell657d4d82014-09-18 00:09:431850bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1851 MediaStreamType type) {
1852 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1853 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1854 return delegate_ &&
1855 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1856}
1857
[email protected]cc9200432013-07-23 23:02:401858SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1859 SiteInstance* instance) {
1860 return controller_.GetSessionStorageNamespace(instance);
1861}
1862
[email protected]6de7fc482014-06-06 10:46:441863SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1864 return controller_.GetSessionStorageNamespaceMap();
1865}
1866
[email protected]9b159a52013-10-03 17:24:551867FrameTree* WebContentsImpl::GetFrameTree() {
1868 return &frame_tree_;
1869}
1870
lukendc35e7f2014-11-10 19:06:141871void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
1872 virtual_keyboard_requested_ = requested;
1873}
1874
1875bool WebContentsImpl::IsVirtualKeyboardRequested() {
1876 return virtual_keyboard_requested_;
1877}
1878
[email protected]95640212014-07-26 18:14:301879AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1880 return accessibility_mode_;
1881}
1882
[email protected]31a71eaf2014-03-13 01:47:361883void WebContentsImpl::AccessibilityEventReceived(
1884 const std::vector<AXEventNotificationDetails>& details) {
1885 FOR_EACH_OBSERVER(
1886 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1887}
1888
dmazzonia656928e2014-09-15 20:28:541889RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
1890 int browser_plugin_instance_id) {
1891 BrowserPluginGuestManager* guest_manager =
1892 GetBrowserContext()->GetGuestManager();
1893 WebContents* guest = guest_manager->GetGuestByInstanceID(
1894 this, browser_plugin_instance_id);
1895 if (!guest)
1896 return NULL;
1897 return guest->GetMainFrame();
1898}
1899
blundellc57b93f2014-10-29 13:19:571900GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
1901 return geolocation_service_context_.get();
1902}
1903
[email protected]edc3af82013-12-12 21:24:071904void WebContentsImpl::OnShowValidationMessage(
1905 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291906 const base::string16& main_text,
1907 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071908 if (delegate_)
1909 delegate_->ShowValidationMessage(
1910 this, anchor_in_root_view, main_text, sub_text);
1911}
1912
1913void WebContentsImpl::OnHideValidationMessage() {
1914 if (delegate_)
1915 delegate_->HideValidationMessage(this);
1916}
1917
1918void WebContentsImpl::OnMoveValidationMessage(
1919 const gfx::Rect& anchor_in_root_view) {
1920 if (delegate_)
1921 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1922}
1923
[email protected]32deec62013-05-15 23:55:041924void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1925 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441926 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041927}
1928
[email protected]95640212014-07-26 18:14:301929BrowserAccessibilityManager*
1930 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1931 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1932 return rfh ? rfh->browser_accessibility_manager() : NULL;
1933}
1934
1935BrowserAccessibilityManager*
1936 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1937 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1938 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1939}
1940
[email protected]b172aee2012-04-10 17:05:261941void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491942 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231943 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491944 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331945}
1946
[email protected]b172aee2012-04-10 17:05:261947void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341948 if (delegate_)
1949 delegate_->ResizeDueToAutoResize(this, new_size);
1950}
1951
[email protected]b172aee2012-04-10 17:05:261952WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201953 if (!delegate_)
1954 return NULL;
[email protected]00c37fc2011-08-02 00:22:501955
[email protected]e5d549d2011-12-28 01:29:201956 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201957 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341958}
1959
[email protected]6b618e62012-08-16 12:59:181960bool WebContentsImpl::Send(IPC::Message* message) {
1961 if (!GetRenderViewHost()) {
1962 delete message;
1963 return false;
1964 }
1965
1966 return GetRenderViewHost()->Send(message);
1967}
1968
[email protected]b172aee2012-04-10 17:05:261969bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501970 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261971 FrameTreeNode* node = frame_tree_.root();
1972
creise42f2a52014-09-18 18:14:571973 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
1974 // is currently only used in --site-per-process and tests.
[email protected]61ac9e242014-03-21 20:55:261975 NavigationEntryImpl* pending_entry =
1976 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
creise42f2a52014-09-18 18:14:571977 if (pending_entry->frame_tree_node_id() != -1) {
1978 FrameTreeNode* subframe =
1979 frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1980 DCHECK(subframe);
1981 if (subframe)
1982 node = subframe;
[email protected]61ac9e242014-03-21 20:55:261983 }
1984
1985 return node->navigator()->NavigateToPendingEntry(
1986 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541987}
[email protected]96d185d2009-04-24 03:28:541988
[email protected]a86c0e962013-12-17 17:10:391989void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1990 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441991 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391992 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441993}
1994
[email protected]20ca0382013-02-28 19:50:071995void WebContentsImpl::AttachInterstitialPage(
1996 InterstitialPageImpl* interstitial_page) {
1997 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211998 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291999
2000 // Cancel any visible dialogs so that they don't interfere with the
2001 // interstitial.
2002 if (dialog_manager_)
2003 dialog_manager_->CancelActiveAndPendingDialogs(this);
2004
[email protected]20ca0382013-02-28 19:50:072005 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2006 DidAttachInterstitialPage());
2007}
2008
2009void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:572010 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212011 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072012 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2013 DidDetachInterstitialPage());
2014}
2015
avi2b177592014-12-10 02:08:022016void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2017 int history_length) {
2018 SetHistoryOffsetAndLengthForView(
2019 GetRenderViewHost(), history_offset, history_length);
2020}
2021
2022void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2023 RenderViewHost* render_view_host,
2024 int history_offset,
2025 int history_length) {
2026 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2027 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142028}
2029
[email protected]4fed3702014-04-01 09:08:002030void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172031 RenderFrameHost* focused_frame = GetFocusedFrame();
2032 if (!focused_frame)
2033 return;
2034
[email protected]959be4c2014-04-08 15:01:332035 focused_frame->Send(new FrameMsg_Reload(
2036 focused_frame->GetRoutingID(), ignore_cache));
2037}
2038
2039void WebContentsImpl::Undo() {
2040 RenderFrameHost* focused_frame = GetFocusedFrame();
2041 if (!focused_frame)
2042 return;
2043
2044 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2045 RecordAction(base::UserMetricsAction("Undo"));
2046}
2047
2048void WebContentsImpl::Redo() {
2049 RenderFrameHost* focused_frame = GetFocusedFrame();
2050 if (!focused_frame)
2051 return;
2052 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2053 RecordAction(base::UserMetricsAction("Redo"));
2054}
2055
2056void WebContentsImpl::Cut() {
2057 RenderFrameHost* focused_frame = GetFocusedFrame();
2058 if (!focused_frame)
2059 return;
2060
2061 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2062 RecordAction(base::UserMetricsAction("Cut"));
2063}
2064
2065void WebContentsImpl::Copy() {
2066 RenderFrameHost* focused_frame = GetFocusedFrame();
2067 if (!focused_frame)
2068 return;
2069
2070 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2071 RecordAction(base::UserMetricsAction("Copy"));
2072}
2073
2074void WebContentsImpl::CopyToFindPboard() {
2075#if defined(OS_MACOSX)
2076 RenderFrameHost* focused_frame = GetFocusedFrame();
2077 if (!focused_frame)
2078 return;
2079
2080 // Windows/Linux don't have the concept of a find pasteboard.
2081 focused_frame->Send(
2082 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2083 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2084#endif
2085}
2086
2087void WebContentsImpl::Paste() {
2088 RenderFrameHost* focused_frame = GetFocusedFrame();
2089 if (!focused_frame)
2090 return;
2091
2092 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2093 RecordAction(base::UserMetricsAction("Paste"));
2094}
2095
2096void WebContentsImpl::PasteAndMatchStyle() {
2097 RenderFrameHost* focused_frame = GetFocusedFrame();
2098 if (!focused_frame)
2099 return;
2100
2101 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2102 focused_frame->GetRoutingID()));
2103 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2104}
2105
2106void WebContentsImpl::Delete() {
2107 RenderFrameHost* focused_frame = GetFocusedFrame();
2108 if (!focused_frame)
2109 return;
2110
2111 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2112 RecordAction(base::UserMetricsAction("DeleteSelection"));
2113}
2114
2115void WebContentsImpl::SelectAll() {
2116 RenderFrameHost* focused_frame = GetFocusedFrame();
2117 if (!focused_frame)
2118 return;
2119
2120 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2121 RecordAction(base::UserMetricsAction("SelectAll"));
2122}
2123
2124void WebContentsImpl::Unselect() {
2125 RenderFrameHost* focused_frame = GetFocusedFrame();
2126 if (!focused_frame)
2127 return;
2128
2129 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2130 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172131}
2132
2133void WebContentsImpl::Replace(const base::string16& word) {
2134 RenderFrameHost* focused_frame = GetFocusedFrame();
2135 if (!focused_frame)
2136 return;
2137
[email protected]959be4c2014-04-08 15:01:332138 focused_frame->Send(new InputMsg_Replace(
2139 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172140}
2141
2142void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2143 RenderFrameHost* focused_frame = GetFocusedFrame();
2144 if (!focused_frame)
2145 return;
2146
[email protected]959be4c2014-04-08 15:01:332147 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2148 focused_frame->GetRoutingID(), word));
2149}
2150
2151void WebContentsImpl::NotifyContextMenuClosed(
2152 const CustomContextMenuContext& context) {
2153 RenderFrameHost* focused_frame = GetFocusedFrame();
2154 if (!focused_frame)
2155 return;
2156
2157 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2158 focused_frame->GetRoutingID(), context));
2159}
2160
2161void WebContentsImpl::ExecuteCustomContextMenuCommand(
2162 int action, const CustomContextMenuContext& context) {
2163 RenderFrameHost* focused_frame = GetFocusedFrame();
2164 if (!focused_frame)
2165 return;
2166
2167 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2168 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002169}
2170
[email protected]fc2b46b2014-05-03 16:33:452171gfx::NativeView WebContentsImpl::GetNativeView() {
2172 return view_->GetNativeView();
2173}
2174
2175gfx::NativeView WebContentsImpl::GetContentNativeView() {
2176 return view_->GetContentNativeView();
2177}
2178
2179gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2180 return view_->GetTopLevelNativeWindow();
2181}
2182
2183gfx::Rect WebContentsImpl::GetViewBounds() {
2184 return view_->GetViewBounds();
2185}
2186
2187gfx::Rect WebContentsImpl::GetContainerBounds() {
2188 gfx::Rect rv;
2189 view_->GetContainerBounds(&rv);
2190 return rv;
2191}
2192
2193DropData* WebContentsImpl::GetDropData() {
2194 return view_->GetDropData();
2195}
2196
2197void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042198 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452199}
2200
2201void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042202 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452203}
2204
2205void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042206 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452207}
2208
2209void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042210 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452211}
2212
[email protected]b172aee2012-04-10 17:05:262213void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272214 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212215 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542216 return;
2217 }
[email protected]0b431992014-06-24 00:08:032218 RenderWidgetHostView* const fullscreen_view =
2219 GetFullscreenRenderWidgetHostView();
2220 if (fullscreen_view) {
2221 fullscreen_view->Focus();
2222 return;
2223 }
[email protected]9f76c1e2012-03-05 15:15:582224 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542225}
2226
[email protected]b172aee2012-04-10 17:05:262227bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212228 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542229}
2230
[email protected]b172aee2012-04-10 17:05:262231InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212232 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222233}
2234
[email protected]b172aee2012-04-10 17:05:262235bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162236 // WebKit creates Document object when MIME type is application/xhtml+xml,
2237 // so we also support this MIME type.
2238 return contents_mime_type_ == "text/html" ||
2239 contents_mime_type_ == "text/xml" ||
2240 contents_mime_type_ == "application/xhtml+xml" ||
2241 contents_mime_type_ == "text/plain" ||
2242 contents_mime_type_ == "text/css" ||
2243 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2244}
2245
[email protected]b172aee2012-04-10 17:05:262246void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592247 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162248 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552249 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012250 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142251 return;
[email protected]c7dd2f62011-07-18 15:57:592252 }
2253
2254 Stop();
2255
2256 // Create the save package and possibly prompt the user for the name to save
2257 // the page as. The user prompt is an asynchronous operation that runs on
2258 // another thread.
2259 save_package_ = new SavePackage(this);
2260 save_package_->GetSaveInfo();
2261}
2262
2263// Used in automated testing to bypass prompting the user for file names.
2264// Instead, the names and paths are hard coded rather than running them through
2265// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342266bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2267 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212268 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592269 // Stop the page from navigating.
2270 Stop();
2271
2272 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212273 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592274}
2275
[email protected]3c71576ce2013-07-23 02:00:012276void WebContentsImpl::SaveFrame(const GURL& url,
2277 const Referrer& referrer) {
2278 if (!GetURL().is_valid())
2279 return;
sammc92af61552014-11-19 23:27:402280 if (delegate_ && delegate_->SaveFrame(url, referrer))
2281 return;
2282
[email protected]3c71576ce2013-07-23 02:00:012283 bool is_main_frame = (url == GetURL());
2284
2285 DownloadManager* dlm =
2286 BrowserContext::GetDownloadManager(GetBrowserContext());
2287 if (!dlm)
2288 return;
2289 int64 post_id = -1;
2290 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272291 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012292 if (entry)
2293 post_id = entry->GetPostID();
2294 }
2295 scoped_ptr<DownloadUrlParameters> params(
2296 DownloadUrlParameters::FromWebContents(this, url));
2297 params->set_referrer(referrer);
2298 params->set_post_id(post_id);
2299 params->set_prefer_cache(true);
2300 if (post_id >= 0)
2301 params->set_method("POST");
2302 params->set_prompt(true);
2303 dlm->DownloadUrl(params.Pass());
2304}
2305
[email protected]b172aee2012-04-10 17:05:262306void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342307 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482308 const base::Callback<void(int64)>& callback) {
2309 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122310}
2311
[email protected]b172aee2012-04-10 17:05:262312const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272313 return contents_mime_type_;
2314}
2315
[email protected]b172aee2012-04-10 17:05:262316bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272317 return notify_disconnection_;
2318}
2319
[email protected]b172aee2012-04-10 17:05:262320void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312321 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182322 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162323}
2324
[email protected]b172aee2012-04-10 17:05:262325void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542326 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182327 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162328}
2329
[email protected]8ff00d72012-10-23 19:12:212330RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272331 return &renderer_preferences_;
2332}
2333
[email protected]e35ccd52012-05-23 16:22:472334void WebContentsImpl::Close() {
2335 Close(GetRenderViewHost());
2336}
2337
[email protected]cf200a562013-05-03 16:24:292338void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462339 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292340 if (browser_plugin_embedder_.get())
2341 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2342 screen_x, screen_y, operation);
2343 if (GetRenderViewHost())
2344 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2345 screen_x, screen_y, operation);
2346}
2347
[email protected]d60f3702013-12-26 16:30:242348void WebContentsImpl::DidGetResourceResponseStart(
2349 const ResourceRequestDetails& details) {
2350 controller_.ssl_manager()->DidStartResourceResponse(details);
2351
2352 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2353 DidGetResourceResponseStart(details));
2354
2355 // TODO(avi): Remove. http://crbug.com/170921
2356 NotificationService::current()->Notify(
2357 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2358 Source<WebContents>(this),
2359 Details<const ResourceRequestDetails>(&details));
2360}
2361
2362void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462363 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242364 const ResourceRedirectDetails& details) {
2365 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2366
2367 FOR_EACH_OBSERVER(
2368 WebContentsObserver,
2369 observers_,
creis114ca1b2014-11-13 23:51:462370 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242371
2372 // TODO(avi): Remove. http://crbug.com/170921
2373 NotificationService::current()->Notify(
2374 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2375 Source<WebContents>(this),
2376 Details<const ResourceRedirectDetails>(&details));
2377}
2378
[email protected]b172aee2012-04-10 17:05:262379void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522380 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582381 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512382 if (delegate_)
2383 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292384 if (browser_plugin_embedder_.get())
2385 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342386}
2387
[email protected]e35ccd52012-05-23 16:22:472388void WebContentsImpl::UserGestureDone() {
2389 OnUserGesture();
2390}
2391
[email protected]b172aee2012-04-10 17:05:262392void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272393 closed_by_user_gesture_ = value;
2394}
2395
[email protected]b172aee2012-04-10 17:05:262396bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272397 return closed_by_user_gesture_;
2398}
2399
[email protected]b172aee2012-04-10 17:05:262400void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502401 if (!delegate_)
2402 return;
2403
[email protected]6286a372013-10-09 04:03:272404 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2405 if (!entry)
[email protected]1788e772010-12-15 16:40:502406 return;
2407
[email protected]6286a372013-10-09 04:03:272408 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122409}
2410
[email protected]b172aee2012-04-10 17:05:262411void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042412 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272413 if (!delegate_)
2414 return;
2415
[email protected]691aa2f2013-05-28 22:52:042416 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272417}
2418
[email protected]b172aee2012-04-10 17:05:262419int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272420 return minimum_zoom_percent_;
2421}
2422
[email protected]b172aee2012-04-10 17:05:262423int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272424 return maximum_zoom_percent_;
2425}
2426
[email protected]b172aee2012-04-10 17:05:262427gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492428 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232429}
2430
[email protected]b172aee2012-04-10 17:05:262431bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052432 if (GetBrowserPluginGuest())
2433 return GetBrowserPluginGuest()->LockMouse(allowed);
2434
[email protected]0bfbf882011-12-22 18:19:272435 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582436 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272437}
2438
[email protected]b172aee2012-04-10 17:05:262439bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442440 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502441}
2442
jochen55ff3502014-12-18 20:52:572443WebContents* WebContentsImpl::GetOpener() const {
2444 return static_cast<WebContents*>(opener_);
2445}
2446
[email protected]cb805452013-05-22 15:16:212447void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482448 if (!color_chooser_info_.get())
2449 return;
2450 RenderFrameHost* rfh = RenderFrameHost::FromID(
2451 color_chooser_info_->render_process_id,
2452 color_chooser_info_->render_frame_id);
2453 if (!rfh)
2454 return;
2455
2456 rfh->Send(new FrameMsg_DidChooseColorResponse(
2457 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202458}
2459
[email protected]cb805452013-05-22 15:16:212460void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482461 if (!color_chooser_info_.get())
2462 return;
2463 RenderFrameHost* rfh = RenderFrameHost::FromID(
2464 color_chooser_info_->render_process_id,
2465 color_chooser_info_->render_frame_id);
2466 if (!rfh)
2467 return;
2468
2469 rfh->Send(new FrameMsg_DidEndColorChooser(
2470 rfh->GetRoutingID(), color_chooser_info_->identifier));
2471 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202472}
2473
[email protected]41225fe2013-03-29 05:32:022474int WebContentsImpl::DownloadImage(const GURL& url,
2475 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302476 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022477 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582478 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022479 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392480 return id;
2481}
2482
[email protected]5dcaf8e2013-12-28 01:31:422483bool WebContentsImpl::IsSubframe() const {
2484 return is_subframe_;
2485}
2486
[email protected]36ec24f2014-01-09 00:32:082487void WebContentsImpl::Find(int request_id,
2488 const base::string16& search_text,
2489 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092490 // See if a top level browser plugin handles the find request first.
2491 if (browser_plugin_embedder_ &&
2492 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2493 return;
2494 }
[email protected]36ec24f2014-01-09 00:32:082495 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2496}
2497
2498void WebContentsImpl::StopFinding(StopFindAction action) {
2499 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2500}
2501
[email protected]4fe53add2014-04-08 19:53:362502void WebContentsImpl::InsertCSS(const std::string& css) {
2503 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2504 GetMainFrame()->GetRoutingID(), css));
2505}
2506
dalecurtisbc6572e12014-09-12 19:22:302507bool WebContentsImpl::WasRecentlyAudible() {
2508 return audio_stream_monitor_.WasRecentlyAudible();
2509}
2510
mlamouriefdca9d2014-09-16 16:55:402511void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2512 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2513}
2514
mlamouri7a78d6fd2015-01-17 13:23:532515void WebContentsImpl::ExitFullscreen() {
2516 // Clean up related state and initiate the fullscreen exit.
2517 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary();
2518 ExitFullscreenMode();
2519}
2520
[email protected]b172aee2012-04-10 17:05:262521bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272522 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172523 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332524 return true;
2525 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272526}
2527
[email protected]b172aee2012-04-10 17:05:262528void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272529 if (delegate_)
2530 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212531}
2532
[email protected]52913802013-12-10 05:52:182533void WebContentsImpl::DidStartProvisionalLoad(
2534 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182535 const GURL& validated_url,
2536 bool is_error_page,
2537 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102538 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482539 FOR_EACH_OBSERVER(
2540 WebContentsObserver,
2541 observers_,
2542 DidStartProvisionalLoadForFrame(
2543 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
[email protected]400992b2012-06-14 00:03:542544}
2545
[email protected]0c3c54f2014-07-31 01:29:002546void WebContentsImpl::DidStartNavigationTransition(
morritaffb82612014-10-31 18:26:592547 RenderFrameHostImpl* render_frame_host) {
[email protected]0c3c54f2014-07-31 01:29:002548#if defined(OS_ANDROID)
2549 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562550 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
morritaffb82612014-10-31 18:26:592551 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002552#endif
2553}
2554
[email protected]3109fbb72014-01-06 23:57:152555void WebContentsImpl::DidFailProvisionalLoadWithError(
2556 RenderFrameHostImpl* render_frame_host,
2557 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2558 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312559 FOR_EACH_OBSERVER(WebContentsObserver,
2560 observers_,
2561 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312562 validated_url,
2563 params.error_code,
2564 params.error_description));
[email protected]3109fbb72014-01-06 23:57:152565}
2566
[email protected]b80624c2014-02-09 02:46:552567void WebContentsImpl::DidFailLoadWithError(
2568 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552569 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552570 int error_code,
2571 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142572 FOR_EACH_OBSERVER(
2573 WebContentsObserver,
2574 observers_,
2575 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552576}
2577
[email protected]52913802013-12-10 05:52:182578void WebContentsImpl::NotifyChangedNavigationState(
2579 InvalidateTypes changed_flags) {
2580 NotifyNavigationStateChanged(changed_flags);
2581}
2582
[email protected]3691e5cf2014-01-22 10:16:202583void WebContentsImpl::AboutToNavigateRenderFrame(
pfeldmanf87691a2015-01-23 16:58:172584 RenderFrameHostImpl* old_host,
2585 RenderFrameHostImpl* new_host) {
creis114ca1b2014-11-13 23:51:462586 // Notify observers that we will navigate in this RenderFrame.
[email protected]3691e5cf2014-01-22 10:16:202587 FOR_EACH_OBSERVER(
2588 WebContentsObserver,
2589 observers_,
pfeldmanf87691a2015-01-23 16:58:172590 AboutToNavigateRenderFrame(old_host, new_host));
[email protected]3691e5cf2014-01-22 10:16:202591}
2592
2593void WebContentsImpl::DidStartNavigationToPendingEntry(
2594 RenderFrameHostImpl* render_frame_host,
2595 const GURL& url,
2596 NavigationController::ReloadType reload_type) {
2597 // Notify observers about navigation.
2598 FOR_EACH_OBSERVER(
2599 WebContentsObserver,
2600 observers_,
2601 DidStartNavigationToPendingEntry(url, reload_type));
2602}
2603
[email protected]8cb834e2014-03-06 14:23:232604void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2605 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:502606 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
2607 // weak pointer of sorts.
2608 const int32_t process_id = render_frame_host->GetProcess()->GetID();
2609 const int32_t frame_id = render_frame_host->GetRoutingID();
2610
[email protected]65920f332014-03-04 21:14:182611 WebContents* new_contents = OpenURL(params);
2612
dchengb907f7332015-01-07 20:35:502613 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:182614 // Notify observers.
2615 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2616 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:462617 render_frame_host,
[email protected]65920f332014-03-04 21:14:182618 params.url,
2619 params.referrer,
2620 params.disposition,
creis114ca1b2014-11-13 23:51:462621 params.transition));
[email protected]65920f332014-03-04 21:14:182622 }
2623}
2624
[email protected]aa62afd2014-04-22 19:22:462625bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2626 if (!delegate_)
2627 return false;
2628 return delegate_->ShouldPreserveAbortedURLs(this);
2629}
2630
[email protected]37567b432014-02-12 01:12:222631void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432632 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222633 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352634 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222635 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482636 FOR_EACH_OBSERVER(WebContentsObserver,
2637 observers_,
2638 DidCommitProvisionalLoadForFrame(
2639 render_frame_host, url, transition_type));
[email protected]37567b432014-02-12 01:12:222640}
2641
[email protected]0d0f4c492014-04-02 06:42:572642void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232643 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572644 // Ensure fullscreen mode is exited before committing the navigation to a
2645 // different page. The next page will not start out assuming it is in
2646 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232647 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192648 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572649 return;
2650 }
2651 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:532652 ExitFullscreen();
[email protected]0d0f4c492014-04-02 06:42:572653 DCHECK(!IsFullscreenForCurrentTab());
2654}
2655
[email protected]37567b432014-02-12 01:12:222656void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:282657 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222658 const LoadCommittedDetails& details,
2659 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2660 if (details.is_navigation_to_different_page()) {
2661 // Clear the status bubble. This is a workaround for a bug where WebKit
2662 // doesn't let us know that the cursor left an element during a
2663 // transition (this is also why the mouse cursor remains as a hand after
2664 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2665 // clear the bubble when a user navigates to a named anchor in the same
2666 // page.
sky8b00392d2015-01-10 00:30:282667 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
[email protected]37567b432014-02-12 01:12:222668 }
2669
2670 if (!details.is_in_page) {
2671 // Once the main frame is navigated, we're no longer considered to have
2672 // displayed insecure content.
2673 displayed_insecure_content_ = false;
2674 SSLManager::NotifySSLInternalStateChanged(
2675 GetController().GetBrowserContext());
2676 }
2677
2678 // Notify observers about navigation.
2679 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2680 DidNavigateMainFrame(details, params));
2681
[email protected]e85165c642014-06-10 14:34:312682 if (delegate_)
[email protected]37567b432014-02-12 01:12:222683 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312684 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222685}
2686
2687void WebContentsImpl::DidNavigateAnyFramePostCommit(
2688 RenderFrameHostImpl* render_frame_host,
2689 const LoadCommittedDetails& details,
2690 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102691 // Now that something has committed, we don't need to track whether the
2692 // initial page has been accessed.
2693 has_accessed_initial_document_ = false;
2694
[email protected]37567b432014-02-12 01:12:222695 // If we navigate off the page, close all JavaScript dialogs.
2696 if (dialog_manager_ && !details.is_in_page)
2697 dialog_manager_->CancelActiveAndPendingDialogs(this);
2698
2699 // Notify observers about navigation.
2700 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:092701 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:222702}
2703
2704void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2705 contents_mime_type_ = mime_type;
2706}
2707
[email protected]277857a2014-06-03 10:38:012708bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312709 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052710 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312711 return false;
2712
[email protected]37567b432014-02-12 01:12:222713 if (delegate_)
2714 return delegate_->CanOverscrollContent();
2715
2716 return false;
2717}
2718
[email protected]37b64c52014-07-11 21:14:052719void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252720 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052721 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252722}
2723
[email protected]b172aee2012-04-10 17:05:262724void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182725 const GURL& url,
[email protected]70435962011-08-02 20:13:282726 const std::string& security_info,
2727 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182728 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402729 ResourceType resource_type) {
[email protected]28620862011-03-22 23:07:192730 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182731 cache.Increment();
2732
2733 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082734 int cert_id = 0;
2735 net::CertStatus cert_status = 0;
2736 int security_bits = -1;
2737 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122738 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212739 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122740 &security_bits, &connection_status,
2741 &signed_certificate_timestamp_ids);
2742 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212743 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002744 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2745 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182746
[email protected]b0f724c2013-09-05 04:21:132747 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2748
2749 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2750 DidLoadResourceFromMemoryCache(details));
2751
[email protected]8bfc8272013-09-09 20:10:532752 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2753 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402754 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532755 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2756 GetRenderProcessHost()->GetID()) :
2757 GetBrowserContext()->GetRequestContextForRenderProcess(
2758 GetRenderProcessHost()->GetID()));
2759 BrowserThread::PostTask(
2760 BrowserThread::IO,
2761 FROM_HERE,
2762 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2763 }
[email protected]724159a2010-12-30 01:11:182764}
2765
[email protected]b172aee2012-04-10 17:05:262766void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392767 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182768 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192769 SSLManager::NotifySSLInternalStateChanged(
2770 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182771}
2772
[email protected]b172aee2012-04-10 17:05:262773void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022774 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582775 LOG(WARNING) << security_origin << " ran insecure content from "
2776 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392777 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412778 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392779 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182780 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412781 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192782 SSLManager::NotifySSLInternalStateChanged(
2783 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182784}
2785
[email protected]501052ff2014-02-21 22:19:072786void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:112787 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:472788 return;
naskofbd033392015-01-27 02:34:472789
[email protected]1d62cf72014-02-07 21:31:572790 RenderFrameHostImpl* rfh =
2791 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142792 FOR_EACH_OBSERVER(
2793 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182794}
2795
naskofbd033392015-01-27 02:34:472796void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:112797 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:122798 return;
[email protected]a1b99262013-12-27 21:56:222799
[email protected]8b3af1e2014-01-24 13:29:122800 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442801 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372802 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422803 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372804
[email protected]61ac9e242014-03-21 20:55:262805 RenderFrameHostImpl* rfh =
2806 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142807 FOR_EACH_OBSERVER(
2808 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312809}
2810
[email protected]960b0372014-05-19 18:01:002811void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
nasko907fcb62015-01-28 04:24:112812 if (!HasValidFrameSource())
2813 return;
2814
[email protected]960b0372014-05-19 18:01:002815 RenderFrameHostImpl* rfh =
2816 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2817 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2818
creis1163acf2014-12-19 21:18:472819 // Any main frame load to a new document should reset the load progress, since
2820 // it will replace the current page and any frames.
2821 if (to_different_document && !rfh->GetParent()) {
2822 ResetLoadProgressState();
2823 loading_frames_in_progress_ = 0;
naskoa7064ad6e2015-01-15 18:44:562824 rfh->frame_tree_node()->set_is_loading(false);
creis1163acf2014-12-19 21:18:472825 }
2826
[email protected]960b0372014-05-19 18:01:002827 // It is possible to get multiple calls to OnDidStartLoading that don't have
2828 // corresponding calls to OnDidStopLoading:
2829 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2830 // out for a cross-process navigation, and it turns into a placeholder for
2831 // one being rendered in a different process.
2832 // - Also, there might be more than one RenderFrameHost sharing the same
2833 // FrameTreeNode (and thus sharing its ID) each sending a start.
2834 // - But in the future, once clamy@ moves navigation network requests to the
2835 // browser process, there's a good chance that callbacks about starting and
2836 // stopping will all be handled by the browser. When that happens, there
2837 // should no longer be a start/stop call imbalance. TODO(avi): When this
2838 // future arrives, update this code to not allow this case.
naskoa7064ad6e2015-01-15 18:44:562839 if (rfh->frame_tree_node()->is_loading())
2840 return;
2841
[email protected]960b0372014-05-19 18:01:002842 DCHECK_GE(loading_frames_in_progress_, 0);
naskoa7064ad6e2015-01-15 18:44:562843 if (loading_frames_in_progress_ == 0)
2844 DidStartLoading(rfh, to_different_document);
2845
2846 ++loading_frames_in_progress_;
2847 rfh->frame_tree_node()->set_is_loading(true);
[email protected]960b0372014-05-19 18:01:002848
nasko3e8c20e2014-12-18 06:54:562849 // Notify the RenderFrameHostManager of the event.
2850 rfh->frame_tree_node()->render_manager()->OnDidStartLoading();
2851
[email protected]960b0372014-05-19 18:01:002852 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2853 SendLoadProgressChanged();
2854}
2855
2856void WebContentsImpl::OnDidStopLoading() {
nasko907fcb62015-01-28 04:24:112857 if (!HasValidFrameSource())
2858 return;
2859
[email protected]960b0372014-05-19 18:01:002860 RenderFrameHostImpl* rfh =
2861 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2862 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
naskoa7064ad6e2015-01-15 18:44:562863 rfh->frame_tree_node()->set_is_loading(false);
[email protected]960b0372014-05-19 18:01:002864
2865 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2866 // Load stopped while we were still tracking load. Make sure we update
2867 // progress based on this frame's completion.
2868 loading_progresses_[render_frame_id] = 1.0;
2869 SendLoadProgressChanged();
2870 // Then we clean-up our states.
2871 if (loading_total_progress_ == 1.0)
2872 ResetLoadProgressState();
2873 }
2874
nasko3e8c20e2014-12-18 06:54:562875 // Notify the RenderFrameHostManager of the event.
2876 rfh->frame_tree_node()->render_manager()->OnDidStopLoading();
2877
[email protected]960b0372014-05-19 18:01:002878 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2879 // calls DidStopLoading() without a matching DidStartLoading().
2880 if (loading_frames_in_progress_ == 0)
2881 return;
2882 --loading_frames_in_progress_;
2883 if (loading_frames_in_progress_ == 0)
2884 DidStopLoading(rfh);
2885}
2886
2887void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
nasko907fcb62015-01-28 04:24:112888 if (!HasValidFrameSource())
2889 return;
2890
[email protected]960b0372014-05-19 18:01:002891 RenderFrameHostImpl* rfh =
2892 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2893 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2894
2895 loading_progresses_[render_frame_id] = load_progress;
2896
2897 // We notify progress change immediately for the first and last updates.
2898 // Also, since the message loop may be pretty busy when a page is loaded, it
2899 // might not execute a posted task in a timely manner so we make sure to
2900 // immediately send progress report if enough time has passed.
2901 base::TimeDelta min_delay =
2902 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2903 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2904 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2905 // If there is a pending task to send progress, it is now obsolete.
2906 loading_weak_factory_.InvalidateWeakPtrs();
2907 SendLoadProgressChanged();
2908 if (loading_total_progress_ == 1.0)
2909 ResetLoadProgressState();
2910 return;
2911 }
2912
2913 if (loading_weak_factory_.HasWeakPtrs())
2914 return;
2915
2916 base::MessageLoop::current()->PostDelayedTask(
2917 FROM_HERE,
2918 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2919 loading_weak_factory_.GetWeakPtr()),
2920 min_delay);
2921}
2922
[email protected]b172aee2012-04-10 17:05:262923void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222924 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2925 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262926}
2927
[email protected]b172aee2012-04-10 17:05:262928void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302929 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262930 minimum_zoom_percent_ = minimum_percent;
2931 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262932}
2933
[email protected]b172aee2012-04-10 17:05:262934void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342935 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432936 if (!delegate_)
2937 return;
2938
[email protected]b9535422012-02-09 01:47:592939 ChildProcessSecurityPolicyImpl* policy =
2940 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222941 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592942 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212943}
2944
[email protected]b172aee2012-04-10 17:05:262945void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2946 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262947 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362948 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432949 if (!delegate_)
2950 return;
2951
[email protected]b9535422012-02-09 01:47:592952 ChildProcessSecurityPolicyImpl* policy =
2953 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322954 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592955 return;
[email protected]8f810632013-06-06 22:33:322956
[email protected]c125e532014-05-10 20:39:062957 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202958}
2959
[email protected]f5273e52014-07-14 16:30:202960void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2961 const GURL& url,
2962 bool user_gesture) {
2963 if (!delegate_)
2964 return;
2965
2966 ChildProcessSecurityPolicyImpl* policy =
2967 ChildProcessSecurityPolicyImpl::GetInstance();
2968 if (policy->IsPseudoScheme(protocol))
2969 return;
2970
2971 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2972}
2973
[email protected]b172aee2012-04-10 17:05:262974void WebContentsImpl::OnFindReply(int request_id,
2975 int number_of_matches,
2976 const gfx::Rect& selection_rect,
2977 int active_match_ordinal,
2978 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432979 if (delegate_) {
2980 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2981 active_match_ordinal, final_update);
2982 }
[email protected]b888919c2011-09-02 00:32:162983}
2984
[email protected]59363fc92012-09-05 03:46:312985#if defined(OS_ANDROID)
2986void WebContentsImpl::OnFindMatchRectsReply(
2987 int version,
2988 const std::vector<gfx::RectF>& rects,
2989 const gfx::RectF& active_rect) {
2990 if (delegate_)
2991 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2992}
[email protected]583418cc2013-01-17 14:01:102993
[email protected]1ff427972013-02-07 21:14:072994void WebContentsImpl::OnOpenDateTimeDialog(
2995 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:172996 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:092997 GetRenderViewHost(),
2998 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132999 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093000 value.minimum,
3001 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173002 value.step,
3003 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103004}
[email protected]59363fc92012-09-05 03:46:313005#endif
3006
[email protected]cfa856d62014-02-22 07:58:403007void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
3008 int automation_id) {
3009 DomOperationNotificationDetails details(json_string, automation_id);
3010 NotificationService::current()->Notify(
3011 NOTIFICATION_DOM_OPERATION_RESPONSE,
3012 Source<WebContents>(this),
3013 Details<DomOperationNotificationDetails>(&details));
3014}
3015
[email protected]b172aee2012-04-10 17:05:263016void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3017 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103018 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253019 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103020 AppCacheAccessed(manifest_url, blocked_by_policy));
3021}
3022
[email protected]8bc5ff02013-11-29 06:34:033023void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483024 int color_chooser_id,
3025 SkColor color,
3026 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113027 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003028 return;
nasko907fcb62015-01-28 04:24:113029
[email protected]aa62afd2014-04-22 19:22:463030 ColorChooser* new_color_chooser = delegate_ ?
3031 delegate_->OpenColorChooser(this, color, suggestions) :
3032 NULL;
[email protected]820957a2014-01-14 14:56:303033 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213034 return;
[email protected]8ed16472014-04-11 19:02:483035 if (color_chooser_info_.get())
3036 color_chooser_info_->chooser->End();
3037
3038 color_chooser_info_.reset(new ColorChooserInfo(
3039 render_frame_message_source_->GetProcess()->GetID(),
3040 render_frame_message_source_->GetRoutingID(),
3041 new_color_chooser,
3042 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203043}
3044
[email protected]b172aee2012-04-10 17:05:263045void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483046 if (color_chooser_info_ &&
3047 color_chooser_id == color_chooser_info_->identifier)
3048 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203049}
3050
[email protected]b172aee2012-04-10 17:05:263051void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323052 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483053 if (color_chooser_info_ &&
3054 color_chooser_id == color_chooser_info_->identifier)
3055 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203056}
3057
[email protected]d0759f492012-04-19 22:50:503058// This exists for render views that don't have a WebUI, but do have WebUI
3059// bindings enabled.
3060void WebContentsImpl::OnWebUISend(const GURL& source_url,
3061 const std::string& name,
3062 const base::ListValue& args) {
3063 if (delegate_)
3064 delegate_->WebUISend(this, source_url, name, args);
3065}
3066
thestigc4cac8f2014-09-04 21:17:503067#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:423068void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3069 const base::FilePath& path,
3070 bool is_hung) {
3071 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3072
3073 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3074 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3075}
3076
3077void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3078 base::ProcessId plugin_pid) {
3079 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3080 PluginCrashed(plugin_path, plugin_pid));
3081}
3082
[email protected]d8415ad92012-08-23 14:40:503083void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443084 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503085 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343086 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163087 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443088 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163089 return;
[email protected]d8415ad92012-08-23 14:40:503090 }
3091
[email protected]8c8fc292012-11-23 18:57:163092 if (!delegate_->RequestPpapiBrokerPermission(
3093 this, url, plugin_path,
3094 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443095 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163096 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443097 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163098 }
[email protected]d8415ad92012-08-23 14:40:503099}
3100
[email protected]ea0309c2013-08-06 19:35:443101void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503102 bool result) {
[email protected]ea0309c2013-08-06 19:35:443103 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503104}
3105
[email protected]c4538072013-03-18 02:17:553106void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:373107 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:083108 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:553109 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:393110 // For more info, see comment above classes BrowserPluginEmbedder and
3111 // BrowserPluginGuest.
3112 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:143113 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:083114 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:373115}
tommyclie6633ca72014-10-31 00:40:423116#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373117
[email protected]41225fe2013-03-29 05:32:023118void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393119 int id,
[email protected]749fadd2013-05-15 08:37:483120 int http_status_code,
[email protected]795c28972012-12-06 06:13:393121 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303122 const std::vector<SkBitmap>& bitmaps,
3123 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133124 if (bitmaps.size() != original_bitmap_sizes.size())
3125 return;
3126
[email protected]41225fe2013-03-29 05:32:023127 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3128 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393129 // Currently WebContents notifies us of ANY downloads so that it is
3130 // possible to get here.
3131 return;
3132 }
3133 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303134 iter->second.Run(
3135 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393136 }
[email protected]41225fe2013-03-29 05:32:023137 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393138}
3139
3140void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393141 const std::vector<FaviconURL>& candidates) {
3142 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293143 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393144}
3145
dalecurtisbc6572e12014-09-12 19:22:303146void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3147 // ChromeOS has its own way of handling power save blocks for media.
3148#if !defined(OS_CHROMEOS)
3149 DCHECK(!audio_power_save_blocker_);
3150 audio_power_save_blocker_ = PowerSaveBlocker::Create(
3151 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing Audio");
3152#endif
3153}
3154
3155void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3156 // ChromeOS has its own way of handling power save blocks for media.
3157#if !defined(OS_CHROMEOS)
3158 DCHECK(!video_power_save_blocker_);
3159 DCHECK(!active_video_players_.empty());
3160 video_power_save_blocker_ = PowerSaveBlocker::Create(
3161 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing Video");
3162#if defined(OS_ANDROID)
3163 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3164 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3165#endif
3166#endif
3167}
3168
3169void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3170 // If there are no more audio players and we don't have audio stream
3171 // monitoring, release the audio power save blocker here instead of during
3172 // NotifyNavigationStateChanged().
3173 if (active_audio_players_.empty() &&
3174 !AudioStreamMonitor::monitoring_available()) {
3175 audio_power_save_blocker_.reset();
3176 }
3177
3178 // If there are no more video players, clear the video power save blocker.
3179 if (active_video_players_.empty())
3180 video_power_save_blocker_.reset();
3181}
3182
[email protected]1dd0bb752014-02-01 01:16:263183void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3184 bool has_video,
avayvod68017be2014-10-10 18:02:433185 bool has_audio,
3186 bool is_remote) {
3187 // Ignore the videos playing remotely and don't hold the wake lock for the
3188 // screen.
3189 if (is_remote) return;
3190
dalecurtisbc6572e12014-09-12 19:22:303191 if (has_audio) {
3192 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3193
3194 // If we don't have audio stream monitoring, allocate the audio power save
3195 // blocker here instead of during NotifyNavigationStateChanged().
3196 if (!audio_power_save_blocker_ &&
3197 !AudioStreamMonitor::monitoring_available()) {
3198 CreateAudioPowerSaveBlocker();
3199 }
[email protected]1dd0bb752014-02-01 01:16:263200 }
loislo0381a742014-09-11 10:58:113201
dalecurtisbc6572e12014-09-12 19:22:303202 if (has_video) {
3203 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3204
3205 // If we're not hidden and have just created a player, create a blocker.
3206 if (!video_power_save_blocker_ && !IsHidden())
3207 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113208 }
[email protected]1dd0bb752014-02-01 01:16:263209}
3210
3211void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303212 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3213 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3214 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063215}
3216
[email protected]50279492014-05-05 23:24:293217void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153218 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293219 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153220}
[email protected]d9030b82013-07-19 08:26:063221
[email protected]e67ebf32013-02-13 11:07:193222void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073223 if (delegate_)
3224 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193225}
3226
[email protected]17e286e2013-03-01 23:29:393227void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3228 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3229 BeforeFormRepostWarningShow());
3230}
3231
[email protected]ec6c05f2013-10-23 18:41:573232void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3233 Activate();
3234 if (delegate_)
3235 delegate_->ShowRepostFormWarningDialog(this);
3236}
3237
[email protected]b4c84012014-04-28 19:51:103238bool WebContentsImpl::HasAccessedInitialDocument() {
3239 return has_accessed_initial_document_;
3240}
3241
[email protected]96d185d2009-04-24 03:28:543242// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593243// loading, or done loading.
3244void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3245 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093246 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263247 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543248 if (is_loading == is_loading_)
3249 return;
3250
3251 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263252 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3253 base::string16());
[email protected]96d185d2009-04-24 03:28:543254 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563255 upload_size_ = 0;
3256 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543257 }
3258
[email protected]fa944cb82013-11-15 17:51:213259 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543260
3261 is_loading_ = is_loading;
3262 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033263 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543264
[email protected]6ebdc9b2010-09-27 16:55:573265 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093266 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213267 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543268
[email protected]eab61442013-11-14 18:35:483269 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593270 if (is_loading) {
naskob8744d22014-08-28 17:07:433271 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3272 this, "URL", url);
[email protected]91621872013-10-08 04:04:593273 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3274 DidStartLoading(render_view_host));
3275 } else {
naskob8744d22014-08-28 17:07:433276 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3277 this, "URL", url);
[email protected]91621872013-10-08 04:04:593278 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3279 DidStopLoading(render_view_host));
3280 }
[email protected]66798902013-10-01 18:40:163281
3282 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213283 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3284 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543285 if (details)
[email protected]8ff00d72012-10-23 19:12:213286 det = Details<LoadNotificationDetails>(details);
3287 NotificationService::current()->Notify(
3288 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543289}
3290
christiankaeed9862014-11-05 10:49:143291void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
3292 RenderFrameHost* focused_frame = GetFocusedFrame();
3293 if (!focused_frame)
3294 return;
3295
3296 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
3297 focused_frame->GetRoutingID(), extent));
3298}
3299
3300void WebContentsImpl::SelectRange(const gfx::Point& base,
3301 const gfx::Point& extent) {
[email protected]959be4c2014-04-08 15:01:333302 RenderFrameHost* focused_frame = GetFocusedFrame();
3303 if (!focused_frame)
3304 return;
3305
3306 focused_frame->Send(
christiankaeed9862014-11-05 10:49:143307 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
[email protected]959be4c2014-04-08 15:01:333308}
3309
[email protected]b172aee2012-04-10 17:05:263310void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463311 // If we are creating a RVH for a restored controller, then we need to make
3312 // sure the RenderView starts with a next_page_id_ larger than the number
3313 // of restored entries. This must be called before the RenderView starts
3314 // navigating (to avoid a race between the browser updating max_page_id and
3315 // the renderer updating next_page_id_). Because of this, we only call this
3316 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563317 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583318 if (max_restored_page_id >
3319 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3320 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3321 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323322}
3323
[email protected]b172aee2012-04-10 17:05:263324bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263325 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323326 // For file URLs without a title, use the pathname instead. In the case of a
3327 // synthesized title, we don't want the update to count toward the "one set
3328 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263329 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323330 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513331 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243332 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323333 explicit_set = false; // Don't count synthetic titles toward the set limit.
3334 } else {
[email protected]8af69c6c2014-03-03 19:05:313335 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323336 explicit_set = true;
3337 }
3338
[email protected]987fc3a2011-05-26 14:18:093339 // If a page is created via window.open and never navigated,
3340 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553341 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093342 if (entry) {
[email protected]36fc0392011-12-25 03:59:513343 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093344 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323345
[email protected]36fc0392011-12-25 03:59:513346 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093347 } else {
3348 if (page_title_when_no_navigation_entry_ == final_title)
3349 return false; // Nothing changed, don't bother.
3350
3351 page_title_when_no_navigation_entry_ = final_title;
3352 }
[email protected]420ae012009-04-24 05:16:323353
[email protected]420ae012009-04-24 05:16:323354 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233355 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323356
[email protected]66798902013-10-01 18:40:163357 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533358 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163359
3360 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213361 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463362 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213363 NotificationService::current()->Notify(
3364 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3365 Source<WebContents>(this),
3366 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043367
[email protected]420ae012009-04-24 05:16:323368 return true;
3369}
3370
[email protected]960b0372014-05-19 18:01:003371void WebContentsImpl::SendLoadProgressChanged() {
3372 loading_last_progress_update_ = base::TimeTicks::Now();
3373 double progress = 0.0;
3374 int frame_count = 0;
3375
3376 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3377 it != loading_progresses_.end();
3378 ++it) {
3379 progress += it->second;
3380 ++frame_count;
3381 }
3382 if (frame_count == 0)
3383 return;
3384 progress /= frame_count;
3385 DCHECK(progress <= 1.0);
3386
3387 if (progress <= loading_total_progress_)
3388 return;
3389 loading_total_progress_ = progress;
3390
3391 if (delegate_)
3392 delegate_->LoadProgressChanged(this, progress);
3393}
3394
3395void WebContentsImpl::ResetLoadProgressState() {
3396 loading_progresses_.clear();
3397 loading_total_progress_ = 0.0;
3398 loading_weak_factory_.InvalidateWeakPtrs();
3399 loading_last_progress_update_ = base::TimeTicks();
3400}
3401
[email protected]02d7b6e2014-06-24 21:01:503402void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3403 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323404 // After sending out a swap notification, we need to send a disconnect
3405 // notification so that clients that pick up a pointer to |this| can NULL the
3406 // pointer. See Bug 1230284.
3407 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113408 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283409 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113410
3411 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283412 std::pair<RenderViewHost*, RenderViewHost*> details =
3413 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213414 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283415 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213416 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283417 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393418
3419 // Ensure that the associated embedder gets cleared after a RenderViewHost
3420 // gets swapped, so we don't reuse the same embedder next time a
3421 // RenderViewHost is attached to this WebContents.
3422 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323423}
3424
[email protected]02d7b6e2014-06-24 21:01:503425void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3426 RenderFrameHost* new_host) {
3427 FOR_EACH_OBSERVER(WebContentsObserver,
3428 observers_,
3429 RenderFrameHostChanged(old_host, new_host));
3430}
3431
[email protected]da7a7182013-09-06 08:11:113432// TODO(avi): Remove this entire function because this notification is already
3433// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263434void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323435 if (!notify_disconnection_)
3436 return;
3437
3438 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213439 NotificationService::current()->Notify(
3440 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3441 Source<WebContents>(this),
3442 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323443}
3444
[email protected]cbb1ef592013-06-05 19:49:463445void WebContentsImpl::NotifyNavigationEntryCommitted(
3446 const LoadCommittedDetails& load_details) {
3447 FOR_EACH_OBSERVER(
3448 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3449}
3450
[email protected]f114fa42013-12-06 17:06:443451bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3452 const IPC::Message& message) {
3453 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313454}
3455
[email protected]c31a84802014-04-03 15:55:493456const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3457 return GetLastCommittedURL();
3458}
3459
[email protected]b849847b2013-12-10 21:57:583460void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3461 // Note this is only for subframes, the notification for the main frame
3462 // happens in RenderViewCreated.
3463 FOR_EACH_OBSERVER(WebContentsObserver,
3464 observers_,
3465 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303466 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583467}
3468
3469void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193470 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583471 FOR_EACH_OBSERVER(WebContentsObserver,
3472 observers_,
3473 RenderFrameDeleted(render_frame_host));
3474}
3475
[email protected]a09d53ce2014-01-31 00:46:423476void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303477 if (delegate_)
3478 delegate_->WorkerCrashed(this);
3479}
3480
[email protected]a09d53ce2014-01-31 00:46:423481void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3482 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103483 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423484 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103485 if (GetBrowserPluginGuest()) {
3486 WebContentsViewGuest* view_guest =
3487 static_cast<WebContentsViewGuest*>(GetView());
3488 context_menu_params = view_guest->ConvertContextMenuParams(params);
3489 }
3490 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423491 return;
3492
[email protected]077e704b2014-05-23 19:24:103493 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3494 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423495}
3496
[email protected]87de04b02014-04-08 22:14:493497void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013498 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493499 const base::string16& message,
3500 const base::string16& default_prompt,
3501 const GURL& frame_url,
3502 JavaScriptMessageType javascript_message_type,
3503 IPC::Message* reply_msg) {
3504 // Suppress JavaScript dialogs when requested. Also suppress messages when
3505 // showing an interstitial as it's shown over the previous page and we don't
3506 // want the hidden page's dialogs to interfere with the interstitial.
3507 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223508 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503509 ShowingInterstitialPage() || !delegate_ ||
3510 delegate_->ShouldSuppressDialogs(this) ||
3511 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493512
3513 if (!suppress_this_message) {
3514 std::string accept_lang = GetContentClient()->browser()->
3515 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503516 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493517 dialog_manager_->RunJavaScriptDialog(
3518 this,
3519 frame_url.GetOrigin(),
3520 accept_lang,
3521 javascript_message_type,
3522 message,
3523 default_prompt,
3524 base::Bind(&WebContentsImpl::OnDialogClosed,
3525 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013526 render_frame_host->GetProcess()->GetID(),
3527 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493528 reply_msg,
3529 false),
3530 &suppress_this_message);
3531 }
3532
3533 if (suppress_this_message) {
3534 // If we are suppressing messages, just reply as if the user immediately
3535 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013536 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3537 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283538 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493539 }
3540
3541 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3542 // http://crbug.com/288961 ). The only safe thing to do here is return.
3543}
3544
3545void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013546 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493547 const base::string16& message,
3548 bool is_reload,
3549 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013550 RenderFrameHostImpl* rfhi =
3551 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493552 if (delegate_)
3553 delegate_->WillRunBeforeUnloadConfirm();
3554
3555 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503556 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT || !delegate_ ||
3557 delegate_->ShouldSuppressDialogs(this) ||
3558 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493559 if (suppress_this_message) {
3560 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3561 return;
3562 }
3563
3564 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503565 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493566 dialog_manager_->RunBeforeUnloadDialog(
3567 this, message, is_reload,
3568 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013569 render_frame_host->GetProcess()->GetID(),
3570 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283571 false));
[email protected]87de04b02014-04-08 22:14:493572}
3573
[email protected]a86c0e962013-12-17 17:10:393574WebContents* WebContentsImpl::GetAsWebContents() {
3575 return this;
3576}
3577
[email protected]7912e822014-04-16 02:37:033578bool WebContentsImpl::IsNeverVisible() {
3579 if (!delegate_)
3580 return false;
3581 return delegate_->IsNeverVisible(this);
3582}
3583
[email protected]95640212014-07-26 18:14:303584#if defined(OS_WIN)
3585gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3586 return accessible_parent_;
3587}
3588#endif
3589
[email protected]5a3bdf52012-05-24 15:12:573590RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3591 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323592}
3593
[email protected]8ff00d72012-10-23 19:12:213594RendererPreferences WebContentsImpl::GetRendererPrefs(
3595 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463596 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513597}
3598
[email protected]b172aee2012-04-10 17:05:263599gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173600 if (delegate_)
3601 return delegate_->GetRootWindowResizerRect();
3602 return gfx::Rect();
3603}
3604
[email protected]7a846df2012-09-20 19:17:393605void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273606 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393607 browser_plugin_embedder_.reset();
3608}
3609
[email protected]b172aee2012-04-10 17:05:263610void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443611 // Don't send notifications if we are just creating a swapped-out RVH for
3612 // the opener chain. These won't be used for view-source or WebUI, so it's
3613 // ok to return early.
creiscce56cd2014-09-29 22:45:223614 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443615 return;
3616
[email protected]86f98a22013-03-20 14:35:003617 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313618 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083619
[email protected]8ff00d72012-10-23 19:12:213620 NotificationService::current()->Notify(
3621 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3622 Source<WebContents>(this),
3623 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323624
3625 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353626 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213627 if (GetRenderManager()->pending_web_ui())
3628 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323629
[email protected]6286a372013-10-09 04:03:273630 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333631 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323632 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183633 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583634 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323635 }
[email protected]0666aef2009-05-13 19:48:083636
[email protected]60780f412013-02-25 16:34:103637 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263638
3639 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253640 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583641
3642 // We tell the observers now instead of when the main RenderFrameHostImpl is
3643 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3644 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363645 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583646 FOR_EACH_OBSERVER(
3647 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303648 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
dgozman24bfc912014-09-29 11:04:183649
3650 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:323651}
3652
[email protected]b172aee2012-04-10 17:05:263653void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523654 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323655 // Don't notify the world, since this came from a renderer in the
3656 // background.
3657 return;
3658 }
3659
[email protected]da7a7182013-09-06 08:11:113660 notify_disconnection_ = true;
3661 // TODO(avi): Remove. http://crbug.com/170921
3662 NotificationService::current()->Notify(
3663 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3664 Source<WebContents>(this),
3665 NotificationService::NoDetails());
3666
[email protected]be1f56ab2011-12-22 06:55:313667 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233668 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303669
3670 // Restore the focus to the tab (otherwise the focus will be on the top
3671 // window).
[email protected]484ae5912010-09-29 19:16:143672 if (was_crashed && !FocusLocationBarByDefault() &&
3673 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063674 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143675 }
[email protected]32ded2212011-11-10 18:51:433676
[email protected]d8c660432011-12-22 20:51:253677 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323678}
3679
[email protected]ec6a7eb2013-04-22 17:34:223680void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3681 base::TerminationStatus status,
3682 int error_code) {
[email protected]151a63d2011-12-20 22:32:523683 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323684 // The pending page's RenderViewHost is gone.
3685 return;
3686 }
3687
[email protected]2fcdcc32014-03-05 02:14:073688 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3689 // renderer may not have made a clean exit.
3690 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:533691 ExitFullscreenMode();
[email protected]2fcdcc32014-03-05 02:14:073692
[email protected]698191dc2014-02-25 01:06:133693 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3694 if (dialog_manager_)
3695 dialog_manager_->CancelActiveAndPendingDialogs(this);
3696
[email protected]f738bdcb2014-07-11 20:40:443697 if (delegate_)
3698 delegate_->HideValidationMessage(this);
3699
[email protected]e3b10d12014-03-28 16:06:093700 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323701 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233702 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453703
[email protected]960b0372014-05-19 18:01:003704 // Reset the loading progress. TODO(avi): What does it mean to have a
3705 // "renderer crash" when there is more than one renderer process serving a
3706 // webpage? Once this function is called at a more granular frame level, we
3707 // probably will need to more granularly reset the state here.
3708 ResetLoadProgressState();
3709 loading_frames_in_progress_ = 0;
3710
[email protected]d8c660432011-12-22 20:51:253711 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273712 observers_,
[email protected]58d5cfe2013-07-10 02:40:523713 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323714}
3715
[email protected]b172aee2012-04-10 17:05:263716void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253717 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063718}
3719
[email protected]b172aee2012-04-10 17:05:263720void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3721 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043722 const PageState& page_state) {
creise1d3e5b2014-12-01 18:21:573723 // Ensure that this state update comes from a RenderViewHost that belongs to
3724 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413725 // TODO(nasko): This should go through RenderFrameHost.
3726 // TODO(creis): We can't update state for cross-process subframes until we
3727 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
creise1d3e5b2014-12-01 18:21:573728 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413729 return;
[email protected]420ae012009-04-24 05:16:323730
3731 // We must be prepared to handle state updates for any page, these occur
3732 // when the user is scrolling and entering form data, as well as when we're
3733 // leaving a page, in which case our state may have already been moved to
3734 // the next page. The navigation controller will look up the appropriate
3735 // NavigationEntry and update it when it is notified via the delegate.
3736
3737 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583738 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323739 if (entry_index < 0)
3740 return;
[email protected]10f417c52011-12-28 21:04:233741 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323742
[email protected]691aa2f2013-05-28 22:52:043743 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323744 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043745 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323746 controller_.NotifyEntryChanged(entry, entry_index);
3747}
3748
sky8b00392d2015-01-10 00:30:283749void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
3750 const GURL& url) {
3751 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
3752 // If we're fullscreen only update the url if it's from the fullscreen
3753 // renderer.
3754 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
3755 if (fs && fs->GetRenderWidgetHost() != render_view_host)
3756 return;
3757 }
[email protected]6934a702011-12-20 00:04:513758 if (delegate_)
avi450ce00e2014-09-24 01:58:523759 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323760}
3761
[email protected]b172aee2012-04-10 17:05:263762void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103763#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293764 // The UI may be in an event-tracking loop, such as between the
3765 // mouse-down and mouse-up in text selection or a button click.
3766 // Defer the close until after tracking is complete, so that we
3767 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293768 // TODO(shess): This could get more fine-grained. For instance,
3769 // closing a tab in another window while selecting text in the
3770 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103771 if (view_->IsEventTracking()) {
3772 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293773 return;
3774 }
[email protected]60780f412013-02-25 16:34:103775#endif
[email protected]07707302009-11-06 00:50:293776
[email protected]420ae012009-04-24 05:16:323777 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523778 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513779 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323780}
3781
[email protected]66bbadaf2014-03-28 16:25:543782void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573783 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3784 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573785}
3786
[email protected]6f2ac772014-07-24 22:22:083787void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253788 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173789#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563790 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173791#endif
3792}
3793
3794bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3795#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563796 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173797#else
3798 return false;
3799#endif
3800}
3801
[email protected]b172aee2012-04-10 17:05:263802void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513803 if (delegate_ && delegate_->IsPopupOrPanel(this))
3804 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323805}
3806
[email protected]e3b10d12014-03-28 16:06:093807void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3808 bool to_different_document) {
3809 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3810 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323811}
3812
[email protected]723971b2014-02-12 11:08:253813void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323814 scoped_ptr<LoadNotificationDetails> details;
3815
[email protected]9595fd82013-04-19 21:28:493816 // Use the last committed entry rather than the active one, in case a
3817 // pending entry has been created.
3818 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203819 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493820
[email protected]420ae012009-04-24 05:16:323821 // An entry may not exist for a stop when loading an initial blank page or
3822 // if an iframe injected by script into a blank page finishes loading.
3823 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203824 base::TimeDelta elapsed =
3825 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323826
3827 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513828 entry->GetVirtualURL(),
3829 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323830 elapsed,
3831 &controller_,
3832 controller_.GetCurrentEntryIndex()));
3833 }
3834
[email protected]e3b10d12014-03-28 16:06:093835 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3836 details.get());
[email protected]420ae012009-04-24 05:16:323837}
3838
[email protected]b172aee2012-04-10 17:05:263839void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163840 controller_.DiscardNonCommittedEntries();
3841
3842 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213843 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163844}
3845
[email protected]59167c22013-06-03 18:07:323846void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103847 has_accessed_initial_document_ = true;
3848
[email protected]d1371bf8e2014-04-19 03:26:243849 // We may have left a failed browser-initiated navigation in the address bar
3850 // to let the user edit it and try again. Clear it now that content might
3851 // show up underneath it.
3852 if (!IsLoading() && controller_.GetPendingEntry())
3853 controller_.DiscardPendingEntry();
3854
[email protected]59167c22013-06-03 18:07:323855 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503856 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323857}
3858
[email protected]3f19f1a2014-05-02 05:23:273859void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473860 // No action is necessary if the opener has already been cleared.
3861 if (!opener_)
3862 return;
3863
3864 // Clear our opener so that future cross-process navigations don't have an
3865 // opener assigned.
3866 RemoveDestructionObserver(opener_);
3867 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273868
3869 // Notify all swapped out RenderViewHosts for this tab. This is important
3870 // in case we go back to them, or if another window in those processes tries
3871 // to access window.opener.
creisbbbeb062014-08-25 18:20:313872 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273873}
3874
[email protected]39f2f9252014-05-03 00:54:013875void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293876 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093877 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293878 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093879
3880 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213881 NotificationService::current()->Notify(
3882 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3883 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293884 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083885}
3886
[email protected]ef3adfc2014-05-11 00:04:543887void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3888 int32 page_id,
3889 const base::string16& title,
3890 base::i18n::TextDirection title_direction) {
3891 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3892
3893 // If we have a title, that's a pretty good indication that we've started
3894 // getting useful data.
3895 SetNotWaitingForResponse();
3896
3897 // Try to find the navigation entry, which might not be the current one.
3898 // For example, it might be from a pending RVH for the pending entry.
3899 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3900 rvh->GetSiteInstance(), page_id);
3901
3902 // We can handle title updates when we don't have an entry in
3903 // UpdateTitleForEntry, but only if the update is from the current RVH.
3904 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3905 if (!entry && rvh != GetRenderViewHost())
3906 return;
3907
3908 // TODO(evan): make use of title_direction.
3909 // http://code.google.com/p/chromium/issues/detail?id=27094
3910 if (!UpdateTitleForEntry(entry, title))
3911 return;
3912
3913 // Broadcast notifications when the UI should be updated.
3914 if (entry == controller_.GetEntryAtOffset(0))
3915 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3916}
3917
3918void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3919 const std::string& encoding) {
3920 SetEncoding(encoding);
3921}
3922
[email protected]39f2f9252014-05-03 00:54:013923void WebContentsImpl::DocumentAvailableInMainFrame(
3924 RenderViewHost* render_view_host) {
3925 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3926 DocumentAvailableInMainFrame());
3927}
[email protected]e1c3a552012-05-04 20:51:323928void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3929 // Tell the active RenderViewHost to run unload handlers and close, as long
3930 // as the request came from a RenderViewHost in the same BrowsingInstance.
3931 // In most cases, we receive this from a swapped out RenderViewHost.
3932 // It is possible to receive it from one that has just been swapped in,
3933 // in which case we might as well deliver the message anyway.
3934 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3935 GetRenderViewHost()->ClosePage();
3936}
3937
[email protected]f546640b2012-05-15 00:03:493938void WebContentsImpl::RouteMessageEvent(
3939 RenderViewHost* rvh,
3940 const ViewMsg_PostMessage_Params& params) {
3941 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363942 // came from a RenderViewHost in the same BrowsingInstance or if this
3943 // WebContents is dedicated to a browser plugin guest.
3944 // Note: This check means that an embedder could theoretically receive a
3945 // postMessage from anyone (not just its own guests). However, this is
3946 // probably not a risk for apps since other pages won't have references
3947 // to App windows.
3948 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3949 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493950 return;
3951
3952 ViewMsg_PostMessage_Params new_params(params);
3953
[email protected]0bc7f3542013-10-21 15:05:533954 if (!params.message_port_ids.empty()) {
3955 MessagePortMessageFilter* message_port_message_filter =
3956 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3957 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093958 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3959 params.message_port_ids,
3960 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533961 }
3962
[email protected]f546640b2012-05-15 00:03:493963 // If there is a source_routing_id, translate it to the routing ID for
3964 // the equivalent swapped out RVH in the target process. If we need
3965 // to create a swapped out RVH for the source tab, we create its opener
3966 // chain as well, since those will also be accessible to the target page.
3967 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3968 // Try to look up the WebContents for the source page.
3969 WebContentsImpl* source_contents = NULL;
3970 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3971 rvh->GetProcess()->GetID(), params.source_routing_id);
3972 if (source_rvh) {
3973 source_contents = static_cast<WebContentsImpl*>(
3974 source_rvh->GetDelegate()->GetAsWebContents());
3975 }
3976
3977 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363978 if (GetBrowserPluginGuest()) {
3979 // We create a swapped out RenderView for the embedder in the guest's
3980 // render process but we intentionally do not expose the embedder's
3981 // opener chain to it.
3982 new_params.source_routing_id =
3983 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3984 } else {
3985 new_params.source_routing_id =
3986 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3987 }
[email protected]f546640b2012-05-15 00:03:493988 } else {
3989 // We couldn't find it, so don't pass a source frame.
3990 new_params.source_routing_id = MSG_ROUTING_NONE;
3991 }
3992 }
3993
3994 // In most cases, we receive this from a swapped out RenderViewHost.
3995 // It is possible to receive it from one that has just been swapped in,
3996 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183997 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493998}
3999
[email protected]a796f202012-05-30 14:14:254000bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:264001 const base::string16& message,
[email protected]a796f202012-05-30 14:14:254002 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:264003 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254004 if (!delegate_)
4005 return false;
4006 return delegate_->AddMessageToConsole(this, level, message, line_no,
4007 source_id);
4008}
4009
[email protected]9e797d22014-08-08 21:31:304010WebPreferences WebContentsImpl::ComputeWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:274011 // We want to base the page config off of the actual URL, rather than the
4012 // virtual URL.
4013 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
4014 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:004015 GURL url = controller_.GetActiveEntry()
4016 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:154017
[email protected]9e797d22014-08-08 21:31:304018 return GetRenderManager()->current_host()->ComputeWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:324019}
4020
[email protected]0eba810b2012-10-18 03:19:364021int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214022 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294023 int render_view_routing_id = MSG_ROUTING_NONE;
4024 GetRenderManager()->CreateRenderFrame(
4025 instance, nullptr, MSG_ROUTING_NONE,
4026 CREATE_RF_SWAPPED_OUT | CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4027 CREATE_RF_HIDDEN,
4028 &render_view_routing_id);
4029 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364030}
4031
[email protected]b172aee2012-04-10 17:05:264032void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:274033 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254034 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224035
[email protected]ea114722012-03-12 01:11:254036 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174037 if (rdh) // NULL in unittests.
4038 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254039}
4040
[email protected]b172aee2012-04-10 17:05:264041void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444042 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254043 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444044}
4045
creiscce56cd2014-09-29 22:45:224046void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:154047 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:224048 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:154049 return;
4050
creiscce56cd2014-09-29 22:45:224051 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
4052 RenderFrameHostImpl* rfhi =
4053 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584054
[email protected]e5fc1632011-08-08 07:51:534055 // Ignore renderer unresponsive event if debugger is attached to the tab
4056 // since the event may be a result of the renderer sitting on a breakpoint.
4057 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364058 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534059 return;
4060
clamyafbf7f02015-01-21 20:38:114061 if (rfhi->IsWaitingForBeforeUnloadACK() ||
creiscce56cd2014-09-29 22:45:224062 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324063 // Hang occurred while firing the beforeunload/unload handler.
4064 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:584065 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324066
[email protected]fa944cb82013-11-15 17:51:214067 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324068 return;
4069
4070 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564071 // nothing we can do to recover. If the hang is in the beforeunload handler,
4072 // pretend the beforeunload listeners have all fired and allow the delegate
4073 // to continue closing; the user will not have the option of cancelling the
4074 // close. Otherwise, pretend the unload listeners have all fired and close
4075 // the tab.
4076 bool close = true;
clamyafbf7f02015-01-21 20:38:114077 if (rfhi->IsWaitingForBeforeUnloadACK() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564078 delegate_->BeforeUnloadFired(this, true, &close);
4079 }
4080 if (close)
creiscce56cd2014-09-29 22:45:224081 Close(rvhi);
[email protected]420ae012009-04-24 05:16:324082 return;
4083 }
4084
[email protected]9f76c1e2012-03-05 15:15:584085 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474086 return;
4087
[email protected]6934a702011-12-20 00:04:514088 if (delegate_)
4089 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324090}
4091
[email protected]b172aee2012-04-10 17:05:264092void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:514093 if (delegate_)
4094 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324095}
4096
[email protected]b172aee2012-04-10 17:05:264097void WebContentsImpl::LoadStateChanged(
4098 const GURL& url,
4099 const net::LoadStateWithParam& load_state,
4100 uint64 upload_position,
4101 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:324102 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564103 upload_position_ = upload_position;
4104 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:504105 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:214106 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:304107 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214108 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324109 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464110 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224111 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4112 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464113 }
[email protected]420ae012009-04-24 05:16:324114}
4115
[email protected]b172aee2012-04-10 17:05:264116void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554117 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324118 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124119 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4120 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514121 if (delegate_)
4122 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094123 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324124}
4125
[email protected]58d5cfe2013-07-10 02:40:524126void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544127 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234128 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224129 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544130}
4131
[email protected]b172aee2012-04-10 17:05:264132void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104133 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214134 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264135 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4136 // here during container initialization and normal window size will be set
4137 // later. In case of tab duplication this resizing to 0x0 prevents setting
4138 // normal size later so just ignore it.
4139 if (!size.IsEmpty())
4140 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324141}
4142
[email protected]af905902013-10-01 21:38:514143void WebContentsImpl::CancelModalDialogsForRenderManager() {
4144 // We need to cancel modal dialogs when doing a process swap, since the load
4145 // deferrer would prevent us from swapping out.
4146 if (dialog_manager_)
4147 dialog_manager_->CancelActiveAndPendingDialogs(this);
4148}
4149
[email protected]02d7b6e2014-06-24 21:01:504150void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4151 RenderFrameHost* new_host,
4152 bool is_main_frame) {
4153 if (is_main_frame) {
4154 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4155 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084156
[email protected]02d7b6e2014-06-24 21:01:504157 // Make sure the visible RVH reflects the new delegate's preferences.
4158 if (delegate_)
4159 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394160
[email protected]02d7b6e2014-06-24 21:01:504161 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4162 }
4163
4164 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544165}
4166
[email protected]14392a52012-05-02 20:28:444167int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4168 SiteInstance* instance) {
4169 if (!opener_)
4170 return MSG_ROUTING_NONE;
4171
4172 // Recursively create RenderViews for anything else in the opener chain.
4173 return opener_->CreateOpenerRenderViews(instance);
4174}
4175
4176int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4177 int opener_route_id = MSG_ROUTING_NONE;
4178
4179 // If this tab has an opener, ensure it has a RenderView in the given
4180 // SiteInstance as well.
4181 if (opener_)
4182 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4183
[email protected]45a22ad2013-02-21 03:25:004184 // If any of the renderers (current, pending, or swapped out) for this
4185 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214186 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4187 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374188
[email protected]fa944cb82013-11-15 17:51:214189 if (GetRenderManager()->pending_render_view_host() &&
4190 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4191 instance)
4192 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004193
[email protected]fa944cb82013-11-15 17:51:214194 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374195 instance);
4196 if (rvh)
4197 return rvh->GetRoutingID();
4198
[email protected]14392a52012-05-02 20:28:444199 // Create a swapped out RenderView in the given SiteInstance if none exists,
4200 // setting its opener to the given route_id. Return the new view's route_id.
carlosk37f793792014-11-27 15:08:294201 int render_view_routing_id = MSG_ROUTING_NONE;
4202 GetRenderManager()->CreateRenderFrame(instance, nullptr, opener_route_id,
4203 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4204 CREATE_RF_SWAPPED_OUT |
4205 CREATE_RF_HIDDEN,
4206 &render_view_routing_id);
4207 return render_view_routing_id;
[email protected]14392a52012-05-02 20:28:444208}
4209
[email protected]b172aee2012-04-10 17:05:264210NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194211 return GetController();
[email protected]3a3d47472010-07-15 21:03:544212}
4213
carlosk37f793792014-11-27 15:08:294214scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderManager(
4215 const GURL& url) {
4216 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(url)));
[email protected]420ae012009-04-24 05:16:324217}
4218
[email protected]10f417c52011-12-28 21:04:234219NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264220 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324221 return controller_.GetLastCommittedEntry();
4222}
4223
[email protected]b172aee2012-04-10 17:05:264224bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164225 RenderViewHost* render_view_host,
4226 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044227 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124228 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434229 TRACE_EVENT0("browser,navigation",
4230 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444231 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484232 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164233 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4234 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4235 // case this because RWH is still a base class of RenderViewHost, and child
4236 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124237 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164238 RenderWidgetHostViewChildFrame* rwh_view_child =
4239 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164240 rwh_view = rwh_view_child;
4241 } else {
lazyboy549b3b42014-10-20 17:16:044242 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164243 }
[email protected]1a98a932009-11-17 00:12:524244
[email protected]420ae012009-04-24 05:16:324245 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444246 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214247 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324248
[email protected]74ce1ad2011-12-16 21:51:464249 // Make sure we use the correct starting page_id in the new RenderView.
4250 UpdateMaxPageIDIfNecessary(render_view_host);
4251 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584252 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464253
[email protected]9f76c1e2012-03-05 15:15:584254 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264255 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494256 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044257 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494258 max_page_id,
4259 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524260 return false;
[email protected]14392a52012-05-02 20:28:444261 }
[email protected]a4127722011-04-27 23:13:524262
avi2b177592014-12-10 02:08:024263 SetHistoryOffsetAndLengthForView(render_view_host,
4264 controller_.GetLastCommittedEntryIndex(),
4265 controller_.GetEntryCount());
4266
[email protected]a220b5932013-09-21 03:47:444267#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504268 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4269 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444270 if (rwh_view) {
4271 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4272 render_widget_host->WasResized();
4273 }
[email protected]f8233cc2011-05-31 20:24:504274#endif
4275
[email protected]420ae012009-04-24 05:16:324276 return true;
4277}
4278
[email protected]82307f6b2014-08-07 03:30:124279bool WebContentsImpl::CreateRenderFrameForRenderManager(
4280 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494281 int parent_routing_id,
4282 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434283 TRACE_EVENT0("browser,navigation",
4284 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124285
4286 RenderFrameHostImpl* rfh =
4287 static_cast<RenderFrameHostImpl*>(render_frame_host);
japhete6adf142014-10-31 00:01:494288 if (!rfh->CreateRenderFrame(parent_routing_id, proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124289 return false;
4290
4291 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4292 // RenderFrameHost will have to be associated with the appropriate
4293 // RenderWidgetHostView or a new one should be created here.
4294
4295 return true;
4296}
4297
[email protected]7d244f12013-08-22 21:41:514298#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454299
[email protected]155c7f22013-12-09 17:07:184300base::android::ScopedJavaLocalRef<jobject>
4301WebContentsImpl::GetJavaWebContents() {
4302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564303 return GetWebContentsAndroid()->GetJavaObject();
4304}
[email protected]155c7f22013-12-09 17:07:184305
[email protected]0e813a52014-08-13 10:34:564306WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184307 WebContentsAndroid* web_contents_android =
4308 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4309 if (!web_contents_android) {
4310 web_contents_android = new WebContentsAndroid(this);
4311 SetUserData(kWebContentsAndroidKey, web_contents_android);
4312 }
[email protected]0e813a52014-08-13 10:34:564313 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184314}
4315
[email protected]7d244f12013-08-22 21:41:514316bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4317 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164318 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044319 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594320 true);
[email protected]7d244f12013-08-22 21:41:514321}
[email protected]fc2b46b2014-05-03 16:33:454322
4323#elif defined(OS_MACOSX)
4324
[email protected]75f4df72014-07-16 22:39:424325void WebContentsImpl::SetAllowOtherViews(bool allow) {
4326 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454327}
4328
[email protected]75f4df72014-07-16 22:39:424329bool WebContentsImpl::GetAllowOtherViews() {
4330 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454331}
4332
[email protected]7d244f12013-08-22 21:41:514333#endif
4334
[email protected]6fba26d2014-04-29 09:38:284335void WebContentsImpl::OnDialogClosed(int render_process_id,
4336 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264337 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494338 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264339 bool success,
[email protected]fcf75d42013-12-03 20:11:264340 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284341 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4342 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494343 last_dialog_suppressed_ = dialog_was_suppressed;
4344
[email protected]beb440c2009-11-06 04:08:544345 if (is_showing_before_unload_dialog_ && !success) {
4346 // If a beforeunload dialog is canceled, we need to stop the throbber from
4347 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284348 if (rfh)
4349 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354350 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104351
[email protected]6d65a462013-06-21 21:29:124352 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4353 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544354 }
[email protected]87de04b02014-04-08 22:14:494355
[email protected]beb440c2009-11-06 04:08:544356 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284357 if (rfh) {
4358 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4359 dialog_was_suppressed);
4360 } else {
4361 // Don't leak the sync IPC reply if the RFH or process is gone.
4362 delete reply_msg;
4363 }
[email protected]beb440c2009-11-06 04:08:544364}
4365
[email protected]b172aee2012-04-10 17:05:264366void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544367 if (encoding == last_reported_encoding_)
4368 return;
4369 last_reported_encoding_ = encoding;
4370
4371 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124372 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104373}
[email protected]f45d2a72010-03-08 23:28:354374
[email protected]1ac10dca2013-08-20 20:47:044375bool WebContentsImpl::IsHidden() {
4376 return capturer_count_ == 0 && !should_normally_be_visible_;
4377}
4378
[email protected]b0936d22013-11-28 06:47:364379RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214380 return frame_tree_.root()->render_manager();
4381}
4382
[email protected]b172aee2012-04-10 17:05:264383RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584384 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4385}
[email protected]7900bfdb2012-05-24 19:31:244386
[email protected]f8497342013-02-05 22:15:024387BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394388 return browser_plugin_guest_.get();
4389}
4390
[email protected]738f57a2013-06-29 21:06:544391void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4392 CHECK(!browser_plugin_guest_);
4393 browser_plugin_guest_.reset(guest);
4394}
4395
[email protected]f8497342013-02-05 22:15:024396BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394397 return browser_plugin_embedder_.get();
4398}
[email protected]8ff00d72012-10-23 19:12:214399
[email protected]d9030b82013-07-19 08:26:064400void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194401 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304402 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4403 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4404 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064405}
4406
4407void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304408 active_audio_players_.clear();
4409 active_video_players_.clear();
4410 audio_power_save_blocker_.reset();
4411 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064412}
4413
[email protected]fc2b46b2014-05-03 16:33:454414gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214415 gfx::Size size;
4416 if (delegate_)
4417 size = delegate_->GetSizeForNewRenderView(this);
4418 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454419 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214420 return size;
4421}
4422
[email protected]ae7eeda2014-07-04 01:53:264423void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4424 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024425 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554426}
4427
[email protected]222f5822014-02-05 23:40:494428void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4429 if (!delegate_)
4430 return;
4431 const gfx::Size new_size = GetPreferredSize();
4432 if (new_size != old_size)
4433 delegate_->UpdatePreferredSize(this, new_size);
4434}
4435
dalecurtisbc6572e12014-09-12 19:22:304436void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4437 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114438 if (!HasValidFrameSource())
4439 return;
4440
dalecurtisbc6572e12014-09-12 19:22:304441 const uintptr_t key =
4442 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4443 DCHECK(std::find((*player_map)[key].begin(),
4444 (*player_map)[key].end(),
4445 player_cookie) == (*player_map)[key].end());
4446 (*player_map)[key].push_back(player_cookie);
4447}
4448
4449void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4450 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114451 if (!HasValidFrameSource())
4452 return;
4453
dalecurtisbc6572e12014-09-12 19:22:304454 const uintptr_t key =
4455 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4456 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4457 if (it == player_map->end())
4458 return;
4459
4460 // Remove the player.
4461 PlayerList::iterator player_it =
4462 std::find(it->second.begin(), it->second.end(), player_cookie);
4463 if (player_it != it->second.end())
4464 it->second.erase(player_it);
4465
4466 // If there are no players left, remove the map entry.
4467 if (it->second.empty())
4468 player_map->erase(it);
4469}
4470
4471void WebContentsImpl::RemoveAllMediaPlayerEntries(
4472 RenderFrameHost* render_frame_host,
4473 ActiveMediaPlayerMap* player_map) {
4474 ActiveMediaPlayerMap::iterator it =
4475 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4476 if (it == player_map->end())
4477 return;
4478 player_map->erase(it);
4479}
4480
[email protected]23f41fd2014-06-21 05:29:174481void WebContentsImpl::ResumeResponseDeferredAtStart() {
4482 FrameTreeNode* node = frame_tree_.root();
4483 node->render_manager()->ResumeResponseDeferredAtStart();
4484}
4485
[email protected]34ff1cfc2014-08-20 06:16:054486void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4487 force_disable_overscroll_content_ = force_disable;
4488 if (view_)
4489 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4490}
4491
[email protected]8ff00d72012-10-23 19:12:214492} // namespace content